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

Commit b49d0bf6 authored by chihhangchuang's avatar chihhangchuang
Browse files

Gets the wallpaper color to update the preview text/icon

Screenshot:
    Before: https://screenshot.googleplex.com/fm9UEBrtv9C.png
    After: https://screenshot.googleplex.com/gp7RzO1Q9uH.png
    Launcher: https://screenshot.googleplex.com/eeVKg3La3bK.png

Video for lockscreen preview: https://drive.google.com/file/d/1jc2GC9BYwnla1Ici1REkb1a-LtlIitcw/view?usp=sharing

Test: Manually
Bug: 146475648
Bug: 156129610
Change-Id: Ica4b9df30e277a5d4d2b4e1838f3cdaf93147ff8
parent c862c981
Loading
Loading
Loading
Loading
+26 −8
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.Toast;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
@@ -55,6 +56,7 @@ import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.WallpaperColorsLoader;


import java.util.List;
import java.util.List;


@@ -91,6 +93,7 @@ public class ThemeFragment extends AppbarFragment {
    private CurrentWallpaperInfoFactory mCurrentWallpaperFactory;
    private CurrentWallpaperInfoFactory mCurrentWallpaperFactory;
    private BottomActionBar mBottomActionBar;
    private BottomActionBar mBottomActionBar;
    private WallpaperPreviewer mWallpaperPreviewer;
    private WallpaperPreviewer mWallpaperPreviewer;
    private ImageView mWallpaperImage;
    private ThemeOptionPreviewer mThemeOptionPreviewer;
    private ThemeOptionPreviewer mThemeOptionPreviewer;
    private ThemeInfoView mThemeInfoView;
    private ThemeInfoView mThemeInfoView;


@@ -118,31 +121,35 @@ public class ThemeFragment extends AppbarFragment {
        mOptionsContainer = view.findViewById(R.id.options_container);
        mOptionsContainer = view.findViewById(R.id.options_container);


        // Set Wallpaper background.
        // Set Wallpaper background.
        mWallpaperImage = view.findViewById(R.id.wallpaper_preview_image);
        mWallpaperPreviewer = new WallpaperPreviewer(
        mWallpaperPreviewer = new WallpaperPreviewer(
                getLifecycle(),
                getLifecycle(),
                getActivity(),
                getActivity(),
                view.findViewById(R.id.wallpaper_preview_image),
                mWallpaperImage,
                view.findViewById(R.id.wallpaper_preview_surface));
                view.findViewById(R.id.wallpaper_preview_surface));
        mCurrentWallpaperFactory.createCurrentWallpaperInfos(
        mCurrentWallpaperFactory.createCurrentWallpaperInfos(
                (homeWallpaper, lockWallpaper, presentationMode) -> {
                (homeWallpaper, lockWallpaper, presentationMode) -> {
                    mCurrentHomeWallpaper = homeWallpaper;
                    mCurrentHomeWallpaper = homeWallpaper;
                    mWallpaperPreviewer.setWallpaper(mCurrentHomeWallpaper);
                    mWallpaperPreviewer.setWallpaper(mCurrentHomeWallpaper);
                    updateThemePreviewColorPerWallpaper();
                }, false);
                }, false);

        ViewGroup previewContainer = view.findViewById(R.id.theme_preview_container);
        previewContainer.setOnClickListener(v -> showFullPreview());
        mThemeOptionPreviewer = new ThemeOptionPreviewer(
                getLifecycle(),
                getContext(),
                previewContainer);

        view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom,
            public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                       int oldLeft, int oldTop, int oldRight, int oldBottom) {
                                       int oldLeft, int oldTop, int oldRight, int oldBottom) {
                mWallpaperPreviewer.updatePreviewCardRadius();
                mWallpaperPreviewer.updatePreviewCardRadius();
                updateThemePreviewColorPerWallpaper();
                view.removeOnLayoutChangeListener(this);
                view.removeOnLayoutChangeListener(this);
            }
            }
        });
        });

        ViewGroup previewContainer = view.findViewById(R.id.theme_preview_container);
        previewContainer.setOnClickListener(v -> showFullPreview());
        mThemeOptionPreviewer = new ThemeOptionPreviewer(
                getLifecycle(),
                getContext(),
                previewContainer);
        return view;
        return view;
    }
    }


