2018-11-21 14:12:00 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2018 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.
|
2021-04-24 09:48:35 +02:00
|
|
|
*
|
|
|
|
|
* Modifications copyright 2021, Lawnchair
|
2018-11-21 14:12:00 -08:00
|
|
|
*/
|
|
|
|
|
package com.android.launcher3.graphics;
|
|
|
|
|
|
2021-07-19 20:54:14 -04:00
|
|
|
import static android.app.WallpaperManager.FLAG_SYSTEM;
|
2018-11-21 14:12:00 -08:00
|
|
|
import static android.view.View.MeasureSpec.EXACTLY;
|
|
|
|
|
import static android.view.View.MeasureSpec.makeMeasureSpec;
|
|
|
|
|
import static android.view.View.VISIBLE;
|
|
|
|
|
|
2020-08-11 18:49:28 -07:00
|
|
|
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
|
2019-11-29 21:47:29 -08:00
|
|
|
import static com.android.launcher3.model.ModelUtils.filterCurrentWorkspaceItems;
|
2020-05-28 00:59:44 -07:00
|
|
|
import static com.android.launcher3.model.ModelUtils.getMissingHotseatRanks;
|
2019-11-29 21:47:29 -08:00
|
|
|
import static com.android.launcher3.model.ModelUtils.sortWorkspaceItemsSpatially;
|
|
|
|
|
|
2018-11-21 14:12:00 -08:00
|
|
|
import android.annotation.TargetApi;
|
|
|
|
|
import android.app.Fragment;
|
2021-07-19 20:54:14 -04:00
|
|
|
import android.app.WallpaperColors;
|
|
|
|
|
import android.app.WallpaperManager;
|
2020-02-18 11:52:53 -08:00
|
|
|
import android.appwidget.AppWidgetHostView;
|
2020-07-13 23:13:00 -07:00
|
|
|
import android.appwidget.AppWidgetProviderInfo;
|
2018-11-21 14:12:00 -08:00
|
|
|
import android.content.Context;
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
import android.content.ContextWrapper;
|
2018-11-21 14:12:00 -08:00
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.graphics.drawable.AdaptiveIconDrawable;
|
|
|
|
|
import android.graphics.drawable.ColorDrawable;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.Looper;
|
|
|
|
|
import android.os.Process;
|
|
|
|
|
import android.util.AttributeSet;
|
2021-07-19 20:54:14 -04:00
|
|
|
import android.util.SparseIntArray;
|
2018-11-21 14:12:00 -08:00
|
|
|
import android.view.ContextThemeWrapper;
|
|
|
|
|
import android.view.LayoutInflater;
|
2021-06-29 18:12:38 -04:00
|
|
|
import android.view.MotionEvent;
|
2018-11-21 14:12:00 -08:00
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
2021-05-20 01:50:03 +08:00
|
|
|
import android.view.WindowInsets;
|
|
|
|
|
import android.view.WindowManager;
|
2018-11-21 14:12:00 -08:00
|
|
|
import android.widget.TextClock;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.BubbleTextView;
|
|
|
|
|
import com.android.launcher3.CellLayout;
|
|
|
|
|
import com.android.launcher3.DeviceProfile;
|
|
|
|
|
import com.android.launcher3.Hotseat;
|
|
|
|
|
import com.android.launcher3.InsettableFrameLayout;
|
|
|
|
|
import com.android.launcher3.InvariantDeviceProfile;
|
2019-11-29 21:47:29 -08:00
|
|
|
import com.android.launcher3.LauncherAppState;
|
2018-11-21 14:12:00 -08:00
|
|
|
import com.android.launcher3.LauncherSettings.Favorites;
|
|
|
|
|
import com.android.launcher3.R;
|
2021-05-20 01:50:03 +08:00
|
|
|
import com.android.launcher3.Utilities;
|
2018-11-21 14:12:00 -08:00
|
|
|
import com.android.launcher3.WorkspaceLayoutManager;
|
|
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
2019-12-09 13:42:57 -08:00
|
|
|
import com.android.launcher3.folder.FolderIcon;
|
2018-11-21 14:12:00 -08:00
|
|
|
import com.android.launcher3.icons.BaseIconFactory;
|
|
|
|
|
import com.android.launcher3.icons.BitmapInfo;
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
import com.android.launcher3.icons.LauncherIcons;
|
2019-11-29 21:47:29 -08:00
|
|
|
import com.android.launcher3.model.BgDataModel;
|
2020-08-11 18:49:28 -07:00
|
|
|
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
2020-02-18 11:52:53 -08:00
|
|
|
import com.android.launcher3.model.WidgetItem;
|
|
|
|
|
import com.android.launcher3.model.WidgetsModel;
|
2020-04-06 15:11:17 -07:00
|
|
|
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;
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
import com.android.launcher3.pm.InstallSessionHelper;
|
|
|
|
|
import com.android.launcher3.pm.UserCache;
|
2020-05-28 00:59:44 -07:00
|
|
|
import com.android.launcher3.uioverrides.PredictedAppIconInflater;
|
2020-02-24 13:50:29 -08:00
|
|
|
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
2020-07-13 23:13:00 -07:00
|
|
|
import com.android.launcher3.util.ComponentKey;
|
2020-05-28 00:59:44 -07:00
|
|
|
import com.android.launcher3.util.IntArray;
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
import com.android.launcher3.util.MainThreadInitializedObject;
|
2018-11-21 14:12:00 -08:00
|
|
|
import com.android.launcher3.views.ActivityContext;
|
|
|
|
|
import com.android.launcher3.views.BaseDragLayer;
|
2021-02-22 14:03:44 +00:00
|
|
|
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
|
2021-07-19 20:54:14 -04:00
|
|
|
import com.android.launcher3.widget.LocalColorExtractor;
|
2020-02-24 13:50:29 -08:00
|
|
|
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2019-11-29 21:47:29 -08:00
|
|
|
import java.util.ArrayList;
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
import java.util.Arrays;
|
2020-08-11 18:49:28 -07:00
|
|
|
import java.util.Collections;
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2021-10-12 15:02:28 +07:00
|
|
|
import app.lawnchair.font.FontCache;
|
|
|
|
|
import app.lawnchair.font.FontManager;
|
2021-10-13 12:04:04 +07:00
|
|
|
import app.lawnchair.icons.CustomAdaptiveIconDrawable;
|
2021-10-12 15:02:28 +07:00
|
|
|
import app.lawnchair.icons.IconPackProvider;
|
|
|
|
|
import app.lawnchair.preferences.PreferenceManager;
|
|
|
|
|
|
2018-11-21 14:12:00 -08:00
|
|
|
/**
|
|
|
|
|
* Utility class for generating the preview of Launcher for a given InvariantDeviceProfile.
|
|
|
|
|
* Steps:
|
|
|
|
|
* 1) Create a dummy icon info with just white icon
|
|
|
|
|
* 2) Inflate a strip down layout definition for Launcher
|
|
|
|
|
* 3) Place appropriate elements like icons and first-page qsb
|
|
|
|
|
* 4) Measure and draw the view on a canvas
|
|
|
|
|
*/
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.O)
|
2021-04-23 11:40:58 -07:00
|
|
|
public class LauncherPreviewRenderer extends ContextWrapper
|
2020-08-10 17:04:40 -07:00
|
|
|
implements ActivityContext, WorkspaceLayoutManager, LayoutInflater.Factory2 {
|
2018-11-21 14:12:00 -08:00
|
|
|
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
/**
|
|
|
|
|
* Context used just for preview. It also provides a few objects (e.g. UserCache) just for
|
|
|
|
|
* preview purposes.
|
|
|
|
|
*/
|
|
|
|
|
public static class PreviewContext extends ContextWrapper {
|
|
|
|
|
|
2020-07-29 23:21:51 -07:00
|
|
|
private final Set<MainThreadInitializedObject> mAllowedObjects = new HashSet<>(
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
Arrays.asList(UserCache.INSTANCE, InstallSessionHelper.INSTANCE,
|
2020-02-24 13:50:29 -08:00
|
|
|
LauncherAppState.INSTANCE, InvariantDeviceProfile.INSTANCE,
|
|
|
|
|
CustomWidgetManager.INSTANCE, PluginManagerWrapper.INSTANCE));
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
|
|
|
|
|
private final InvariantDeviceProfile mIdp;
|
|
|
|
|
private final Map<MainThreadInitializedObject, Object> mObjectMap = new HashMap<>();
|
|
|
|
|
private final ConcurrentLinkedQueue<LauncherIconsForPreview> mIconPool =
|
|
|
|
|
new ConcurrentLinkedQueue<>();
|
|
|
|
|
|
2021-05-19 19:42:14 -07:00
|
|
|
private boolean mDestroyed = false;
|
|
|
|
|
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
public PreviewContext(Context base, InvariantDeviceProfile idp) {
|
|
|
|
|
super(base);
|
|
|
|
|
mIdp = idp;
|
2021-10-12 15:02:28 +07:00
|
|
|
putBaseInstance(PreferenceManager.INSTANCE);
|
|
|
|
|
putBaseInstance(FontCache.INSTANCE);
|
|
|
|
|
putBaseInstance(FontManager.INSTANCE);
|
|
|
|
|
putBaseInstance(IconPackProvider.INSTANCE);
|
2021-05-19 19:42:14 -07:00
|
|
|
mObjectMap.put(InvariantDeviceProfile.INSTANCE, idp);
|
|
|
|
|
mObjectMap.put(LauncherAppState.INSTANCE,
|
|
|
|
|
new LauncherAppState(this, null /* iconCacheFileName */));
|
2021-10-12 15:02:28 +07:00
|
|
|
}
|
2021-05-19 19:42:14 -07:00
|
|
|
|
2021-10-12 15:02:28 +07:00
|
|
|
private void putBaseInstance(MainThreadInitializedObject mainThreadInitializedObject) {
|
|
|
|
|
mAllowedObjects.add(mainThreadInitializedObject);
|
|
|
|
|
mObjectMap.put(mainThreadInitializedObject, mainThreadInitializedObject.get(getBaseContext()));
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Context getApplicationContext() {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-24 13:50:29 -08:00
|
|
|
public void onDestroy() {
|
2021-05-19 19:42:14 -07:00
|
|
|
CustomWidgetManager.INSTANCE.get(this).onDestroy();
|
|
|
|
|
LauncherAppState.INSTANCE.get(this).onTerminate();
|
|
|
|
|
mDestroyed = true;
|
2020-02-24 13:50:29 -08:00
|
|
|
}
|
|
|
|
|
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
/**
|
|
|
|
|
* Find a cached object from mObjectMap if we have already created one. If not, generate
|
|
|
|
|
* an object using the provider.
|
|
|
|
|
*/
|
|
|
|
|
public <T> T getObject(MainThreadInitializedObject<T> mainThreadInitializedObject,
|
|
|
|
|
MainThreadInitializedObject.ObjectProvider<T> provider) {
|
2021-05-19 19:42:14 -07:00
|
|
|
if (FeatureFlags.IS_STUDIO_BUILD && mDestroyed) {
|
|
|
|
|
throw new RuntimeException("Context already destroyed");
|
|
|
|
|
}
|
2020-07-29 23:21:51 -07:00
|
|
|
if (!mAllowedObjects.contains(mainThreadInitializedObject)) {
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
throw new IllegalStateException("Leaking unknown objects");
|
|
|
|
|
}
|
|
|
|
|
if (mObjectMap.containsKey(mainThreadInitializedObject)) {
|
|
|
|
|
return (T) mObjectMap.get(mainThreadInitializedObject);
|
|
|
|
|
}
|
|
|
|
|
T t = provider.get(this);
|
|
|
|
|
mObjectMap.put(mainThreadInitializedObject, t);
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LauncherIcons newLauncherIcons(Context context, boolean shapeDetection) {
|
|
|
|
|
LauncherIconsForPreview launcherIconsForPreview = mIconPool.poll();
|
|
|
|
|
if (launcherIconsForPreview != null) {
|
|
|
|
|
return launcherIconsForPreview;
|
|
|
|
|
}
|
|
|
|
|
return new LauncherIconsForPreview(context, mIdp.fillResIconDpi, mIdp.iconBitmapSize,
|
|
|
|
|
-1 /* poolId */, shapeDetection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final class LauncherIconsForPreview extends LauncherIcons {
|
|
|
|
|
|
|
|
|
|
private LauncherIconsForPreview(Context context, int fillResIconDpi, int iconBitmapSize,
|
|
|
|
|
int poolId, boolean shapeDetection) {
|
|
|
|
|
super(context, fillResIconDpi, iconBitmapSize, poolId, shapeDetection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void recycle() {
|
|
|
|
|
// Clear any temporary state variables
|
|
|
|
|
clear();
|
|
|
|
|
mIconPool.offer(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 14:12:00 -08:00
|
|
|
private final Handler mUiHandler;
|
|
|
|
|
private final Context mContext;
|
|
|
|
|
private final InvariantDeviceProfile mIdp;
|
|
|
|
|
private final DeviceProfile mDp;
|
|
|
|
|
private final Rect mInsets;
|
2019-03-27 16:03:06 -07:00
|
|
|
private final WorkspaceItemInfo mWorkspaceItemInfo;
|
2020-08-10 17:04:40 -07:00
|
|
|
private final LayoutInflater mHomeElementInflater;
|
|
|
|
|
private final InsettableFrameLayout mRootView;
|
|
|
|
|
private final Hotseat mHotseat;
|
|
|
|
|
private final CellLayout mWorkspace;
|
2021-07-19 20:54:14 -04:00
|
|
|
private final SparseIntArray mWallpaperColorResources;
|
|
|
|
|
|
|
|
|
|
public LauncherPreviewRenderer(Context context,
|
|
|
|
|
InvariantDeviceProfile idp,
|
|
|
|
|
WallpaperColors wallpaperColorsOverride) {
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2021-04-23 11:40:58 -07:00
|
|
|
super(context);
|
2018-11-21 14:12:00 -08:00
|
|
|
mUiHandler = new Handler(Looper.getMainLooper());
|
|
|
|
|
mContext = context;
|
|
|
|
|
mIdp = idp;
|
2021-04-22 10:12:54 -07:00
|
|
|
mDp = idp.getDeviceProfile(context).copy(context);
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2021-05-20 01:50:03 +08:00
|
|
|
if (Utilities.ATLEAST_R) {
|
|
|
|
|
WindowInsets currentWindowInsets = context.getSystemService(WindowManager.class)
|
|
|
|
|
.getCurrentWindowMetrics().getWindowInsets();
|
|
|
|
|
mInsets = new Rect(
|
|
|
|
|
currentWindowInsets.getSystemWindowInsetLeft(),
|
|
|
|
|
currentWindowInsets.getSystemWindowInsetTop(),
|
|
|
|
|
currentWindowInsets.getSystemWindowInsetRight(),
|
|
|
|
|
currentWindowInsets.getSystemWindowInsetBottom());
|
|
|
|
|
} else {
|
|
|
|
|
mInsets = new Rect();
|
|
|
|
|
mInsets.left = mInsets.right = (mDp.widthPx - mDp.availableWidthPx) / 2;
|
|
|
|
|
mInsets.top = mInsets.bottom = (mDp.heightPx - mDp.availableHeightPx) / 2;
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
mDp.updateInsets(mInsets);
|
|
|
|
|
|
|
|
|
|
BaseIconFactory iconFactory =
|
|
|
|
|
new BaseIconFactory(context, mIdp.fillResIconDpi, mIdp.iconBitmapSize) { };
|
2021-10-13 12:04:04 +07:00
|
|
|
BitmapInfo iconInfo = iconFactory.createBadgedIconBitmap(new CustomAdaptiveIconDrawable(
|
2018-11-21 14:12:00 -08:00
|
|
|
new ColorDrawable(Color.WHITE), new ColorDrawable(Color.WHITE)),
|
|
|
|
|
Process.myUserHandle(),
|
|
|
|
|
Build.VERSION.SDK_INT);
|
|
|
|
|
|
2019-03-27 16:03:06 -07:00
|
|
|
mWorkspaceItemInfo = new WorkspaceItemInfo();
|
2019-10-25 13:41:28 -07:00
|
|
|
mWorkspaceItemInfo.bitmap = iconInfo;
|
2019-03-27 16:03:06 -07:00
|
|
|
mWorkspaceItemInfo.intent = new Intent();
|
|
|
|
|
mWorkspaceItemInfo.contentDescription = mWorkspaceItemInfo.title =
|
2018-11-21 14:12:00 -08:00
|
|
|
context.getString(R.string.label_application);
|
2020-08-10 17:04:40 -07:00
|
|
|
|
|
|
|
|
mHomeElementInflater = LayoutInflater.from(
|
|
|
|
|
new ContextThemeWrapper(this, R.style.HomeScreenElementTheme));
|
|
|
|
|
mHomeElementInflater.setFactory2(this);
|
|
|
|
|
|
|
|
|
|
mRootView = (InsettableFrameLayout) mHomeElementInflater.inflate(
|
|
|
|
|
R.layout.launcher_preview_layout, null, false);
|
|
|
|
|
mRootView.setInsets(mInsets);
|
|
|
|
|
measureView(mRootView, mDp.widthPx, mDp.heightPx);
|
|
|
|
|
|
|
|
|
|
mHotseat = mRootView.findViewById(R.id.hotseat);
|
|
|
|
|
mHotseat.resetLayout(false);
|
|
|
|
|
|
|
|
|
|
mWorkspace = mRootView.findViewById(R.id.workspace);
|
|
|
|
|
mWorkspace.setPadding(mDp.workspacePadding.left + mDp.cellLayoutPaddingLeftRightPx,
|
|
|
|
|
mDp.workspacePadding.top,
|
|
|
|
|
mDp.workspacePadding.right + mDp.cellLayoutPaddingLeftRightPx,
|
|
|
|
|
mDp.workspacePadding.bottom);
|
2021-07-19 20:54:14 -04:00
|
|
|
|
|
|
|
|
if (Utilities.ATLEAST_S) {
|
|
|
|
|
WallpaperColors wallpaperColors = wallpaperColorsOverride != null
|
|
|
|
|
? wallpaperColorsOverride
|
|
|
|
|
: WallpaperManager.getInstance(context).getWallpaperColors(FLAG_SYSTEM);
|
2021-08-04 14:21:27 -04:00
|
|
|
mWallpaperColorResources = wallpaperColors != null ? LocalColorExtractor.newInstance(
|
|
|
|
|
context).generateColorsOverride(wallpaperColors) : null;
|
2021-07-19 20:54:14 -04:00
|
|
|
} else {
|
|
|
|
|
mWallpaperColorResources = null;
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 16:22:50 -08:00
|
|
|
/** Populate preview and render it. */
|
2021-05-19 19:42:14 -07:00
|
|
|
public View getRenderedView(BgDataModel dataModel,
|
|
|
|
|
Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
|
|
|
|
|
populate(dataModel, widgetProviderInfoMap);
|
2020-08-10 17:04:40 -07:00
|
|
|
return mRootView;
|
2020-03-06 16:22:50 -08:00
|
|
|
}
|
|
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
@Override
|
|
|
|
|
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
|
|
|
|
|
if ("TextClock".equals(name)) {
|
|
|
|
|
// Workaround for TextClock accessing handler for unregistering ticker.
|
|
|
|
|
return new TextClock(context, attrs) {
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
@Override
|
|
|
|
|
public Handler getHandler() {
|
|
|
|
|
return mUiHandler;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} else if (!"fragment".equals(name)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PreviewFragment);
|
|
|
|
|
FragmentWithPreview f = (FragmentWithPreview) Fragment.instantiate(
|
|
|
|
|
context, ta.getString(R.styleable.PreviewFragment_android_name));
|
|
|
|
|
f.enterPreviewMode(context);
|
|
|
|
|
f.onInit(null);
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
View view = f.onCreateView(LayoutInflater.from(context), (ViewGroup) parent, null);
|
|
|
|
|
view.setId(ta.getInt(R.styleable.PreviewFragment_android_id, View.NO_ID));
|
|
|
|
|
return view;
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
@Override
|
|
|
|
|
public View onCreateView(String name, Context context, AttributeSet attrs) {
|
|
|
|
|
return onCreateView(null, name, context, attrs);
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
@Override
|
|
|
|
|
public BaseDragLayer getDragLayer() {
|
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
@Override
|
|
|
|
|
public DeviceProfile getDeviceProfile() {
|
|
|
|
|
return mDp;
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
@Override
|
|
|
|
|
public Hotseat getHotseat() {
|
|
|
|
|
return mHotseat;
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
@Override
|
|
|
|
|
public CellLayout getScreenWithId(int screenId) {
|
|
|
|
|
return mWorkspace;
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
private void inflateAndAddIcon(WorkspaceItemInfo info) {
|
|
|
|
|
BubbleTextView icon = (BubbleTextView) mHomeElementInflater.inflate(
|
|
|
|
|
R.layout.app_icon, mWorkspace, false);
|
|
|
|
|
icon.applyFromWorkspaceItem(info);
|
|
|
|
|
addInScreenFromBind(icon, info);
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
private void inflateAndAddFolder(FolderInfo info) {
|
|
|
|
|
FolderIcon folderIcon = FolderIcon.inflateIcon(R.layout.folder_icon, this, mWorkspace,
|
|
|
|
|
info);
|
|
|
|
|
addInScreenFromBind(folderIcon, info);
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
private void inflateAndAddWidgets(
|
|
|
|
|
LauncherAppWidgetInfo info,
|
|
|
|
|
Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
|
|
|
|
|
if (widgetProviderInfoMap == null) {
|
|
|
|
|
return;
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|
2020-08-10 17:04:40 -07:00
|
|
|
AppWidgetProviderInfo providerInfo = widgetProviderInfoMap.get(
|
|
|
|
|
new ComponentKey(info.providerName, info.user));
|
|
|
|
|
if (providerInfo == null) {
|
|
|
|
|
return;
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|
2020-08-10 17:04:40 -07:00
|
|
|
inflateAndAddWidgets(info, LauncherAppWidgetProviderInfo.fromProviderInfo(
|
|
|
|
|
getApplicationContext(), providerInfo));
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
private void inflateAndAddWidgets(LauncherAppWidgetInfo info, WidgetsModel widgetsModel) {
|
|
|
|
|
WidgetItem widgetItem = widgetsModel.getWidgetProviderInfoByProviderName(
|
|
|
|
|
info.providerName);
|
|
|
|
|
if (widgetItem == null) {
|
|
|
|
|
return;
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|
2020-08-10 17:04:40 -07:00
|
|
|
inflateAndAddWidgets(info, widgetItem.widgetInfo);
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
private void inflateAndAddWidgets(
|
|
|
|
|
LauncherAppWidgetInfo info, LauncherAppWidgetProviderInfo providerInfo) {
|
|
|
|
|
AppWidgetHostView view = new AppWidgetHostView(mContext);
|
|
|
|
|
view.setAppWidget(-1, providerInfo);
|
|
|
|
|
view.updateAppWidget(null);
|
|
|
|
|
view.setTag(info);
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2021-07-19 20:54:14 -04:00
|
|
|
if (mWallpaperColorResources != null) {
|
|
|
|
|
view.setColorResources(mWallpaperColorResources);
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|
|
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
addInScreenFromBind(view, info);
|
|
|
|
|
}
|
2019-12-09 13:42:57 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
private void inflateAndAddPredictedIcon(WorkspaceItemInfo info) {
|
|
|
|
|
View view = PredictedAppIconInflater.inflate(mHomeElementInflater, mWorkspace, info);
|
|
|
|
|
if (view != null) {
|
|
|
|
|
addInScreenFromBind(view, info);
|
2020-07-13 23:13:00 -07:00
|
|
|
}
|
2020-08-10 17:04:40 -07:00
|
|
|
}
|
2020-07-13 23:13:00 -07:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
private void dispatchVisibilityAggregated(View view, boolean isVisible) {
|
|
|
|
|
// Similar to View.dispatchVisibilityAggregated implementation.
|
|
|
|
|
final boolean thisVisible = view.getVisibility() == VISIBLE;
|
|
|
|
|
if (thisVisible || !isVisible) {
|
|
|
|
|
view.onVisibilityAggregated(isVisible);
|
2020-07-13 23:13:00 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
if (view instanceof ViewGroup) {
|
|
|
|
|
isVisible = thisVisible && isVisible;
|
|
|
|
|
ViewGroup vg = (ViewGroup) view;
|
|
|
|
|
int count = vg.getChildCount();
|
2020-02-18 11:52:53 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
dispatchVisibilityAggregated(vg.getChildAt(i), isVisible);
|
2020-05-28 00:59:44 -07:00
|
|
|
}
|
|
|
|
|
}
|
2020-08-10 17:04:40 -07:00
|
|
|
}
|
2020-05-28 00:59:44 -07:00
|
|
|
|
2021-05-19 19:42:14 -07:00
|
|
|
private void populate(BgDataModel dataModel,
|
|
|
|
|
Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
|
2021-04-23 11:40:58 -07:00
|
|
|
// Separate the items that are on the current screen, and the other remaining items.
|
|
|
|
|
ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
|
|
|
|
|
ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<>();
|
|
|
|
|
ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<>();
|
|
|
|
|
ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<>();
|
|
|
|
|
filterCurrentWorkspaceItems(0 /* currentScreenId */,
|
2021-05-19 19:42:14 -07:00
|
|
|
dataModel.workspaceItems, currentWorkspaceItems,
|
2021-04-23 11:40:58 -07:00
|
|
|
otherWorkspaceItems);
|
2021-05-19 19:42:14 -07:00
|
|
|
filterCurrentWorkspaceItems(0 /* currentScreenId */, dataModel.appWidgets,
|
2021-04-23 11:40:58 -07:00
|
|
|
currentAppWidgets, otherAppWidgets);
|
|
|
|
|
sortWorkspaceItemsSpatially(mIdp, currentWorkspaceItems);
|
|
|
|
|
for (ItemInfo itemInfo : currentWorkspaceItems) {
|
|
|
|
|
switch (itemInfo.itemType) {
|
|
|
|
|
case Favorites.ITEM_TYPE_APPLICATION:
|
|
|
|
|
case Favorites.ITEM_TYPE_SHORTCUT:
|
|
|
|
|
case Favorites.ITEM_TYPE_DEEP_SHORTCUT:
|
|
|
|
|
inflateAndAddIcon((WorkspaceItemInfo) itemInfo);
|
|
|
|
|
break;
|
|
|
|
|
case Favorites.ITEM_TYPE_FOLDER:
|
|
|
|
|
inflateAndAddFolder((FolderInfo) itemInfo);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-23 11:40:58 -07:00
|
|
|
for (ItemInfo itemInfo : currentAppWidgets) {
|
|
|
|
|
switch (itemInfo.itemType) {
|
|
|
|
|
case Favorites.ITEM_TYPE_APPWIDGET:
|
|
|
|
|
case Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
|
2021-05-19 19:42:14 -07:00
|
|
|
if (widgetProviderInfoMap != null) {
|
|
|
|
|
inflateAndAddWidgets(
|
|
|
|
|
(LauncherAppWidgetInfo) itemInfo, widgetProviderInfoMap);
|
2021-04-23 11:40:58 -07:00
|
|
|
} else {
|
|
|
|
|
inflateAndAddWidgets((LauncherAppWidgetInfo) itemInfo,
|
2021-05-19 19:42:14 -07:00
|
|
|
dataModel.widgetsModel);
|
2019-11-29 21:47:29 -08:00
|
|
|
}
|
2021-04-23 11:40:58 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|
2020-08-10 17:04:40 -07:00
|
|
|
}
|
2021-04-23 11:40:58 -07:00
|
|
|
IntArray ranks = getMissingHotseatRanks(currentWorkspaceItems,
|
|
|
|
|
mDp.numShownHotseatIcons);
|
2021-05-19 19:42:14 -07:00
|
|
|
FixedContainerItems hotseatpredictions =
|
|
|
|
|
dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
|
|
|
|
|
List<ItemInfo> predictions = hotseatpredictions == null
|
|
|
|
|
? Collections.emptyList() : hotseatpredictions.items;
|
2021-04-23 11:40:58 -07:00
|
|
|
int count = Math.min(ranks.size(), predictions.size());
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
int rank = ranks.get(i);
|
|
|
|
|
WorkspaceItemInfo itemInfo =
|
|
|
|
|
new WorkspaceItemInfo((WorkspaceItemInfo) predictions.get(i));
|
|
|
|
|
itemInfo.container = CONTAINER_HOTSEAT_PREDICTION;
|
|
|
|
|
itemInfo.rank = rank;
|
|
|
|
|
itemInfo.cellX = mHotseat.getCellXFromOrder(rank);
|
|
|
|
|
itemInfo.cellY = mHotseat.getCellYFromOrder(rank);
|
|
|
|
|
itemInfo.screenId = rank;
|
|
|
|
|
inflateAndAddPredictedIcon(itemInfo);
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
// Add first page QSB
|
2021-10-08 12:14:19 +07:00
|
|
|
if (FeatureFlags.topQsbOnFirstScreenEnabled(mContext)) {
|
2020-08-10 17:04:40 -07:00
|
|
|
View qsb = mHomeElementInflater.inflate(
|
|
|
|
|
R.layout.search_container_workspace, mWorkspace, false);
|
|
|
|
|
CellLayout.LayoutParams lp =
|
|
|
|
|
new CellLayout.LayoutParams(0, 0, mWorkspace.getCountX(), 1);
|
|
|
|
|
lp.canReorder = false;
|
|
|
|
|
mWorkspace.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true);
|
2020-03-06 16:22:50 -08:00
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
|
2020-08-10 17:04:40 -07:00
|
|
|
measureView(mRootView, mDp.widthPx, mDp.heightPx);
|
|
|
|
|
dispatchVisibilityAggregated(mRootView, true);
|
|
|
|
|
measureView(mRootView, mDp.widthPx, mDp.heightPx);
|
|
|
|
|
// Additional measure for views which use auto text size API
|
|
|
|
|
measureView(mRootView, mDp.widthPx, mDp.heightPx);
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|
|
|
|
|
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
private static void measureView(View view, int width, int height) {
|
|
|
|
|
view.measure(makeMeasureSpec(width, EXACTLY), makeMeasureSpec(height, EXACTLY));
|
|
|
|
|
view.layout(0, 0, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 18:12:38 -04:00
|
|
|
/** Root layout for launcher preview that intercepts all touch events. */
|
|
|
|
|
public static class LauncherPreviewLayout extends InsettableFrameLayout {
|
|
|
|
|
public LauncherPreviewLayout(Context context, AttributeSet attrs) {
|
|
|
|
|
super(context, attrs);
|
Render user's actual workspace in ThemePicker preview (Part 3)
go/grid-migration-preview
With this change, we can see actual grid migration in wallpaper preview.
The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.
UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.
Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
2020-01-12 01:07:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-06-29 18:12:38 -04:00
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
|
return true;
|
2020-02-18 11:52:53 -08:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-21 14:12:00 -08:00
|
|
|
}
|