@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;
   }
 }
 @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
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_my_profile, container, false);

    ivAvatar = (ImageView) rootView.findViewById(R.id.avatar);
    imageFrag = (ImageView) rootView.findViewById(R.id.img_flag);
    lblName = (TextView) rootView.findViewById(R.id.lbl_name);
    lblAge = (TextView) rootView.findViewById(R.id.lbl_age);
    lblNation = (TextView) rootView.findViewById(R.id.lbl_nation);
    lblDescription = (TextView) rootView.findViewById(R.id.lbl_description);
    tvTitlebar = (TextView) rootView.findViewById(R.id.tv_title_bar);

    rootView.findViewById(R.id.btnShowDrawer).setOnClickListener(this);
    rootView.findViewById(R.id.button_edit).setOnClickListener(this);
    ivAvatar.setOnClickListener(this);

    userID = mPrefs.getString(Prefs.ID, null);

    if (UIUtils.ensureNetworkInternet(context, false)) {
      showLoading();
      requestGetUserInfo();
    } else {
      setInfo(null);
    }

    return rootView;
  }
예제 #5
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);
  }
예제 #6
0
 @Override
 public void onClick(View v) {
   UIUtils.hideSoftInput(mActivity);
   Intent intent;
   switch (v.getId()) {
     case R.id.btnShowDrawer:
       if (mActivity != null) {
         mActivity.showNavigationDrawer();
       }
       break;
     case R.id.button_edit:
       intent = new Intent(mActivity.context, EditProfileActivity.class);
       startActivityForResult(intent, Contains.REQUEST_EDIT_INFO);
       break;
     case R.id.avatar:
       askHowTakePhoto();
       break;
   }
 }
예제 #7
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();
    }
  }