mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Support predicted icons in preview
Fixes: 152789575 Test: https://screenshot.googleplex.com/r3AtHp3TAh0 Change-Id: I22f7ee2a69f2df12ade16f50bf455651dbfce597
This commit is contained in:
@@ -47,6 +47,7 @@ import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.touch.ItemClickHandler;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.util.SafeCloseable;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.views.DoubleShadowBubbleTextView;
|
||||
|
||||
/**
|
||||
@@ -68,7 +69,6 @@ public class PredictedAppIcon extends DoubleShadowBubbleTextView implements
|
||||
private int mPlateColor;
|
||||
boolean mDrawForDrag = false;
|
||||
|
||||
|
||||
public PredictedAppIcon(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
@@ -79,10 +79,8 @@ public class PredictedAppIcon extends DoubleShadowBubbleTextView implements
|
||||
|
||||
public PredictedAppIcon(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mDeviceProfile = Launcher.getLauncher(context).getDeviceProfile();
|
||||
mDeviceProfile = ActivityContext.lookupContext(context).getDeviceProfile();
|
||||
mNormalizedIconRadius = IconNormalizer.getNormalizedCircleSize(getIconSize()) / 2;
|
||||
setOnClickListener(ItemClickHandler.INSTANCE);
|
||||
setOnFocusChangeListener(Launcher.getLauncher(context).getFocusHandler());
|
||||
int shadowSize = context.getResources().getDimensionPixelSize(
|
||||
R.dimen.blur_size_thin_outline);
|
||||
mShadowFilter = new BlurMaskFilter(shadowSize, BlurMaskFilter.Blur.OUTER);
|
||||
@@ -241,6 +239,8 @@ public class PredictedAppIcon extends DoubleShadowBubbleTextView implements
|
||||
PredictedAppIcon icon = (PredictedAppIcon) LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.predicted_app_icon, parent, false);
|
||||
icon.applyFromWorkspaceItem(info);
|
||||
icon.setOnClickListener(ItemClickHandler.INSTANCE);
|
||||
icon.setOnFocusChangeListener(Launcher.getLauncher(parent.getContext()).getFocusHandler());
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.uioverrides;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
|
||||
/** A util class that inflates a predicted app icon */
|
||||
public class PredictedAppIconInflater {
|
||||
public static View inflate(LayoutInflater inflater, ViewGroup parent, WorkspaceItemInfo info) {
|
||||
PredictedAppIcon icon = (PredictedAppIcon) inflater.inflate(
|
||||
R.layout.predicted_app_icon, parent, false);
|
||||
icon.applyFromWorkspaceItem(info);
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import static android.view.View.VISIBLE;
|
||||
import static com.android.launcher3.config.FeatureFlags.ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER;
|
||||
import static com.android.launcher3.config.FeatureFlags.MULTI_DB_GRID_MIRATION_ALGO;
|
||||
import static com.android.launcher3.model.ModelUtils.filterCurrentWorkspaceItems;
|
||||
import static com.android.launcher3.model.ModelUtils.getMissingHotseatRanks;
|
||||
import static com.android.launcher3.model.ModelUtils.sortWorkspaceItemsSpatially;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
@@ -80,13 +81,16 @@ import com.android.launcher3.model.LoaderResults;
|
||||
import com.android.launcher3.model.LoaderTask;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.FolderInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.pm.InstallSessionHelper;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.uioverrides.PredictedAppIconInflater;
|
||||
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
import com.android.launcher3.util.MainThreadInitializedObject;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.views.BaseDragLayer;
|
||||
@@ -376,6 +380,13 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
|
||||
addInScreenFromBind(view, info);
|
||||
}
|
||||
|
||||
private void inflateAndAddPredictedIcon(WorkspaceItemInfo info) {
|
||||
View view = PredictedAppIconInflater.inflate(mHomeElementInflater, mWorkspace, info);
|
||||
if (view != null) {
|
||||
addInScreenFromBind(view, info);
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchVisibilityAggregated(View view, boolean isVisible) {
|
||||
// Similar to View.dispatchVisibilityAggregated implementation.
|
||||
final boolean thisVisible = view.getVisibility() == VISIBLE;
|
||||
@@ -468,6 +479,21 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
IntArray ranks = getMissingHotseatRanks(currentWorkspaceItems,
|
||||
mIdp.numHotseatIcons);
|
||||
int count = Math.min(ranks.size(), workspaceResult.mCachedPredictedItems.size());
|
||||
for (int i = 0; i < count; i++) {
|
||||
AppInfo appInfo = workspaceResult.mCachedPredictedItems.get(i);
|
||||
int rank = ranks.get(i);
|
||||
WorkspaceItemInfo itemInfo = new WorkspaceItemInfo(appInfo);
|
||||
itemInfo.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
|
||||
itemInfo.rank = rank;
|
||||
itemInfo.cellX = mHotseat.getCellXFromOrder(rank);
|
||||
itemInfo.cellY = mHotseat.getCellYFromOrder(rank);
|
||||
itemInfo.screenId = rank;
|
||||
inflateAndAddPredictedIcon(itemInfo);
|
||||
}
|
||||
} else {
|
||||
// Add hotseat icons
|
||||
for (int i = 0; i < mIdp.numHotseatIcons; i++) {
|
||||
@@ -561,7 +587,7 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
|
||||
}
|
||||
|
||||
return new WorkspaceResult(mBgDataModel.workspaceItems, mBgDataModel.appWidgets,
|
||||
mBgDataModel.widgetsModel);
|
||||
mBgDataModel.cachedPredictedItems, mBgDataModel.widgetsModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,7 +616,7 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
|
||||
loadWorkspace(allShortcuts, LauncherSettings.Favorites.PREVIEW_CONTENT_URI);
|
||||
mBgDataModel.widgetsModel.update(mApp, null);
|
||||
return new WorkspaceResult(mBgDataModel.workspaceItems, mBgDataModel.appWidgets,
|
||||
mBgDataModel.widgetsModel);
|
||||
mBgDataModel.cachedPredictedItems, mBgDataModel.widgetsModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,12 +636,15 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
|
||||
private static class WorkspaceResult {
|
||||
private final ArrayList<ItemInfo> mWorkspaceItems;
|
||||
private final ArrayList<LauncherAppWidgetInfo> mAppWidgets;
|
||||
private final ArrayList<AppInfo> mCachedPredictedItems;
|
||||
private final WidgetsModel mWidgetsModel;
|
||||
|
||||
private WorkspaceResult(ArrayList<ItemInfo> workspaceItems,
|
||||
ArrayList<LauncherAppWidgetInfo> appWidgets, WidgetsModel widgetsModel) {
|
||||
ArrayList<LauncherAppWidgetInfo> appWidgets,
|
||||
ArrayList<AppInfo> cachedPredictedItems, WidgetsModel widgetsModel) {
|
||||
mWorkspaceItems = workspaceItems;
|
||||
mAppWidgets = appWidgets;
|
||||
mCachedPredictedItems = cachedPredictedItems;
|
||||
mWidgetsModel = widgetsModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.uioverrides;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
|
||||
/** A util class that inflates a predicted app icon */
|
||||
public class PredictedAppIconInflater {
|
||||
public static View inflate(LayoutInflater inflater, ViewGroup parent, WorkspaceItemInfo info) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user