Merge "Simplifying some launcher themes" into ub-launcher3-master

This commit is contained in:
Sunny Goyal
2017-02-17 17:53:58 +00:00
committed by Android (Google) Code Review
43 changed files with 195 additions and 229 deletions
@@ -29,6 +29,7 @@ import android.view.ViewConfiguration;
import android.widget.TextView;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.Themes;
/**
* The track and scrollbar that shows when you scroll the list.
@@ -102,7 +103,7 @@ public class BaseRecyclerViewFastScrollBar {
mThumbPaint = new Paint();
mThumbPaint.setAntiAlias(true);
mThumbPaint.setColor(Utilities.getColorAccent(rv.getContext()));
mThumbPaint.setColor(Themes.getColorAccent(rv.getContext()));
mThumbPaint.setStyle(Paint.Style.FILL);
mWidth = mMinWidth = res.getDimensionPixelSize(R.dimen.container_fastscroll_thumb_min_width);
@@ -113,7 +113,7 @@ public class BubbleTextView extends TextView
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.BubbleTextView, defStyle, 0);
mCustomShadowsEnabled = a.getBoolean(R.styleable.BubbleTextView_customShadows, true);
mCustomShadowsEnabled = a.getBoolean(R.styleable.BubbleTextView_customShadows, false);
mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
mDeferShadowGenerationOnTouch =
a.getBoolean(R.styleable.BubbleTextView_deferShadowGeneration, false);
@@ -395,7 +395,7 @@ public class BubbleTextView extends TextView
}
// If text is transparent, don't draw any shadow
if (getCurrentTextColor() == getResources().getColor(android.R.color.transparent)) {
if ((getCurrentTextColor() >> 24) == 0) {
getPaint().clearShadowLayer();
super.draw(canvas);
return;
+2 -2
View File
@@ -25,7 +25,6 @@ import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -40,6 +39,7 @@ import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.Themes;
public class Hotseat extends FrameLayout
implements UserEventDispatcher.LogContainerProvider {
@@ -70,7 +70,7 @@ public class Hotseat extends FrameLayout
mLauncher = Launcher.getLauncher(context);
mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
mBackgroundColor = ColorUtils.setAlphaComponent(
ContextCompat.getColor(context, R.color.all_apps_container_color), 0);
Themes.getAttrColor(context, android.R.attr.colorPrimary), 0);
mBackground = new ColorDrawable(mBackgroundColor);
setBackground(mBackground);
}
+4 -6
View File
@@ -27,7 +27,6 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
@@ -45,7 +44,6 @@ import android.os.UserHandle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextThemeWrapper;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserManagerCompat;
@@ -56,6 +54,7 @@ import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.Provider;
import com.android.launcher3.util.SQLiteCacheHelper;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Thunk;
import java.util.Collections;
@@ -132,10 +131,9 @@ public class IconCache {
IconProvider.class, context, R.string.icon_provider_class);
mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
mActivityBgColor = context.getResources().getColor(R.color.quantum_panel_bg_color);
mPackageBgColor = Utilities.getAttrColor(
new ContextThemeWrapper(context, R.style.WidgetContainerTheme),
android.R.attr.colorPrimary);
mActivityBgColor = Themes.getColorPrimary(context, R.style.LauncherTheme);
mPackageBgColor = Themes.getColorPrimary(context, R.style.WidgetContainerTheme);
mLowResOptions = new BitmapFactory.Options();
// Always prefer RGB_565 config for low res. If the bitmap has transparency, it will
// automatically be loaded as ALPHA_8888.
@@ -25,6 +25,7 @@ import android.util.Log;
import android.widget.Toast;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.util.Themes;
public class InfoDropTarget extends UninstallDropTarget {
@@ -42,7 +43,7 @@ public class InfoDropTarget extends UninstallDropTarget {
protected void onFinishInflate() {
super.onFinishInflate();
// Get the hover color
mHoverColor = Utilities.getColorAccent(getContext());
mHoverColor = Themes.getColorAccent(getContext());
setDrawable(R.drawable.ic_info_launcher);
}
@@ -35,6 +35,7 @@ import android.view.View.OnClickListener;
import com.android.launcher3.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.graphics.DrawableFactory;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.util.Themes;
public class PendingAppWidgetHostView extends LauncherAppWidgetHostView
implements OnClickListener, ItemInfoUpdateReceiver {
@@ -69,7 +70,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView
mDisabledForSafeMode = disabledForSafeMode;
mPaint = new TextPaint();
mPaint.setColor(Utilities.getAttrColor(getContext(), android.R.attr.textColorPrimary));
mPaint.setColor(Themes.getAttrColor(getContext(), android.R.attr.textColorPrimary));
mPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
mLauncher.getDeviceProfile().iconTextSizePx, getResources().getDisplayMetrics()));
setBackgroundResource(R.drawable.round_rect_primary);
-12
View File
@@ -27,7 +27,6 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
@@ -608,17 +607,6 @@ public final class Utilities {
return c == null || c.isEmpty();
}
public static int getColorAccent(Context context) {
return getAttrColor(context, android.R.attr.colorAccent);
}
public static int getAttrColor(Context context, int attr) {
TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
int colorAccent = ta.getColor(0, 0);
ta.recycle();
return colorAccent;
}
public static void sendCustomAccessibilityEvent(View target, int type, String text) {
AccessibilityManager accessibilityManager = (AccessibilityManager)
target.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
@@ -464,10 +464,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
setLayoutParams(mlp);
} else {
View navBarBg = findViewById(R.id.nav_bar_bg);
if (Utilities.isAtLeastO()) {
navBarBg.setBackgroundColor(getResources().getColor(
R.color.all_apps_light_navbar_color));
}
ViewGroup.LayoutParams navBarBgLp = navBarBg.getLayoutParams();
navBarBgLp.height = insets.bottom;
navBarBg.setLayoutParams(navBarBgLp);
@@ -7,7 +7,6 @@ import android.animation.AnimatorSet;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.Log;
@@ -26,6 +25,7 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.TouchController;
/**
@@ -102,7 +102,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
mProgress = 1f;
mEvaluator = new ArgbEvaluator();
mAllAppsBackgroundColor = ContextCompat.getColor(l, R.color.all_apps_container_color);
mAllAppsBackgroundColor = Themes.getAttrColor(l, android.R.attr.colorPrimary);
}
@Override
@@ -45,6 +45,7 @@ import com.android.launcher3.Workspace.ItemOperator;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
@@ -107,7 +108,7 @@ public class FolderPagedView extends PagedView {
mIsRtl = Utilities.isRtl(getResources());
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
setEdgeGlowColor(getResources().getColor(R.color.folder_edge_effect_color));
setEdgeGlowColor(Themes.getAttrColor(context, android.R.attr.colorEdgeEffect));
mFocusIndicatorHelper = new ViewGroupFocusHelper(this);
}
@@ -77,7 +77,7 @@ public class DrawableFactory {
if (mPreloadProgressPath == null) {
mPreloadProgressPath = getPreloadProgressPath(context);
}
return new PreloadIconDrawable(icon, mPreloadProgressPath);
return new PreloadIconDrawable(icon, mPreloadProgressPath, context);
}
@@ -23,6 +23,8 @@ import android.support.v4.graphics.ColorUtils;
import android.util.Log;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.Themes;
/**
* Contains colors based on the dominant color of an icon.
@@ -36,7 +38,6 @@ public class IconPalette {
private static final float MIN_PRELOAD_COLOR_SATURATION = 0.2f;
private static final float MIN_PRELOAD_COLOR_LIGHTNESS = 0.6f;
private static final int DEFAULT_PRELOAD_COLOR = 0xFF009688;
public final int dominantColor;
public final int backgroundColor;
@@ -53,14 +54,14 @@ public class IconPalette {
/**
* Returns a color suitable for the progress bar color of preload icon.
*/
public int getPreloadProgressColor() {
public int getPreloadProgressColor(Context context) {
int result = dominantColor;
// Make sure that the dominant color has enough saturation to be visible properly.
float[] hsv = new float[3];
Color.colorToHSV(result, hsv);
if (hsv[1] < MIN_PRELOAD_COLOR_SATURATION) {
result = DEFAULT_PRELOAD_COLOR;
result = Themes.getColorAccent(context);
} else {
hsv[2] = Math.max(MIN_PRELOAD_COLOR_LIGHTNESS, hsv[2]);
result = Color.HSVToColor(hsv);
@@ -20,6 +20,7 @@ package com.android.launcher3.graphics;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
@@ -75,6 +76,8 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
private final Matrix mTmpMatrix = new Matrix();
private final PathMeasure mPathMeasure = new PathMeasure();
private final Context mContext;
// Path in [0, 100] bounds.
private final Path mProgressPath;
@@ -100,8 +103,9 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
/**
* @param progressPath fixed path in the bounds [0, 0, 100, 100] representing a progress bar.
*/
public PreloadIconDrawable(Bitmap b, Path progressPath) {
public PreloadIconDrawable(Bitmap b, Path progressPath, Context context) {
super(b);
mContext = context;
mProgressPath = progressPath;
mScaledTrackPath = new Path();
mScaledProgressPath = new Path();
@@ -262,7 +266,7 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
setIsDisabled(true);
} else if (mIndicatorColor == 0) {
// Update the indicator color
mIndicatorColor = getIconPalette().getPreloadProgressColor();
mIndicatorColor = getIconPalette().getPreloadProgressColor(mContext);
}
if (progress < 1 && progress > 0) {
@@ -24,6 +24,7 @@ import android.graphics.Path;
import android.graphics.PixelFormat;
import com.android.launcher3.R;
import com.android.launcher3.util.Themes;
import android.graphics.drawable.Drawable;
@@ -45,14 +46,15 @@ public class CaretDrawable extends Drawable {
final int strokeWidth = res.getDimensionPixelSize(R.dimen.all_apps_caret_stroke_width);
final int shadowSpread = res.getDimensionPixelSize(R.dimen.all_apps_caret_shadow_spread);
mCaretPaint.setColor(res.getColor(R.color.all_apps_caret_color));
mCaretPaint.setColor(res.getColor(R.color.workspace_icon_text_color));
mCaretPaint.setAntiAlias(true);
mCaretPaint.setStrokeWidth(strokeWidth);
mCaretPaint.setStyle(Paint.Style.STROKE);
mCaretPaint.setStrokeCap(Paint.Cap.SQUARE);
mCaretPaint.setStrokeJoin(Paint.Join.MITER);
mShadowPaint.setColor(res.getColor(R.color.all_apps_caret_shadow_color));
mShadowPaint.setColor(res.getColor(R.color.default_shadow_color_no_alpha));
mShadowPaint.setAlpha(Themes.getAlpha(context, android.R.attr.spotShadowAlpha));
mShadowPaint.setAntiAlias(true);
mShadowPaint.setStrokeWidth(strokeWidth + (shadowSpread * 2));
mShadowPaint.setStyle(Paint.Style.STROKE);
@@ -37,6 +37,7 @@ import android.view.animation.OvershootInterpolator;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.Themes;
/**
* {@link PageIndicator} which shows dots per page. The active page is shown with the current
@@ -111,8 +112,8 @@ public class PageIndicatorDots extends PageIndicator {
mDotRadius = getResources().getDimension(R.dimen.page_indicator_dot_size) / 2;
setOutlineProvider(new MyOutlineProver());
mActiveColor = Utilities.getColorAccent(context);
mInActiveColor = getResources().getColor(R.color.page_indicator_dot_color);
mActiveColor = Themes.getColorAccent(context);
mInActiveColor = Themes.getAttrColor(context, android.R.attr.colorControlHighlight);
mIsRtl = Utilities.isRtl(getResources());
}
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.util;
import android.content.Context;
import android.content.res.TypedArray;
import android.view.ContextThemeWrapper;
/**
* Various utility methods associated with theming.
*/
public class Themes {
public static int getColorAccent(Context context) {
return getAttrColor(context, android.R.attr.colorAccent);
}
public static int getColorPrimary(Context context, int theme) {
return getAttrColor(new ContextThemeWrapper(context, theme), android.R.attr.colorPrimary);
}
public static int getAttrColor(Context context, int attr) {
TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
int colorAccent = ta.getColor(0, 0);
ta.recycle();
return colorAccent;
}
/**
* Returns the alpha corresponding to the theme attribute {@param attr}, in the range [0, 255].
*/
public static int getAlpha(Context context, int attr) {
TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
float alpha = ta.getFloat(0, 0);
ta.recycle();
return (int) (255 * alpha + 0.5f);
}
}