Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5028)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java

Issue 2912083003: Replace assets for avatar placeholder on Android (Closed)
Patch Set: Use vector asset for account avatar picture Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java
index a1fafb5f57fbb4b1ff98701e73a7307236f11330..fd093b82ad0a31296ee08e9ba84e9f87a7d48cc5 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/signin/AccountManagementFragment.java
@@ -31,6 +31,7 @@ import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.support.annotation.Nullable;
+import android.support.v7.content.res.AppCompatResources;
import android.text.TextUtils;
import android.util.Pair;
import android.widget.ListView;
@@ -436,8 +437,8 @@ public class AccountManagementFragment extends PreferenceFragment
boolean isChildAccount = mProfile.isChild();
pref.setUseReducedPadding(isChildAccount);
pref.setIcon(new BitmapDrawable(getResources(),
- isChildAccount ? getBadgedUserPicture(account.name, getResources()) :
- getUserPicture(account.name, getResources())));
+ isChildAccount ? getBadgedUserPicture(account.name, getActivity())
+ : getUserPicture(account.name, getActivity())));
pref.setOrder(nextPrefOrder++);
prefScreen.addPreference(pref);
@@ -450,7 +451,7 @@ public class AccountManagementFragment extends PreferenceFragment
@Override
public void onProfileDownloaded(String accountId, String fullName, String givenName,
Bitmap bitmap) {
- updateUserNamePictureCache(accountId, fullName, bitmap);
+ updateUserNamePictureCache(getActivity(), accountId, fullName, bitmap);
updateAccountsList();
}
@@ -568,23 +569,24 @@ public class AccountManagementFragment extends PreferenceFragment
* @param bitmap A bitmap to convert.
* @return A rounded picture bitmap.
*/
- public static Bitmap makeRoundUserPicture(Bitmap bitmap) {
+ public static Bitmap makeRoundUserPicture(Context context, Bitmap bitmap) {
if (bitmap == null) return null;
- Bitmap output = Bitmap.createBitmap(
- bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
+ int imageSizePx = context.getResources().getDimensionPixelSize(R.dimen.user_picture_size);
+ Bitmap output = Bitmap.createBitmap(imageSizePx, imageSizePx, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
- final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
-
canvas.drawARGB(0, 0, 0, 0);
paint.setAntiAlias(true);
paint.setColor(0xFFFFFFFF);
canvas.drawCircle(bitmap.getWidth() * 0.5f, bitmap.getHeight() * 0.5f,
bitmap.getWidth() * 0.5f, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
- canvas.drawBitmap(bitmap, rect, rect, paint);
+
+ Rect srcRect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
+ Rect dstRect = new Rect(0, 0, imageSizePx, imageSizePx);
+ canvas.drawBitmap(bitmap, srcRect, dstRect, paint);
return output;
}
@@ -631,10 +633,10 @@ public class AccountManagementFragment extends PreferenceFragment
* @param bitmap User picture.
*/
public static void updateUserNamePictureCache(
- String accountId, String fullName, Bitmap bitmap) {
+ Context context, String accountId, String fullName, Bitmap bitmap) {
sChildAccountId = null;
sCachedBadgedPicture = null;
- sToNamePicture.put(accountId, new Pair<>(fullName, makeRoundUserPicture(bitmap)));
+ sToNamePicture.put(accountId, new Pair<>(fullName, makeRoundUserPicture(context, bitmap)));
}
/**
@@ -653,15 +655,17 @@ public class AccountManagementFragment extends PreferenceFragment
* @param accountId A child account.
* @return A user picture with badge for a given child account.
*/
- public static Bitmap getBadgedUserPicture(String accountId, Resources res) {
+ public static Bitmap getBadgedUserPicture(String accountId, Context context) {
if (sChildAccountId != null) {
assert TextUtils.equals(accountId, sChildAccountId);
return sCachedBadgedPicture;
}
sChildAccountId = accountId;
- Bitmap picture = getUserPicture(accountId, res);
- Bitmap badge = BitmapFactory.decodeResource(res, R.drawable.ic_account_child_20dp);
- sCachedBadgedPicture = overlayChildBadgeOnUserPicture(picture, badge, res);
+ Bitmap picture = getUserPicture(accountId, context);
+ Bitmap badge = BitmapFactory.decodeResource(
+ context.getResources(), R.drawable.ic_account_child_20dp);
+ sCachedBadgedPicture =
+ overlayChildBadgeOnUserPicture(picture, badge, context.getResources());
return sCachedBadgedPicture;
}
@@ -670,13 +674,23 @@ public class AccountManagementFragment extends PreferenceFragment
* unavailable.
*
* @param accountId An account.
- * @param resources The collection containing the application resources.
+ * @param context
Theresa 2017/06/01 23:22:15 nit: Add a JavaDoc description for context and add
bsazonov 2017/06/02 13:17:20 Done. I've also reordered params in some method to
* @return A user picture for a given account.
*/
- public static Bitmap getUserPicture(String accountId, Resources resources) {
+ public static Bitmap getUserPicture(String accountId, Context context) {
Pair<String, Bitmap> pair = sToNamePicture.get(accountId);
- return pair != null ? pair.second : BitmapFactory.decodeResource(resources,
- R.drawable.account_management_no_picture);
+ return pair != null ? pair.second : getAvatarPlaceholder(context);
+ }
+
+ private static Bitmap getAvatarPlaceholder(Context context) {
+ Drawable drawable =
+ AppCompatResources.getDrawable(context, R.drawable.logo_avatar_anonymous);
+ int imageSizePx = context.getResources().getDimensionPixelOffset(R.dimen.user_picture_size);
+ Bitmap bitmap = Bitmap.createBitmap(imageSizePx, imageSizePx, Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ drawable.draw(canvas);
+ return bitmap;
}
/**

Powered by Google App Engine
This is Rietveld 408576698