@@ -168,6 +175,17 @@ public class ThemeFragment extends AppbarFragment {
        setUpOptions(savedInstanceState);
        setUpOptions(savedInstanceState);
    }
    }


    private void updateThemePreviewColorPerWallpaper() {
        if (mCurrentHomeWallpaper != null && mWallpaperImage.getMeasuredWidth() > 0
                && mWallpaperImage.getMeasuredHeight() > 0) {
            WallpaperColorsLoader.getWallpaperColors(
                    mCurrentHomeWallpaper.getThumbAsset(getContext()),
                    mWallpaperImage.getMeasuredWidth(),
                    mWallpaperImage.getMeasuredHeight(),
                    mThemeOptionPreviewer::updateColorForLauncherWidgets);
        }
    }

    private void applyTheme() {
    private void applyTheme() {
        mThemeManager.apply(mSelectedTheme, new Callback() {
        mThemeManager.apply(mSelectedTheme, new Callback() {
            @Override
            @Override
+16 −8
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.widget.ImageView;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
@@ -42,6 +43,7 @@ import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.module.InjectorProvider;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.BottomActionBar;
import com.android.wallpaper.widget.WallpaperColorsLoader;


import com.bumptech.glide.Glide;
import com.bumptech.glide.Glide;


@@ -101,27 +103,33 @@ public class ThemeFullPreviewFragment extends AppbarFragment {
        Glide.get(getContext()).clearMemory();
        Glide.get(getContext()).clearMemory();


        // Set wallpaper background.
        // Set wallpaper background.
        ImageView wallpaperImageView = view.findViewById(R.id.wallpaper_preview_image);
        final WallpaperPreviewer wallpaperPreviewer = new WallpaperPreviewer(
        final WallpaperPreviewer wallpaperPreviewer = new WallpaperPreviewer(
                getLifecycle(),
                getLifecycle(),
                getActivity(),
                getActivity(),
                view.findViewById(R.id.wallpaper_preview_image),
                wallpaperImageView,
                view.findViewById(R.id.wallpaper_preview_surface));
                view.findViewById(R.id.wallpaper_preview_surface));
        wallpaperPreviewer.setWallpaper(mWallpaper);
        wallpaperPreviewer.setWallpaper(mWallpaper);

        // Set theme option.
        final ThemeOptionPreviewer themeOptionPreviewer = new ThemeOptionPreviewer(
                getLifecycle(),
                getContext(),
                view.findViewById(R.id.theme_preview_container));
        themeOptionPreviewer.setThemeBundle(mThemeBundle);
        view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom,
            public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                       int oldLeft, int oldTop, int oldRight, int oldBottom) {
                                       int oldLeft, int oldTop, int oldRight, int oldBottom) {
                wallpaperPreviewer.updatePreviewCardRadius();
                wallpaperPreviewer.updatePreviewCardRadius();
                WallpaperColorsLoader.getWallpaperColors(
                        mWallpaper.getThumbAsset(getContext()),
                        wallpaperImageView.getMeasuredWidth(),
                        wallpaperImageView.getMeasuredHeight(),
                        themeOptionPreviewer::updateColorForLauncherWidgets);
                view.removeOnLayoutChangeListener(this);
                view.removeOnLayoutChangeListener(this);
            }
            }
        });
        });

        // Set theme option.
        final ThemeOptionPreviewer themeOptionPreviewer = new ThemeOptionPreviewer(
                getLifecycle(),
                getContext(),
                view.findViewById(R.id.theme_preview_container));
        themeOptionPreviewer.setThemeBundle(mThemeBundle);
        return view;
        return view;
    }
    }


+26 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.customization.picker.theme;
import static android.view.View.MeasureSpec.EXACTLY;
import static android.view.View.MeasureSpec.EXACTLY;
import static android.view.View.MeasureSpec.makeMeasureSpec;
import static android.view.View.MeasureSpec.makeMeasureSpec;


import android.app.WallpaperColors;
import android.content.Context;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.Resources;
@@ -156,6 +157,31 @@ class ThemeOptionPreviewer implements LifecycleObserver {
        setQsbRadius(previewInfo.bottomSheeetCornerRadius);
        setQsbRadius(previewInfo.bottomSheeetCornerRadius);
    }
    }


    /**
     * Updates the color of widgets in launcher (like top status bar, smart space, and app name
     * text) which will change its content color according to different wallpapers.
     */
    public void updateColorForLauncherWidgets(WallpaperColors colors) {
        int color = mContext.getColor(
                (colors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) == 0
                        ? R.color.text_color_light
                        : R.color.text_color_dark);
        // Update the top status bar clock text color.
        mClock.setTextColor(color);
        // Update the top status bar icon color.
        ViewGroup iconsContainer = mContentView.findViewById(R.id.theme_preview_top_bar_icons);
        for (int i = 0; i < iconsContainer.getChildCount(); i++) {
            ((ImageView) iconsContainer.getChildAt(i))
                    .setImageTintList(ColorStateList.valueOf(color));
        }
        // Update smart space date color.
        ((TextView) mContentView.findViewById(R.id.smart_space_date)).setTextColor(color);
        // Update shape app icon name text color.
        for (int id : mShapeIconAppNameIds) {
            ((TextView) mContentView.findViewById(id)).setTextColor(color);
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    @MainThread
    @MainThread
    public void onResume() {
    public void onResume() {