Loading quickstep/src/com/android/launcher3/uioverrides/PreviewSurfaceRenderer.java 0 → 100644 +45 −0 Original line number Diff line number Diff line /* * 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 static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import android.content.Context; import android.os.Bundle; import android.util.Size; import android.view.View; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.graphics.LauncherPreviewRenderer; import com.android.systemui.shared.system.SurfaceViewRequestReceiver; /** Render preview using surface view. */ public class PreviewSurfaceRenderer { /** Handle a received surface view request. */ public static void render(Context context, Bundle bundle) { final String gridName = bundle.getString("name"); bundle.remove("name"); final InvariantDeviceProfile idp = new InvariantDeviceProfile(context, gridName); MAIN_EXECUTOR.execute(() -> { View view = new LauncherPreviewRenderer(context, idp).getRenderedView(); new SurfaceViewRequestReceiver().onReceive(context, bundle, view, new Size(view.getMeasuredWidth(), view.getMeasuredHeight())); }); } } src/com/android/launcher3/config/FeatureFlags.java +4 −2 Original line number Diff line number Diff line Loading @@ -131,8 +131,10 @@ public final class FeatureFlags { "MULTI_DB_GRID_MIRATION_ALGO", false, "Use the multi-db grid migration algorithm"); public static final BooleanFlag ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER = getDebugFlag( "ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER", true, "Show launcher preview in grid picker"); "ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER", true, "Show launcher preview in grid picker"); public static final BooleanFlag USE_SURFACE_VIEW_FOR_GRID_PREVIEW = getDebugFlag( "USE_SURFACE_VIEW_FOR_GRID_PREVIEW", false, "Use surface view for grid preview"); public static final BooleanFlag ENABLE_OVERVIEW_ACTIONS = getDebugFlag( "ENABLE_OVERVIEW_ACTIONS", true, "Show app actions instead of the shelf in Overview." Loading src/com/android/launcher3/graphics/GridOptionsProvider.java +21 −0 Original line number Diff line number Diff line package com.android.launcher3.graphics; import static com.android.launcher3.config.FeatureFlags.USE_SURFACE_VIEW_FOR_GRID_PREVIEW; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import android.content.ContentProvider; Loading @@ -19,6 +20,7 @@ import android.util.Xml; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.InvariantDeviceProfile.GridOption; import com.android.launcher3.R; import com.android.launcher3.uioverrides.PreviewSurfaceRenderer; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -62,6 +64,11 @@ public class GridOptionsProvider extends ContentProvider { private static final String KEY_PREVIEW = "preview"; private static final String MIME_TYPE_PNG = "image/png"; private static final String METHOD_GET_PREVIEW = "get_preview"; private static final String METADATA_KEY_PREVIEW_VERSION = "preview_version"; public static final PipeDataWriter<Future<Bitmap>> BITMAP_WRITER = new PipeDataWriter<Future<Bitmap>>() { @Override Loading Loading @@ -98,6 +105,10 @@ public class GridOptionsProvider extends ContentProvider { .add(KEY_IS_DEFAULT, idp.numColumns == gridOption.numColumns && idp.numRows == gridOption.numRows); } Bundle metadata = new Bundle(); metadata.putString(METADATA_KEY_PREVIEW_VERSION, USE_SURFACE_VIEW_FOR_GRID_PREVIEW.get() ? "V2" : "V1"); cursor.setExtras(metadata); return cursor; } Loading Loading @@ -188,4 +199,14 @@ public class GridOptionsProvider extends ContentProvider { throw new FileNotFoundException(e.getMessage()); } } @Override public Bundle call(String method, String arg, Bundle extras) { if (!METHOD_GET_PREVIEW.equals(method)) { return null; } PreviewSurfaceRenderer.render(getContext(), extras); return null; } } src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +11 −1 Original line number Diff line number Diff line Loading @@ -262,6 +262,13 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> { }); } /** Populate preview and render it. */ public View getRenderedView() { MainThreadRenderer renderer = new MainThreadRenderer(mContext); renderer.populate(); return renderer.mRootView; } private class MainThreadRenderer extends ContextThemeWrapper implements ActivityContext, WorkspaceLayoutManager, LayoutInflater.Factory2 { Loading Loading @@ -388,7 +395,7 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> { } } private void renderScreenShot(Canvas canvas) { private void populate() { if (ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER.get()) { boolean needsToMigrate = needsToMigrate(mContext, mIdp); boolean success = false; Loading Loading @@ -499,7 +506,10 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> { measureView(mRootView, mDp.widthPx, mDp.heightPx); // Additional measure for views which use auto text size API measureView(mRootView, mDp.widthPx, mDp.heightPx); } private void renderScreenShot(Canvas canvas) { populate(); mRootView.draw(canvas); dispatchVisibilityAggregated(mRootView, false); } Loading src_ui_overrides/com/android/launcher3/uioverrides/PreviewSurfaceRenderer.java 0 → 100644 +27 −0 Original line number Diff line number Diff line /* * 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.content.Context; import android.os.Bundle; /** Render preview using surface view. */ public class PreviewSurfaceRenderer { /** Handle a received surface view request. */ public static void render(Context context, Bundle bundle) { } } Loading
quickstep/src/com/android/launcher3/uioverrides/PreviewSurfaceRenderer.java 0 → 100644 +45 −0 Original line number Diff line number Diff line /* * 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 static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import android.content.Context; import android.os.Bundle; import android.util.Size; import android.view.View; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.graphics.LauncherPreviewRenderer; import com.android.systemui.shared.system.SurfaceViewRequestReceiver; /** Render preview using surface view. */ public class PreviewSurfaceRenderer { /** Handle a received surface view request. */ public static void render(Context context, Bundle bundle) { final String gridName = bundle.getString("name"); bundle.remove("name"); final InvariantDeviceProfile idp = new InvariantDeviceProfile(context, gridName); MAIN_EXECUTOR.execute(() -> { View view = new LauncherPreviewRenderer(context, idp).getRenderedView(); new SurfaceViewRequestReceiver().onReceive(context, bundle, view, new Size(view.getMeasuredWidth(), view.getMeasuredHeight())); }); } }
src/com/android/launcher3/config/FeatureFlags.java +4 −2 Original line number Diff line number Diff line Loading @@ -131,8 +131,10 @@ public final class FeatureFlags { "MULTI_DB_GRID_MIRATION_ALGO", false, "Use the multi-db grid migration algorithm"); public static final BooleanFlag ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER = getDebugFlag( "ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER", true, "Show launcher preview in grid picker"); "ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER", true, "Show launcher preview in grid picker"); public static final BooleanFlag USE_SURFACE_VIEW_FOR_GRID_PREVIEW = getDebugFlag( "USE_SURFACE_VIEW_FOR_GRID_PREVIEW", false, "Use surface view for grid preview"); public static final BooleanFlag ENABLE_OVERVIEW_ACTIONS = getDebugFlag( "ENABLE_OVERVIEW_ACTIONS", true, "Show app actions instead of the shelf in Overview." Loading
src/com/android/launcher3/graphics/GridOptionsProvider.java +21 −0 Original line number Diff line number Diff line package com.android.launcher3.graphics; import static com.android.launcher3.config.FeatureFlags.USE_SURFACE_VIEW_FOR_GRID_PREVIEW; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import android.content.ContentProvider; Loading @@ -19,6 +20,7 @@ import android.util.Xml; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.InvariantDeviceProfile.GridOption; import com.android.launcher3.R; import com.android.launcher3.uioverrides.PreviewSurfaceRenderer; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -62,6 +64,11 @@ public class GridOptionsProvider extends ContentProvider { private static final String KEY_PREVIEW = "preview"; private static final String MIME_TYPE_PNG = "image/png"; private static final String METHOD_GET_PREVIEW = "get_preview"; private static final String METADATA_KEY_PREVIEW_VERSION = "preview_version"; public static final PipeDataWriter<Future<Bitmap>> BITMAP_WRITER = new PipeDataWriter<Future<Bitmap>>() { @Override Loading Loading @@ -98,6 +105,10 @@ public class GridOptionsProvider extends ContentProvider { .add(KEY_IS_DEFAULT, idp.numColumns == gridOption.numColumns && idp.numRows == gridOption.numRows); } Bundle metadata = new Bundle(); metadata.putString(METADATA_KEY_PREVIEW_VERSION, USE_SURFACE_VIEW_FOR_GRID_PREVIEW.get() ? "V2" : "V1"); cursor.setExtras(metadata); return cursor; } Loading Loading @@ -188,4 +199,14 @@ public class GridOptionsProvider extends ContentProvider { throw new FileNotFoundException(e.getMessage()); } } @Override public Bundle call(String method, String arg, Bundle extras) { if (!METHOD_GET_PREVIEW.equals(method)) { return null; } PreviewSurfaceRenderer.render(getContext(), extras); return null; } }
src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +11 −1 Original line number Diff line number Diff line Loading @@ -262,6 +262,13 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> { }); } /** Populate preview and render it. */ public View getRenderedView() { MainThreadRenderer renderer = new MainThreadRenderer(mContext); renderer.populate(); return renderer.mRootView; } private class MainThreadRenderer extends ContextThemeWrapper implements ActivityContext, WorkspaceLayoutManager, LayoutInflater.Factory2 { Loading Loading @@ -388,7 +395,7 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> { } } private void renderScreenShot(Canvas canvas) { private void populate() { if (ENABLE_LAUNCHER_PREVIEW_IN_GRID_PICKER.get()) { boolean needsToMigrate = needsToMigrate(mContext, mIdp); boolean success = false; Loading Loading @@ -499,7 +506,10 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> { measureView(mRootView, mDp.widthPx, mDp.heightPx); // Additional measure for views which use auto text size API measureView(mRootView, mDp.widthPx, mDp.heightPx); } private void renderScreenShot(Canvas canvas) { populate(); mRootView.draw(canvas); dispatchVisibilityAggregated(mRootView, false); } Loading
src_ui_overrides/com/android/launcher3/uioverrides/PreviewSurfaceRenderer.java 0 → 100644 +27 −0 Original line number Diff line number Diff line /* * 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.content.Context; import android.os.Bundle; /** Render preview using surface view. */ public class PreviewSurfaceRenderer { /** Handle a received surface view request. */ public static void render(Context context, Bundle bundle) { } }