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

Commit 19186838 authored by Gary Mai's avatar Gary Mai
Browse files

Add type for action (call/sms) shortcuts

Update all pinned shortcuts that are SHORTCUT_TYPE_CONTACT_URI.

Test: Manually verified pinning short cuts on O.
Also see that pinned shortcuts for quick contacts are updated
when one of them changes.

Bug: 34128487
Bug: 36032908
Change-Id: I2237dda56cc83caa55f175c7d4ed2b4a86031e0f
parent a172da63
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -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
@@ -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;
            }
@@ -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)
@@ -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) {
+44 −51
Original line number Diff line number Diff line
@@ -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;
@@ -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.
 */
@@ -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);
@@ -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);
@@ -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);
        }
@@ -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);
@@ -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);
@@ -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);
    }
@@ -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));
@@ -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());