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;
 }
  /** 显示帐号在别处登录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());
      }
    }
  }
  /** 帐号被移除的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 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();
 }
  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();
  }
  /**
   * 根据消息内容和消息类型获取消息内容提示
   *
   * @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;
  }
  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;
  }
Beispiel #12
0
  /** 手机震动和声音提示 */
  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();
    }
  }