Java Code Examples for io.flutter.plugin.common.MethodCall#arguments()

The following examples show how to use io.flutter.plugin.common.MethodCall#arguments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void userRegister(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  String username, password;
  RegisterOptionalUserInfo optionalUserInfo = new RegisterOptionalUserInfo();
  try {
    JSONObject params = new JSONObject(map);
    username = params.getString("username");
    password = params.getString("password");

    if (params.has("nickname"))
      optionalUserInfo.setNickname(params.getString("nickname"));
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }
  Log.d("Android","Action - userRegister: username=" + username + ",pw=" + password);

  JMessageClient.register(username, password, optionalUserInfo, new BasicCallback() {
    @Override
    public void gotResult(int status, String desc) {
      handleResult(status, desc, result);
    }
  });
}
 
Example 2
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void login(MethodCall call, final Result result) {

    HashMap<String, Object> map = call.arguments();
    String username, password;

    try {
      JSONObject params = new JSONObject(map);
      username = params.getString("username");
      password = params.getString("password");
    } catch (JSONException e) {
      e.printStackTrace();
      handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
      return;
    }
    Log.d("Android","Action - login: username=" + username + ",pw=" + password);

    JMessageClient.login(username, password, new BasicCallback() {
      @Override
      public void gotResult(int status, String desc) {
        handleResult(status, desc, result);
      }
    });
  }
 
