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

Commit 95c268e8 authored by Brian Attwell's avatar Brian Attwell
Browse files

Use thumbnail for color extraction

Previously, Contacts was downscaling the full sized image returned from
ContactsLoader. The resulting thumbnail was different enough from the thumbnails
synced by ContactSyncAdapter that about 20% of contact photos had different
extracted colors in Bugle and Contacts.

Bug: 17258486
Change-Id: I8e2cd239195a18afbe0610e47104d7cbe63d3f23
parent 3d29145a
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.Loader;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
@@ -1475,13 +1476,24 @@ public class QuickContactActivity extends ContactsActivity {
            @Override
            protected MaterialPalette doInBackground(Void... params) {

                if (imageViewDrawable instanceof BitmapDrawable) {
                    final Bitmap bitmap = ((BitmapDrawable) imageViewDrawable).getBitmap();
                if (imageViewDrawable instanceof BitmapDrawable
                        && mContactData.getThumbnailPhotoBinaryData() != null
                        && mContactData.getThumbnailPhotoBinaryData().length > 0) {
                    // Perform the color analysis on the thumbnail instead of the full sized
                    // image, so that our results will be as similar as possible to the Bugle
                    // app.
                    final Bitmap bitmap = BitmapFactory.decodeByteArray(
                            mContactData.getThumbnailPhotoBinaryData(), 0,
                            mContactData.getThumbnailPhotoBinaryData().length);
                    try {
                        final int primaryColor = colorFromBitmap(bitmap);
                        if (primaryColor != 0) {
                            return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(
                                    primaryColor);
                        }
                    } finally {
                        bitmap.recycle();
                    }
                }
                if (imageViewDrawable instanceof LetterTileDrawable) {
                    final int primaryColor = ((LetterTileDrawable) imageViewDrawable).getColor();