@Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   final Activity activity = getActivity();
   mAccountManager = AccountManager.getInstance(activity);
   mSettingHelper = SettingHelper.getInstance(activity);
   mAvatarManager = AvatarManager.getInstance(activity);
   mThemeManager = ThemeManager.getInstance(activity);
   mUserTheme = getUserTheme();
   mNickname = mSettingHelper.getAccountNickname();
   mInfoAdapter = new PersonalInfoAdapter(activity, setupViewItems(activity));
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_personal_info, container, false);
    mHeaderView = rootView.findViewById(R.id.header);
    mTopImageView = (ImageView) rootView.findViewById(R.id.theme_top_image);
    mTopImageView.setOnLongClickListener(this);
    displayThemeImages();
    mAvatarImage = (ImageView) rootView.findViewById(R.id.avatar_image);
    MiscUtils.showAvatarThumb(
        mAvatarManager,
        mSettingHelper.getAccountAvatarThumb(),
        mAvatarImage,
        R.drawable.contact_single);
    mAvatarImage.setOnClickListener(this);
    mListView = (ListView) rootView.findViewById(R.id.list);
    View listHeader = inflater.inflate(R.layout.personal_info_list_header, mListView, false);
    mListHeaderView = listHeader;
    mListView.addHeaderView(listHeader);
    mListView.setAdapter(mInfoAdapter);
    mListView.setOnItemClickListener(mInfoAdapter);
    mListView.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {}

          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            ViewHelper.setTranslationY(
                mHeaderView, Math.max(-getScrollY(), -mHeaderView.getMeasuredHeight()));
          }
        });
    return rootView;
  }
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   switch (requestCode) {
     case REQUEST_CODE_UPLOAD_AVATAR:
       if (resultCode == Activity.RESULT_OK) {
         MiscUtils.showAvatarThumb(
             mAvatarManager,
             mSettingHelper.getAccountAvatarThumb(),
             mAvatarImage,
             R.drawable.contact_single);
       }
       break;
     default:
       break;
   }
 }
  @Override
  public void onResume() {
    super.onResume();
    UserTheme userTheme = getUserTheme();
    String oldThemeName = getThemeName(mUserTheme);
    String newThemeName = getThemeName(userTheme);
    if (newThemeName != null && !newThemeName.equals(oldThemeName)) {
      mUserTheme = userTheme;
      displayThemeImages();
    }

    String nickname = mSettingHelper.getAccountNickname();
    if (!TextUtils.isEmpty(nickname) && !nickname.equals(mNickname)) {
      mNickname = nickname;
      mInfoAdapter.updateItems(setupViewItems(getActivity()));
    }
  }
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    boolean handled = true;
    Activity activity = getActivity();

    switch (item.getItemId()) {
      case R.id.menu_show_avatar:
        UILauncher.launchShowFriendAvatarImage(activity, mSettingHelper.getAccountAvatar());
        break;
      case R.id.menu_upload_avatar:
        UILauncher.launchUploadAvatarUIAndSave(this, REQUEST_CODE_UPLOAD_AVATAR);
        break;
      case R.id.preview_all_info:
        UILauncher.launchMyInfoUI(activity);
        break;
      default:
        handled = false;
        break;
    }

    return handled || super.onContextItemSelected(item);
  }
 private UserTheme getUserTheme() {
   String themeName = mSettingHelper.getUserTheme();
   return TextUtils.isEmpty(themeName) ? null : UserTheme.fromThemeName(themeName);
 }