/** Key for extra passed in from calling fragment to indicate if this is a newly created user */
public static final String EXTRA_NEW_USER = "new_user";
+ private static final String KEY_SAVED_PHOTO = "pending_photo";
+
HashMap<String,Boolean> mSelectedPackages = new HashMap<String,Boolean>();
private boolean mFirstTime = true;
private boolean mNewUser;
private Dialog mEditUserInfoDialog;
private EditUserPhotoController mEditUserPhotoController;
+ private Bitmap mSavedPhoto;
private BroadcastReceiver mUserBackgrounding = new BroadcastReceiver() {
@Override
if (icicle != null) {
mUser = new UserHandle(icicle.getInt(EXTRA_USER_ID));
+ mSavedPhoto = (Bitmap) icicle.getParcelable(KEY_SAVED_PHOTO);
} else {
Bundle args = getArguments();
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(EXTRA_USER_ID, mUser.getIdentifier());
+ if (mEditUserInfoDialog != null && mEditUserInfoDialog.isShowing()
+ && mEditUserPhotoController != null) {
+ outState.putParcelable(KEY_SAVED_PHOTO,
+ mEditUserPhotoController.getNewUserPhotoBitmap());
+ }
}
public void onResume() {
new AppLoadingTask().execute((Void[]) null);
UserInfo info = mUserManager.getUserInfo(mUser.getIdentifier());
- Bitmap userIcon = mUserManager.getUserIcon(mUser.getIdentifier());
- CircleFramedDrawable circularIcon =
- CircleFramedDrawable.getInstance(this.getActivity(), userIcon);
((TextView) mHeaderView.findViewById(android.R.id.title)).setText(info.name);
- ((ImageView) mHeaderView.findViewById(android.R.id.icon)).setImageDrawable(circularIcon);
+ ((ImageView) mHeaderView.findViewById(android.R.id.icon)).setImageDrawable(
+ getCircularUserIcon());
}
public void onPause() {
}
}
+ private Drawable getCircularUserIcon() {
+ Bitmap userIcon = mUserManager.getUserIcon(mUser.getIdentifier());
+ CircleFramedDrawable circularIcon =
+ CircleFramedDrawable.getInstance(this.getActivity(), userIcon);
+ return circularIcon;
+ }
+
private void updateUserAppList() {
IPackageManager ipm = IPackageManager.Stub.asInterface(
ServiceManager.getService("package"));
userNameView.setText(info.name);
final ImageView userPhotoView = (ImageView) content.findViewById(R.id.user_photo);
- userPhotoView.setImageDrawable(mUserIconView.getDrawable());
+ Drawable drawable = null;
+ if (mSavedPhoto != null) {
+ drawable = CircleFramedDrawable.getInstance(getActivity(), mSavedPhoto);
+ } else {
+ drawable = mUserIconView.getDrawable();
+ if (drawable == null) {
+ drawable = getCircularUserIcon();
+ }
+ }
+ userPhotoView.setImageDrawable(drawable);
- mEditUserPhotoController = new EditUserPhotoController(this, userPhotoView);
+ mEditUserPhotoController = new EditUserPhotoController(this, userPhotoView,
+ mSavedPhoto, drawable);
mEditUserInfoDialog = new AlertDialog.Builder(getActivity())
.setTitle(R.string.user_info_settings_title)
}
}
// Update the photo if changed.
- Drawable userPhoto = mEditUserPhotoController.getNewUserPhotoDrawable();
- if (userPhoto != null
- && !userPhoto.equals(mUserIconView.getDrawable())) {
- mUserIconView.setImageDrawable(userPhoto);
+ Drawable drawable = mEditUserPhotoController.getNewUserPhotoDrawable();
+ Bitmap bitmap = mEditUserPhotoController.getNewUserPhotoBitmap();
+ if (drawable != null && bitmap != null
+ && !drawable.equals(mUserIconView.getDrawable())) {
+ mUserIconView.setImageDrawable(drawable);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
}
removeDialog(DIALOG_ID_EDIT_USER_INFO);
}
+ clearEditUserInfoDialog();
}
})
- .setNegativeButton(android.R.string.cancel, null)
+ .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ clearEditUserInfoDialog();
+ }
+ })
.create();
// Make sure the IME is up.
return null;
}
+ private void clearEditUserInfoDialog() {
+ mEditUserInfoDialog = null;
+ mSavedPhoto = null;
+ }
+
private static class EditUserPhotoController {
private static final int POPUP_LIST_ITEM_ID_CHOOSE_PHOTO = 1;
private static final int POPUP_LIST_ITEM_ID_TAKE_PHOTO = 2;
private Bitmap mNewUserPhotoBitmap;
private Drawable mNewUserPhotoDrawable;
- public EditUserPhotoController(Fragment fragment, ImageView view) {
+ public EditUserPhotoController(Fragment fragment, ImageView view,
+ Bitmap bitmap, Drawable drawable) {
mContext = view.getContext();
mFragment = fragment;
mImageView = view;
showUpdatePhotoPopup();
}
});
+ mNewUserPhotoBitmap = bitmap;
+ mNewUserPhotoDrawable = drawable;
}
public boolean onActivityResult(int requestCode, int resultCode, final Intent data) {