Пример #1
0
 //    @Override
 //    public void setUserVisibleHint(boolean visible){
 //        super.setUserVisibleHint(visible);
 ////        if (visible && isResumed()){
 //        if (visible){
 //            setInfo(null);
 //        }
 //    }
 @Override
 public void onAttach(Activity activity) {
   super.onAttach(activity);
   mActivity = ((HomeActivity) activity);
   mPrefs = mActivity.getMPrefs();
   //        picasso = Picasso.with(mActivity);
   picasso = mActivity.getPicasso();
 }
Пример #2
0
 private void requestGetUserInfo() {
   CallService customPost =
       new CallService(
           CallMethod.POST,
           "getUserInfo",
           mActivity.getUserId(),
           mActivity.getToken(),
           mActivity.getDeviceId(),
           mActivity.getVersion(),
           mActivity.getLocale(),
           new JsonCallBackListener() {
             @Override
             public void handleData(String mCmd, JSONObject json) throws JSONException {
               //                if (mActivity != null) {
               //                    mActivity.hideLoading();
               //                }
               if (json != null) {
                 int status = json.getInt("StatusCode");
                 if (status == 1) {
                   JSONObject userInfo = json.getJSONArray("Data").getJSONObject(0);
                   BLSharePreferences.setUserInfo(context, userInfo.toString());
                   setInfo(userInfo);
                   sendBroadcastUpdateProfile();
                 }
               }
               hideLoading();
             }
           });
   try {
     String url = Webservice.makeGetProfileURL(userID);
     customPost.execute(url);
   } catch (Exception e) {
     hideLoading();
     Logs.log(e);
     //            if (mActivity != null) {
     //                mActivity.hideLoading();
     //            }
   }
 }
Пример #3
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;
   }
 }
Пример #4
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();
    }
  }
Пример #5
0
 private void beginCrop(Uri source) {
   Uri outputUri = Uri.fromFile(new File(mActivity.getCacheDir(), "cropped"));
   //        new Crop(source).output(outputUri).asSquare().start(mActivity);
   Crop.of(source, outputUri).asSquare().start(mActivity);
 }