Search in sources :

Example 1 with LetterTileDrawable

use of com.android.contacts.common.lettertiles.LetterTileDrawable in project android_packages_apps_Dialer by LineageOS.

the class IconFactory method createFlatIcon.

private Icon createFlatIcon(@NonNull String displayName, @NonNull String lookupKey, @Nullable InputStream inputStream) {
    Drawable drawable;
    if (inputStream == null) {
        // No photo for contact; use a letter tile.
        LetterTileDrawable letterTileDrawable = new LetterTileDrawable(context.getResources());
        letterTileDrawable.setCanonicalDialerLetterTileDetails(displayName, lookupKey, LetterTileDrawable.SHAPE_CIRCLE, LetterTileDrawable.TYPE_DEFAULT);
        drawable = letterTileDrawable;
    } else {
        // There's a photo, create a circular drawable from it.
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
        drawable = createCircularDrawable(bitmap);
    }
    int iconSize = context.getResources().getDimensionPixelSize(R.dimen.launcher_shortcut_icon_size);
    return Icon.createWithBitmap(DrawableConverter.drawableToBitmap(drawable, iconSize, /* width */
    iconSize));
}
Also used : Bitmap(android.graphics.Bitmap) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) Drawable(android.graphics.drawable.Drawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable)

Example 2 with LetterTileDrawable

use of com.android.contacts.common.lettertiles.LetterTileDrawable in project android_packages_apps_Dialer by LineageOS.

the class ContactPhotoLoader method createLetterTileDrawable.

/**
 * @return a {@link LetterTileDrawable} based on the ContactInfo.
 */
private Drawable createLetterTileDrawable() {
    ContactInfoHelper helper = new ContactInfoHelper(mContext, GeoUtil.getCurrentCountryIso(mContext));
    LetterTileDrawable drawable = new LetterTileDrawable(mContext.getResources());
    drawable.setCanonicalDialerLetterTileDetails(mContactInfo.name, mContactInfo.lookupKey, LetterTileDrawable.SHAPE_CIRCLE, helper.isBusiness(mContactInfo.sourceType) ? LetterTileDrawable.TYPE_BUSINESS : LetterTileDrawable.TYPE_DEFAULT);
    return drawable;
}
Also used : ContactInfoHelper(com.android.dialer.phonenumbercache.ContactInfoHelper) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable)

Example 3 with LetterTileDrawable

use of com.android.contacts.common.lettertiles.LetterTileDrawable in project android_packages_apps_Dialer by MoKee.

the class ContactPhotoLoader method createLetterTileDrawable.

/**
 * @return a {@link LetterTileDrawable} based on the ContactInfo.
 */
private Drawable createLetterTileDrawable() {
    LetterTileDrawable drawable = new LetterTileDrawable(mContext.getResources());
    drawable.setIsCircular(true);
    ContactInfoHelper helper = new ContactInfoHelper(mContext, GeoUtil.getCurrentCountryIso(mContext));
    if (helper.isBusiness(mContactInfo.sourceType)) {
        drawable.setContactType(LetterTileDrawable.TYPE_BUSINESS);
    }
    drawable.setLetterAndColorFromContactDetails(mContactInfo.name, mContactInfo.lookupKey);
    return drawable;
}
Also used : ContactInfoHelper(com.android.dialer.calllog.ContactInfoHelper) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable)

Example 4 with LetterTileDrawable

use of com.android.contacts.common.lettertiles.LetterTileDrawable in project android_packages_apps_Dialer by MoKee.

the class ContactPhotoLoaderTest method testGetIcon_Photo_Invalid.

public void testGetIcon_Photo_Invalid() {
    ContactInfo info = getTestContactInfo();
    info.photoUri = Uri.parse("file://invalid/uri");
    ContactPhotoLoader loader = new ContactPhotoLoader(mContext, info);
    // Should fall back to LetterTileDrawable
    assertTrue(loader.getIcon() instanceof LetterTileDrawable);
}
Also used : LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) ContactInfo(com.android.dialer.calllog.ContactInfo)

Example 5 with LetterTileDrawable

use of com.android.contacts.common.lettertiles.LetterTileDrawable in project packages_apps_Contacts by AOKP.

the class QuickContactActivity method extractAndApplyTintFromPhotoViewAsynchronously.

/**
 * Asynchronously extract the most vibrant color from the PhotoView. Once extracted,
 * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms
 * on a Nexus 5.
 */
private void extractAndApplyTintFromPhotoViewAsynchronously() {
    if (mScroller == null) {
        return;
    }
    final Drawable imageViewDrawable = mPhotoView.getDrawable();
    new AsyncTask<Void, Void, MaterialPalette>() {

        @Override
        protected MaterialPalette doInBackground(Void... params) {
            if (imageViewDrawable instanceof BitmapDrawable && mContactData != null && 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();
                return mMaterialColorMapUtils.calculatePrimaryAndSecondaryColor(primaryColor);
            }
            return MaterialColorMapUtils.getDefaultPrimaryAndSecondaryColors(getResources());
        }

        @Override
        protected void onPostExecute(MaterialPalette palette) {
            super.onPostExecute(palette);
            if (mHasComputedThemeColor) {
                // a rotation or onNewIntent() is perfectly fine.
                return;
            }
            // color needs to be extracted
            if (imageViewDrawable == mPhotoView.getDrawable()) {
                mHasComputedThemeColor = true;
                setThemeColor(palette);
                // update color and photo in suggestion card
                onAggregationSuggestionChange();
            }
        }
    }.execute();
}
Also used : Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) LetterTileDrawable(com.android.contacts.common.lettertiles.LetterTileDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) MaterialPalette(com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette)

Aggregations

LetterTileDrawable (com.android.contacts.common.lettertiles.LetterTileDrawable)11 Bitmap (android.graphics.Bitmap)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 Drawable (android.graphics.drawable.Drawable)3 LayoutInflater (android.view.LayoutInflater)2 ImageView (android.widget.ImageView)2 ContactInfo (com.android.dialer.calllog.ContactInfo)2 Resources (android.content.res.Resources)1 AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 RequiresApi (android.support.annotation.RequiresApi)1 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)1 ContactType (com.android.contacts.common.lettertiles.LetterTileDrawable.ContactType)1 MaterialPalette (com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette)1 ContactInfoHelper (com.android.dialer.calllog.ContactInfoHelper)1 ContactInfoHelper (com.android.dialer.phonenumbercache.ContactInfoHelper)1 VisualVoicemailEnabledChecker (com.android.dialer.voicemail.VisualVoicemailEnabledChecker)1 VisualVoicemailEnabledChecker (com.android.dialer.voicemailstatus.VisualVoicemailEnabledChecker)1