コード例 #1
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
       //            case R.id.tvChangeNumber:
       //                finish();
       //                break;
     case R.id.button_back:
       finish();
       break;
     case R.id.button_verify:
       if (UIUtils.ensureNetworkInternet(this, false)) {
         showLoading();
         UIUtils.hideSoftInput(v);
         String verifyCode = etVerifyCode.getText().toString();
         if (verifyCode.length() != 6) {
           UIUtils.alert(this, R.string.invalid_verify_code_length);
           hideLoading();
           return;
         }
         if (TextUtil.isEmpty(verifyCode)) {
           UIUtils.alert(this, R.string.please_enter_your_verify_code_sent_to_phone_number);
           hideLoading();
           return;
         }
         requestVerifyCode(verifyCode);
       }
       break;
     default:
       UIUtils.alert(this, "Still builiding.. !");
       break;
   }
 }
コード例 #2
0
 @Override
 public void handleData(String mCmd, JSONObject json) throws JSONException {
   if (mCmd.equals(cmdVerifySignupPhone)) {
     if (json != null) {
       Log.d(TAG, json.toString());
       int status = json.getInt("status");
       if (status == 1) {
         Prefs.setPhoneNo(mPrefs, phoneCode, phoneNumber);
         Intent intent = new Intent(context, SignUpStep2Activity.class);
         startActivity(intent);
         finish();
       } else {
         try {
           String error = json.get("Error").toString();
           if (error.equals("wrong code")) {
             UIUtils.alert(this, R.string.your_verify_code_is_not_correct);
           }
         } catch (Exception e) {
           try {
             String errorCode = json.get("errorCode").toString();
             ErrorCode.showErrorAlert(this, errorCode);
           } catch (Exception e1) {
             UIUtils.alert(this, json.toString());
           }
         }
       }
     }
   }
   hideLoading();
 }
コード例 #3
0
 private void onPhoto(Uri imgUri) {
   filePath = AndroidUtils.getPath(mActivity, imgUri);
   if (UIUtils.ensureNetworkInternet(context, false)) {
     if (filePath != null) {
       showLoading();
       requestUpdateAvatar();
     } else {
       hideLoading();
       UIUtils.alert(context, R.string.cannot_get_file_path_image_picture);
     }
   }
 }
コード例 #4
0
  private void onPickCamera() {
    boolean takePhoto = Utils.isIntentAvailable(context, MediaStore.ACTION_IMAGE_CAPTURE);
    if (!takePhoto) {
      UIUtils.alert(context, R.string.not_found_camera);
      return;
    }

    mPhotoPath = Utils.nextPath(context) + ".png";
    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);
  }
コード例 #5
0
  private void requestUpdateAvatar() {
    final File file = new File(filePath);
    if (file.exists() && file.canRead() && file.isFile()) {
      if (file.length() > Values.FILE_SIZE_LIMIT) {
        hideLoading();
        UIUtils.alert(context, getString(R.string.file_size_must_be_less_than_size_limit, "30MB"));
        return;
      }
    } else {
      hideLoading();
      UIUtils.alert(context, R.string.file_not_found);
      return;
    }
    //        Toast.makeText(context, "requestUpdateAvatar() called!", Toast.LENGTH_SHORT).show();
    try {
      final String url =
          Webservice.get(Webservice.URL_UPDATE_PROFILE_AVATAR, mActivity.getUserId());

      uploadTask =
          new AsyncTask<Object, Object, String>() {
            @Override
            protected String doInBackground(Object... params) {
              String response =
                  HttpUtils.uploadFileByPost(
                      url,
                      mActivity.getUserId(),
                      mActivity.getToken(),
                      mActivity.getDeviceId(),
                      mActivity.getVersion(),
                      mActivity.getLocale(),
                      file,
                      Contains.FILE_TYPE_IMAGE,
                      filePath);
              return response;
            }

            @Override
            protected void onPostExecute(String response) {
              if (response != null) {
                try {
                  JSONObject json = new JSONObject(response);
                  //                            Log.d(TAG, json.toString());
                  //                            UIUtils.alert(context, "return: " +
                  // json.toString());
                  if (json != null) {
                    int status = json.getInt("StatusCode");
                    if (status == 1) {
                      JSONObject userInfo = json.getJSONObject("Data");
                      BLSharePreferences.setUserInfo(context, userInfo.toString());
                      setInfo(userInfo);
                      sendBroadcastUpdateProfile();
                    } else {
                      try {
                        String errorCode = json.get("errorCode").toString();
                        if (errorCode.equals(ErrorCode.CODE_CONNECT_SERVER_FAIL)) {
                          UIUtils.alert(
                              context,
                              R.string.connect_to_server_failed_plz_wait_a_moment_and_try_again);
                        } else {
                          UIUtils.alert(context, "errorCode: " + errorCode);
                        }
                      } catch (Exception e) {
                        UIUtils.alert(context, json.toString());
                        Log.d(TAG, json.toString());
                      }
                    }
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                  UIUtils.alert(context, "Exception: " + e.getMessage());
                }
              } else {
                UIUtils.alert(context, R.string.upload_failed);
              }
              hideLoading();
            }
          };

      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) {
      hideLoading();
      e.printStackTrace();
    }
  }