Loading src/com/android/launcher3/LauncherModel.java +0 −11 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; import java.util.function.Supplier; Loading Loading @@ -126,16 +125,6 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi mBgAllAppsList = new AllAppsList(iconCache, appFilter); } /** * Returns AppInfo with corresponding package name. * TODO: move to enqueueModelTask */ public Optional<AppInfo> getAppInfoByPackageName(String pkg) { return mBgAllAppsList.data.stream() .filter(info -> info.componentName.getPackageName().equals(pkg)) .findAny(); } /** * Adds the provided items to the workspace. */ Loading src/com/android/launcher3/folder/FolderNameProvider.java +34 −3 Original line number Diff line number Diff line Loading @@ -21,9 +21,14 @@ import android.text.TextUtils; import android.util.Log; import com.android.launcher3.AppInfo; import com.android.launcher3.FolderInfo; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.model.AllAppsList; import com.android.launcher3.model.BaseModelUpdateTask; import com.android.launcher3.model.BgDataModel; import com.android.launcher3.util.IntSparseArrayMap; import com.android.launcher3.util.ResourceBasedOverride; import java.util.ArrayList; Loading @@ -50,6 +55,8 @@ public class FolderNameProvider implements ResourceBasedOverride { * name edit box can also be used to provide suggestion. */ public static final int SUGGEST_MAX = 4; protected IntSparseArrayMap<FolderInfo> mFolderInfos; protected List<AppInfo> mAppInfos; /** * Retrieve instance of this object that can be overridden in runtime based on the build Loading @@ -58,9 +65,16 @@ public class FolderNameProvider implements ResourceBasedOverride { public static FolderNameProvider newInstance(Context context) { FolderNameProvider fnp = Overrides.getObject(FolderNameProvider.class, context.getApplicationContext(), R.string.folder_name_provider_class); fnp.load(context); return fnp; } private void load(Context context) { LauncherAppState.getInstance(context).getModel().enqueueModelUpdateTask( new FolderNameWorker()); } /** * Generate and rank the suggested Folder names. */ Loading Loading @@ -92,9 +106,8 @@ public class FolderNameProvider implements ResourceBasedOverride { .collect(Collectors.toList()); if (distinctItemInfos.size() == 1) { Optional<AppInfo> info = LauncherAppState.getInstance(context).getModel() .getAppInfoByPackageName(distinctItemInfos.get(0).getTargetComponent() .getPackageName()); Optional<AppInfo> info = getAppInfoByPackageName( distinctItemInfos.get(0).getTargetComponent().getPackageName()); // Place it as first viable suggestion and shift everything else info.ifPresent(i -> setAsFirstSuggestion(nameInfos, i.title.toString())); } Loading @@ -103,6 +116,15 @@ public class FolderNameProvider implements ResourceBasedOverride { } } private Optional<AppInfo> getAppInfoByPackageName(String packageName) { if (mAppInfos == null || mAppInfos.isEmpty()) { return Optional.empty(); } return mAppInfos.stream() .filter(info -> info.componentName.getPackageName().equals(packageName)) .findAny(); } private void setAsFirstSuggestion(FolderNameInfo[] nameInfos, CharSequence label) { if (nameInfos.length == 0 || contains(nameInfos, label)) { return; Loading Loading @@ -143,4 +165,13 @@ public class FolderNameProvider implements ResourceBasedOverride { Map<Object, Boolean> map = new ConcurrentHashMap<>(); return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; } private class FolderNameWorker extends BaseModelUpdateTask { @Override public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) { mFolderInfos = dataModel.folders.clone(); mAppInfos = Arrays.asList(apps.copyData()); } } } Loading
src/com/android/launcher3/LauncherModel.java +0 −11 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; import java.util.function.Supplier; Loading Loading @@ -126,16 +125,6 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi mBgAllAppsList = new AllAppsList(iconCache, appFilter); } /** * Returns AppInfo with corresponding package name. * TODO: move to enqueueModelTask */ public Optional<AppInfo> getAppInfoByPackageName(String pkg) { return mBgAllAppsList.data.stream() .filter(info -> info.componentName.getPackageName().equals(pkg)) .findAny(); } /** * Adds the provided items to the workspace. */ Loading
src/com/android/launcher3/folder/FolderNameProvider.java +34 −3 Original line number Diff line number Diff line Loading @@ -21,9 +21,14 @@ import android.text.TextUtils; import android.util.Log; import com.android.launcher3.AppInfo; import com.android.launcher3.FolderInfo; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.model.AllAppsList; import com.android.launcher3.model.BaseModelUpdateTask; import com.android.launcher3.model.BgDataModel; import com.android.launcher3.util.IntSparseArrayMap; import com.android.launcher3.util.ResourceBasedOverride; import java.util.ArrayList; Loading @@ -50,6 +55,8 @@ public class FolderNameProvider implements ResourceBasedOverride { * name edit box can also be used to provide suggestion. */ public static final int SUGGEST_MAX = 4; protected IntSparseArrayMap<FolderInfo> mFolderInfos; protected List<AppInfo> mAppInfos; /** * Retrieve instance of this object that can be overridden in runtime based on the build Loading @@ -58,9 +65,16 @@ public class FolderNameProvider implements ResourceBasedOverride { public static FolderNameProvider newInstance(Context context) { FolderNameProvider fnp = Overrides.getObject(FolderNameProvider.class, context.getApplicationContext(), R.string.folder_name_provider_class); fnp.load(context); return fnp; } private void load(Context context) { LauncherAppState.getInstance(context).getModel().enqueueModelUpdateTask( new FolderNameWorker()); } /** * Generate and rank the suggested Folder names. */ Loading Loading @@ -92,9 +106,8 @@ public class FolderNameProvider implements ResourceBasedOverride { .collect(Collectors.toList()); if (distinctItemInfos.size() == 1) { Optional<AppInfo> info = LauncherAppState.getInstance(context).getModel() .getAppInfoByPackageName(distinctItemInfos.get(0).getTargetComponent() .getPackageName()); Optional<AppInfo> info = getAppInfoByPackageName( distinctItemInfos.get(0).getTargetComponent().getPackageName()); // Place it as first viable suggestion and shift everything else info.ifPresent(i -> setAsFirstSuggestion(nameInfos, i.title.toString())); } Loading @@ -103,6 +116,15 @@ public class FolderNameProvider implements ResourceBasedOverride { } } private Optional<AppInfo> getAppInfoByPackageName(String packageName) { if (mAppInfos == null || mAppInfos.isEmpty()) { return Optional.empty(); } return mAppInfos.stream() .filter(info -> info.componentName.getPackageName().equals(packageName)) .findAny(); } private void setAsFirstSuggestion(FolderNameInfo[] nameInfos, CharSequence label) { if (nameInfos.length == 0 || contains(nameInfos, label)) { return; Loading Loading @@ -143,4 +165,13 @@ public class FolderNameProvider implements ResourceBasedOverride { Map<Object, Boolean> map = new ConcurrentHashMap<>(); return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; } private class FolderNameWorker extends BaseModelUpdateTask { @Override public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) { mFolderInfos = dataModel.folders.clone(); mAppInfos = Arrays.asList(apps.copyData()); } } }