public static String getThumbnailImagePath(String imagePath) { String path = imagePath.substring(0, imagePath.lastIndexOf("/") + 1); path += "th" + imagePath.substring(imagePath.lastIndexOf("/") + 1, imagePath.length()); EMLog.d("msg", "original image path:" + imagePath); EMLog.d("msg", "thum image path:" + path); return path; }
@Override public void onInfo(MediaRecorder mr, int what, int extra) { EMLog.v("video", "onInfo"); if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { EMLog.v("video", "max duration reached"); stopRecording(); btn_switch.setVisibility(View.VISIBLE); chronometer.stop(); btnStart.setVisibility(View.VISIBLE); btnStop.setVisibility(View.INVISIBLE); chronometer.stop(); if (localPath == null) { return; } String st3 = getResources().getString(R.string.Whether_to_send); new AlertDialog.Builder(this) .setMessage(st3) .setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { arg0.dismiss(); sendVideo(null); } }) .setNegativeButton(R.string.cancel, null) .setCancelable(false) .show(); } }
public boolean updateParseNickName(final String nickname) { String username = EMChatManager.getInstance().getCurrentUser(); ParseQuery<ParseObject> pQuery = ParseQuery.getQuery(CONFIG_TABLE_NAME); pQuery.whereEqualTo(CONFIG_USERNAME, username); ParseObject pUser = null; try { pUser = pQuery.getFirst(); if (pUser == null) { return false; } pUser.put(CONFIG_NICK, nickname); pUser.save(); return true; } catch (ParseException e) { if (e.getCode() == ParseException.OBJECT_NOT_FOUND) { pUser = new ParseObject(CONFIG_TABLE_NAME); pUser.put(CONFIG_USERNAME, username); pUser.put(CONFIG_NICK, nickname); try { pUser.save(); return true; } catch (ParseException e1) { e1.printStackTrace(); EMLog.e(TAG, "parse error " + e1.getMessage()); } } e.printStackTrace(); EMLog.e(TAG, "parse error " + e.getMessage()); } return false; }
public String uploadParseAvatar(byte[] data) { String username = EMChatManager.getInstance().getCurrentUser(); ParseQuery<ParseObject> pQuery = ParseQuery.getQuery(CONFIG_TABLE_NAME); pQuery.whereEqualTo(CONFIG_USERNAME, username); ParseObject pUser = null; try { pUser = pQuery.getFirst(); if (pUser == null) { pUser = new ParseObject(CONFIG_TABLE_NAME); pUser.put(CONFIG_USERNAME, username); } ParseFile pFile = new ParseFile(data); pUser.put(CONFIG_AVATAR, pFile); pUser.save(); return pFile.getUrl(); } catch (ParseException e) { if (e.getCode() == ParseException.OBJECT_NOT_FOUND) { try { pUser = new ParseObject(CONFIG_TABLE_NAME); pUser.put(CONFIG_USERNAME, username); ParseFile pFile = new ParseFile(data); pUser.put(CONFIG_AVATAR, pFile); pUser.save(); return pFile.getUrl(); } catch (ParseException e1) { e1.printStackTrace(); EMLog.e(TAG, "parse error " + e1.getMessage()); } } else { e.printStackTrace(); EMLog.e(TAG, "parse error " + e.getMessage()); } } return null; }
@Override public void onSyncSucess(final boolean success) { EMLog.d(TAG, "on contact list sync success:" + success); ContactlistFragment.this .getActivity() .runOnUiThread( new Runnable() { public void run() { getActivity() .runOnUiThread( new Runnable() { @Override public void run() { if (success) { progressBar.setVisibility(View.GONE); refresh(); } else { String s1 = getResources().getString(R.string.get_failed_please_check); Toast.makeText(getActivity(), s1, 1).show(); progressBar.setVisibility(View.GONE); } } }); } }); }
@Override public Object[] getSections() { positionOfSection = new SparseIntArray(); sectionOfPosition = new SparseIntArray(); int count = getCount(); list = new ArrayList<String>(); list.add(getContext().getString(R.string.search_header)); positionOfSection.put(0, 0); sectionOfPosition.put(0, 0); for (int i = 1; i < count; i++) { String letter = getItem(i).getHeader(); EMLog.d( TAG, "contactadapter getsection getHeader:" + letter + " name:" + getItem(i).getUsername()); int section = list.size() - 1; if (list.get(section) != null && !list.get(section).equals(letter)) { list.add(letter); section++; positionOfSection.put(section, i); } sectionOfPosition.put(i, section); } return list.toArray(new String[list.size()]); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == 100) { Uri uri = data.getParcelableExtra("uri"); String[] projects = new String[] {MediaStore.Video.Media.DATA, MediaStore.Video.Media.DURATION}; Cursor cursor = getActivity().getContentResolver().query(uri, projects, null, null, null); int duration = 0; String filePath = null; if (cursor.moveToFirst()) { // 路径:MediaStore.Audio.Media.DATA filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); // 总播放时长:MediaStore.Audio.Media.DURATION duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); EMLog.d(TAG, "duration:" + duration); } if (cursor != null) { cursor.close(); cursor = null; } getActivity() .setResult( Activity.RESULT_OK, getActivity().getIntent().putExtra("path", filePath).putExtra("dur", duration)); getActivity().finish(); } } }
/** 显示帐号在别处登录dialog */ private void showConflictDialog() { isConflictDialogShow = true; DemoHXSDKHelper.getInstance().logout(false, null); String st = getResources().getString(R.string.Logoff_notification); if (mycontext.isFinishing()) { // clear up global variables try { if (conflictBuilder == null) conflictBuilder = new android.app.AlertDialog.Builder(mycontext); conflictBuilder.setTitle(st); conflictBuilder.setMessage(R.string.connect_conflict); conflictBuilder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); conflictBuilder = null; finish(); startActivity(new Intent(mycontext, LoginContainerActivity.class)); } }); conflictBuilder.setCancelable(false); conflictBuilder.create().show(); isConflict = true; } catch (Exception e) { EMLog.e(TAG, "---------color conflictBuilder error" + e.getMessage()); } } }
@Override public void onError(MediaRecorder mr, int what, int extra) { EMLog.e("video", "recording onError:"); stopRecording(); Toast.makeText(this, "Recording error has occurred. Stopping the recording", Toast.LENGTH_SHORT) .show(); }
/** 帐号被移除的dialog */ private void showAccountRemovedDialog() { isAccountRemovedDialogShow = true; DemoHXSDKHelper.getInstance().logout(true, null); String st5 = getResources().getString(R.string.Remove_the_notification); if (!AugurContainerActivity.this.isFinishing()) { // clear up global variables try { if (accountRemovedBuilder == null) accountRemovedBuilder = new android.app.AlertDialog.Builder(AugurContainerActivity.this); accountRemovedBuilder.setTitle(st5); accountRemovedBuilder.setMessage(R.string.em_user_remove); accountRemovedBuilder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); accountRemovedBuilder = null; finish(); startActivity( new Intent(AugurContainerActivity.this, LoginContainerActivity.class)); } }); accountRemovedBuilder.setCancelable(false); accountRemovedBuilder.create().show(); isCurrentAccountRemoved = true; } catch (Exception e) { EMLog.e(TAG, "---------color userRemovedBuilder error" + e.getMessage()); } } }
@Override public void onSyncComplete(final boolean success) { EMLog.d(TAG, "on contact list sync success:" + success); getActivity() .runOnUiThread( new Runnable() { public void run() { getActivity() .runOnUiThread( new Runnable() { @Override public void run() { if (success) { loadingView.setVisibility(View.GONE); refresh(); } else { String s1 = getResources() .getString( com.xuhai.telescopes.R.string.get_failed_please_check); Toast.makeText(getActivity(), s1, Toast.LENGTH_LONG).show(); loadingView.setVisibility(View.GONE); } } }); } }); }
public void sendVideo(View view) { if (TextUtils.isEmpty(localPath)) { EMLog.e("Recorder", "recorder fail please try again!"); return; } if (msc == null) msc = new MediaScannerConnection( this, new MediaScannerConnectionClient() { @Override public void onScanCompleted(String path, Uri uri) { L.d("scanner completed"); msc.disconnect(); progressDialog.dismiss(); setResult(RESULT_OK, getIntent().putExtra("uri", uri)); finish(); } @Override public void onMediaScannerConnected() { msc.scanFile(localPath, "video/*"); } }); if (progressDialog == null) { progressDialog = new ProgressDialog(this); progressDialog.setMessage("processing..."); progressDialog.setCancelable(false); } progressDialog.show(); msc.connect(); }
@Override public void onSyncSucess(final boolean success) { EMLog.d(TAG, "onSyncGroupsFinish success:" + success); runOnUiThread( new Runnable() { public void run() { swipeRefreshLayout.setRefreshing(false); if (success) { handler.postDelayed( new Runnable() { @Override public void run() { refresh(); progressBar.setVisibility(View.GONE); } }, 1000); } else { if (!GroupsActivity.this.isFinishing()) { String s1 = getResources().getString(R.string.Failed_to_get_group_chat_information); Toast.makeText(GroupsActivity.this, s1, Toast.LENGTH_LONG).show(); progressBar.setVisibility(View.GONE); } } } }); }
public static String getThumbnailImagePath(String thumbRemoteUrl) { String thumbImageName = thumbRemoteUrl.substring(thumbRemoteUrl.lastIndexOf("/") + 1, thumbRemoteUrl.length()); String path = PathUtil.getInstance().getImagePath() + "/" + "th" + thumbImageName; EMLog.d("msg", "thum image path:" + path); return path; }
@SuppressWarnings("unused") @Override public void onReceive(Context context, Intent intent) { abortBroadcast(); EMLog.d("收到消息", "收到透传消息"); // 获取cmd message对象 String msgId = intent.getStringExtra("msgid"); EMMessage message = intent.getParcelableExtra("message"); // 获取消息body CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody(); String action = cmdMsgBody.action; // 获取自定义action // 获取扩展属性 此处省略 // message.getStringAttribute(""); EMLog.d("收到消息", String.format("透传消息:action:%s,message:%s", action, message.toString())); // String st9 = getResources().getString(R.string.receive_the_passthrough); // Toast.makeText(MainActivity.this, st9+action, Toast.LENGTH_SHORT).show(); }
@Override public void onReceiveLocation(BDLocation location) { if (location == null) { return; } Log.d("map On location change received:" + location); Log.d("map addr:" + location.getAddrStr()); sendButton.setEnabled(true); if (progressDialog != null) { progressDialog.dismiss(); } if (lastLocation != null) { if (lastLocation.getLatitude() == location.getLatitude() && lastLocation.getLongitude() == location.getLongitude()) { Log.d("map same location, skip refresh"); // mMapView.refresh(); //need this refresh? return; } } lastLocation = location; GeoPoint gcj02Point = new GeoPoint((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6)); EMLog.d(TAG, "GCJ-02 loc:" + gcj02Point); GeoPoint point = CoordinateConvert.fromGcjToBaidu(gcj02Point); EMLog.d(TAG, "converted BD-09 loc:" + point); // GeoPoint p1 = gcjToBaidu(location.getLatitude(), // location.getLongitude()); // System.err.println("johnson change to baidu:" + p1); // GeoPoint p2 = baiduToGcj(location.getLatitude(), // location.getLongitude()); // System.err.println("johnson change to gcj:" + p2); OverlayItem addrItem = new OverlayItem(point, "title", location.getAddrStr()); mAddrOverlay.removeAll(); mAddrOverlay.addItem(addrItem); mMapView.getController().setZoom(17); mMapView.refresh(); mMapController.animateTo(point); }
@Override protected synchronized FilterResults performFiltering(CharSequence prefix) { FilterResults results = new FilterResults(); if (mOriginalList == null) { mOriginalList = new ArrayList<User>(); } EMLog.d(TAG, "contacts original size: " + mOriginalList.size()); EMLog.d(TAG, "contacts copy size: " + copyUserList.size()); if (prefix == null || prefix.length() == 0) { results.values = copyUserList; results.count = copyUserList.size(); } else { String prefixString = prefix.toString(); final int count = mOriginalList.size(); final ArrayList<User> newValues = new ArrayList<User>(); for (int i = 0; i < count; i++) { final User user = mOriginalList.get(i); String username = user.getUsername(); if (username.startsWith(prefixString)) { newValues.add(user); } else { final String[] words = username.split(" "); final int wordCount = words.length; // Start at index 0, in case valueText starts with // space(s) for (int k = 0; k < wordCount; k++) { if (words[k].startsWith(prefixString)) { newValues.add(user); break; } } } } results.values = newValues; results.count = newValues.size(); } EMLog.d(TAG, "contacts filter results size: " + results.count); return results; }
public synchronized void onNewMesg(List<EMMessage> messages) { if (EMChatManager.getInstance().isSlientMessage(messages.get(messages.size() - 1))) { return; } // 判断app是否在后台 if (!EasyUtils.isAppRunningForeground(appContext)) { EMLog.d(TAG, "app is running in backgroud"); sendNotification(messages, false); } else { sendNotification(messages, true); } viberateAndPlayTone(messages.get(messages.size() - 1)); }
@Override protected synchronized void publishResults(CharSequence constraint, FilterResults results) { userList.clear(); userList.addAll((List<User>) results.values); EMLog.d(TAG, "publish contacts filter results size: " + results.count); if (results.count > 0) { notiyfyByFilter = true; notifyDataSetChanged(); notiyfyByFilter = false; } else { notifyDataSetInvalidated(); } }
/** * 根据消息内容和消息类型获取消息内容提示 * * @param message * @param context * @return */ private String getMessageDigest(EMMessage message, Context context) { String digest = ""; switch (message.getType()) { case LOCATION: // 位置消息 if (message.direct == EMMessage.Direct.RECEIVE) { // 从sdk中提到了ui中,使用更简单不犯错的获取string的方法 // digest = EasyUtils.getAppResourceString(context, // "location_recv"); digest = getStrng(context, R.string.location_recv); digest = String.format(digest, message.getFrom()); return digest; } else { // digest = EasyUtils.getAppResourceString(context, // "location_prefix"); digest = getStrng(context, R.string.location_prefix); } break; case IMAGE: // 图片消息 ImageMessageBody imageBody = (ImageMessageBody) message.getBody(); digest = getStrng(context, R.string.picture) + imageBody.getFileName(); break; case VOICE: // 语音消息 digest = getStrng(context, R.string.voice); break; case VIDEO: // 视频消息 digest = getStrng(context, R.string.video); break; case TXT: // 文本消息 if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) { digest = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotMenuMessageDigest(message); } else if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { TextMessageBody txtBody = (TextMessageBody) message.getBody(); digest = getStrng(context, R.string.voice_call) + txtBody.getMessage(); } else { TextMessageBody txtBody = (TextMessageBody) message.getBody(); digest = txtBody.getMessage(); } break; case FILE: // 普通文件消息 digest = getStrng(context, R.string.file); break; default: EMLog.e(TAG, "unknow type"); return ""; } return digest; }
@Override public void onSyncComplete(final boolean success) { EMLog.d(TAG, "on contactinfo list sync success:" + success); getActivity() .runOnUiThread( new Runnable() { @Override public void run() { loadingView.setVisibility(View.GONE); if (success) { refresh(); } } }); }
public void stopRecording() { if (mediaRecorder != null) { mediaRecorder.setOnErrorListener(null); mediaRecorder.setOnInfoListener(null); try { mediaRecorder.stop(); } catch (IllegalStateException e) { EMLog.e("video", "stopRecording error:" + e.getMessage()); } } releaseRecorder(); if (mCamera != null) { mCamera.stopPreview(); releaseCamera(); } }
@Override public void surfaceCreated(SurfaceHolder holder) { if (mCamera == null) { if (!initCamera()) { showFailDialog(); return; } } try { mCamera.setPreviewDisplay(mSurfaceHolder); mCamera.startPreview(); handleSurfaceChanged(); } catch (Exception e1) { EMLog.e("video", "start preview fail " + e1.getMessage()); showFailDialog(); } }
@Override public void onClick(View v) { String st = activity.getResources().getString(R.string.Is_download_voice_click_later); if (isPlaying) { if (((ChatActivity) activity).playMsgId != null && ((ChatActivity) activity).playMsgId.equals(message.getMsgId())) { currentPlayListener.stopPlayVoice(); return; } currentPlayListener.stopPlayVoice(); } if (message.direct == EMMessage.Direct.SEND) { // for sent msg, we will try to play the voice file directly playVoice(voiceBody.getLocalUrl()); } else { if (message.status == EMMessage.Status.SUCCESS) { File file = new File(voiceBody.getLocalUrl()); if (file.exists() && file.isFile()) playVoice(voiceBody.getLocalUrl()); else EMLog.e(TAG, "file not exist"); } else if (message.status == EMMessage.Status.INPROGRESS) { String s = new String(); Toast.makeText(activity, st, Toast.LENGTH_SHORT).show(); } else if (message.status == EMMessage.Status.FAIL) { Toast.makeText(activity, st, Toast.LENGTH_SHORT).show(); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { EMChatManager.getInstance().asyncFetchMessage(message); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); adapter.notifyDataSetChanged(); } }.execute(); } } }
@SuppressLint("NewApi") private boolean initCamera() { try { if (frontCamera == 0) { mCamera = Camera.open(CameraInfo.CAMERA_FACING_BACK); } else { mCamera = Camera.open(CameraInfo.CAMERA_FACING_FRONT); } Camera.Parameters camParams = mCamera.getParameters(); mCamera.lock(); mSurfaceHolder = mVideoView.getHolder(); mSurfaceHolder.addCallback(this); mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mCamera.setDisplayOrientation(90); } catch (RuntimeException ex) { EMLog.e("video", "init Camera fail " + ex.getMessage()); return false; } return true; }
/** 手机震动和声音提示 */ public void viberateAndPlayTone(EMMessage message) { if (message != null) { if (EMChatManager.getInstance().isSlientMessage(message)) { return; } } com.easemob.applib.model.HXSDKModel model = HXSDKHelper.getInstance().getModel(); if (!model.getSettingMsgNotification()) { return; } if (System.currentTimeMillis() - lastNotifiyTime < 1000) { // received new messages within 2 seconds, skip play ringtone return; } try { lastNotifiyTime = System.currentTimeMillis(); // 判断是否处于静音模式 if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { EMLog.e(TAG, "in slient mode now"); return; } if (model.getSettingMsgVibrate()) { long[] pattern = new long[] {0, 180, 80, 120}; vibrator.vibrate(pattern, -1); } if (model.getSettingMsgSound()) { if (ringtone == null) { Uri notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); ringtone = RingtoneManager.getRingtone(appContext, notificationUri); if (ringtone == null) { EMLog.d(TAG, "cant find ringtone at:" + notificationUri.getPath()); return; } } if (!ringtone.isPlaying()) { String vendor = Build.MANUFACTURER; ringtone.play(); // for samsung S3, we meet a bug that the phone will // continue ringtone without stop // so add below special handler to stop it after 3s if // needed if (vendor != null && vendor.toLowerCase().contains("samsung")) { Thread ctlThread = new Thread() { public void run() { try { Thread.sleep(3000); if (ringtone.isPlaying()) { ringtone.stop(); } } catch (Exception e) { } } }; ctlThread.run(); } } } } catch (Exception e) { e.printStackTrace(); } }
private void toggleBlockGroup() { if (switchButton.isSwitchOpen()) { EMLog.d(TAG, "change to unblock group msg"); if (progressDialog == null) { progressDialog = new ProgressDialog(GroupDetailsActivity.this); progressDialog.setCanceledOnTouchOutside(false); } progressDialog.setMessage(getString(RHelper.get("string.Is_unblock"))); progressDialog.show(); new Thread( new Runnable() { public void run() { try { EMGroupManager.getInstance().unblockGroupMessage(groupId); runOnUiThread( new Runnable() { public void run() { switchButton.closeSwitch(); progressDialog.dismiss(); } }); } catch (Exception e) { e.printStackTrace(); runOnUiThread( new Runnable() { public void run() { progressDialog.dismiss(); Toast.makeText( getApplicationContext(), RHelper.get("string.remove_group_of"), 1) .show(); } }); } } }) .start(); } else { String st8 = getResources().getString(RHelper.get("string.group_is_blocked")); final String st9 = getResources().getString(RHelper.get("string.group_of_shielding")); EMLog.d(TAG, "change to block group msg"); if (progressDialog == null) { progressDialog = new ProgressDialog(GroupDetailsActivity.this); progressDialog.setCanceledOnTouchOutside(false); } progressDialog.setMessage(st8); progressDialog.show(); new Thread( new Runnable() { public void run() { try { EMGroupManager.getInstance().blockGroupMessage(groupId); runOnUiThread( new Runnable() { public void run() { switchButton.openSwitch(); progressDialog.dismiss(); } }); } catch (Exception e) { e.printStackTrace(); runOnUiThread( new Runnable() { public void run() { progressDialog.dismiss(); Toast.makeText(getApplicationContext(), st9, 1).show(); } }); } } }) .start(); } }
public static String getImagePath(String remoteUrl) { String imageName = remoteUrl.substring(remoteUrl.lastIndexOf("/") + 1, remoteUrl.length()); String path = PathUtil.getInstance().getImagePath() + "/" + imageName; EMLog.d("msg", "image path:" + path); return path; }
@Override public void surfaceDestroyed(SurfaceHolder arg0) { EMLog.v("video", "surfaceDestroyed"); }