Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f3a0b8f authored by Oli Lan's avatar Oli Lan
Browse files

Offer colored default avatars if no preselected images are provided.

In the new avatar picker, if no preselected images have been provided,
this CL adds several color variations of the default avatar to the
picker instead.

Bug: 215134398
Test: manual
Change-Id: I3e1f617c760b241517f94c606f5cb21eafcc022d
parent b4751120
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.util;

import android.annotation.ColorInt;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@@ -72,9 +73,30 @@ public class UserIcons {
            // Return colored icon instead
            colorResId = USER_ICON_COLORS[userId % USER_ICON_COLORS.length];
        }
        return getDefaultUserIconInColor(resources, resources.getColor(colorResId, null));
    }

    /**
     * Returns a default user icon in a particular color.
     *
     * @param resources resources object to fetch the user icon
     * @param color the color used for the icon
     */
    public static Drawable getDefaultUserIconInColor(Resources resources, @ColorInt int color) {
        Drawable icon = resources.getDrawable(R.drawable.ic_account_circle, null).mutate();
        icon.setColorFilter(resources.getColor(colorResId, null), Mode.SRC_IN);
        icon.setColorFilter(color, Mode.SRC_IN);
        icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
        return icon;
    }

    /**
     * Returns an array containing colors to be used for default user icons.
     */
    public static int[] getUserIconColors(Resources resources) {
        int[] result = new int[USER_ICON_COLORS.length];
        for (int i = 0; i < result.length; i++) {
            result[i] = resources.getColor(USER_ICON_COLORS[i], null);
        }
        return result;
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true">
        <shape android:shape="oval">
            <solid android:color="?android:attr/colorPrimary"/>
            <stroke
                android:color="?android:attr/colorPrimary"
                android:width="@dimen/avatar_picker_padding"/>
        </shape>
    </item>
</selector>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
    android:id="@+id/glif_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:icon="@drawable/ic_account_circle"
    android:icon="@drawable/ic_account_circle_outline"
    app:sucUsePartnerResource="true"
    app:sucHeaderText="@string/avatar_picker_title">

+2 −2
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ class AvatarPhotoController {

        switch (requestCode) {
            case REQUEST_CODE_CROP_PHOTO:
                mActivity.returnResult(pictureUri);
                mActivity.returnUriResult(pictureUri);
                return true;
            case REQUEST_CODE_TAKE_PHOTO:
            case REQUEST_CODE_CHOOSE_PHOTO:
@@ -232,7 +232,7 @@ class AvatarPhotoController {
            @Override
            protected void onPostExecute(Bitmap bitmap) {
                saveBitmapToFile(bitmap, new File(mImagesDir, CROP_PICTURE_FILE_NAME));
                mActivity.returnResult(mCropPictureUri);
                mActivity.returnUriResult(mCropPictureUri);
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
    }
Loading