diff options
author | Romain Guy <romainguy@google.com> | 2011-11-30 14:07:34 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-30 14:07:34 -0800 |
commit | 7797cae2564eccf6d817b06d8116bd9cdc8e9ed4 (patch) | |
tree | 9b22ed385c89079ff298265168a1e39e7388304c | |
parent | e8ba2aba934e3767d2081007bba93bad68566d22 (diff) | |
parent | 39fe17c8fb764a9233182cc408e37b1a59182b00 (diff) | |
download | frameworks_base-7797cae2564eccf6d817b06d8116bd9cdc8e9ed4.zip frameworks_base-7797cae2564eccf6d817b06d8116bd9cdc8e9ed4.tar.gz frameworks_base-7797cae2564eccf6d817b06d8116bd9cdc8e9ed4.tar.bz2 |
Merge "Cache drawable constant states instead of drawables Bug #5678369" into ics-mr1
-rw-r--r-- | core/java/android/app/ApplicationPackageManager.java | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java index 8ed7481..180a442 100644 --- a/core/java/android/app/ApplicationPackageManager.java +++ b/core/java/android/app/ApplicationPackageManager.java @@ -625,7 +625,7 @@ final class ApplicationPackageManager extends PackageManager { return info.activityInfo.loadIcon(this); } - throw new NameNotFoundException(intent.toURI()); + throw new NameNotFoundException(intent.toUri(0)); } @Override public Drawable getDefaultActivityIcon() { @@ -728,15 +728,22 @@ final class ApplicationPackageManager extends PackageManager { private Drawable getCachedIcon(ResourceName name) { synchronized (sSync) { - WeakReference<Drawable> wr = sIconCache.get(name); + WeakReference<Drawable.ConstantState> wr = sIconCache.get(name); if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for " + name + ": " + wr); if (wr != null) { // we have the activity - Drawable dr = wr.get(); - if (dr != null) { - if (DEBUG_ICONS) Log.v(TAG, "Get cached drawable for " - + name + ": " + dr); - return dr; + Drawable.ConstantState state = wr.get(); + if (state != null) { + if (DEBUG_ICONS) { + Log.v(TAG, "Get cached drawable state for " + name + ": " + state); + } + // Note: It's okay here to not use the newDrawable(Resources) variant + // of the API. The ConstantState comes from a drawable that was + // originally created by passing the proper app Resources instance + // which means the state should already contain the proper + // resources specific information (like density.) See + // BitmapDrawable.BitmapState for instance. + return state.newDrawable(); } // our entry has been purged sIconCache.remove(name); @@ -747,14 +754,12 @@ final class ApplicationPackageManager extends PackageManager { private void putCachedIcon(ResourceName name, Drawable dr) { synchronized (sSync) { - sIconCache.put(name, new WeakReference<Drawable>(dr)); - if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable for " - + name + ": " + dr); + sIconCache.put(name, new WeakReference<Drawable.ConstantState>(dr.getConstantState())); + if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr); } } - static final void handlePackageBroadcast(int cmd, String[] pkgList, - boolean hasPkgInfo) { + static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) { boolean immediateGc = false; if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) { immediateGc = true; @@ -1226,8 +1231,8 @@ final class ApplicationPackageManager extends PackageManager { private final IPackageManager mPM; private static final Object sSync = new Object(); - private static HashMap<ResourceName, WeakReference<Drawable> > sIconCache - = new HashMap<ResourceName, WeakReference<Drawable> >(); - private static HashMap<ResourceName, WeakReference<CharSequence> > sStringCache - = new HashMap<ResourceName, WeakReference<CharSequence> >(); + private static HashMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache + = new HashMap<ResourceName, WeakReference<Drawable.ConstantState>>(); + private static HashMap<ResourceName, WeakReference<CharSequence>> sStringCache + = new HashMap<ResourceName, WeakReference<CharSequence>>(); } |