Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 359fb55a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Send message to launcher renderer to update grid (3/3)" into main

parents 1dc86702 de4d7457
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ android_library {
        "com_android_wm_shell_flags_lib",
        "dagger2",
        "jsr330",

        "com_android_systemui_shared_flags_lib",
    ],
    manifest: "AndroidManifest-common.xml",
    sdk_version: "current",
+18 −4
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
import android.os.Message;
import android.os.Messenger;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;
@@ -80,8 +81,10 @@ public class GridCustomizationsProvider extends ContentProvider {
    private static final String KEY_SURFACE_PACKAGE = "surface_package";
    private static final String KEY_CALLBACK = "callback";
    public static final String KEY_HIDE_BOTTOM_ROW = "hide_bottom_row";
    public static final String KEY_GRID_NAME = "grid_name";

    private static final int MESSAGE_ID_UPDATE_PREVIEW = 1337;
    private static final int MESSAGE_ID_UPDATE_GRID = 7414;

    /**
     * Here we use the IBinder and the screen ID as the key of the active previews.
@@ -245,11 +248,22 @@ public class GridCustomizationsProvider extends ContentProvider {
            if (destroyed) {
                return true;
            }
            if (message.what == MESSAGE_ID_UPDATE_PREVIEW) {

            switch (message.what) {
                case MESSAGE_ID_UPDATE_PREVIEW:
                    renderer.hideBottomRow(message.getData().getBoolean(KEY_HIDE_BOTTOM_ROW));
            } else {
                    break;
                case MESSAGE_ID_UPDATE_GRID:
                    String gridName = message.getData().getString(KEY_GRID_NAME);
                    if (!TextUtils.isEmpty(gridName)) {
                        renderer.updateGrid(gridName);
                    }
                    break;
                default:
                    destroyObserver(this);
                    break;
            }

            return true;
        }

+52 −6
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.view.SurfaceControlViewHost;
import android.view.SurfaceControlViewHost.SurfacePackage;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -61,6 +62,7 @@ import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.Themes;
import com.android.launcher3.widget.LocalColorExtractor;
import com.android.systemui.shared.Flags;

import java.util.ArrayList;
import java.util.Map;
@@ -96,6 +98,7 @@ public class PreviewSurfaceRenderer {
    private boolean mDestroyed = false;
    private LauncherPreviewRenderer mRenderer;
    private boolean mHideQsb;
    @Nullable private FrameLayout mViewRoot = null;

    public PreviewSurfaceRenderer(Context context, Bundle bundle) throws Exception {
        mContext = context;
@@ -193,6 +196,19 @@ public class PreviewSurfaceRenderer {
        MODEL_EXECUTOR.execute(this::loadModelData);
    }

    /**
     * Update the grid of the launcher preview
     *
     * @param gridName Name of the grid, e.g. normal, practical
     */
    public void updateGrid(@NonNull String gridName) {
        if (gridName.equals(mGridName)) {
            return;
        }
        mGridName = gridName;
        loadAsync();
    }

    /**
     * Hides the components in the bottom row.
     *
@@ -302,11 +318,41 @@ public class PreviewSurfaceRenderer {
        view.setPivotY(0);
        view.setTranslationX((mWidth - scale * view.getWidth()) / 2);
        view.setTranslationY((mHeight - scale * view.getHeight()) / 2);
        if (!Flags.newCustomizationPickerUi()) {
            view.setAlpha(0);
            view.animate().alpha(1)
                    .setInterpolator(new AccelerateDecelerateInterpolator())
                    .setDuration(FADE_IN_ANIMATION_DURATION)
                    .start();
        mSurfaceControlViewHost.setView(view, view.getMeasuredWidth(), view.getMeasuredHeight());
            mSurfaceControlViewHost.setView(
                    view,
                    view.getMeasuredWidth(),
                    view.getMeasuredHeight()
            );
            return;
        }

        if (mViewRoot == null) {
            mViewRoot = new FrameLayout(inflationContext);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.WRAP_CONTENT, // Width
                    FrameLayout.LayoutParams.WRAP_CONTENT  // Height
            );
            mViewRoot.setLayoutParams(layoutParams);
            mViewRoot.addView(view);
            mViewRoot.setAlpha(0);
            mViewRoot.animate().alpha(1)
                    .setInterpolator(new AccelerateDecelerateInterpolator())
                    .setDuration(FADE_IN_ANIMATION_DURATION)
                    .start();
            mSurfaceControlViewHost.setView(
                    mViewRoot,
                    view.getMeasuredWidth(),
                    view.getMeasuredHeight()
            );
        } else  {
            mViewRoot.removeAllViews();
            mViewRoot.addView(view);
        }
    }
}