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

Commit de361f6b authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Switch to public API for surface view when rendering preview

Bug: 152003916
Test: Manual
Change-Id: I112c4de21032f09895014ffe3a01cfc06ce588d2
parent c7647b6e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -67,8 +67,8 @@ public class GridOptionsManager implements CustomizationManager<GridOption> {
    }

    /** Call through content provider API to render preview */
    public void renderPreview(Bundle bundle, String gridName) {
        mProvider.renderPreview(gridName, bundle);
    public Bundle renderPreview(Bundle bundle, String gridName) {
        return mProvider.renderPreview(gridName, bundle);
    }

    private static class FetchTask extends AsyncTask<Void, Void, Pair<List<GridOption>, String>> {
+2 −2
Original line number Diff line number Diff line
@@ -118,9 +118,9 @@ public class LauncherGridOptionsProvider {
     * @param bundle    surface view request bundle generated from
     *                  {@link SurfaceViewRequestUtils#createSurfaceBundle(SurfaceView)}.
     */
    void renderPreview(String name, Bundle bundle) {
    Bundle renderPreview(String name, Bundle bundle) {
        bundle.putString("name", name);
        mPreviewUtils.renderPreview(bundle);
        return mPreviewUtils.renderPreview(bundle);
    }

    int applyGrid(String name) {
+24 −5
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
@@ -47,7 +49,6 @@ import com.android.customization.module.ThemesUserEventLogger;
import com.android.customization.picker.BasePreviewAdapter;
import com.android.customization.picker.BasePreviewAdapter.PreviewPage;
import com.android.customization.widget.OptionSelectorController;
import com.android.systemui.shared.system.SurfaceViewRequestUtils;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.asset.ContentUriAsset;
@@ -55,6 +56,7 @@ import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.ToolbarFragment;
import com.android.wallpaper.util.SurfaceViewUtils;
import com.android.wallpaper.widget.PreviewPager;

import com.bumptech.glide.Glide;
@@ -282,11 +284,18 @@ public class GridFragment extends ToolbarFragment {
            if (usesSurfaceViewForPreview) {
                mPreviewSurface.setZOrderOnTop(true);
                mPreviewSurface.getHolder().addCallback(new SurfaceHolder.Callback() {

                    private Message mCallback;

                    @Override
                    public void surfaceCreated(SurfaceHolder holder) {
                        Bundle bundle = SurfaceViewRequestUtils.createSurfaceBundle(
                                mPreviewSurface);
                        mGridManager.renderPreview(bundle, mName);
                        Bundle result = mGridManager.renderPreview(
                                SurfaceViewUtils.createSurfaceViewRequest(mPreviewSurface), mName);
                        if (result != null) {
                            mPreviewSurface.setChildSurfacePackage(
                                    SurfaceViewUtils.getSurfacePackage(result));
                            mCallback = SurfaceViewUtils.getCallback(result);
                        }
                    }

                    @Override
@@ -294,7 +303,17 @@ public class GridFragment extends ToolbarFragment {
                            int height) {}

                    @Override
                    public void surfaceDestroyed(SurfaceHolder holder) {}
                    public void surfaceDestroyed(SurfaceHolder holder) {
                        if (mCallback != null) {
                            try {
                                mCallback.replyTo.send(mCallback);
                            } catch (RemoteException e) {
                                e.printStackTrace();
                            } finally {
                                mCallback = null;
                            }
                        }
                    }
                });
            } else {
                mPreviewAsset.loadDrawableWithTransition(mActivity,