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));
}
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;
}
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;
}
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);
}
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();
}
Aggregations