@Override
 public void onResponse(ResponseStatus response, Object deliverParam) {
   if (mIsDestroy || !isAdded()) {
     return;
   }
   mUserInfo.photo = mBackupPhoto;
   if (mPhotoStatus == PhotoStatus.DELETE) {
     mBackupPhoto = null;
     mUserInfo.photo = null;
   }
   try {
     mUserDataProvider.setLoginUserInfo(mUserInfo.clone());
   } catch (Exception e) {
     Log.e(TAG, " " + e.getMessage());
   }
   LocalBroadcastManager.getInstance(mContext)
       .sendBroadcast(new Intent(Setting.BROADCAST_UPDATE_MYINFO));
   mPopup.dismissWiat();
   mPopup.show(
       PopupType.CONFIRM,
       getString(R.string.info),
       getString(R.string.user_modify_success),
       mPopupSucess,
       null,
       null);
 }
  private void setImage(Bitmap bmp) {
    if (bmp == null) {
      return;
    }
    mBlurBmp = ImageUtil.fastBlur(bmp, 32);
    mLayout.setBlurBackGroud(mBlurBmp);
    mRbmp = ImageUtil.getRoundedBitmap(bmp, false);
    mLayout.setUserPhoto(mRbmp);

    mPhotoStatus = PhotoStatus.MODIFY;
    mUserInfo.photo = Base64.encodeToString(ImageUtil.bitmapToByteArray(bmp), 0);
    mUserInfo.photo = mUserInfo.photo.replaceAll("\n", "");
    mBackupPhoto = mUserInfo.photo;
  }
 private void createUser() {
   Calendar cal =
       mUserInfo.getTimeCalendar(mTimeConvertProvider, User.UserTimeType.expiry_datetime);
   int year = cal.get(Calendar.YEAR);
   if (year > 2030) {
     cal.set(Calendar.YEAR, 2030);
     mUserInfo.setTimeCalendar(mTimeConvertProvider, User.UserTimeType.expiry_datetime, cal);
   }
   cal = mUserInfo.getTimeCalendar(mTimeConvertProvider, User.UserTimeType.start_datetime);
   year = cal.get(Calendar.YEAR);
   if (year < 2000) {
     cal.set(Calendar.YEAR, 2000);
     mUserInfo.setTimeCalendar(mTimeConvertProvider, User.UserTimeType.start_datetime, cal);
   }
 }
 @Override
 public void OnPositive() {
   mUserInfo.photo = mBackupPhoto;
   if (mPhotoStatus == PhotoStatus.DELETE) {
     mBackupPhoto = null;
     mUserInfo.photo = null;
   }
   try {
     sendLocalBroadcast(Setting.BROADCAST_USER, mUserInfo.clone());
   } catch (CloneNotSupportedException e) {
     e.printStackTrace();
     return;
   }
   mScreenControl.backScreen();
 }
 private void editOperator() {
   Bundle bundle = new Bundle();
   try {
     bundle.putSerializable(User.TAG, mUserInfo.clone());
     bundle.putSerializable(Setting.DISABLE_MODIFY, true);
   } catch (CloneNotSupportedException e) {
     e.printStackTrace();
     return;
   }
   mScreenControl.addScreen(ScreenType.USER_PERMISSION, bundle);
 }
 private void editFingerPrint() {
   Bundle bundle = new Bundle();
   try {
     bundle.putSerializable(User.TAG, mUserInfo.clone());
     bundle.putSerializable(Setting.DISABLE_MODIFY, true);
   } catch (CloneNotSupportedException e) {
     e.printStackTrace();
     return;
   }
   mScreenControl.addScreen(ScreenType.FINGERPRINT_REGISTER, bundle);
 }
 @Override
 public void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   Log.e(TAG, "onSaveInstanceState");
   User bundleItem = null;
   try {
     bundleItem = (User) mUserInfo.clone();
   } catch (CloneNotSupportedException e) {
     e.printStackTrace();
     return;
   }
   outState.putSerializable(User.TAG, bundleItem);
   outState.putInt("photoStatus", mPhotoStatus.ordinal());
 }
  private void setView() {
    if (mUserInfo == null) {
      return;
    }
    mLayout.setUserID(mUserInfo.user_id);
    mLayout.setUserName(mUserInfo.name);

    if (mUserInfo.pin_exist) {
      mLayout.showPin(true);
    } else {
      mLayout.showPin(false);
    }
    mLayout.setUserID(mUserInfo.user_id);
    mLayout.setUserName(mUserInfo.name);
    mLayout.setEmail(mUserInfo.email);
    mLayout.setTelephone(mUserInfo.phone_number);
    mLayout.setLoginID(mUserInfo.login_id);
    setPermission();

    if (mUserInfo.password_exist || (mPasswordData != null && !mPasswordData.isEmpty())) {
      mLayout.setPassword(getString(R.string.password_display));
    } else {
      mLayout.setPassword("");
    }

    if (mUserInfo.user_group != null) {
      mLayout.setUserGroup(mUserInfo.user_group.name);
      mLayout.setUserGroupID(mUserInfo.user_group.id);
    } else {
      //   mLayout.setUserGroup(getString(R.string.all_users));
      mLayout.setUserGroupID(String.valueOf(1));
    }

    if (mUserInfo.isActive()) {
      mLayout.setStatus(getString(R.string.status) + " " + getString(R.string.active));
    } else {
      mLayout.setStatus(getString(R.string.status) + " " + getString(R.string.inactive));
    }
    mLayout.setStatusSwitch(mUserInfo.isActive());
    mLayout.setDateStart(
        mUserInfo.getTimeFormmat(
            mTimeConvertProvider,
            User.UserTimeType.start_datetime,
            TimeConvertProvider.DATE_TYPE.FORMAT_DATE));
    mLayout.setDateEnd(
        mUserInfo.getTimeFormmat(
            mTimeConvertProvider,
            User.UserTimeType.expiry_datetime,
            TimeConvertProvider.DATE_TYPE.FORMAT_DATE));
    setAccessGroupCount();
    setFingerCount();
    setCardCount();

    if (mUserInfo.pin_exist || (mPinData != null && !mPinData.isEmpty())) {
      mLayout.setPin(getString(R.string.password_display));
    } else {
      mLayout.setPin("");
    }
    mPinSwitch.init(
        getActivity(),
        new OnChangeListener() {
          @Override
          public void onChange(boolean on) {
            if (BuildConfig.DEBUG) {
              Log.e(TAG, "pin :" + on);
            }
            if (on) {
              showPinPasswodPopup();
            } else {
              mLayout.setPin("");
              mPinData = null;
            }
          }
        },
        (mUserInfo.pin_exist || (mPinData != null && !mPinData.isEmpty())));
    mPinSwitch.setSwitch((mUserInfo.pin_exist || (mPinData != null && !mPinData.isEmpty())));
    mLayout.setUserPhotoDefault();
    if (mRbmp != null) {
      mLayout.setUserPhoto(mRbmp);
    } else if (bmp != null) {
      mRbmp = ImageUtil.getRoundedBitmap(bmp, false);
      mLayout.setUserPhoto(mRbmp);
    } else {
      if (mUserInfo.photo != null && !mUserInfo.photo.isEmpty()) {
        byte[] photoByte = Base64.decode(mUserInfo.photo, 0);
        bmp = ImageUtil.byteArrayToBitmap(photoByte);
        if (bmp != null) {
          mBlurBmp = ImageUtil.fastBlur(bmp, 32);
          mLayout.setBlurBackGroud(mBlurBmp);
          mRbmp = ImageUtil.getRoundedBitmap(bmp, false);
          mLayout.setUserPhoto(mRbmp);
        }
      }
    }
    isExistImageCheck();
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (super.onOptionsItemSelected(item)) {
      return true;
    }
    switch (item.getItemId()) {
      case R.id.action_save:
        if (mInvalidChecker.isEmptyString(
            getString(R.string.info), getString(R.string.user_create_empty), mLayout.getUserID())) {
          return true;
        }

        if (mLayout.isOperator()) {
          if (mInvalidChecker.isEmptyString(
              getString(R.string.info),
              getString(R.string.user_create_empty_idpassword),
              mLayout.getUserLoginID())) {
            return true;
          }
          if (!mUserInfo.password_exist) {
            if (mPasswordData == null) {
              mPopup.show(
                  PopupType.ALERT,
                  getString(R.string.info),
                  getString(R.string.user_create_empty_idpassword),
                  null,
                  null,
                  null);
              return true;
            }
          }
        }

        if (mInvalidChecker.isInvalidEmail(
            getString(R.string.info), getString(R.string.invalid_email), mLayout.getEmail())) {
          return true;
        }

        if (mPinData != null && mPinData.length() > 0 && mPinData.length() < 4) {
          mPopup.show(
              PopupType.ALERT,
              getString(R.string.info),
              getString(R.string.pincount),
              null,
              null,
              null);
          return true;
        }

        UpdateClone();
        mPopup.showWait(true);
        User user = null;
        try {
          user = mUserInfo.clone();
        } catch (CloneNotSupportedException e) {
          e.printStackTrace();
          return true;
        }
        user.setMyProfile();
        mUserDataProvider.modifyMyProfile(
            TAG, user, mModifyUserListener, mModifyUserErrorListener, null);
        return true;
      default:
        break;
    }
    return false;
  }
  private void UpdateClone() {
    if (mUserInfo.roles != null && mUserInfo.roles.size() > 0) {
      mUserInfo.password = mPasswordData;
      if (mLayout.getUserLoginID().equals("")) {
        mUserInfo.login_id = null;
      } else {
        mUserInfo.login_id = mLayout.getUserLoginID();
      }
    } else {
      mUserInfo.login_id = null;
      mUserInfo.password = null;
    }

    mUserInfo.name = mLayout.getUserName();
    mUserInfo.email = mLayout.getEmail();
    mUserInfo.phone_number = mLayout.getTelephone();

    if (mPinSwitch.getOn()) {
      if (mPinData != null && mPinData.length() > 3) {
        mUserInfo.pin_exist = true;
        mUserInfo.pin = mPinData;
      }
    } else {
      mUserInfo.pin = "";
    }

    switch (mPhotoStatus) {
      case NOT_MODIFY:
        if (mUserInfo.photo != null) {
          mBackupPhoto = mUserInfo.photo;
        }
        mUserInfo.photo = null;
        break;
      case MODIFY:
        break;
      case DELETE:
        mUserInfo.photo = "";
        break;
    }
  }