Loading packages/SettingsLib/src/com/android/settingslib/users/CreateUserDialogController.java +23 −27 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public class CreateUserDialogController { private Bitmap mSavedPhoto; private String mSavedName; private Drawable mSavedDrawable; private String mCachedDrawablePath; private String mUserName; private Drawable mNewUserIcon; private Boolean mIsAdmin; Loading Loading @@ -117,6 +118,7 @@ public class CreateUserDialogController { mUserNameView = null; mSuccessCallback = null; mCancelCallback = null; mCachedDrawablePath = null; mCurrentState = INITIAL_DIALOG; } Loading @@ -124,13 +126,7 @@ public class CreateUserDialogController { * Notifies that the containing activity or fragment was reinitialized. */ public void onRestoreInstanceState(Bundle savedInstanceState) { String pendingPhoto = savedInstanceState.getString(KEY_SAVED_PHOTO); if (pendingPhoto != null) { ThreadUtils.postOnBackgroundThread(() -> { mSavedPhoto = EditUserPhotoController.loadNewUserPhotoBitmap( new File(pendingPhoto)); }); } mCachedDrawablePath = savedInstanceState.getString(KEY_SAVED_PHOTO); mCurrentState = savedInstanceState.getInt(KEY_CURRENT_STATE); if (savedInstanceState.containsKey(KEY_IS_ADMIN)) { mIsAdmin = savedInstanceState.getBoolean(KEY_IS_ADMIN); Loading @@ -143,15 +139,12 @@ public class CreateUserDialogController { * Notifies that the containing activity or fragment is saving its state for later use. */ public void onSaveInstanceState(Bundle savedInstanceState) { if (mUserCreationDialog != null && mEditUserPhotoController != null) { // Bitmap cannot be stored into bundle because it may exceed parcel limit // Store it in a temporary file instead ThreadUtils.postOnBackgroundThread(() -> { File file = mEditUserPhotoController.saveNewUserPhotoBitmap(); if (file != null) { savedInstanceState.putString(KEY_SAVED_PHOTO, file.getPath()); if (mUserCreationDialog != null && mEditUserPhotoController != null && mCachedDrawablePath == null) { mCachedDrawablePath = mEditUserPhotoController.getCachedDrawablePath(); } }); if (mCachedDrawablePath != null) { savedInstanceState.putString(KEY_SAVED_PHOTO, mCachedDrawablePath); } if (mIsAdmin != null) { savedInstanceState.putBoolean(KEY_IS_ADMIN, Boolean.TRUE.equals(mIsAdmin)); Loading Loading @@ -271,9 +264,10 @@ public class CreateUserDialogController { mGrantAdminView.setVisibility(View.GONE); break; case CREATE_USER_AND_CLOSE: mNewUserIcon = mEditUserPhotoController != null mNewUserIcon = (mEditUserPhotoController != null && mEditUserPhotoController.getNewUserPhotoDrawable() != null) ? mEditUserPhotoController.getNewUserPhotoDrawable() : null; : mSavedDrawable; String newName = mUserNameView.getText().toString().trim(); String defaultName = mActivity.getString(R.string.user_new_user_name); Loading @@ -295,12 +289,17 @@ public class CreateUserDialogController { } } private Drawable getUserIcon(Drawable defaultUserIcon) { if (mSavedPhoto != null) { private void setUserIcon(Drawable defaultUserIcon, ImageView userPhotoView) { if (mCachedDrawablePath != null) { ThreadUtils.postOnBackgroundThread(() -> { mSavedPhoto = EditUserPhotoController.loadNewUserPhotoBitmap( new File(mCachedDrawablePath)); mSavedDrawable = CircleFramedDrawable.getInstance(mActivity, mSavedPhoto); return mSavedDrawable; ThreadUtils.postOnMainThread(() -> userPhotoView.setImageDrawable(mSavedDrawable)); }); } else { userPhotoView.setImageDrawable(defaultUserIcon); } return defaultUserIcon; } private void addUserInfoEditView() { Loading @@ -312,10 +311,7 @@ public class CreateUserDialogController { // if oldUserIcon param is null then we use a default gray user icon Drawable defaultUserIcon = UserIcons.getDefaultUserIcon( mActivity.getResources(), UserHandle.USER_NULL, false); // in case a new photo was selected and the activity got recreated we have to load the image Drawable userIcon = getUserIcon(defaultUserIcon); userPhotoView.setImageDrawable(userIcon); setUserIcon(defaultUserIcon, userPhotoView); if (isChangePhotoRestrictedByBase(mActivity)) { // some users can't change their photos so we need to remove the suggestive icon mEditUserInfoView.findViewById(R.id.add_a_photo_icon).setVisibility(View.GONE); Loading packages/SettingsLib/src/com/android/settingslib/users/EditUserPhotoController.java +8 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ public class EditUserPhotoController { private final File mImagesDir; private Bitmap mNewUserPhotoBitmap; private Drawable mNewUserPhotoDrawable; private String mCachedDrawablePath; public EditUserPhotoController(Activity activity, ActivityStarter activityStarter, ImageView view, Bitmap savedBitmap, Drawable savedDrawable, String fileAuthority) { Loading Loading @@ -156,6 +157,9 @@ public class EditUserPhotoController { private void onPhotoProcessed(Bitmap bitmap) { if (bitmap != null) { mNewUserPhotoBitmap = bitmap; ThreadUtils.postOnBackgroundThread(() -> { mCachedDrawablePath = saveNewUserPhotoBitmap().getPath(); }); mNewUserPhotoDrawable = CircleFramedDrawable .getInstance(mImageView.getContext(), mNewUserPhotoBitmap); mImageView.setImageDrawable(mNewUserPhotoDrawable); Loading Loading @@ -186,4 +190,8 @@ public class EditUserPhotoController { void removeNewUserPhotoBitmapFile() { new File(mImagesDir, NEW_USER_PHOTO_FILE_NAME).delete(); } String getCachedDrawablePath() { return mCachedDrawablePath; } } Loading
packages/SettingsLib/src/com/android/settingslib/users/CreateUserDialogController.java +23 −27 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public class CreateUserDialogController { private Bitmap mSavedPhoto; private String mSavedName; private Drawable mSavedDrawable; private String mCachedDrawablePath; private String mUserName; private Drawable mNewUserIcon; private Boolean mIsAdmin; Loading Loading @@ -117,6 +118,7 @@ public class CreateUserDialogController { mUserNameView = null; mSuccessCallback = null; mCancelCallback = null; mCachedDrawablePath = null; mCurrentState = INITIAL_DIALOG; } Loading @@ -124,13 +126,7 @@ public class CreateUserDialogController { * Notifies that the containing activity or fragment was reinitialized. */ public void onRestoreInstanceState(Bundle savedInstanceState) { String pendingPhoto = savedInstanceState.getString(KEY_SAVED_PHOTO); if (pendingPhoto != null) { ThreadUtils.postOnBackgroundThread(() -> { mSavedPhoto = EditUserPhotoController.loadNewUserPhotoBitmap( new File(pendingPhoto)); }); } mCachedDrawablePath = savedInstanceState.getString(KEY_SAVED_PHOTO); mCurrentState = savedInstanceState.getInt(KEY_CURRENT_STATE); if (savedInstanceState.containsKey(KEY_IS_ADMIN)) { mIsAdmin = savedInstanceState.getBoolean(KEY_IS_ADMIN); Loading @@ -143,15 +139,12 @@ public class CreateUserDialogController { * Notifies that the containing activity or fragment is saving its state for later use. */ public void onSaveInstanceState(Bundle savedInstanceState) { if (mUserCreationDialog != null && mEditUserPhotoController != null) { // Bitmap cannot be stored into bundle because it may exceed parcel limit // Store it in a temporary file instead ThreadUtils.postOnBackgroundThread(() -> { File file = mEditUserPhotoController.saveNewUserPhotoBitmap(); if (file != null) { savedInstanceState.putString(KEY_SAVED_PHOTO, file.getPath()); if (mUserCreationDialog != null && mEditUserPhotoController != null && mCachedDrawablePath == null) { mCachedDrawablePath = mEditUserPhotoController.getCachedDrawablePath(); } }); if (mCachedDrawablePath != null) { savedInstanceState.putString(KEY_SAVED_PHOTO, mCachedDrawablePath); } if (mIsAdmin != null) { savedInstanceState.putBoolean(KEY_IS_ADMIN, Boolean.TRUE.equals(mIsAdmin)); Loading Loading @@ -271,9 +264,10 @@ public class CreateUserDialogController { mGrantAdminView.setVisibility(View.GONE); break; case CREATE_USER_AND_CLOSE: mNewUserIcon = mEditUserPhotoController != null mNewUserIcon = (mEditUserPhotoController != null && mEditUserPhotoController.getNewUserPhotoDrawable() != null) ? mEditUserPhotoController.getNewUserPhotoDrawable() : null; : mSavedDrawable; String newName = mUserNameView.getText().toString().trim(); String defaultName = mActivity.getString(R.string.user_new_user_name); Loading @@ -295,12 +289,17 @@ public class CreateUserDialogController { } } private Drawable getUserIcon(Drawable defaultUserIcon) { if (mSavedPhoto != null) { private void setUserIcon(Drawable defaultUserIcon, ImageView userPhotoView) { if (mCachedDrawablePath != null) { ThreadUtils.postOnBackgroundThread(() -> { mSavedPhoto = EditUserPhotoController.loadNewUserPhotoBitmap( new File(mCachedDrawablePath)); mSavedDrawable = CircleFramedDrawable.getInstance(mActivity, mSavedPhoto); return mSavedDrawable; ThreadUtils.postOnMainThread(() -> userPhotoView.setImageDrawable(mSavedDrawable)); }); } else { userPhotoView.setImageDrawable(defaultUserIcon); } return defaultUserIcon; } private void addUserInfoEditView() { Loading @@ -312,10 +311,7 @@ public class CreateUserDialogController { // if oldUserIcon param is null then we use a default gray user icon Drawable defaultUserIcon = UserIcons.getDefaultUserIcon( mActivity.getResources(), UserHandle.USER_NULL, false); // in case a new photo was selected and the activity got recreated we have to load the image Drawable userIcon = getUserIcon(defaultUserIcon); userPhotoView.setImageDrawable(userIcon); setUserIcon(defaultUserIcon, userPhotoView); if (isChangePhotoRestrictedByBase(mActivity)) { // some users can't change their photos so we need to remove the suggestive icon mEditUserInfoView.findViewById(R.id.add_a_photo_icon).setVisibility(View.GONE); Loading
packages/SettingsLib/src/com/android/settingslib/users/EditUserPhotoController.java +8 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ public class EditUserPhotoController { private final File mImagesDir; private Bitmap mNewUserPhotoBitmap; private Drawable mNewUserPhotoDrawable; private String mCachedDrawablePath; public EditUserPhotoController(Activity activity, ActivityStarter activityStarter, ImageView view, Bitmap savedBitmap, Drawable savedDrawable, String fileAuthority) { Loading Loading @@ -156,6 +157,9 @@ public class EditUserPhotoController { private void onPhotoProcessed(Bitmap bitmap) { if (bitmap != null) { mNewUserPhotoBitmap = bitmap; ThreadUtils.postOnBackgroundThread(() -> { mCachedDrawablePath = saveNewUserPhotoBitmap().getPath(); }); mNewUserPhotoDrawable = CircleFramedDrawable .getInstance(mImageView.getContext(), mNewUserPhotoBitmap); mImageView.setImageDrawable(mNewUserPhotoDrawable); Loading Loading @@ -186,4 +190,8 @@ public class EditUserPhotoController { void removeNewUserPhotoBitmapFile() { new File(mImagesDir, NEW_USER_PHOTO_FILE_NAME).delete(); } String getCachedDrawablePath() { return mCachedDrawablePath; } }