@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.child_layout); init(); setSupportActionBar(toolbar); JMessageClient.registerEventReceiver(this); JMessageClient.setNotificationMode(JMessageClient.NOTI_MODE_NO_NOTIFICATION); listener = new LocationListener(); toolbar.setSubtitle("孩子"); toolbar.setNavigationIcon(R.mipmap.ic_keyboard_backspace_white_24dp); toolbar.setNavigationOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); location.setText("软件已开启,请按home键退出"); client = new LocationClient(this); client.registerLocationListener(listener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开gps option.setCoorType("bd09ll"); // 设置坐标类型 client.setLocOption(option); client.start(); }
public void sendSingleTextMessage(JSONArray data, CallbackContext callbackContext) { Log.i(TAG, " sendSingleTextMessage \n" + data); final CallbackContext cb = callbackContext; try { String username = data.getString(0); String text = data.getString(1); Conversation conversation = JMessageClient.getSingleConversation(username); if (conversation == null) { conversation = Conversation.createSingleConversation(username); } if (conversation == null) { callbackContext.error("无法创建对话"); return; } TextContent content = new TextContent(text); final Message msg = conversation.createSendMessage(content); JMessageClient.sendMessage(msg); callbackContext.success("正在发送"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("error reading id json"); } }
/** * 鍦ㄤ細璇濆垪琛ㄤ腑鎺ユ敹娑堟伅 * * @param event */ public void onEventMainThread(MessageEvent event) { Log.i(TAG, "onEventMainThread MessageEvent execute"); Message msg = event.getMessage(); String targetID = msg.getTargetID(); ConversationType convType = msg.getTargetType(); Conversation conv; if (convType == ConversationType.group) { conv = JMessageClient.getGroupConversation(Integer.parseInt(targetID)); } else { conv = JMessageClient.getSingleConversation(targetID); } if (conv != null && convType == ConversationType.single) { // 濡傛灉缂撳瓨浜嗗ご鍍忥紝鐩存帴鍒锋柊浼氳瘽鍒楄〃 if (NativeImageLoader.getInstance().getBitmapFromMemCache(targetID) != null) { Log.i("Test", "conversation "); mConvListController.refreshConvList(); // 娌℃湁澶村儚锛屼粠Conversation鎷� } else { File file = conv.getAvatarFile(); // 鎷垮埌鍚庣紦瀛樺苟鍒锋柊 if (file != null) { mConvListController.loadAvatarAndRefresh(targetID, file.getAbsolutePath()); // conversation涓病鏈夊ご鍍忥紝鐩存帴鍒锋柊锛孲DK浼氬湪鍚庡彴鑾峰緱澶村儚锛屾嬁鍒板悗浼氭墽琛宱nEvent(ConversationRefreshEvent // conversationRefreshEvent) } else mConvListController.refreshConvList(); } } else { mConvListController.refreshConvList(); } }
protected void pluginInitialize() { Log.i(TAG, "pluginInitialize"); JMessageClient.init(cordova.getActivity().getApplicationContext()); JMessageClient.registerEventReceiver(this); JPushInterface.init(this.cordova.getActivity().getApplicationContext()); }
/** * 初始化用户头像缓存 * * @param userIDList 用户ID List * @param length 头像宽高 * @param callBack 缓存回调 */ public void setAvatarCache( final List<String> userIDList, final int length, final cacheAvatarCallBack callBack) { final Handler handler = new Handler() { @Override public void handleMessage(android.os.Message msg) { super.handleMessage(msg); if (msg.getData() != null) { callBack.onCacheAvatarCallBack(msg.getData().getInt("status", -1)); } } }; for (final String userID : userIDList) { // 若为CurrentUser,直接获取本地的头像(CurrentUser本地头像为最新) if (userID.equals(JMessageClient.getMyInfo().getUserName())) { File file = JMessageClient.getMyInfo().getAvatar(); if (file == null || !file.exists()) { continue; } else { Bitmap bitmap = BitmapLoader.getBitmapFromFile(file.getAbsolutePath(), length, length); if (null != bitmap) { mMemoryCache.put(userID, bitmap); } continue; } } else if (mMemoryCache.get(userID) != null) { continue; } else { JMessageClient.getUserInfo( userID, new GetUserInfoCallback(false) { @Override public void gotResult(int i, String s, UserInfo userInfo) { if (i == 0) { File file = userInfo.getAvatar(); if (file != null) { Bitmap bitmap = BitmapLoader.getBitmapFromFile(file.getAbsolutePath(), length, length); addBitmapToMemoryCache(userID, bitmap); } else { // Bitmap bitmap = // BitmapLoader.getBitmapFromFile(getR.drawable.head_icon, length, length); } android.os.Message msg = handler.obtainMessage(); Bundle bundle = new Bundle(); bundle.putInt("status", 0); msg.setData(bundle); msg.sendToTarget(); } } }); } } }
public ChatListAdapter(Context context, String targetID) { this.context = context; this.mActivity = (Activity) context; this.mTargetID = targetID; this.mConv = JMessageClient.getSingleConversation(mTargetID); this.mMsgList = mConv.getMessagesFromNewest(0, mOffset); reverse(mMsgList); mStart = mOffset; List<String> userIDList = new ArrayList<>(); userIDList.add(targetID); userIDList.add(JMessageClient.getMyInfo().getUserName()); }
@Override public void onResume() { // 褰撳墠鐢ㄦ埛淇℃伅涓虹┖锛岄渶瑕侀噸鏂扮櫥褰� if (null == JMessageClient.getMyInfo() || TextUtils.isEmpty(JMessageClient.getMyInfo().getUserName())) { // Intent intent = new Intent(); // intent.setClass(this.getActivity(), LoginActivity.class); // startActivity(intent); // getActivity().finish(); } else { dismissPopWindow(); mConvListController.refreshConvList(); } super.onResume(); }
@Override protected void onDestroy() { super.onDestroy(); JMessageClient.unRegisterEventReceiver(this); client.stop(); }
/** * setAvatarCache的重载函数 * * @param userName * @param length * @param callBack */ public void setAvatarCache( final String userName, final int length, final cacheAvatarCallBack callBack) { final Handler handler = new Handler() { @Override public void handleMessage(android.os.Message msg) { super.handleMessage(msg); if (msg.getData() != null) { callBack.onCacheAvatarCallBack(msg.getData().getInt("status", -1)); } } }; JMessageClient.getUserInfo( userName, new GetUserInfoCallback(false) { @Override public void gotResult(int status, String desc, UserInfo userInfo) { if (status == 0) { File file = userInfo.getAvatar(); if (file != null) { Bitmap bitmap = BitmapLoader.getBitmapFromFile(file.getAbsolutePath(), length, length); addBitmapToMemoryCache(userName, bitmap); } android.os.Message msg = handler.obtainMessage(); Bundle bundle = new Bundle(); bundle.putInt("status", 0); msg.setData(bundle); msg.sendToTarget(); } } }); }
private void handleGroupChangeMsg(Message msg, ViewHolder holder, TextView msgTime) { UserInfo myInfo = JMessageClient.getMyInfo(); GroupInfo groupInfo = (GroupInfo) msg.getTargetInfo(); String content = ((EventNotificationContent) msg.getContent()).getEventText(); EventNotificationContent.EventNotificationType type = ((EventNotificationContent) msg.getContent()).getEventNotificationType(); switch (type) { case group_member_added: holder.groupChange.setText(content); holder.groupChange.setVisibility(View.VISIBLE); break; case group_member_exit: holder.groupChange.setVisibility(View.GONE); msgTime.setVisibility(View.GONE); break; case group_member_removed: List<String> userNames = ((EventNotificationContent) msg.getContent()).getUserNames(); // 被删除的人显示EventNotification if (userNames.contains(myInfo.getNickname()) || userNames.contains(myInfo.getUserName())) { holder.groupChange.setText(content); holder.groupChange.setVisibility(View.VISIBLE); // 群主亦显示 } else if (myInfo.getUserName().equals(groupInfo.getGroupOwner())) { holder.groupChange.setText(content); holder.groupChange.setVisibility(View.VISIBLE); } else { holder.groupChange.setVisibility(View.GONE); msgTime.setVisibility(View.GONE); } break; } }
public void initModule() { UserInfo userInfo = JMessageClient.getMyInfo(); mTitleBarTitle = (TextView) findViewById(R.id.title_bar_title); mTitleBarTitle.setText(mContext.getString(R.string.actionbar_me)); mScrollView = (PullScrollView) findViewById(R.id.scroll_view); mContentLl = (LinearLayout) findViewById(R.id.content_list_ll); mAvatarIv = (ImageView) findViewById(R.id.my_avatar_iv); mTakePhotoBtn = (ImageButton) findViewById(R.id.take_photo_iv); mUserInfoRl = (RelativeLayout) findViewById(R.id.user_info_rl); mUserNameTv = (TextView) findViewById(R.id.user_name_tv); mSettingRl = (RelativeLayout) findViewById(R.id.setting_rl); mLogoutRl = (RelativeLayout) findViewById(R.id.logout_rl); mScrollView.setHeader(mAvatarIv); if (userInfo != null) { mUserNameTv.setText(userInfo.getUserName()); File file = userInfo.getAvatar(); if (file != null && file.isFile()) { Log.i("MeView", "file.getAbsolutePath() " + file.getAbsolutePath()); DisplayMetrics dm = new DisplayMetrics(); ((Activity) mContext).getWindowManager().getDefaultDisplay().getMetrics(dm); double density = dm.density; Bitmap bitmap = BitmapLoader.getBitmapFromFile( file.getAbsolutePath(), dm.widthPixels, (int) (density * 300)); mAvatarIv.setImageBitmap(bitmap); } else mAvatarIv.setImageResource(R.drawable.friends_sends_pictures_no); } }
@Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); JMessageClient.registerEventReceiver(this); LayoutInflater layoutInflater = getActivity().getLayoutInflater(); mRootView = layoutInflater.inflate( R.layout.fragment_conv_list, (ViewGroup) getActivity().findViewById(R.id.main_view), false); mConvListView = new ConversationListView(mRootView, this.getActivity()); mConvListView.initModule(); mMenuView = getActivity().getLayoutInflater().inflate(R.layout.drop_down_menu, null); mConvListController = new ConversationListController(mConvListView, this); mConvListView.setListener(mConvListController); mConvListView.setItemListeners(mConvListController); mConvListView.setLongClickListener(mConvListController); mMenuPopWindow = new PopupWindow( mMenuView, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true); mMenuItemView = new MenuItemView(mMenuView); mMenuItemView.initModule(); mMenuController = new MenuItemController(mMenuItemView, this, mConvListController); mMenuItemView.setListeners(mMenuController); }
@Override protected void onPause() { RecordVoiceBtnController.mIsPressed = false; JMessageClient.exitConversaion(); Log.i(TAG, "[Life cycle] - onPause"); super.onPause(); }
private void getUserInfo(final String targetId) { JMessageClient.getUserInfo( targetId, new GetUserInfoCallback() { @Override public void gotResult(final int status, String desc, final UserInfo userInfo) { mLoadingDialog.dismiss(); if (status == 0) { Conversation conv = Conversation.createSingleConversation(targetId); if (!TextUtils.isEmpty(userInfo.getAvatar())) { userInfo.getAvatarBitmap( new GetAvatarBitmapCallback() { @Override public void gotResult(int status, String desc, Bitmap bitmap) { if (status == 0) { mController.getAdapter().notifyDataSetChanged(); } else { HandleResponseCode.onHandle(mContext.getActivity(), status, false); } } }); mController.getAdapter().setToTop(conv); } else { mController.refreshConvList(conv); } mAddFriendDialog.cancel(); } else { HandleResponseCode.onHandle(mContext.getActivity(), status, true); } } }); }
/** 释放资源 */ @Override protected void onDestroy() { // TODO Auto-generated method stub JMessageClient.unRegisterEventReceiver(this); unregisterReceiver(mReceiver); mChatController.releaseMediaPlayer(); mChatView.releaseRecorder(); super.onDestroy(); }
public void onEventMainThread(MessageEvent event) { Message msg = event.getMessage(); TextContent content = (TextContent) msg.getContent(); SharedPreferences sp = getSharedPreferences("contracts", Activity.MODE_PRIVATE); String name = sp.getString("name", ""); if (!name.equals("") && name.equals(content.getText())) { String location = ""; if (ll != null) { location = String.valueOf(ll.latitude) + "," + String.valueOf(ll.longitude); } JMessageClient.sendMessage( JMessageClient.createSingleTextMessage( content.getText(), location.equals("") ? "failed" : location)); } else { } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.logout: JMessageClient.logout(); finish(); break; } }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.relogin_btn: // 隐藏软键盘 InputMethodManager manager = ((InputMethodManager) mContext.getSystemService(Activity.INPUT_METHOD_SERVICE)); if (mContext.getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (mContext.getCurrentFocus() != null) manager.hideSoftInputFromWindow( mContext.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } final String password = mReloginView.getPassword(); if (password.equals("")) { mReloginView.passwordError(mContext); break; } mLD = new LoadingDialog(); mLoadingDialog = mLD.createLoadingDialog(mContext, mContext.getString(R.string.login_hint)); mLoadingDialog.show(); Log.i("ReloginController", "mUserName: " + mUserName); JMessageClient.login( mUserName, password, new BasicCallback() { @Override public void gotResult(final int status, final String desc) { mContext.runOnUiThread( new Runnable() { @Override public void run() { mLoadingDialog.dismiss(); if (status == 0) { mContext.StartRelogin(); } else { HandleResponseCode.onHandle(mContext, status); } } }); } }); break; case R.id.relogin_switch_user_btn: mContext.StartSwitchUser(); break; case R.id.register_btn: mContext.StartRegisterActivity(); break; } }
public MsgListAdapter(Context context, long groupId) { initData(context); this.mGroupId = groupId; this.mIsGroup = true; this.mConv = JMessageClient.getGroupConversation(mGroupId); this.mMsgList = mConv.getMessagesFromNewest(0, mOffset); reverse(mMsgList); mStart = mOffset; checkSendingImgMsg(); }
public void deleteSingleConversation(JSONArray data, CallbackContext callbackContext) { try { String username = data.getString(0); JMessageClient.deleteSingleConversation(username); callbackContext.success("deleteSingleConversation ok"); } catch (JSONException e) { callbackContext.error("deleteSingleConversation failed"); e.printStackTrace(); } }
@Override protected void onResume() { if (!RecordVoiceBtnController.mIsPressed) mChatView.dismissRecordDialog(); String targetID = getIntent().getStringExtra(JChatDemoApplication.TARGET_ID); boolean isGroup = getIntent().getBooleanExtra(JChatDemoApplication.IS_GROUP, false); if (isGroup) { try { long groupID = getIntent().getLongExtra(JChatDemoApplication.GROUP_ID, 0); if (groupID == 0) { JMessageClient.enterGroupConversation(Long.parseLong(targetID)); } else JMessageClient.enterGroupConversation(groupID); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } } else if (null != targetID) { JMessageClient.enterSingleConversaion(targetID); } mChatController.getAdapter().initMediaPlayer(); Log.i(TAG, "[Life cycle] - onResume"); super.onResume(); }
private void setUserInfo(UserInfo.Field field, UserInfo info, CallbackContext callbackContext) { final CallbackContext cb = callbackContext; JMessageClient.updateMyInfo( field, info, new BasicCallback() { @Override public void gotResult(final int status, String desc) { cb.success("set userinfo ok"); } }); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { UserInfo userInfo = mMemberList.get(position); String userName = userInfo.getUserName(); Intent intent = new Intent(); if (userName.equals(JMessageClient.getMyInfo().getUserName())) { intent.setClass(mContext, MeInfoActivity.class); mContext.startActivity(intent); } else { intent.setClass(mContext, FriendInfoActivity.class); intent.putExtra(JChatDemoApplication.TARGET_ID, userInfo.getUserName()); intent.putExtra(JChatDemoApplication.GROUP_ID, mGroupId); mContext.startActivity(intent); } }
@Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); JMessageClient.registerEventReceiver(this); setContentView(R.layout.activity_chat); mChatView = (ChatView) findViewById(R.id.chat_view); mChatView.initModule(mDensity, mDensityDpi); mChatController = new ChatController(mChatView, this); mChatView.setListeners(mChatController); mChatView.setOnTouchListener(mChatController); mChatView.setOnSizeChangedListener(mChatController); mChatView.setOnKbdStateListener(mChatController); initReceiver(); }
public void setSendImg(long groupId, int[] msgIds) { Message msg; mConv = JMessageClient.getGroupConversation(groupId); for (int msgId : msgIds) { msg = mConv.getMessage(msgId); if (msg != null) { mMsgList.add(msg); incrementStartPosition(); mMsgQueue.offer(msg); } } Message message = mMsgQueue.element(); sendNextImgMsg(message); notifyDataSetChanged(); }
public void setUserNickname(JSONArray data, CallbackContext callbackContext) { Log.i(TAG, "setUserNickname"); try { String nickName = data.getString(0); Log.i(TAG, "setUserNickname" + nickName); UserInfo myUserInfo = JMessageClient.getMyInfo(); myUserInfo.setNickname(nickName); this.setUserInfo(UserInfo.Field.nickname, myUserInfo, callbackContext); callbackContext.success("update userinfo ok"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Error reading alias JSON"); } }
/** * 从发送队列中出列,并发送图片 * * @param msg 图片消息 */ private void sendNextImgMsg(Message msg) { JMessageClient.sendMessage(msg); msg.setOnSendCompleteCallback( new BasicCallback() { @Override public void gotResult(int i, String s) { // 出列 mMsgQueue.poll(); // 如果队列不为空,则继续发送下一张 if (!mMsgQueue.isEmpty()) { sendNextImgMsg(mMsgQueue.element()); } notifyDataSetChanged(); } }); }
// 更新极光推送头像 private void updateAvatarInJPush(final String imgKey) { JMessageClient.updateUserAvatar( imageFile, new BasicCallback() { @Override public void gotResult(int i, String s) { LogUtils.d("updateUserAvatar", "状态码:" + i + "描述:" + s); if (i == 0) { UserInfo userInfo = JMessageClient.getMyInfo(); LogUtils.d("avatar1111", userInfo.getAvatar()); LogUtils.d("avatar2222", userInfo.getAvatarFile().getPath()); updateLocalUser(imgKey); } } }); }
public void getAllSingleConversation(JSONArray data, CallbackContext callbackContext) { Log.i(TAG, " getAllSingleConversation \n" + data); List<Conversation> list = JMessageClient.getConversationList(); Log.i(TAG, "JMessageGetAllSingleConversation" + list.size()); JSONArray jsonRusult = new JSONArray(); for (int i = 0; i < list.size(); ++i) { Conversation conv = list.get(i); if (conv.getType() == ConversationType.single) { UserInfo info = (UserInfo) conv.getTargetInfo(); Message msg = conv.getLatestMessage(); String contentText = ""; if (msg != null) { switch (msg.getContentType()) { case text: { contentText = ((TextContent) msg.getContent()).getText(); } break; default: break; } } JSONObject jsonItem = new JSONObject(); try { jsonItem.put("username", info.getUserName()); jsonItem.put("nickname", info.getNickname()); // jsonItem.put("avatar", info.getAvatar()); jsonItem.put("lastMessage", contentText); jsonItem.put("unreadCount", conv.getUnReadMsgCnt()); jsonRusult.put(jsonItem); } catch (JSONException e) { e.printStackTrace(); } } } callbackContext.success(jsonRusult); }
private void resendImage(final ViewHolder holder, Animation sendingAnim, Message msg) { ImageContent imgContent = (ImageContent) msg.getContent(); final String path = imgContent.getLocalThumbnailPath(); holder.sendingIv.setVisibility(View.VISIBLE); holder.sendingIv.startAnimation(sendingAnim); holder.picture.setAlpha(0.75f); holder.resend.setVisibility(View.GONE); holder.progressTv.setVisibility(View.VISIBLE); try { // 显示上传进度 msg.setOnContentUploadProgressCallback( new ProgressUpdateCallback() { @Override public void onProgressUpdate(final double progress) { mActivity.runOnUiThread( new Runnable() { @Override public void run() { String progressStr = (int) (progress * 100) + "%"; holder.progressTv.setText(progressStr); } }); } }); if (!msg.isSendCompleteCallbackExists()) { msg.setOnSendCompleteCallback( new BasicCallback() { @Override public void gotResult(final int status, String desc) { holder.sendingIv.clearAnimation(); holder.sendingIv.setVisibility(View.GONE); holder.progressTv.setVisibility(View.GONE); holder.picture.setAlpha(1.0f); if (status != 0) { HandleResponseCode.onHandle(mContext, status, false); holder.resend.setVisibility(View.VISIBLE); } } }); } JMessageClient.sendMessage(msg); } catch (Exception e) { e.printStackTrace(); } }