Loading src/com/android/contacts/DynamicShortcuts.java +12 −9 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ public class DynamicShortcuts { // though new ones may be added private static final int SHORTCUT_TYPE_UNKNOWN = 0; private static final int SHORTCUT_TYPE_CONTACT_URI = 1; private static final int SHORTCUT_TYPE_ACTION_URI = 2; // The spec specifies that it should be 44dp @ xxxhdpi // Note that ShortcutManager.getIconMaxWidth and ShortcutManager.getMaxHeight return different Loading Loading @@ -163,8 +164,7 @@ public class DynamicShortcuts { for (ShortcutInfo shortcut : mShortcutManager.getPinnedShortcuts()) { final PersistableBundle extras = shortcut.getExtras(); if (!shortcut.isDynamic() || extras == null || extras.getInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_UNKNOWN) != if (extras == null || extras.getInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_UNKNOWN) != SHORTCUT_TYPE_CONTACT_URI) { continue; } Loading Loading @@ -285,7 +285,7 @@ public class DynamicShortcuts { return null; } final PersistableBundle extras = new PersistableBundle(); extras.putInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_CONTACT_URI); extras.putInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_ACTION_URI); final ShortcutInfo.Builder builder = new ShortcutInfo.Builder(mContext, id) .setIntent(action) Loading Loading @@ -325,12 +325,15 @@ public class DynamicShortcuts { private void addIconForContact(long id, String lookupKey, String displayName, ShortcutInfo.Builder builder) { final Bitmap bitmap = getContactPhoto(id); if (bitmap != null) { builder.setIcon(Icon.createWithBitmap(bitmap)); } else { builder.setIcon(Icon.createWithBitmap(getFallbackAvatar(displayName, lookupKey))); Bitmap bitmap = getContactPhoto(id); if (bitmap == null) { bitmap = getFallbackAvatar(displayName, lookupKey); } // TODO: Use createWithAdaptiveBitmap if >= O. Since we create these, we'll also need to // return AdaptiveIconDrawables when >= O as well. final Icon icon = Icon.createWithBitmap(bitmap); builder.setIcon(icon); } private Bitmap getContactPhoto(long id) { Loading src/com/android/contacts/ShortcutIntentBuilder.java +44 −51 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.contacts; import android.app.ActivityManager; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; import android.content.Intent; import android.content.pm.ShortcutInfo; Loading Loading @@ -50,10 +51,6 @@ import com.android.contacts.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.util.BitmapUtil; import com.android.contacts.util.ImplicitIntentsUtil; import com.google.common.collect.Lists; import java.util.List; /** * Constructs shortcut intents. */ Loading Loading @@ -269,6 +266,16 @@ public class ShortcutIntentBuilder { private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName, String lookupKey, byte[] bitmapData) { Intent intent = null; if (BuildCompat.isAtLeastO()) { final long contactId = ContentUris.parseId(contactUri); final ShortcutManager sm = (ShortcutManager) mContext.getSystemService(Context.SHORTCUT_SERVICE); final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getQuickContactShortcutInfo( contactId, lookupKey, displayName); intent = sm.createShortcutResultIntent(shortcutInfo); } final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); if (TextUtils.isEmpty(displayName)) { displayName = mContext.getResources().getString(R.string.missing_name); Loading @@ -279,15 +286,6 @@ public class ShortcutIntentBuilder { final Bitmap icon = generateQuickContactIcon(drawable); Intent intent = null; if (BuildCompat.isAtLeastO()) { final ShortcutManager sm = (ShortcutManager) mContext.getSystemService(Context.SHORTCUT_SERVICE); final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo( lookupKey, displayName, shortcutIntent, Icon.createWithBitmap(icon)); intent = sm.createShortcutResultIntent(shortcutInfo); } intent = intent == null ? new Intent() : intent; intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); Loading @@ -303,7 +301,7 @@ public class ShortcutIntentBuilder { final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); final Bitmap icon; final Uri phoneUri; final String shortcutName; if (TextUtils.isEmpty(displayName)) { displayName = mContext.getResources().getString(R.string.missing_name); } Loading @@ -313,10 +311,13 @@ public class ShortcutIntentBuilder { phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null); icon = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.quantum_ic_phone_vd_theme_24); shortcutName = mContext.getResources() .getString(R.string.call_by_shortcut, displayName); } else { phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null); icon = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.quantum_ic_message_vd_theme_24); shortcutName = mContext.getResources().getString(R.string.sms_by_shortcut, displayName); } final Intent shortcutIntent = new Intent(shortcutAction, phoneUri); Loading @@ -328,6 +329,8 @@ public class ShortcutIntentBuilder { mContext.getSystemService(Context.SHORTCUT_SERVICE); final String id = shortcutAction + lookupKey; final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); // TODO: Use createWithAdaptiveBitmap if >= O. Since we create these, we'll also need to // return AdaptiveIconDrawables when >= O as well. final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo( id, displayName, shortcutIntent, Icon.createWithBitmap(icon)); intent = sm.createShortcutResultIntent(shortcutInfo); Loading @@ -336,13 +339,7 @@ public class ShortcutIntentBuilder { intent = intent == null ? new Intent() : intent; intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); if (TextUtils.equals(shortcutAction, Intent.ACTION_CALL)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.call_by_shortcut, displayName)); } else if (TextUtils.equals(shortcutAction, Intent.ACTION_SENDTO)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.sms_by_shortcut, displayName)); } intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName); mListener.onShortcutIntentCreated(uri, intent); } Loading Loading @@ -395,13 +392,10 @@ public class ShortcutIntentBuilder { photoPaint.setFilterBitmap(true); Rect dst = new Rect(0, 0, mIconSize, mIconSize); // Create the overlay if we're pre-O. O created shortcuts have the app badge which overlaps // the type overlay. if (!BuildCompat.isAtLeastO()) { // Create an overlay for the phone number type // Create an overlay for the phone number type if we're pre-O. O created shortcuts have the // app badge which overlaps the type overlay. CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel); if (overlay != null) { if (!BuildCompat.isAtLeastO() && overlay != null) { TextPaint textPaint = new TextPaint( Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size)); Loading @@ -425,7 +419,6 @@ public class ShortcutIntentBuilder { canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2, mIconSize - fmi.descent - textPadding, textPaint); } } // Draw the phone action icon as an overlay Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight()); Loading Loading
src/com/android/contacts/DynamicShortcuts.java +12 −9 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ public class DynamicShortcuts { // though new ones may be added private static final int SHORTCUT_TYPE_UNKNOWN = 0; private static final int SHORTCUT_TYPE_CONTACT_URI = 1; private static final int SHORTCUT_TYPE_ACTION_URI = 2; // The spec specifies that it should be 44dp @ xxxhdpi // Note that ShortcutManager.getIconMaxWidth and ShortcutManager.getMaxHeight return different Loading Loading @@ -163,8 +164,7 @@ public class DynamicShortcuts { for (ShortcutInfo shortcut : mShortcutManager.getPinnedShortcuts()) { final PersistableBundle extras = shortcut.getExtras(); if (!shortcut.isDynamic() || extras == null || extras.getInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_UNKNOWN) != if (extras == null || extras.getInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_UNKNOWN) != SHORTCUT_TYPE_CONTACT_URI) { continue; } Loading Loading @@ -285,7 +285,7 @@ public class DynamicShortcuts { return null; } final PersistableBundle extras = new PersistableBundle(); extras.putInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_CONTACT_URI); extras.putInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_ACTION_URI); final ShortcutInfo.Builder builder = new ShortcutInfo.Builder(mContext, id) .setIntent(action) Loading Loading @@ -325,12 +325,15 @@ public class DynamicShortcuts { private void addIconForContact(long id, String lookupKey, String displayName, ShortcutInfo.Builder builder) { final Bitmap bitmap = getContactPhoto(id); if (bitmap != null) { builder.setIcon(Icon.createWithBitmap(bitmap)); } else { builder.setIcon(Icon.createWithBitmap(getFallbackAvatar(displayName, lookupKey))); Bitmap bitmap = getContactPhoto(id); if (bitmap == null) { bitmap = getFallbackAvatar(displayName, lookupKey); } // TODO: Use createWithAdaptiveBitmap if >= O. Since we create these, we'll also need to // return AdaptiveIconDrawables when >= O as well. final Icon icon = Icon.createWithBitmap(bitmap); builder.setIcon(icon); } private Bitmap getContactPhoto(long id) { Loading
src/com/android/contacts/ShortcutIntentBuilder.java +44 −51 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.contacts; import android.app.ActivityManager; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; import android.content.Intent; import android.content.pm.ShortcutInfo; Loading Loading @@ -50,10 +51,6 @@ import com.android.contacts.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.util.BitmapUtil; import com.android.contacts.util.ImplicitIntentsUtil; import com.google.common.collect.Lists; import java.util.List; /** * Constructs shortcut intents. */ Loading Loading @@ -269,6 +266,16 @@ public class ShortcutIntentBuilder { private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName, String lookupKey, byte[] bitmapData) { Intent intent = null; if (BuildCompat.isAtLeastO()) { final long contactId = ContentUris.parseId(contactUri); final ShortcutManager sm = (ShortcutManager) mContext.getSystemService(Context.SHORTCUT_SERVICE); final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getQuickContactShortcutInfo( contactId, lookupKey, displayName); intent = sm.createShortcutResultIntent(shortcutInfo); } final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); if (TextUtils.isEmpty(displayName)) { displayName = mContext.getResources().getString(R.string.missing_name); Loading @@ -279,15 +286,6 @@ public class ShortcutIntentBuilder { final Bitmap icon = generateQuickContactIcon(drawable); Intent intent = null; if (BuildCompat.isAtLeastO()) { final ShortcutManager sm = (ShortcutManager) mContext.getSystemService(Context.SHORTCUT_SERVICE); final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo( lookupKey, displayName, shortcutIntent, Icon.createWithBitmap(icon)); intent = sm.createShortcutResultIntent(shortcutInfo); } intent = intent == null ? new Intent() : intent; intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); Loading @@ -303,7 +301,7 @@ public class ShortcutIntentBuilder { final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); final Bitmap icon; final Uri phoneUri; final String shortcutName; if (TextUtils.isEmpty(displayName)) { displayName = mContext.getResources().getString(R.string.missing_name); } Loading @@ -313,10 +311,13 @@ public class ShortcutIntentBuilder { phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null); icon = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.quantum_ic_phone_vd_theme_24); shortcutName = mContext.getResources() .getString(R.string.call_by_shortcut, displayName); } else { phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null); icon = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.quantum_ic_message_vd_theme_24); shortcutName = mContext.getResources().getString(R.string.sms_by_shortcut, displayName); } final Intent shortcutIntent = new Intent(shortcutAction, phoneUri); Loading @@ -328,6 +329,8 @@ public class ShortcutIntentBuilder { mContext.getSystemService(Context.SHORTCUT_SERVICE); final String id = shortcutAction + lookupKey; final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); // TODO: Use createWithAdaptiveBitmap if >= O. Since we create these, we'll also need to // return AdaptiveIconDrawables when >= O as well. final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo( id, displayName, shortcutIntent, Icon.createWithBitmap(icon)); intent = sm.createShortcutResultIntent(shortcutInfo); Loading @@ -336,13 +339,7 @@ public class ShortcutIntentBuilder { intent = intent == null ? new Intent() : intent; intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); if (TextUtils.equals(shortcutAction, Intent.ACTION_CALL)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.call_by_shortcut, displayName)); } else if (TextUtils.equals(shortcutAction, Intent.ACTION_SENDTO)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.sms_by_shortcut, displayName)); } intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName); mListener.onShortcutIntentCreated(uri, intent); } Loading Loading @@ -395,13 +392,10 @@ public class ShortcutIntentBuilder { photoPaint.setFilterBitmap(true); Rect dst = new Rect(0, 0, mIconSize, mIconSize); // Create the overlay if we're pre-O. O created shortcuts have the app badge which overlaps // the type overlay. if (!BuildCompat.isAtLeastO()) { // Create an overlay for the phone number type // Create an overlay for the phone number type if we're pre-O. O created shortcuts have the // app badge which overlaps the type overlay. CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel); if (overlay != null) { if (!BuildCompat.isAtLeastO() && overlay != null) { TextPaint textPaint = new TextPaint( Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size)); Loading @@ -425,7 +419,6 @@ public class ShortcutIntentBuilder { canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2, mIconSize - fmi.descent - textPadding, textPaint); } } // Draw the phone action icon as an overlay Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight()); Loading