Lazy loading high res icons
> Loading low-res icons for icons which are not visible on the homescreen. Change-Id: I8ac7bf09f6030ed554cb60a4cd402f3f36ffe12b
This commit is contained in:
1 parent
5d85c44fd8
commit
34b6527cef
10 files changed
+209
-36
No files matched your search
@@ -34,6 +34,8 @@ import android.view.MotionEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.launcher3.IconCache.IconLoadRequest;
|
||||
|
||||
/**
|
||||
* TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
|
||||
* because we want to make the bubble taller than the text and TextView's clip is
|
||||
@@ -74,6 +76,8 @@ public class BubbleTextView extends TextView {
|
||||
private boolean mStayPressed;
|
||||
private boolean mIgnorePressedStateChange;
|
||||
|
||||
private IconLoadRequest mIconLoadRequest;
|
||||
|
||||
public BubbleTextView(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
@@ -163,6 +167,9 @@ public class BubbleTextView extends TextView {
|
||||
}
|
||||
// We don't need to check the info since it's not a ShortcutInfo
|
||||
super.setTag(info);
|
||||
|
||||
// Verify high res immediately
|
||||
verifyHighRes();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -450,4 +457,42 @@ public class BubbleTextView extends TextView {
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the item info if it is same as what the view is pointing to currently.
|
||||
*/
|
||||
public void reapplyItemInfo(final ItemInfo info) {
|
||||
if (getTag() == info) {
|
||||
mIconLoadRequest = null;
|
||||
if (info instanceof AppInfo) {
|
||||
applyFromApplicationInfo((AppInfo) info);
|
||||
} else if (info instanceof ShortcutInfo) {
|
||||
applyFromShortcutInfo((ShortcutInfo) info,
|
||||
LauncherAppState.getInstance().getIconCache(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the current icon is high-res otherwise posts a request to load the icon.
|
||||
*/
|
||||
public void verifyHighRes() {
|
||||
if (mIconLoadRequest != null) {
|
||||
mIconLoadRequest.cancel();
|
||||
mIconLoadRequest = null;
|
||||
}
|
||||
if (getTag() instanceof AppInfo) {
|
||||
AppInfo info = (AppInfo) getTag();
|
||||
if (info.usingLowResIcon) {
|
||||
mIconLoadRequest = LauncherAppState.getInstance().getIconCache()
|
||||
.updateIconInBackground(BubbleTextView.this, info);
|
||||
}
|
||||
} else if (getTag() instanceof ShortcutInfo) {
|
||||
ShortcutInfo info = (ShortcutInfo) getTag();
|
||||
if (info.usingLowResIcon) {
|
||||
mIconLoadRequest = LauncherAppState.getInstance().getIconCache()
|
||||
.updateIconInBackground(BubbleTextView.this, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user