Example 3
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void updateMyPassword(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  String oldPwd, newPwd;
  try {
    JSONObject params = new JSONObject(map);
    oldPwd = params.getString("oldPwd");
    newPwd = params.getString("newPwd");
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  JMessageClient.updateUserPassword(oldPwd, newPwd, new BasicCallback() {
    @Override
    public void gotResult(int status, String desc) {
      handleResult(status, desc, result);
    }
  });
}
 
Example 4
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void updateMyAvatar(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  try {
    JSONObject params = new JSONObject(map);
    if (!params.has("imgPath")) {
      handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
      return;
    }

    String imgPath = params.getString("imgPath");
    File img = new File(imgPath);
    String format = imgPath.substring(imgPath.lastIndexOf(".") + 1);
    JMessageClient.updateUserAvatar(img, format, new BasicCallback() {
      @Override
      public void gotResult(int status, String desc) {
        handleResult(status, desc, result);
      }
    });

  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }
}
 
Example 5
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void getGroupMembers(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  long groupId;

  try {
    JSONObject params = new JSONObject(map);
    groupId = Long.parseLong(params.getString("id"));
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  JMessageClient.getGroupMembers(groupId, new RequestCallback<List<GroupMemberInfo>>() {
    @Override
    public void gotResult(int status, String desc, List<GroupMemberInfo> groupMemberInfos) {
      if (status == 0) {
        handleResult(toJson(groupMemberInfos), status, desc, result);

      } else {
        handleResult(status, desc, result);
      }
    }
  });
}
 
Example 6
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void groupSilenceMembers(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  long groupId;
  try {
    JSONObject params = new JSONObject(map);
    groupId = Long.parseLong(params.getString("groupId"));

  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }
  JMessageClient.getGroupInfo(groupId, new GetGroupInfoCallback() {
    @Override
    public void gotResult(int status, String desc, GroupInfo groupInfo) {
      if (status == 0) {
        List<GroupMemberInfo> groupSilenceMemberInfos = groupInfo.getGroupSilenceMemberInfos();
        handleResult(toJson(groupSilenceMemberInfos), status, desc, result);
      } else {
        handleResult(status, desc, result);
      }
    }
  });
}
 
Example 7
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void setup(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();
  try {
    JSONObject params = new JSONObject(map);

    boolean isOpenMessageRoaming = false;
    if (params.has("isOpenMessageRoaming")) {
      isOpenMessageRoaming = params.getBoolean("isOpenMessageRoaming");
    }

    if (params.has("appkey")) {
      JmessageFlutterPlugin.appKey = params.getString("appkey");
    }
    JMessageClient.init(registrar.context(), isOpenMessageRoaming);
    JMessageClient.registerEventReceiver(this);
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }
}
 
Example 8
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void sendCustomMessage(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();
  try {
    JSONObject params = new JSONObject(map);
    Conversation conversation = JMessageUtils.createConversation(params);
    if (conversation == null) {
      handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, result);
      return;
    }

    JSONObject customObject = params.getJSONObject("customObject");

    MessageSendingOptions options = null;
    if (params.has("messageSendingOptions")) {
      options = toMessageSendingOptions(params.getJSONObject("messageSendingOptions"));
    }

    CustomContent content = new CustomContent();
    content.setAllValues(fromJson(customObject));
    sendMessage(conversation, content, options, result);
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }
}
 
Example 9
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void updateGroupInfo(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  long groupId;
  try {
    JSONObject params = new JSONObject(map);
    groupId = Long.parseLong(params.getString("id"));
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  JMessageClient.getGroupInfo(groupId, new GetGroupInfoCallback() {
    @Override
    public void gotResult(int status, String desc, GroupInfo groupInfo) {
      if (status == 0) {
        handleResult(toJson(groupInfo), status, desc, result);

      } else {
        handleResult(status, desc, result);
      }
    }
  });
}
 
Example 10
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void sendDraftMessage(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();


  MessageSendingOptions messageSendingOptions = null;
  Conversation conversation;

  try {
    JSONObject params = new JSONObject(map);
    conversation = JMessageUtils.createConversation(params);
    final Message message = conversation.getMessage(Integer.parseInt(params.getString("id")));

    if (params.has("messageSendingOptions")) {
      messageSendingOptions = toMessageSendingOptions(params.getJSONObject("messageSendingOptions"));
    }

    message.setOnSendCompleteCallback(new BasicCallback() {
      @Override
      public void gotResult(int status, String desc) {
        if (status == 0) {
          HashMap json = JsonUtils.toJson(message);
          handleResult(json, status, desc, result);
        } else {
          handleResult(status, desc, result);
        }
      }
    });

    if (messageSendingOptions == null) {
      JMessageClient.sendMessage(message);
    } else {
      JMessageClient.sendMessage(message, messageSendingOptions);
    }

  } catch (Exception e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }
}
 
Example 11
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void sendCrossDeviceTransCommand(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  try {
    JSONObject params = new JSONObject(map);
    String message = params.getString("message");
    String type = params.getString("platform");

    PlatformType platformType = PlatformType.all;
    if (type.equals("android")) {
      platformType = PlatformType.android;
    }else if (type.equals("ios")) {
      platformType = PlatformType.ios;
    }else if (type.equals("windows")) {
      platformType = PlatformType.windows;
    }else if (type.equals("web")) {
      platformType = PlatformType.web;
    }else {//all
      platformType = PlatformType.all;
    }

    JMessageClient.sendCrossDeviceTransCommand(platformType, message, new BasicCallback() {
      @Override
      public void gotResult(int status, String desc) {
        handleResult(status, desc, result);
      }
    });

  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }
}
 
Example 12
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void addGroupMembers(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();

  long groupId;
  JSONArray usernameJsonArr;
  String appKey;
  List<String> usernameList = new ArrayList<String>();

  try {
    JSONObject params = new JSONObject(map);

    groupId = Long.parseLong(params.getString("id"));
    appKey = params.has("appKey") ? params.getString("appKey") : JmessageFlutterPlugin.appKey;
    usernameJsonArr = params.getJSONArray("usernameArray");

    for (int i = 0; i < usernameJsonArr.length(); i++) {
      usernameList.add(usernameJsonArr.getString(i));
    }
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  JMessageClient.addGroupMembers(groupId, appKey, usernameList, new BasicCallback() {
    @Override
    public void gotResult(int status, String desc) {
      handleResult(status, desc, result);
    }
  });
}
 
Example 13
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void downloadOriginalImage(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  final Message msg;
  try {
    JSONObject params = new JSONObject(map);
    msg = JMessageUtils.getMessage(params);
    if (msg == null) {
      handleResult(ERR_CODE_MESSAGE, ERR_MSG_MESSAGE, result);
      return;
    }
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  if (msg.getContentType() != ContentType.image) {
    handleResult(ERR_CODE_MESSAGE, "Message type isn't image", result);
    return;
  }

  ImageContent content = (ImageContent) msg.getContent();
  content.downloadOriginImage(msg, new DownloadCompletionCallback() {
    @Override
    public void onComplete(int status, String desc, File file) {
      if (status == 0) {
        HashMap res= new HashMap();
        res.put("messageId", msg.getId());
        res.put("filePath", file.getAbsolutePath());
        handleResult(res, status, desc, result);

      } else {
        handleResult(status, desc, result);
      }
    }
  });
}
 
Example 14
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void isGroupBlocked(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  long groupId;
  try {
    JSONObject params = new JSONObject(map);
    groupId = Long.parseLong(params.getString("id"));
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  JMessageClient.getGroupInfo(groupId, new GetGroupInfoCallback() {
    @Override
    public void gotResult(int status, String desc, GroupInfo groupInfo) {
      if (status != 0) {
        handleResult(status, desc, result);
        return;
      }

      boolean isBlocked = (groupInfo.isGroupBlocked() == 1);
      HashMap res= new HashMap();
      res.put("isBlocked", isBlocked);
      handleResult(res, status, desc, result);
    }
  });
}
 
Example 15
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void getMessageUnreceiptCount(MethodCall call, final Result result) {
  Log.d(TAG,"getMessageUnreceiptCount:" + call.arguments);

  HashMap<String, Object> map = call.arguments();

  Conversation conversation;
  String messageId;
  try {
    JSONObject params = new JSONObject(map);

    conversation = JMessageUtils.getConversation(params);
    if (conversation == null) {
      handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, result);
      return;
    }

    messageId = params.getString("id");
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  Message msg = conversation.getMessage(Integer.parseInt(messageId));
  int count = 0;
  if (msg != null) {
      count = msg.getUnreceiptCnt();
  }else {
      Log.d(TAG,"this message was not found.");
  }
  result.success(count);
}
 
Example 16
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void sendTextMessage(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();
  String text;
  Map<String, String> extras = null;
  MessageSendingOptions messageSendingOptions = null;
  Conversation conversation;

  try {
    JSONObject params = new JSONObject(map);
    conversation = JMessageUtils.createConversation(params);
    if (conversation == null) {
      handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, result);
      return;
    }

    text = params.getString("text");

    if (params.has("extras")) {
      extras = fromJson(params.getJSONObject("extras"));
    }

    if (params.has("messageSendingOptions")) {
      messageSendingOptions = toMessageSendingOptions(params.getJSONObject("messageSendingOptions"));
    }
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  TextContent content = new TextContent(text);
  if (extras != null) {
    content.setExtras(extras);
  }

  sendMessage(conversation, content, messageSendingOptions, result);
}
 
Example 17
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void downloadThumbGroupAvatar(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();
  String id;
  try {
    JSONObject params = new JSONObject(map);
    id = params.getString("id");
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  JMessageClient.getGroupInfo(Long.parseLong(id), new GetGroupInfoCallback() {
    @Override
    public void gotResult(int status, String desc, GroupInfo groupInfo) {
      if (status == 0) {
        File avatarFile = groupInfo.getAvatarFile();
        HashMap res= new HashMap();
        res.put("id", groupInfo.getGroupID()+"");
        String avatarFilePath = (avatarFile == null ? "" : avatarFile.getAbsolutePath());
        res.put("filePath", avatarFilePath);
        result.success(res);
      } else {
        handleResult(status, desc, result);
      }
    }
  });
}
 
Example 18
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void getMessageById(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();

  Conversation conversation;
  String messageId;
  try {
    JSONObject params = new JSONObject(map);
    conversation = JMessageUtils.getConversation(params);

    if (conversation == null) {
      handleResult(ERR_CODE_CONVERSATION, "Can't get conversation", result);
      return;
    }

    messageId = params.getString("messageId");
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  Message msg = conversation.getMessage(Integer.parseInt(messageId));

  if (msg == null) {
    result.success(null);
  } else {
    result.success(toJson(msg));
  }
}
 
Example 19
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void deleteMessageById(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();
  Conversation conversation;
  String messageId;

  try {
    JSONObject params = new JSONObject(map);

    conversation = JMessageUtils.getConversation(params);

    if (conversation == null) {
      handleResult(ERR_CODE_CONVERSATION, "Can't get conversation", result);
      return;
    }

    messageId = params.getString("messageId");
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  boolean success = conversation.deleteMessage(Integer.parseInt(messageId));

  if (success) {
    result.success(null);
  } else {
    HashMap error = new HashMap();
    error.put("code", ERR_CODE_MESSAGE);
    error.put("description", ERR_MSG_MESSAGE);
    result.error(ERR_CODE_MESSAGE + "", ERR_MSG_MESSAGE, "");
  }
}
 
Example 20
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 4 votes vote down vote up
private void sendLocationMessage(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();

  double latitude, longitude;
  int scale;
  String address;
  Map<String, String> extras = null;
  MessageSendingOptions options = null;
  Conversation conversation;

  try {
    JSONObject params = new JSONObject(map);

    conversation = JMessageUtils.createConversation(params);
    if (conversation == null) {
      handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, result);
      return;
    }

    latitude = params.getDouble("latitude");
    longitude = params.getDouble("longitude");
    scale = params.getInt("scale");
    address = params.getString("address");

    if (params.has("extras")) {
      extras = fromJson(params.getJSONObject("extras"));
    }

    if (params.has("messageSendingOptions")) {
      options = toMessageSendingOptions(params.getJSONObject("messageSendingOptions"));
    }
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  LocationContent content = new LocationContent(latitude, longitude, scale, address);
  if (extras != null) {
    content.setExtras(extras);
  }

  sendMessage(conversation, content, options, result);
}