From abef55a1c1f1fda4f42e4b4223534dd21f3dc19f Mon Sep 17 00:00:00 2001 From: Andrew Sapperstein Date: Sun, 19 Jun 2016 12:49:00 -0700 Subject: [PATCH] Update Launcher to use theme colors. Instead of using hard-coded variants of colors, use the theme color that corresponds (colorAccent, colorPrimary, etc). Updated: - "Search for more apps" text - App info drop target hover color - PageIndicatorDots - All apps & widget scroll bar & scroll popup colors - All apps section text color - widget picker background color TODO: - widget picker header color BUG: 28625102 Change-Id: I74b543ff71b8caef8cd950c8183ac84c759cb4d5 --- res/drawable-ldrtl/container_fastscroll_popup_bg.xml | 2 +- res/drawable/container_fastscroll_popup_bg.xml | 2 +- res/layout/all_apps_search_market.xml | 2 +- res/layout/widget_cell.xml | 2 +- res/layout/widgets_list_row_view.xml | 2 +- res/layout/widgets_view.xml | 3 ++- res/values-v21/styles.xml | 5 +---- res/values/colors.xml | 10 ---------- res/values/styles.xml | 2 +- src/com/android/launcher3/BaseContainerView.java | 8 ++++---- src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java | 4 +--- src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java | 2 +- src/com/android/launcher3/BubbleTextView.java | 2 +- src/com/android/launcher3/InfoDropTarget.java | 2 +- src/com/android/launcher3/Launcher.java | 8 ++++++++ src/com/android/launcher3/Utilities.java | 8 ++++++++ src/com/android/launcher3/WidgetPreviewLoader.java | 2 +- src/com/android/launcher3/allapps/AllAppsContainerView.java | 2 +- src/com/android/launcher3/allapps/AllAppsGridAdapter.java | 2 +- .../android/launcher3/pageindicators/PageIndicatorDots.java | 2 +- src/com/android/launcher3/widget/WidgetCell.java | 2 +- src/com/android/launcher3/widget/WidgetsContainerView.java | 4 ++-- src/com/android/launcher3/widget/WidgetsListAdapter.java | 8 ++++---- 23 files changed, 44 insertions(+), 42 deletions(-) diff --git a/res/drawable-ldrtl/container_fastscroll_popup_bg.xml b/res/drawable-ldrtl/container_fastscroll_popup_bg.xml index d79096807..2bbf5cd72 100644 --- a/res/drawable-ldrtl/container_fastscroll_popup_bg.xml +++ b/res/drawable-ldrtl/container_fastscroll_popup_bg.xml @@ -16,7 +16,7 @@ --> - + diff --git a/res/drawable/container_fastscroll_popup_bg.xml b/res/drawable/container_fastscroll_popup_bg.xml index 2ef07ab96..3dc76800b 100644 --- a/res/drawable/container_fastscroll_popup_bg.xml +++ b/res/drawable/container_fastscroll_popup_bg.xml @@ -16,7 +16,7 @@ --> - + diff --git a/res/layout/all_apps_search_market.xml b/res/layout/all_apps_search_market.xml index 4bdca993a..741c96a24 100644 --- a/res/layout/all_apps_search_market.xml +++ b/res/layout/all_apps_search_market.xml @@ -23,7 +23,7 @@ android:paddingRight="16dp" android:fontFamily="sans-serif-medium" android:textSize="14sp" - android:textColor="@color/launcher_accent_color" + android:textColor="?android:attr/colorAccent" android:text="@string/all_apps_search_market_message" android:textAllCaps="true" android:focusable="true" diff --git a/res/layout/widget_cell.xml b/res/layout/widget_cell.xml index 7fefebaec..15f369f6b 100644 --- a/res/layout/widget_cell.xml +++ b/res/layout/widget_cell.xml @@ -21,7 +21,7 @@ android:layout_weight="1" android:orientation="vertical" android:focusable="true" - android:background="@color/widgets_cell_color" + android:background="?android:attr/colorPrimary" android:gravity="center_horizontal"> diff --git a/res/layout/widgets_view.xml b/res/layout/widgets_view.xml index 0503466de..e9bbd37da 100644 --- a/res/layout/widgets_view.xml +++ b/res/layout/widgets_view.xml @@ -25,7 +25,8 @@ android:paddingTop="@dimen/container_bounds_inset" android:paddingBottom="@dimen/container_bounds_inset" android:descendantFocusability="afterDescendants" - launcher:revealBackground="@drawable/quantum_panel_shape_dark"> + launcher:revealBackground="@drawable/quantum_panel_shape_dark" + android:theme="@android:style/Theme.DeviceDefault.Settings"> true #00000000 #00000000 - @color/launcher_accent_color - @color/launcher_accent_color - @color/launcher_accent_color - \ No newline at end of file + diff --git a/res/values/colors.xml b/res/values/colors.xml index 132953551..44e77e22b 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -22,7 +22,6 @@ over the delete target or the info target --> #FFC1C1C1 #FFF0592B - #FF009688 #80000000 #80c6c5c5 @@ -38,20 +37,11 @@ #FF374248 #FFFFFFFF - #ff009688 #40FFFFFF #FFF - - #009688 - #009688 - - - #009688 - #FFFFFF #C4C4C4 - #263238 diff --git a/res/values/styles.xml b/res/values/styles.xml index 1b7072d1d..0bfd0a041 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -31,7 +31,7 @@ - diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java index 7c7cb0b62..d7dec6e0b 100644 --- a/src/com/android/launcher3/BaseContainerView.java +++ b/src/com/android/launcher3/BaseContainerView.java @@ -50,10 +50,10 @@ public abstract class BaseContainerView extends FrameLayout { public BaseContainerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - int width = ((Launcher) context).getDeviceProfile().availableWidthPx; + Launcher launcher = Launcher.getLauncher(context); + int width = launcher.getDeviceProfile().availableWidthPx; if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && - this instanceof AllAppsContainerView && - !((Launcher) context).getDeviceProfile().isLandscape) { + this instanceof AllAppsContainerView && launcher.getDeviceProfile().isLandscape) { mHorizontalPadding = 0; } else { mHorizontalPadding = DeviceProfile.getContainerPadding(context, width); @@ -89,4 +89,4 @@ public abstract class BaseContainerView extends FrameLayout { public final View getRevealView() { return mRevealView; } -} \ No newline at end of file +} diff --git a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java index fd0045e63..4ab0ea34b 100644 --- a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java +++ b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java @@ -81,9 +81,7 @@ public class BaseRecyclerViewFastScrollBar { mTrackPaint = new Paint(); mTrackPaint.setColor(rv.getFastScrollerTrackColor(Color.BLACK)); mTrackPaint.setAlpha(MAX_TRACK_ALPHA); - mThumbInactiveColor = rv.getFastScrollerThumbInactiveColor( - res.getColor(R.color.container_fastscroll_thumb_inactive_color)); - mThumbActiveColor = res.getColor(R.color.container_fastscroll_thumb_active_color); + mThumbActiveColor = mThumbInactiveColor = Utilities.getColorAccent(rv.getContext()); mThumbPaint = new Paint(); mThumbPaint.setAntiAlias(true); mThumbPaint.setColor(mThumbInactiveColor); diff --git a/src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java b/src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java index ebaba1880..baf96fe0e 100644 --- a/src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java +++ b/src/com/android/launcher3/BaseRecyclerViewFastScrollPopup.java @@ -53,7 +53,7 @@ public class BaseRecyclerViewFastScrollPopup { mRes = res; mRv = rv; mBgOriginalSize = res.getDimensionPixelSize(R.dimen.container_fastscroll_popup_size); - mBg = res.getDrawable(R.drawable.container_fastscroll_popup_bg); + mBg = rv.getContext().getDrawable(R.drawable.container_fastscroll_popup_bg); mBg.setBounds(0, 0, mBgOriginalSize, mBgOriginalSize); mTextPaint = new Paint(); mTextPaint.setColor(Color.WHITE); diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index be00aec34..3287015f4 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -103,7 +103,7 @@ public class BubbleTextView extends TextView public BubbleTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - mLauncher = (Launcher) context; + mLauncher = Launcher.getLauncher(context); DeviceProfile grid = mLauncher.getDeviceProfile(); TypedArray a = context.obtainStyledAttributes(attrs, diff --git a/src/com/android/launcher3/InfoDropTarget.java b/src/com/android/launcher3/InfoDropTarget.java index 259370c1c..e136bcd99 100644 --- a/src/com/android/launcher3/InfoDropTarget.java +++ b/src/com/android/launcher3/InfoDropTarget.java @@ -43,7 +43,7 @@ public class InfoDropTarget extends UninstallDropTarget { protected void onFinishInflate() { super.onFinishInflate(); // Get the hover color - mHoverColor = getResources().getColor(R.color.info_target_hover_tint); + mHoverColor = Utilities.getColorAccent(getContext()); setDrawable(R.drawable.ic_info_launcher); } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 156c1b0b0..6124c895a 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -38,6 +38,7 @@ import android.content.ComponentCallbacks2; import android.content.ComponentName; import android.content.ContentValues; import android.content.Context; +import android.content.ContextWrapper; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; @@ -4523,6 +4524,13 @@ public class Launcher extends Activity } } + public static Launcher getLauncher(Context context) { + if (context instanceof Launcher) { + return (Launcher) context; + } + return ((Launcher) ((ContextWrapper) context).getBaseContext()); + } + private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener, Runnable { @Override diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 35113758a..0306d573b 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -30,6 +30,7 @@ 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.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -839,4 +840,11 @@ public final class Utilities { return getBitmap().getWidth(); } } + + public static int getColorAccent(Context context) { + TypedArray ta = context.obtainStyledAttributes(new int[]{android.R.attr.colorAccent}); + int colorAccent = ta.getColor(0, 0); + ta.recycle(); + return colorAccent; + } } diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java index d9bd78251..45e65b55b 100644 --- a/src/com/android/launcher3/WidgetPreviewLoader.java +++ b/src/com/android/launcher3/WidgetPreviewLoader.java @@ -584,7 +584,7 @@ public class WidgetPreviewLoader { // which would gets re-written next time. mVersions = getPackageVersion(mKey.componentName.getPackageName()); - Launcher launcher = (Launcher) mCaller.getContext(); + Launcher launcher = Launcher.getLauncher(mCaller.getContext()); // it's not in the db... we need to generate it preview = generatePreview(launcher, mInfo, unusedBitmap, mPreviewWidth, mPreviewHeight); diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index b5dc0c086..cd7d3e36f 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -178,7 +178,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc super(context, attrs, defStyleAttr); Resources res = context.getResources(); - mLauncher = (Launcher) context; + mLauncher = Launcher.getLauncher(context); mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); mApps = new AlphabeticalAppsList(context); mAdapter = new AllAppsGridAdapter(mLauncher, mApps, this, mLauncher, this); diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index c68356ed5..ca2556e52 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -378,7 +378,7 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter { public WidgetsListAdapter(View.OnClickListener iconClickListener, View.OnLongClickListener iconLongClickListener, - Launcher launcher) { - mLayoutInflater = launcher.getLayoutInflater(); + Context context) { + mLayoutInflater = LayoutInflater.from(context); mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache(); mIconClickListener = iconClickListener; mIconLongClickListener = iconLongClickListener; - mIndent = launcher.getResources().getDimensionPixelSize(R.dimen.widget_section_indent); + mIndent = context.getResources().getDimensionPixelSize(R.dimen.widget_section_indent); } public void setWidgetsModel(WidgetsModel w) { -- 2.11.0