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

Commit 42cf9daa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Gets wallpaper color from live wallpaper to be used for workspace...

Merge "Gets wallpaper color from live wallpaper to be used for workspace preview" into ub-launcher3-master
parents fbc4732b 117d5e1f
Loading
Loading
Loading
Loading
+39 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static android.view.View.MeasureSpec.EXACTLY;
import static android.view.View.MeasureSpec.makeMeasureSpec;

import android.app.Activity;
import android.app.WallpaperColors;
import android.content.Intent;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -31,6 +32,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.MainThread;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Lifecycle;
@@ -43,7 +45,9 @@ import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.util.ScreenSizeCalculator;
import com.android.wallpaper.util.SizeCalculator;
import com.android.wallpaper.util.WallpaperConnection;
import com.android.wallpaper.util.WallpaperConnection.WallpaperConnectionListener;
import com.android.wallpaper.widget.LiveTileOverlay;
import com.android.wallpaper.widget.WallpaperColorsLoader;

/** A class to load the wallpaper to the view. */
public class WallpaperPreviewer implements LifecycleObserver {
@@ -63,6 +67,13 @@ public class WallpaperPreviewer implements LifecycleObserver {
    // Home workspace surface is behind the app window, and so must the home image wallpaper like
    // the live wallpaper. This view is rendered on mWallpaperSurface for home image wallpaper.
    private ImageView mHomeImageWallpaper;
    @Nullable private WallpaperColorsListener mWallpaperColorsListener;

    /** Interface for getting {@link WallpaperColors} from wallpaper. */
    public interface WallpaperColorsListener {
        /** Gets called when wallpaper color is available or updated. */
        void onWallpaperColorsChanged(WallpaperColors colors);
    }

    public WallpaperPreviewer(Lifecycle lifecycle, Activity activity, ImageView homePreview,
                              SurfaceView wallpaperSurface) {
@@ -129,9 +140,16 @@ public class WallpaperPreviewer implements LifecycleObserver {
        cardView.setRadius(SizeCalculator.getPreviewCornerRadius(mActivity, cardWidth));
    }

    /** Loads the wallpaper. */
    public void setWallpaper(WallpaperInfo wallpaperInfo) {
    /**
     * Sets a wallpaper to be shown on preview screen.
     *
     * @param wallpaperInfo the wallpaper to preview
     * @param listener the listener for getting the wallpaper color of {@param wallpaperInfo}
     */
    public void setWallpaper(WallpaperInfo wallpaperInfo,
                             @Nullable WallpaperColorsListener listener) {
        mWallpaper =  wallpaperInfo;
        mWallpaperColorsListener = listener;
        setUpWallpaperPreview();
    }

@@ -151,10 +169,21 @@ public class WallpaperPreviewer implements LifecycleObserver {
                                mActivity.getColor(R.color.secondary_color));
                setUpLiveWallpaperPreview(mWallpaper);
            } else {
                // Ensure live wallpaper connection is disconnected.
                if (mWallpaperConnection != null) {
                    mWallpaperConnection.disconnect();
                    mWallpaperConnection = null;
                }

                // Load wallpaper color for static wallpaper.
                WallpaperColorsLoader.getWallpaperColors(
                        mActivity,
                        mWallpaper.getThumbAsset(mActivity),
                        colors -> {
                            if (mWallpaperColorsListener != null) {
                                mWallpaperColorsListener.onWallpaperColorsChanged(colors);
                            }
                        });
            }
        }
    }
@@ -176,7 +205,14 @@ public class WallpaperPreviewer implements LifecycleObserver {

        mWallpaperConnection = new WallpaperConnection(
                getWallpaperIntent(homeWallpaper.getWallpaperComponent()), mActivity,
                /* listener= */ null, mPreviewGlobalRect);
                new WallpaperConnectionListener() {
                    @Override
                    public void onWallpaperColorsChanged(WallpaperColors colors, int displayId) {
                        if (mWallpaperColorsListener != null) {
                            mWallpaperColorsListener.onWallpaperColorsChanged(colors);
                        }
                    }
                }, mPreviewGlobalRect);

        LiveTileOverlay.INSTANCE.update(new RectF(mPreviewLocalRect),
                ((CardView) mHomePreview.getParent()).getRadius());
+1 −1
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ public class GridFragment extends AppbarFragment {
                .getCurrentWallpaperFactory(getContext().getApplicationContext());
        factory.createCurrentWallpaperInfos((homeWallpaper, lockWallpaper, presentationMode) -> {
            mHomeWallpaper = homeWallpaper;
            wallpaperPreviewer.setWallpaper(mHomeWallpaper);
            wallpaperPreviewer.setWallpaper(mHomeWallpaper, /* listener= */ null);
        }, false);

        mGridOptionPreviewer = new GridOptionPreviewer(mGridManager,
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public class GridFullPreviewFragment extends AppbarFragment {
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mWallpaperPreviewer.setWallpaper(mWallpaper);
        mWallpaperPreviewer.setWallpaper(mWallpaper, /* listener= */ null);
        mGridOptionPreviewer.setGridOption(mGridOption);
    }

+2 −10
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.customization.picker.theme.ThemeFullPreviewFragment.EX
import static com.android.customization.picker.theme.ThemeFullPreviewFragment.EXTRA_THEME_OPTION_TITLE;
import static com.android.customization.picker.theme.ThemeFullPreviewFragment.EXTRA_WALLPAPER_INFO;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
@@ -45,7 +44,6 @@ import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.widget.WallpaperColorsLoader;

import org.json.JSONArray;
import org.json.JSONException;
@@ -101,14 +99,8 @@ public class CustomThemeNameFragment extends CustomThemeStepFragment {
        currentWallpaperFactory.createCurrentWallpaperInfos(
                (homeWallpaper, lockWallpaper, presentationMode) -> {
                    mCurrentHomeWallpaper = homeWallpaper;
                    wallpaperPreviewer.setWallpaper(homeWallpaper);
                    Context context =  getContext();
                    if (context != null) {
                        WallpaperColorsLoader.getWallpaperColors(
                                context,
                                mCurrentHomeWallpaper.getThumbAsset(context),
                    wallpaperPreviewer.setWallpaper(homeWallpaper,
                            mThemeOptionPreviewer::updateColorForLauncherWidgets);
                    }
                }, false);

        // Set theme default name.
+2 −9
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.WallpaperColorsLoader;

import java.util.List;

@@ -138,14 +137,8 @@ public class ThemeFragment extends AppbarFragment {
        mCurrentWallpaperFactory.createCurrentWallpaperInfos(
                (homeWallpaper, lockWallpaper, presentationMode) -> {
                    mCurrentHomeWallpaper = homeWallpaper;
                    mWallpaperPreviewer.setWallpaper(mCurrentHomeWallpaper);
                    Context context = getContext();
                    if (context != null) {
                        WallpaperColorsLoader.getWallpaperColors(
                                context,
                                mCurrentHomeWallpaper.getThumbAsset(context),
                    mWallpaperPreviewer.setWallpaper(mCurrentHomeWallpaper,
                            mThemeOptionPreviewer::updateColorForLauncherWidgets);
                    }
                }, false);

        view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
Loading