mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 23:36:47 +00:00
@@ -18,11 +18,8 @@ package app.lawnchair;
|
||||
|
||||
import android.app.WallpaperColors;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
@@ -42,12 +39,19 @@ import dev.kdrag0n.monet.theme.ColorScheme;
|
||||
public class AccentColorExtractor extends LocalColorExtractor implements ThemeProvider.ColorSchemeChangeListener {
|
||||
|
||||
private final ThemeProvider mThemeProvider;
|
||||
private Listener mListener;
|
||||
|
||||
@Keep
|
||||
public AccentColorExtractor(Context context) {
|
||||
mThemeProvider = ThemeProvider.INSTANCE.get(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListener(@Nullable Listener listener) {
|
||||
mListener = listener;
|
||||
notifyListener();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected SparseIntArray generateColorsOverride(ColorScheme colorScheme) {
|
||||
SparseIntArray colorRes = new SparseIntArray(5 * 13);
|
||||
@@ -71,7 +75,15 @@ public class AccentColorExtractor extends LocalColorExtractor implements ThemePr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorSchemeChanged() {}
|
||||
public void onColorSchemeChanged() {
|
||||
notifyListener();
|
||||
}
|
||||
|
||||
protected void notifyListener() {
|
||||
if (mListener != null) {
|
||||
mListener.onColorsChanged(generateColorsOverride(mThemeProvider.getColorScheme()));
|
||||
}
|
||||
}
|
||||
|
||||
// Shade number -> color resource ID maps
|
||||
private static final SparseIntArray ACCENT1_RES = new SparseIntArray(13);
|
||||
|
||||
@@ -451,9 +451,7 @@ public class LauncherPreviewRenderer extends ContextWrapper
|
||||
mContext, info.appWidgetId, providerInfo);
|
||||
|
||||
if (mWallpaperColorResources != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
view.setColorResources(mWallpaperColorResources);
|
||||
}
|
||||
view.setColorResources(mWallpaperColorResources);
|
||||
}
|
||||
|
||||
view.setTag(info);
|
||||
@@ -615,6 +613,11 @@ public class LauncherPreviewRenderer extends ContextWrapper
|
||||
protected boolean shouldAllowDirectClick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorsChanged(SparseIntArray colors) {
|
||||
post(() -> setColorResources(colors));
|
||||
}
|
||||
}
|
||||
|
||||
/** Root layout for launcher preview that intercepts all touch events. */
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.view.Display;
|
||||
import android.view.SurfaceControlViewHost;
|
||||
import android.view.SurfaceControlViewHost.SurfacePackage;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -48,6 +49,7 @@ import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext;
|
||||
import com.android.launcher3.model.BaseLauncherBinder;
|
||||
@@ -66,7 +68,6 @@ import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import app.lawnchair.AccentColorExtractor;
|
||||
|
||||
/** Render preview using surface view. */
|
||||
@SuppressWarnings("NewApi")
|
||||
@@ -218,7 +219,11 @@ public class PreviewSurfaceRenderer {
|
||||
return new ContextThemeWrapper(context,
|
||||
Themes.getActivityThemeRes(context));
|
||||
}
|
||||
AccentColorExtractor.newInstance(context)
|
||||
if (Utilities.ATLEAST_R) {
|
||||
context = context.createWindowContext(
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, null);
|
||||
}
|
||||
LocalColorExtractor.newInstance(mContext)
|
||||
.applyColorsOverride(context, mWallpaperColors);
|
||||
return new ContextThemeWrapper(context,
|
||||
Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
|
||||
|
||||
@@ -32,7 +32,7 @@ import com.android.launcher3.util.Executors;
|
||||
/**
|
||||
* Launcher AppWidgetHostView with support for rounded corners and a fallback View.
|
||||
*/
|
||||
public abstract class BaseLauncherAppWidgetHostView extends NavigableAppWidgetHostView {
|
||||
public abstract class BaseLauncherAppWidgetHostView extends NavigableAppWidgetHostView implements LocalColorExtractor.Listener {
|
||||
|
||||
private static final ViewOutlineProvider VIEW_OUTLINE_PROVIDER = new ViewOutlineProvider() {
|
||||
@Override
|
||||
@@ -61,6 +61,7 @@ public abstract class BaseLauncherAppWidgetHostView extends NavigableAppWidgetHo
|
||||
};
|
||||
|
||||
private boolean mIsCornerRadiusEnforced;
|
||||
private final LocalColorExtractor mColorExtractor;
|
||||
|
||||
public BaseLauncherAppWidgetHostView(Context context) {
|
||||
super(context);
|
||||
@@ -70,6 +71,7 @@ public abstract class BaseLauncherAppWidgetHostView extends NavigableAppWidgetHo
|
||||
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mEnforcedCornerRadius = RoundedCornerEnforcement.computeEnforcedRadius(getContext());
|
||||
mColorExtractor = LocalColorExtractor.newInstance(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,6 +87,18 @@ public abstract class BaseLauncherAppWidgetHostView extends NavigableAppWidgetHo
|
||||
updateAppWidget(new RemoteViews(getAppWidgetInfo().provider.getPackageName(), 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mColorExtractor.setListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mColorExtractor.setListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
try {
|
||||
|
||||
@@ -379,6 +379,11 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorsChanged(SparseIntArray colors) {
|
||||
post(() -> setColorResources(colors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener interface to be called when {@code CellLayout} is about to layout this child view
|
||||
*/
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
package com.android.launcher3.widget;
|
||||
|
||||
import android.app.WallpaperColors;
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -28,6 +31,18 @@ import com.android.launcher3.util.ResourceBasedOverride;
|
||||
/** Extracts the colors we need from the wallpaper at given locations. */
|
||||
public class LocalColorExtractor implements ResourceBasedOverride {
|
||||
|
||||
/** Listener for color changes on a screen location. */
|
||||
public interface Listener {
|
||||
/**
|
||||
* Method called when the colors on a registered location has changed.
|
||||
*
|
||||
* {@code extractedColors} maps the color resources {@code android.R.colors.system_*} to
|
||||
* their value, in a format that can be passed directly to
|
||||
* {@link AppWidgetHostView#setColorResources(SparseIntArray)}.
|
||||
*/
|
||||
void onColorsChanged(SparseIntArray extractedColors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of LocalColorExtractor
|
||||
*/
|
||||
@@ -36,6 +51,11 @@ public class LocalColorExtractor implements ResourceBasedOverride {
|
||||
R.string.local_colors_extraction_class);
|
||||
}
|
||||
|
||||
/** Sets the object that will receive the color changes. */
|
||||
public void setListener(@Nullable Listener listener) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the base context to contain the colors override
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user