OSDN Git Service

Revert "Add shortcut manager support to Settings (2/2) b/28298258"
authorHyunyoung Song <hyunyoungs@google.com>
Tue, 10 May 2016 17:15:48 +0000 (17:15 +0000)
committerHyunyoung Song <hyunyoungs@google.com>
Tue, 10 May 2016 17:16:33 +0000 (17:16 +0000)
b/28643184
This reverts commit 79ec6df771b0c05609a611a939f08fcd51f45b74.

Change-Id: I3de8a27e88a5a84825e914725259530b22756da0

src/com/android/settings/CreateShortcut.java
src/com/android/settings/SettingsActivity.java
src/com/android/settings/ShortcutInfoPublisher.java [deleted file]

index befc9e0..7317738 100644 (file)
@@ -59,14 +59,14 @@ public class CreateShortcut extends LauncherActivity {
         ResolveInfo resolveInfo = itemForPosition(position).resolveInfo;
         ActivityInfo activityInfo = resolveInfo.activityInfo;
         if (activityInfo.icon != 0) {
-            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(this, activityInfo.icon));
+            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon));
         }
         setResult(RESULT_OK, intent);
         finish();
     }
 
-    static Bitmap createIcon(Context ctx, int resource) {
-        Context context = new ContextThemeWrapper(ctx, android.R.style.Theme_Material);
+    private Bitmap createIcon(int resource) {
+        Context context = new ContextThemeWrapper(this, android.R.style.Theme_Material);
         View view = LayoutInflater.from(context).inflate(R.layout.shortcut_badge, null);
         ((ImageView) view.findViewById(android.R.id.icon)).setImageResource(resource);
 
index b3df4a4..3209b51 100644 (file)
@@ -43,7 +43,6 @@ import android.transition.TransitionManager;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
-
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -537,8 +536,6 @@ public class SettingsActivity extends SettingsDrawerActivity
         final ComponentName cn = intent.getComponent();
         final String className = cn.getClassName();
 
-        publishShortcuts();
-
         mIsShowingDashboard = className.equals(Settings.class.getName())
                 || className.equals(Settings.WirelessSettings.class.getName())
                 || className.equals(Settings.DeviceSettings.class.getName())
@@ -1019,18 +1016,6 @@ public class SettingsActivity extends SettingsDrawerActivity
         return f;
     }
 
-    private void publishShortcuts() {
-        AsyncTask.execute(new Runnable() {
-            @Override
-            public void run() {
-                if (!getSharedPreferences(ShortcutInfoPublisher.PREF_FILE, Context.MODE_PRIVATE)
-                        .getBoolean(ShortcutInfoPublisher.PREF_KEY, false)) {
-                    ShortcutInfoPublisher.setDynamicShortcuts(SettingsActivity.this, getTileCache());
-                }
-            }
-        });
-    }
-
     private void updateTilesList() {
         // Generally the items that are will be changing from these updates will
         // not be in the top list of tiles, so run it in the background and the
diff --git a/src/com/android/settings/ShortcutInfoPublisher.java b/src/com/android/settings/ShortcutInfoPublisher.java
deleted file mode 100644 (file)
index 893292e..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-package com.android.settings;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.pm.ShortcutInfo;
-import android.content.pm.ShortcutManager;
-import android.graphics.drawable.Icon;
-import android.util.Log;
-import android.util.Pair;
-import com.android.settingslib.drawer.Tile;
-import com.android.settingslib.drawer.TileUtils;
-
-import java.util.*;
-
-/**
- * Helper class that publish top 5 tiles to the {@link ShortcutManager}.
- *
- * Assumptions:
- * <li>
- *     <ul> Intent short class name is used as unique identifier for creating {@link ShortcutInfo}. </ul>
- *     <ul> {@link Tile}s are sorted in ascending order of the priority field. </ul>
- * </li>
- */
-public class ShortcutInfoPublisher {
-    private static boolean DBG = false;
-    private static String TAG = "ShortcutInfoPublisher";
-
-    public static String PREF_FILE = "shortcut_publisher";
-    public static String PREF_KEY = "shortcut_published";
-
-    /**
-     * For any {@param dShortcutMap} if any of them requires updating because {@link Tile} is different, update.
-     *
-     * Note: Once ShortcutInfo.getTitle supports res id, this will NOT be required on Locale change.
-     * TODO: call on ACTION_LOCALE_CHANGED broadcast intent.
-     */
-    public static void updateShortcuts(Context context, Collection<Tile> tileList) {
-        ShortcutManager sm = context.getSystemService(ShortcutManager.class);
-        HashMap<String, ShortcutInfo> updateShortcutsMap = new HashMap<>();
-        for (ShortcutInfo s: sm.getDynamicShortcuts()) {
-            updateShortcutsMap.put(s.getId(), s);
-        }
-        for (ShortcutInfo s: sm.getPinnedShortcuts()) {
-            updateShortcutsMap.put(s.getId(), s);
-        }
-        ArrayList<ShortcutInfo> updateShortcuts = new ArrayList<>();
-        for(Tile t: tileList) {
-            if (publishedButChanged(updateShortcutsMap, t)){
-                ShortcutInfo s = buildShortcutInfo(context, t);
-                updateShortcuts.add(s);
-                if (DBG) Log.d(TAG, "update: " + s.getId());
-            }
-        }
-        // This check is not required if being called from foreground activity.
-        if (sm.getRemainingCallCount() > 0 && updateShortcuts.size() > 0) {
-            sm.updateShortcuts(updateShortcuts);
-            if (DBG) Log.d(TAG, "ShortcutManager.updateshortcuts: " + updateShortcuts.size());
-        }
-    }
-
-    /**
-     * Set the 5 top Tile as {@link ShortcutInfo}.
-     *
-     * Note: once one time loading of static list is supported, this will NOT be required.
-     */
-    public static void setDynamicShortcuts(Context context, Map<Pair<String, String>, Tile> tiles) {
-        ShortcutManager sm = context.getSystemService(ShortcutManager.class);
-        // Sort the tiles so that tiles with higher priority is at the beginning.
-        ArrayList<Tile> tileList = new ArrayList<>();
-        tileList.addAll(tiles.values());
-        Collections.sort(tileList, TileUtils.TILE_COMPARATOR);
-
-        int max = sm.getMaxDynamicShortcutCount();
-        ArrayList<ShortcutInfo> dShortcutList = new ArrayList<>();
-        for(Tile t: tileList) {
-            ShortcutInfo s = buildShortcutInfo(context, t);
-            dShortcutList.add(s);
-            if (DBG) Log.d(TAG, "add new shortcut: " + s.getId());
-            if (dShortcutList.size() >= max) {
-                break;
-            }
-        }
-        // This check is not required if being called from foreground activity.
-        if (sm.getRemainingCallCount() > 0) {
-            sm.setDynamicShortcuts(dShortcutList);
-            if (DBG) Log.d(TAG, "ShortcutManager.setDynamicShortcuts");
-            SharedPreferences sharedPref = context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE);
-            SharedPreferences.Editor editor = sharedPref.edit();
-            editor.putBoolean(PREF_KEY, true);
-            editor.commit();
-        }
-    }
-
-    /**
-     * Extract string from {@link Tile} that should be used for shortcut id.
-     */
-    private static String getShortcutInfoId(Tile t) {
-        return t.intent.getComponent().getShortClassName();
-    }
-
-    /**
-     * Build ShortcutInfo from given Tile.
-     */
-    private static ShortcutInfo buildShortcutInfo(Context context, Tile t) {
-        return new ShortcutInfo.Builder(context)
-                .setId(getShortcutInfoId(t))
-                .setTitle(t.title.toString())
-                .setIntent(t.intent)
-                .setIcon(Icon.createWithBitmap(CreateShortcut.createIcon(context, t.icon.getResId())))
-                .setWeight(t.priority)
-                .build();
-    }
-
-    private static boolean publishedButChanged(Map<String, ShortcutInfo> shortcutMap, Tile t) {
-        ShortcutInfo s = shortcutMap.get(getShortcutInfoId(t));
-        if (s == null) {
-            return false; // never published.
-        }
-        if (t.priority != s.getWeight()) {
-            if (DBG) Log.d(TAG, s.getId() +  " *weight* diff s:" + s.getWeight() + "t:" + t.priority);
-            return true;
-        } else if (!t.intent.equals(s.getIntent())) {
-            if (DBG) Log.d(TAG, s.getId() + " *intent* diff s:" + s.getIntent() + "t:" + t.intent);
-            return true;
-        } else if (!t.title.equals(s.getTitle())) {
-            if (DBG) Log.d(TAG, s.getId() + " *title* diff s:" + s.getTitle() + "t:" + t.title);
-            return true;
-        } else if (!t.icon.sameAs(s.getIcon())) {
-            if (DBG) Log.d(TAG, s.getId() + " *icon* diff s:" + s.getIcon() + "t:" + t.icon);
-            return true;
-        }
-        return false;
-    }
-}