Merge "Theming on Scrim- and GradientView" into ub-launcher3-dorval-polish
This commit is contained in:
committed by
Android (Google) Code Review
commit
552e6c803c
@@ -99,6 +99,7 @@ import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.dragndrop.DragView;
|
||||
import com.android.launcher3.dragndrop.PinItemDragListener;
|
||||
import com.android.launcher3.dynamicui.ExtractedColors;
|
||||
import com.android.launcher3.dynamicui.WallpaperColorInfo;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.keyboard.CustomActionsPopup;
|
||||
@@ -149,7 +150,8 @@ import java.util.Set;
|
||||
public class Launcher extends BaseActivity
|
||||
implements LauncherExterns, View.OnClickListener, OnLongClickListener,
|
||||
LauncherModel.Callbacks, View.OnTouchListener, LauncherProviderChangeListener,
|
||||
AccessibilityManager.AccessibilityStateChangeListener {
|
||||
AccessibilityManager.AccessibilityStateChangeListener,
|
||||
WallpaperColorInfo.OnThemeChangeListener {
|
||||
public static final String TAG = "Launcher";
|
||||
static final boolean LOGD = false;
|
||||
|
||||
@@ -365,6 +367,10 @@ public class Launcher extends BaseActivity
|
||||
mLauncherCallbacks.preOnCreate();
|
||||
}
|
||||
|
||||
WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
|
||||
wallpaperColorInfo.setOnThemeChangeListener(this);
|
||||
overrideTheme(wallpaperColorInfo.isDark());
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
LauncherAppState app = LauncherAppState.getInstance(this);
|
||||
@@ -463,6 +469,17 @@ public class Launcher extends BaseActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThemeChanged() {
|
||||
recreate();
|
||||
}
|
||||
|
||||
protected void overrideTheme(boolean isDark) {
|
||||
if (isDark) {
|
||||
setTheme(R.style.LauncherThemeDark);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View findViewById(int id) {
|
||||
return mLauncherView.findViewById(id);
|
||||
@@ -1856,6 +1873,8 @@ public class Launcher extends BaseActivity
|
||||
((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
|
||||
.removeAccessibilityStateChangeListener(this);
|
||||
|
||||
WallpaperColorInfo.getInstance(this).setOnThemeChangeListener(null);
|
||||
|
||||
LauncherAnimUtils.onDestroyActivity();
|
||||
|
||||
if (mLauncherCallbacks != null) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.anim.SpringAnimationHandler;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dynamicui.ExtractedColors;
|
||||
import com.android.launcher3.graphics.GradientView;
|
||||
import com.android.launcher3.graphics.ScrimView;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
||||
@@ -43,7 +42,7 @@ import com.android.launcher3.util.TouchController;
|
||||
* closer to top or closer to the page indicator.
|
||||
*/
|
||||
public class AllAppsTransitionController implements TouchController, VerticalPullDetector.Listener,
|
||||
ExtractedColors.OnChangeListener, SearchUiManager.OnScrollRangeChangeListener {
|
||||
SearchUiManager.OnScrollRangeChangeListener {
|
||||
|
||||
private static final String TAG = "AllAppsTrans";
|
||||
private static final boolean DBG = false;
|
||||
@@ -112,7 +111,6 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
|
||||
|
||||
mEvaluator = new ArgbEvaluator();
|
||||
mAllAppsBackgroundColor = Themes.getAttrColor(l, android.R.attr.colorPrimary);
|
||||
mLauncher.getExtractedColors().addOnChangeListener(this);
|
||||
mIsDarkTheme = Themes.getAttrBoolean(mLauncher, R.attr.isPrimaryColorDark);
|
||||
}
|
||||
|
||||
@@ -293,7 +291,6 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
|
||||
if (mGradientView == null) {
|
||||
mGradientView = (GradientView) mLauncher.findViewById(R.id.gradient_bg);
|
||||
mGradientView.setVisibility(View.VISIBLE);
|
||||
onExtractedColorsChanged();
|
||||
}
|
||||
mGradientView.setProgress(progress);
|
||||
|
||||
@@ -305,20 +302,6 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
|
||||
mScrimView.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtractedColorsChanged() {
|
||||
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
|
||||
if (mGradientView != null) {
|
||||
int color1 = mLauncher.getExtractedColors()
|
||||
.getColor(ExtractedColors.ALLAPPS_GRADIENT_MAIN_INDEX);
|
||||
int color2 = mLauncher.getExtractedColors()
|
||||
.getColor(ExtractedColors.ALLAPPS_GRADIENT_SECONDARY_INDEX);
|
||||
mGradientView.onExtractedColorsChanged(color1, color2);
|
||||
mGradientView.requestLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace
|
||||
*/
|
||||
|
||||
@@ -65,9 +65,6 @@ public class ColorExtractionService extends IntentService {
|
||||
|
||||
if (FeatureFlags.QSB_IN_HOTSEAT || FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
|
||||
extractedColors.updateWallpaperThemePalette(null);
|
||||
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
|
||||
extractedColors.updateAllAppsGradientPalette(this);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// We extract colors for the hotseat and status bar separately,
|
||||
@@ -80,9 +77,6 @@ public class ColorExtractionService extends IntentService {
|
||||
|
||||
if (FeatureFlags.QSB_IN_HOTSEAT || FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
|
||||
extractedColors.updateWallpaperThemePalette(getWallpaperPalette());
|
||||
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
|
||||
extractedColors.updateAllAppsGradientPalette(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.util.Log;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dynamicui.colorextraction.ColorExtractor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -165,20 +164,6 @@ public class ExtractedColors {
|
||||
? defaultColor : wallpaperPalette.getVibrantColor(defaultColor));
|
||||
}
|
||||
|
||||
public void updateAllAppsGradientPalette(Context context) {
|
||||
// TODO use isAtLeastO when available
|
||||
try {
|
||||
WallpaperManager.class.getDeclaredMethod("getWallpaperColors", int.class);
|
||||
ColorExtractor extractor = new ColorExtractor(context);
|
||||
ColorExtractor.GradientColors colors = extractor.getColors();
|
||||
setColorAtIndex(ALLAPPS_GRADIENT_MAIN_INDEX, colors.getMainColor());
|
||||
setColorAtIndex(ALLAPPS_GRADIENT_SECONDARY_INDEX, colors.getSecondaryColor());
|
||||
} catch (NoSuchMethodException e) {
|
||||
setColorAtIndex(ALLAPPS_GRADIENT_MAIN_INDEX, Color.WHITE);
|
||||
setColorAtIndex(ALLAPPS_GRADIENT_SECONDARY_INDEX, Color.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
public void addOnChangeListener(OnChangeListener listener) {
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.android.launcher3.dynamicui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.graphics.ColorUtils;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.launcher3.compat.WallpaperColorsCompat;
|
||||
import com.android.launcher3.compat.WallpaperManagerCompat;
|
||||
import com.android.launcher3.dynamicui.colorextraction.types.ExtractionType;
|
||||
import com.android.launcher3.dynamicui.colorextraction.types.Tonal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static android.app.WallpaperManager.FLAG_SYSTEM;
|
||||
|
||||
public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChangedListenerCompat {
|
||||
|
||||
private static final int FALLBACK_COLOR = Color.WHITE;
|
||||
private static final Object sInstanceLock = new Object();
|
||||
private static WallpaperColorInfo sInstance;
|
||||
|
||||
public static WallpaperColorInfo getInstance(Context context) {
|
||||
synchronized (sInstanceLock) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new WallpaperColorInfo(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private final ArrayList<OnChangeListener> mListeners = new ArrayList<>();
|
||||
private final WallpaperManagerCompat mWallpaperManager;
|
||||
private final ExtractionType mExtractionType;
|
||||
private int mMainColor;
|
||||
private int mSecondaryColor;
|
||||
private boolean mIsDark;
|
||||
private OnThemeChangeListener mOnThemeChangeListener;
|
||||
|
||||
private WallpaperColorInfo(Context context) {
|
||||
mWallpaperManager = WallpaperManagerCompat.getInstance(context);
|
||||
mWallpaperManager.addOnColorsChangedListener(this);
|
||||
mExtractionType = new Tonal(); // TODO create and use DefaultExtractionLogic
|
||||
update(mWallpaperManager.getWallpaperColors(FLAG_SYSTEM));
|
||||
}
|
||||
|
||||
public int getMainColor() {
|
||||
return mMainColor;
|
||||
}
|
||||
|
||||
public int getSecondaryColor() {
|
||||
return mSecondaryColor;
|
||||
}
|
||||
|
||||
public boolean isDark() {
|
||||
return mIsDark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorsChanged(WallpaperColorsCompat colors, int which) {
|
||||
if (which == FLAG_SYSTEM) {
|
||||
boolean wasDarkTheme = mIsDark;
|
||||
update(colors);
|
||||
notifyChange(wasDarkTheme != mIsDark);
|
||||
}
|
||||
}
|
||||
|
||||
private void update(WallpaperColorsCompat wallpaperColors) {
|
||||
Pair<Integer, Integer> colors = mExtractionType.extractInto(wallpaperColors);
|
||||
if (colors != null) {
|
||||
mMainColor = colors.first;
|
||||
mSecondaryColor = colors.second;
|
||||
} else {
|
||||
mMainColor = FALLBACK_COLOR;
|
||||
mSecondaryColor = FALLBACK_COLOR;
|
||||
}
|
||||
float[] hsl = new float[3];
|
||||
ColorUtils.colorToHSL(mMainColor, hsl);
|
||||
mIsDark = hsl[2] < 0.2f;
|
||||
}
|
||||
|
||||
public void setOnThemeChangeListener(OnThemeChangeListener onThemeChangeListener) {
|
||||
this.mOnThemeChangeListener = onThemeChangeListener;
|
||||
}
|
||||
|
||||
public void addOnChangeListener(OnChangeListener listener) {
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeOnChangeListener(OnChangeListener listener) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void notifyChange(boolean themeChanged) {
|
||||
if (themeChanged) {
|
||||
if (mOnThemeChangeListener != null) {
|
||||
mOnThemeChangeListener.onThemeChanged();
|
||||
}
|
||||
} else {
|
||||
for (OnChangeListener listener : mListeners) {
|
||||
listener.onExtractedColorsChanged(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnChangeListener {
|
||||
void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo);
|
||||
}
|
||||
|
||||
public interface OnThemeChangeListener {
|
||||
void onThemeChanged();
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package com.android.launcher3.dynamicui.colorextraction;
|
||||
|
||||
import static android.app.WallpaperManager.FLAG_SYSTEM;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.android.launcher3.compat.WallpaperColorsCompat;
|
||||
import com.android.launcher3.compat.WallpaperManagerCompat;
|
||||
import com.android.launcher3.dynamicui.colorextraction.types.ExtractionType;
|
||||
import com.android.launcher3.dynamicui.colorextraction.types.Tonal;
|
||||
|
||||
|
||||
/**
|
||||
* Class to process wallpaper colors and generate a tonal palette based on them.
|
||||
*
|
||||
* TODO remove this class if available by platform
|
||||
*/
|
||||
public class ColorExtractor {
|
||||
private static final int FALLBACK_COLOR = Color.WHITE;
|
||||
|
||||
private final Context mContext;
|
||||
private int mMainFallbackColor = FALLBACK_COLOR;
|
||||
private int mSecondaryFallbackColor = FALLBACK_COLOR;
|
||||
private final GradientColors mSystemColors;
|
||||
private final ExtractionType mExtractionType;
|
||||
|
||||
public ColorExtractor(Context context) {
|
||||
mContext = context;
|
||||
mSystemColors = new GradientColors();
|
||||
mExtractionType = new Tonal();
|
||||
|
||||
extractFrom(WallpaperManagerCompat.getInstance(context).getWallpaperColors(FLAG_SYSTEM));
|
||||
}
|
||||
|
||||
public GradientColors getColors() {
|
||||
return mSystemColors;
|
||||
}
|
||||
|
||||
private void extractFrom(WallpaperColorsCompat inWallpaperColors) {
|
||||
applyFallback(mSystemColors);
|
||||
if (inWallpaperColors == null) {
|
||||
return;
|
||||
}
|
||||
mExtractionType.extractInto(inWallpaperColors, mSystemColors);
|
||||
}
|
||||
|
||||
private void applyFallback(GradientColors outGradientColors) {
|
||||
outGradientColors.setMainColor(mMainFallbackColor);
|
||||
outGradientColors.setSecondaryColor(mSecondaryFallbackColor);
|
||||
}
|
||||
|
||||
public static class GradientColors {
|
||||
private int mMainColor = FALLBACK_COLOR;
|
||||
private int mSecondaryColor = FALLBACK_COLOR;
|
||||
private boolean mSupportsDarkText;
|
||||
|
||||
public void setMainColor(int mainColor) {
|
||||
mMainColor = mainColor;
|
||||
}
|
||||
|
||||
public void setSecondaryColor(int secondaryColor) {
|
||||
mSecondaryColor = secondaryColor;
|
||||
}
|
||||
|
||||
public void setSupportsDarkText(boolean supportsDarkText) {
|
||||
mSupportsDarkText = supportsDarkText;
|
||||
}
|
||||
|
||||
public void set(GradientColors other) {
|
||||
mMainColor = other.mMainColor;
|
||||
mSecondaryColor = other.mSecondaryColor;
|
||||
mSupportsDarkText = other.mSupportsDarkText;
|
||||
}
|
||||
|
||||
public int getMainColor() {
|
||||
return mMainColor;
|
||||
}
|
||||
|
||||
public int getSecondaryColor() {
|
||||
return mSecondaryColor;
|
||||
}
|
||||
|
||||
public boolean supportsDarkText() {
|
||||
return mSupportsDarkText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || o.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
GradientColors other = (GradientColors) o;
|
||||
return other.mMainColor == mMainColor &&
|
||||
other.mSecondaryColor == mSecondaryColor &&
|
||||
other.mSupportsDarkText == mSupportsDarkText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int code = mMainColor;
|
||||
code = 31 * code + mSecondaryColor;
|
||||
code = 31 * code + (mSupportsDarkText ? 0 : 1);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
package com.android.launcher3.dynamicui.colorextraction.types;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.launcher3.compat.WallpaperColorsCompat;
|
||||
import com.android.launcher3.dynamicui.colorextraction.ColorExtractor;
|
||||
|
||||
|
||||
/**
|
||||
* Interface to allow various color extraction implementations.
|
||||
*
|
||||
* TODO remove this class if available by platform
|
||||
*/
|
||||
public interface ExtractionType {
|
||||
|
||||
/**
|
||||
* Executes color extraction by reading WallpaperColors and setting
|
||||
* main and secondary colors on GradientColors.
|
||||
* main and secondary colors.
|
||||
*
|
||||
* @param inWallpaperColors where to read from
|
||||
* @param outGradientColors object that should receive the colors
|
||||
* @param wallpaperColors where to read from
|
||||
* @return a pair of main and secondary color
|
||||
*/
|
||||
void extractInto(WallpaperColorsCompat inWallpaperColors,
|
||||
ColorExtractor.GradientColors outGradientColors);
|
||||
@Nullable Pair<Integer, Integer> extractInto(WallpaperColorsCompat wallpaperColors);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.util.Pair;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.launcher3.compat.WallpaperColorsCompat;
|
||||
import com.android.launcher3.dynamicui.colorextraction.ColorExtractor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -33,11 +32,13 @@ public class Tonal implements ExtractionType {
|
||||
private static final float MIN_COLOR_OCCURRENCE = 0.1f;
|
||||
private static final float MIN_LUMINOSITY = 0.5f;
|
||||
|
||||
public void extractInto(
|
||||
WallpaperColorsCompat wallpaperColors, ColorExtractor.GradientColors gradientColors) {
|
||||
public @Nullable Pair<Integer, Integer> extractInto(WallpaperColorsCompat wallpaperColors) {
|
||||
if (wallpaperColors == null) {
|
||||
return null;
|
||||
}
|
||||
SparseIntArray colorsArray = wallpaperColors.getColors();
|
||||
if (colorsArray.size() == 0) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
// Tonal is not really a sort, it takes a color from the extracted
|
||||
// palette and finds a best fit amongst a collection of pre-defined
|
||||
@@ -91,13 +92,13 @@ public class Tonal implements ExtractionType {
|
||||
// Fall back to population sort if we couldn't find a tonal palette
|
||||
if (palette == null) {
|
||||
Log.w(TAG, "Could not find a tonal palette!");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
int fitIndex = bestFit(palette, hsl[0], hsl[1], hsl[2]);
|
||||
if (fitIndex == -1) {
|
||||
Log.w(TAG, "Could not find best fit!");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
float[] h = fit(palette.h, hsl[0], fitIndex,
|
||||
Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
|
||||
@@ -108,12 +109,13 @@ public class Tonal implements ExtractionType {
|
||||
hsl[0] = fract(h[0]) * 360.0f;
|
||||
hsl[1] = s[0];
|
||||
hsl[2] = l[0];
|
||||
gradientColors.setMainColor(ColorUtils.HSLToColor(hsl));
|
||||
int mainColor = ColorUtils.HSLToColor(hsl);
|
||||
|
||||
hsl[0] = fract(h[1]) * 360.0f;
|
||||
hsl[1] = s[1];
|
||||
hsl[2] = l[1];
|
||||
gradientColors.setSecondaryColor(ColorUtils.HSLToColor(hsl));
|
||||
int secondaryColor = ColorUtils.HSLToColor(hsl);
|
||||
return new Pair<>(mainColor, secondaryColor);
|
||||
}
|
||||
|
||||
private static void populationSort(@NonNull List<Pair<Integer, Integer>> wallpaperColors) {
|
||||
|
||||
@@ -33,20 +33,20 @@ import android.view.animation.Interpolator;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.dynamicui.WallpaperColorInfo;
|
||||
|
||||
/**
|
||||
* Draws a translucent radial gradient background from an initial state with progress 0.0 to a
|
||||
* final state with progress 1.0;
|
||||
*/
|
||||
public class GradientView extends View {
|
||||
public class GradientView extends View implements WallpaperColorInfo.OnChangeListener {
|
||||
|
||||
private static final int DEFAULT_COLOR = Color.WHITE;
|
||||
private static final float GRADIENT_ALPHA_MASK_LENGTH_DP = 300;
|
||||
private static final int FINAL_GRADIENT_ALPHA = 0xBF;
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static Bitmap sFinalGradientMask;
|
||||
private static Bitmap sAlphaGradientMask;
|
||||
private final Bitmap mFinalGradientMask;
|
||||
private final Bitmap mAlphaGradientMask;
|
||||
|
||||
private int mColor1 = DEFAULT_COLOR;
|
||||
private int mColor2 = DEFAULT_COLOR;
|
||||
@@ -61,30 +61,48 @@ public class GradientView extends View {
|
||||
private final Paint mDebugPaint = DEBUG ? new Paint() : null;
|
||||
private final Interpolator mAccelerator = new AccelerateInterpolator();
|
||||
private final float mAlphaStart;
|
||||
private final WallpaperColorInfo mWallpaperColorInfo;
|
||||
|
||||
public GradientView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.mAppContext = context.getApplicationContext();
|
||||
this.mMaskHeight = Utilities.pxFromDp(GRADIENT_ALPHA_MASK_LENGTH_DP,
|
||||
mAppContext.getResources().getDisplayMetrics());
|
||||
this.mAlphaStart = Launcher.getLauncher(context)
|
||||
.getDeviceProfile().isVerticalBarLayout() ? 0 : 100;
|
||||
Launcher launcher = Launcher.getLauncher(context);
|
||||
this.mAlphaStart = launcher.getDeviceProfile().isVerticalBarLayout() ? 0 : 100;
|
||||
this.mWallpaperColorInfo = WallpaperColorInfo.getInstance(launcher);
|
||||
updateColors();
|
||||
|
||||
if (sFinalGradientMask == null) {
|
||||
sFinalGradientMask = Utilities.convertToAlphaMask(
|
||||
Utilities.createOnePixBitmap(), FINAL_GRADIENT_ALPHA);
|
||||
}
|
||||
if (sAlphaGradientMask == null) {
|
||||
Bitmap alphaMaskFromResource = BitmapFactory.decodeResource(context.getResources(),
|
||||
R.drawable.all_apps_alpha_mask);
|
||||
sAlphaGradientMask = Utilities.convertToAlphaMask(
|
||||
alphaMaskFromResource, FINAL_GRADIENT_ALPHA);
|
||||
}
|
||||
int finalAlpha = 0xBF;
|
||||
mFinalGradientMask = Utilities.convertToAlphaMask(
|
||||
Utilities.createOnePixBitmap(), finalAlpha);
|
||||
Bitmap alphaMaskFromResource = BitmapFactory.decodeResource(context.getResources(),
|
||||
R.drawable.all_apps_alpha_mask);
|
||||
mAlphaGradientMask = Utilities.convertToAlphaMask(
|
||||
alphaMaskFromResource, finalAlpha);
|
||||
}
|
||||
|
||||
public void onExtractedColorsChanged(int color1, int color2) {
|
||||
this.mColor1 = color1;
|
||||
this.mColor2 = color2;
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mWallpaperColorInfo.addOnChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mWallpaperColorInfo.removeOnChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExtractedColorsChanged(WallpaperColorInfo info) {
|
||||
updateColors();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void updateColors() {
|
||||
this.mColor1 = mWallpaperColorInfo.getMainColor();
|
||||
this.mColor2 = mWallpaperColorInfo.getSecondaryColor();
|
||||
if (mWidth + mHeight > 0) {
|
||||
createRadialShader();
|
||||
}
|
||||
@@ -130,8 +148,8 @@ public class GradientView extends View {
|
||||
mPaint.setAlpha((int) (mAlphaStart + interpolatedAlpha));
|
||||
mAlphaMaskRect.set(0, startMaskY, mWidth, startMaskY + mMaskHeight);
|
||||
mFinalMaskRect.set(0, startMaskY + mMaskHeight, mWidth, mHeight);
|
||||
canvas.drawBitmap(sAlphaGradientMask, null, mAlphaMaskRect, mPaint);
|
||||
canvas.drawBitmap(sFinalGradientMask, null, mFinalMaskRect, mPaint);
|
||||
canvas.drawBitmap(mAlphaGradientMask, null, mAlphaMaskRect, mPaint);
|
||||
canvas.drawBitmap(mFinalGradientMask, null, mFinalMaskRect, mPaint);
|
||||
|
||||
if (DEBUG) {
|
||||
mDebugPaint.setColor(0xFF00FF00);
|
||||
@@ -139,5 +157,4 @@ public class GradientView extends View {
|
||||
canvas.drawLine(0, startMaskY + mMaskHeight, mWidth, startMaskY + mMaskHeight, mDebugPaint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,8 +42,8 @@ public class ScrimView extends View {
|
||||
private static final float MASK_START_LENGTH_FACTOR = 1f;
|
||||
private static final boolean APPLY_ALPHA = true;
|
||||
|
||||
private static Bitmap sFinalScrimMask;
|
||||
private static Bitmap sAlphaScrimMask;
|
||||
private final Bitmap mFinalScrimMask;
|
||||
private final Bitmap mAlphaScrimMask;
|
||||
|
||||
private final int mMaskHeight;
|
||||
private int mVisibleHeight;
|
||||
@@ -67,15 +67,11 @@ public class ScrimView extends View {
|
||||
int scrimColor = Themes.getAttrColor(context, R.attr.allAppsScrimColor);
|
||||
int scrimAlpha = Color.alpha(scrimColor);
|
||||
mPaint.setColor(scrimColor);
|
||||
if (sFinalScrimMask == null) {
|
||||
sFinalScrimMask = Utilities.convertToAlphaMask(
|
||||
Utilities.createOnePixBitmap(), scrimAlpha);
|
||||
}
|
||||
if (sAlphaScrimMask == null) {
|
||||
Bitmap alphaMaskFromResource = BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.all_apps_alpha_mask);
|
||||
sAlphaScrimMask = Utilities.convertToAlphaMask(alphaMaskFromResource, scrimAlpha);
|
||||
}
|
||||
mFinalScrimMask = Utilities.convertToAlphaMask(
|
||||
Utilities.createOnePixBitmap(), scrimAlpha);
|
||||
Bitmap alphaMaskFromResource = BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.all_apps_alpha_mask);
|
||||
mAlphaScrimMask = Utilities.convertToAlphaMask(alphaMaskFromResource, scrimAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,8 +102,8 @@ public class ScrimView extends View {
|
||||
protected void onDraw(Canvas canvas) {
|
||||
mAlphaMaskRect.set(0, 0, getWidth(), mMaskHeight);
|
||||
mFinalMaskRect.set(0, mMaskHeight, getWidth(), getHeight());
|
||||
canvas.drawBitmap(sAlphaScrimMask, null, mAlphaMaskRect, mPaint);
|
||||
canvas.drawBitmap(sFinalScrimMask, null, mFinalMaskRect, mPaint);
|
||||
canvas.drawBitmap(mAlphaScrimMask, null, mAlphaMaskRect, mPaint);
|
||||
canvas.drawBitmap(mFinalScrimMask, null, mFinalMaskRect, mPaint);
|
||||
|
||||
if (DEBUG) {
|
||||
mDebugPaint.setColor(0xFF0000FF);
|
||||
|
||||
Reference in New Issue
Block a user