Beispiel #1
0
 private void sendMessage() {
   String message = etMessage.getText().toString();
   if (message.trim().isEmpty()) {
     UIUtils.alert(this, R.string.message_is_empty);
     return;
   }
   if (isSendSMS) {
     sendMessageToServer(
         Prefs.getSendSmsJSON(
             userID,
             mItem.getChatGroupID() != null ? mItem.getChatGroupID() : "",
             mItem.getMemberID() != null ? mItem.getMemberID() : "",
             mItem.getID(),
             Message.Type.CHAT_TYPE_SEND_SMS,
             message,
             DateUtils.nowTime(),
             token));
   } else {
     sendMessageToServer(
         Prefs.getSendMessageJSON(
             userID,
             mItem.getChatGroupID(),
             mItem.getMemberID(),
             Message.Type.CHAT_TYPE_MESSAGE,
             message,
             DateUtils.nowTime(),
             token));
   }
   etMessage.setText("");
 }
Beispiel #2
0
 private void actionPopup(int actionId) {
   if (isMsLief) {
     return;
   }
   switch (actionId) {
     case ACTION_ID_CALL:
       startCall();
       break;
     case ACTION_ID_REMOVE:
       String title =
           String.format(getString(R.string.remove_from_your_lovedones), mItem.getFullName());
       if (UIUtils.ensureNetworkInternet(this, false)) {
         UIUtils.alert(
             this,
             title,
             true,
             R.string.cancel,
             null,
             R.string.yes,
             new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialog, int which) {
                 removeUser();
               }
             });
       }
       break;
   }
 }
Beispiel #3
0
 private void shareLocation() {
   if (haveGoogleService) {
     if (mLastLocation != null) {
       sendMessageLocation(mLastLocation);
     } else {
       if (isProviderGPSEnabled()) {
         Toast.makeText(this, R.string.please_wait_to_get_location_from_gps, Toast.LENGTH_LONG)
             .show();
         startLocationUpdates();
       } else {
         UIUtils.alert(this, R.string.please_turn_on_gps_to_get_your_location);
       }
     }
   } else {
     UIUtils.alert(this, R.string.cannot_get_your_location);
   }
 }
Beispiel #4
0
 private void onPhoto(Uri imgUri) {
   filePath = AndroidUtils.getPath(this, imgUri);
   if (UIUtils.ensureNetworkInternet(this, false)) {
     if (filePath != null) {
       requestUpdateAvatar(filePath);
     } else {
       hideLoading();
       UIUtils.alert(this, R.string.file_not_found);
     }
   }
 }
Beispiel #5
0
 @Override
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   switch (action) {
     case Actions.SHOW_ALERT_SEND_SMS_FAILED_OUT_OF_FREE_SMS:
       showAlertSmsLimit(true);
       break;
     case Actions.SHOW_ALERT_SEND_SMS_FAILED_WRONG_NUMBER:
       UIUtils.alert(
           ChatScreen.this, R.string.cannot_send_message_cause_wrong_number, R.string.oop);
       break;
   }
 }
Beispiel #6
0
  private void onPickCamera() {
    boolean takePhoto = Utils.isIntentAvailable(this, MediaStore.ACTION_IMAGE_CAPTURE);
    if (!takePhoto) {
      UIUtils.alert(this, R.string.not_found_camera);
      return;
    }

    mPhotoPath = Utils.nextPath(this) + ".jpg";
    Uri imageUri = Uri.fromFile(new File(mPhotoPath));

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    Intent openInChooser = Intent.createChooser(intent, getString(R.string.complete_action_using));
    startActivityForResult(openInChooser, PICK_CAMERA);
  }
Beispiel #7
0
 private void sendMessageImage(String urlImage) {
   if (TextUtil.isEmpty(urlImage)) {
     UIUtils.alert(this, R.string.url_image_is_null);
     return;
   }
   sendMessageToServer(
       Prefs.getSendMessageJSON(
           userID,
           mItem.getChatGroupID(),
           mItem.getMemberID(),
           Message.Type.CHAT_TYPE_IMAGE,
           urlImage,
           DateUtils.nowTime(),
           token));
   etMessage.setText("");
 }
Beispiel #8
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.ivMore:
       UIUtils.hideSoftInput(this);
       showMoreAction(true, v);
       break;
     case R.id.tvContentAlert:
       break;
     case R.id.ivBackgroundAlert:
       showAlertSmsLimit(false);
       break;
     case R.id.ivBack:
       UIUtils.hideSoftInput(this);
       finish();
       break;
     case R.id.tvCall:
     case R.id.tvCallNow:
       startCall();
       break;
     case R.id.tvSend:
       //			UIUtils.hideSoftInput(this);
       if (UIUtils.ensureNetworkInternet(this, false)) {
         sendMessage();
       }
       break;
     case R.id.ivAction:
       if (UIUtils.ensureNetworkInternet(this, false)) {
         if (isSendSMS) {
           return;
         }
         askWhatForShare();
       }
       break;
     default:
       UIUtils.alert(this, "still building");
       break;
   }
 }
Beispiel #9
0
  private void requestUpdateAvatar(final String filePath) {
    if (filePath == null) {
      UIUtils.alert(this, R.string.file_not_found);
      hideLoading();
      return;
    }
    if (UIUtils.ensureNetworkInternet(this, false)) {
      showLoading();
      final File file = new File(filePath);
      if (file.exists() && file.canRead() && file.isFile()) {
        if (file.length() > Values.FILE_SIZE_LIMIT) {
          UIUtils.alert(this, getString(R.string.file_size_must_be_less_than_size_limit, "30MB"));
          hideLoading();
          return;
        }
      } else {
        UIUtils.alert(this, R.string.file_not_found);
        hideLoading();
        return;
      }

      try {
        uploadTask =
            new AsyncTask<Object, Object, String>() {
              @Override
              protected String doInBackground(Object... params) {
                String response =
                    HttpUtils.uploadFileImageByPost(RemoteMethods.uploadImage, filePath);
                return response;
              }

              @Override
              protected void onPostExecute(String response) {
                if (response != null) {
                  try {
                    JSONObject json = new JSONObject(response);
                    Log.d(TAG, json.toString());
                    int status = json.getInt("status");
                    if (status == 1) {
                      urlImage = json.getString("data");
                      sendMessageImage(urlImage);
                    } else {
                      try {
                        String errorCode = json.get("errorCode").toString();
                        if (errorCode.equals(CallServicePOST.ErrorCode.CONNECT_SERVER_FAIL)) {
                          UIUtils.alert(
                              ChatScreen.this,
                              R.string.connect_to_server_failed_plz_wait_a_moment_and_try_again);
                        } else if (errorCode.equals(CallServiceCustomPOST.ErrorCode.FULL_STORAGE)) {
                          UIUtils.alert(
                              ChatScreen.this, R.string.full_storage_please_upgrade, R.string.oop);
                        } else {
                          UIUtils.alert(ChatScreen.this, "errorCode: " + errorCode);
                        }
                      } catch (Exception e) {
                        Log.d(TAG, json.toString());
                      }
                    }
                    hideLoading();
                  } catch (Exception e) {
                    hideLoading();
                    e.printStackTrace();
                  }
                } else {
                  hideLoading();
                  UIUtils.alert(ChatScreen.this, R.string.upload_failed);
                }
              }
            };

        boolean isPending = (uploadTask.getStatus().equals(AsyncTask.Status.PENDING));
        if (isPending) {
          Log.i(TAG, "upFile + " + isPending);
          uploadTask.execute();
          if (uploadTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
            uploadTask = null;
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }