Loading high resolution icons for first 3 items in a folder

> Sometimes a folder gets rearranged, without updating the model,
   like when an app in uninstalled. In that case, we need to update
   the icons for folder items, which were previously hidden

Bug: 22813360
Change-Id: I99754911c969bf2153efb2948c226c1c69219b88
This commit is contained in:
Sunny Goyal
2015-07-29 11:45:41 -07:00
parent 3f7550c1ed
commit 317698bd01
7 changed files with 46 additions and 3 deletions

View File

@@ -34,11 +34,13 @@ import android.util.SparseArray;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewParent;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.TextView;
import com.android.launcher3.IconCache.IconLoadRequest;
import com.android.launcher3.model.PackageItemInfo;
@@ -538,6 +540,13 @@ public class BubbleTextView extends TextView
} else if (info instanceof ShortcutInfo) {
applyFromShortcutInfo((ShortcutInfo) info,
LauncherAppState.getInstance().getIconCache());
if ((info.rank < FolderIcon.NUM_ITEMS_IN_PREVIEW) && (info.container >= 0)) {
View folderIcon =
mLauncher.getWorkspace().getHomescreenIconByItemId(info.container);
if (folderIcon != null) {
folderIcon.invalidate();
}
}
} else if (info instanceof PackageItemInfo) {
applyFromPackageItemInfo((PackageItemInfo) info);
}

View File

@@ -1389,7 +1389,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
// Compares item position based on rank and position giving priority to the rank.
private static final Comparator<ItemInfo> ITEM_POS_COMPARATOR = new Comparator<ItemInfo>() {
public static final Comparator<ItemInfo> ITEM_POS_COMPARATOR = new Comparator<ItemInfo>() {
@Override
public int compare(ItemInfo lhs, ItemInfo rhs) {

View File

@@ -329,6 +329,10 @@ public class FolderPagedView extends PagedView {
lp.cellY = info.cellY;
currentPage.addViewToCellLayout(
v, -1, mFolder.mLauncher.getViewIdForItem(info), lp, true);
if (rank < FolderIcon.NUM_ITEMS_IN_PREVIEW && v instanceof BubbleTextView) {
((BubbleTextView) v).verifyHighRes();
}
}
rank ++;

View File

@@ -2662,6 +2662,7 @@ public class Launcher extends Activity
throw new IllegalArgumentException("Input must be a FolderIcon");
}
// TODO(sunnygoyal): Re-evaluate this code.
FolderIcon folderIcon = (FolderIcon) v;
final FolderInfo info = folderIcon.getFolderInfo();
Folder openFolder = mWorkspace.getFolderForTag(info);

View File

@@ -2303,6 +2303,21 @@ public class LauncherModel extends BroadcastReceiver
}
}
// Sort all the folder items and make sure the first 3 items are high resolution.
for (FolderInfo folder : sBgFolders) {
Collections.sort(folder.contents, Folder.ITEM_POS_COMPARATOR);
int pos = 0;
for (ShortcutInfo info : folder.contents) {
if (info.usingLowResIcon) {
info.updateIcon(mIconCache, false);
}
pos ++;
if (pos >= FolderIcon.NUM_ITEMS_IN_PREVIEW) {
break;
}
}
}
if (restoredRows.size() > 0) {
// Update restored items that no longer require special handling
ContentValues values = new ContentValues();

View File

@@ -198,13 +198,17 @@ public class ShortcutInfo extends ItemInfo {
return mIcon;
}
public void updateIcon(IconCache iconCache) {
public void updateIcon(IconCache iconCache, boolean useLowRes) {
if (itemType == Favorites.ITEM_TYPE_APPLICATION) {
iconCache.getTitleAndIcon(this, promisedIntent != null ? promisedIntent : intent, user,
shouldUseLowResIcon());
useLowRes);
}
}
public void updateIcon(IconCache iconCache) {
updateIcon(iconCache, shouldUseLowResIcon());
}
@Override
void onAddToDatabase(Context context, ContentValues values) {
super.onAddToDatabase(context, values);

View File

@@ -4059,6 +4059,16 @@ public class Workspace extends PagedView
});
}
public View getHomescreenIconByItemId(final long id) {
return getFirstMatch(new ItemOperator() {
@Override
public boolean evaluate(ItemInfo info, View v, View parent) {
return info.id == id;
}
});
}
public View getViewForTag(final Object tag) {
return getFirstMatch(new ItemOperator() {