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

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

Fix shortcut icons on O am: dbf3e83d

Change-Id: If1916abecc35fb8ba27c2932bf3af573c0e0df50
parents 068bb327 dbf3e83d
Loading
Loading
Loading
Loading
+18 −6
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Data;
import android.support.v4.graphics.drawable.IconCompat;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v4.os.BuildCompat;
import android.support.v4.os.BuildCompat;
@@ -292,11 +293,15 @@ public class ShortcutIntentBuilder {
        final Intent shortcutIntent = ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut(
        final Intent shortcutIntent = ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut(
                mContext, contactUri);
                mContext, contactUri);


        final Bitmap icon = generateQuickContactIcon(drawable);


        intent = intent == null ? new Intent() : intent;
        intent = intent == null ? new Intent() : intent;

        final Bitmap icon = generateQuickContactIcon(drawable);
        if (BuildCompat.isAtLeastO()) {
            final IconCompat compatIcon = IconCompat.createWithAdaptiveBitmap(icon);
            compatIcon.addToShortcutIntent(intent);
        } else {
            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
        }
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);


@@ -332,18 +337,25 @@ public class ShortcutIntentBuilder {
        shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


        Intent intent = null;
        Intent intent = null;
        IconCompat compatAdaptiveIcon = null;
        if (BuildCompat.isAtLeastO()) {
        if (BuildCompat.isAtLeastO()) {
            compatAdaptiveIcon = IconCompat.createWithAdaptiveBitmap(icon);
            final ShortcutManager sm = (ShortcutManager)
            final ShortcutManager sm = (ShortcutManager)
                    mContext.getSystemService(Context.SHORTCUT_SERVICE);
                    mContext.getSystemService(Context.SHORTCUT_SERVICE);
            final String id = shortcutAction + lookupKey;
            final String id = shortcutAction + lookupKey;
            final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext);
            final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext);
            final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo(
            final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo(
                    id, displayName, shortcutIntent, Icon.createWithAdaptiveBitmap(icon));
                    id, displayName, shortcutIntent, compatAdaptiveIcon.toIcon());
            intent = sm.createShortcutResultIntent(shortcutInfo);
            intent = sm.createShortcutResultIntent(shortcutInfo);
        }
        }


        intent = intent == null ? new Intent() : intent;
        intent = intent == null ? new Intent() : intent;
        // This will be non-null in O and above.
        if (compatAdaptiveIcon != null) {
            compatAdaptiveIcon.addToShortcutIntent(intent);
        } else {
            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
        }
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);