From 9b29ca5add472b6bdebfa7936142b3aad6cbe3c5 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 17 Feb 2017 10:39:44 -0800 Subject: [PATCH] Defining HomeScreenElementTheme for elements which appear on top of wallpaper > Using HomeScreenElementTheme for workspace items > Fixing view inflation where wrong layout inflater was being used Change-Id: I92e278dbfb609ad7af9c2f47351f23f03cf12049 --- res/drawable/ic_setting.xml | 2 +- res/drawable/ic_wallpaper.xml | 2 +- res/drawable/ic_widget.xml | 2 +- res/layout-land/launcher.xml | 2 ++ res/layout-port/launcher.xml | 1 + res/layout-sw720dp/launcher.xml | 1 + res/layout/drop_target_bar_horz.xml | 1 + res/layout/drop_target_bar_vert.xml | 1 + res/layout/hotseat.xml | 1 + res/layout/overview_panel.xml | 4 +++- res/layout/page_indicator.xml | 1 + res/values/colors.xml | 5 ----- res/values/styles.xml | 14 ++++++++++++-- src/com/android/launcher3/CellLayout.java | 3 ++- src/com/android/launcher3/Launcher.java | 5 +++-- src/com/android/launcher3/PagedView.java | 8 ++++---- src/com/android/launcher3/WidgetPreviewLoader.java | 9 +++++---- src/com/android/launcher3/Workspace.java | 9 ++++----- src/com/android/launcher3/folder/FolderIcon.java | 3 ++- .../android/launcher3/folder/FolderPagedView.java | 4 ---- .../launcher3/pageindicators/CaretDrawable.java | 2 +- 21 files changed, 47 insertions(+), 33 deletions(-) diff --git a/res/drawable/ic_setting.xml b/res/drawable/ic_setting.xml index e89c158c8b..b0009c59ef 100644 --- a/res/drawable/ic_setting.xml +++ b/res/drawable/ic_setting.xml @@ -19,6 +19,6 @@ Copyright (C) 2016 The Android Open Source Project android:viewportWidth="48.0" android:viewportHeight="48.0"> diff --git a/res/drawable/ic_wallpaper.xml b/res/drawable/ic_wallpaper.xml index b7fcfbf55b..30f6d1ae46 100644 --- a/res/drawable/ic_wallpaper.xml +++ b/res/drawable/ic_wallpaper.xml @@ -19,6 +19,6 @@ Copyright (C) 2016 The Android Open Source Project android:viewportWidth="48.0" android:viewportHeight="48.0"> diff --git a/res/drawable/ic_widget.xml b/res/drawable/ic_widget.xml index 97706e36d7..6c1469daad 100644 --- a/res/drawable/ic_widget.xml +++ b/res/drawable/ic_widget.xml @@ -19,6 +19,6 @@ Copyright (C) 2016 The Android Open Source Project android:viewportWidth="48.0" android:viewportHeight="48.0"> diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml index ef0dfdcc6b..6c1b1d3ca6 100644 --- a/res/layout-land/launcher.xml +++ b/res/layout-land/launcher.xml @@ -35,6 +35,7 @@ diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml index dd981dd20e..1fdf546b88 100644 --- a/res/layout-port/launcher.xml +++ b/res/layout-port/launcher.xml @@ -36,6 +36,7 @@ - #80c6c5c5 - #FFF - #FFFFFFFF - #FF000000 - #FFFFFFFF - #40FFFFFF #FFF diff --git a/res/values/styles.xml b/res/values/styles.xml index 8a46e839f0..26ddb9c6a7 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -29,6 +29,17 @@ + + + @@ -86,7 +96,7 @@ 7.5dp 16dp 16dp - @color/workspace_icon_text_color + ?android:attr/textColorPrimary @dimen/drop_target_text_size true end diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index e0fcbf04d5..cac6c065a9 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -57,6 +57,7 @@ import com.android.launcher3.graphics.DragPreviewProvider; import com.android.launcher3.util.CellAndSpan; import com.android.launcher3.util.GridOccupancy; import com.android.launcher3.util.ParcelableSparseArray; +import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; import java.lang.annotation.Retention; @@ -236,7 +237,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler { for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } - mDragOutlinePaint.setColor(getResources().getColor(R.color.outline_color)); + mDragOutlinePaint.setColor(Themes.getAttrColor(context, android.R.attr.textColorPrimary)); // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 14b9c82902..c5cefa6780 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -65,6 +65,7 @@ import android.view.HapticFeedbackConstants; import android.view.KeyEvent; import android.view.KeyboardShortcutGroup; import android.view.KeyboardShortcutInfo; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MotionEvent; import android.view.View; @@ -1432,8 +1433,8 @@ public class Launcher extends BaseActivity * @return A View inflated from layoutResId. */ public View createShortcut(ViewGroup parent, ShortcutInfo info) { - BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon, - parent, false); + BubbleTextView favorite = (BubbleTextView) LayoutInflater.from(parent.getContext()) + .inflate(R.layout.app_icon, parent, false); favorite.applyFromShortcutInfo(info); favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx); favorite.setOnClickListener(this); diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index fb6a611e75..31e3dda328 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -50,6 +50,7 @@ import android.view.animation.Interpolator; import com.android.launcher3.anim.PropertyListBuilder; import com.android.launcher3.pageindicators.PageIndicator; import com.android.launcher3.util.LauncherEdgeEffect; +import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; import java.util.ArrayList; @@ -226,11 +227,10 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc mMinSnapVelocity = (int) (MIN_SNAP_VELOCITY * density); setOnHierarchyChangeListener(this); setWillNotDraw(false); - } - protected void setEdgeGlowColor(int color) { - mEdgeGlowLeft.setColor(color); - mEdgeGlowRight.setColor(color); + int edgeEffectColor = Themes.getAttrColor(getContext(), android.R.attr.colorEdgeEffect); + mEdgeGlowLeft.setColor(edgeEffectColor); + mEdgeGlowRight.setColor(edgeEffectColor); } protected void setDefaultInterpolator(Interpolator interpolator) { diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java index 689cc9b3eb..6dc65d9a53 100644 --- a/src/com/android/launcher3/WidgetPreviewLoader.java +++ b/src/com/android/launcher3/WidgetPreviewLoader.java @@ -416,19 +416,20 @@ public class WidgetPreviewLoader { float shadowBlur = res.getDimension(R.dimen.widget_preview_shadow_blur); float keyShadowDistance = res.getDimension(R.dimen.widget_preview_key_shadow_distance); float corner = res.getDimension(R.dimen.widget_preview_corner_radius); + int shadowColor = ColorUtils.setAlphaComponent( + res.getColor(R.color.default_shadow_color_no_alpha), + ShadowGenerator.AMBIENT_SHADOW_ALPHA); RectF bounds = new RectF(shadowBlur, shadowBlur, width - shadowBlur, height - shadowBlur - keyShadowDistance); p.setColor(Color.WHITE); // Key shadow - p.setShadowLayer(shadowBlur, 0, keyShadowDistance, - ShadowGenerator.KEY_SHADOW_ALPHA << 24); + p.setShadowLayer(shadowBlur, 0, keyShadowDistance, shadowColor); c.drawRoundRect(bounds, corner, corner, p); // Ambient shadow - p.setShadowLayer(shadowBlur, 0, 0, - ColorUtils.setAlphaComponent(Color.BLACK, ShadowGenerator.AMBIENT_SHADOW_ALPHA)); + p.setShadowLayer(shadowBlur, 0, 0, shadowColor); c.drawRoundRect(bounds, corner, corner, p); p.clearShadowLayer(); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 56aa69e5cd..6d52ea3daa 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -43,6 +43,7 @@ import android.util.AttributeSet; import android.util.Log; import android.util.Property; import android.util.SparseArray; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewDebug; @@ -528,8 +529,6 @@ public class Workspace extends PagedView // Set the wallpaper dimensions when Launcher starts up setWallpaperDimension(); - - setEdgeGlowColor(getResources().getColor(R.color.workspace_edge_effect_color)); } @Override @@ -622,7 +621,7 @@ public class Workspace extends PagedView if (qsb == null) { // In transposed layout, we add the QSB in the Grid. As workspace does not touch the // edges, we do not need a full width QSB. - qsb = mLauncher.getLayoutInflater().inflate( + qsb = LayoutInflater.from(getContext()).inflate( mLauncher.getDeviceProfile().isVerticalBarLayout() ? R.layout.qsb_container : R.layout.qsb_blocker_view, firstPage, false); @@ -707,7 +706,7 @@ public class Workspace extends PagedView // Inflate the cell layout, but do not add it automatically so that we can get the newly // created CellLayout. - CellLayout newScreen = (CellLayout) mLauncher.getLayoutInflater().inflate( + CellLayout newScreen = (CellLayout) LayoutInflater.from(getContext()).inflate( R.layout.workspace_screen, this, false /* attachToRoot */); newScreen.setOnLongClickListener(mLongClickListener); newScreen.setOnClickListener(mLauncher); @@ -725,7 +724,7 @@ public class Workspace extends PagedView public void createCustomContentContainer() { CellLayout customScreen = (CellLayout) - mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, this, false); + LayoutInflater.from(getContext()).inflate(R.layout.workspace_screen, this, false); customScreen.disableDragTarget(); customScreen.disableJailContent(); diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index 96d56759df..6045400225 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -177,7 +177,8 @@ public class FolderIcon extends FrameLayout implements FolderListener { } DeviceProfile grid = launcher.getDeviceProfile(); - FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false); + FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext()) + .inflate(resId, group, false); // For performance and compatibility reasons we render the preview using a software layer. // In particular, hardware path clipping has spotty ecosystem support and bad performance. diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index eecce183a6..532e5a6c75 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -35,17 +35,14 @@ import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; -import com.android.launcher3.LauncherModel; import com.android.launcher3.PagedView; import com.android.launcher3.R; import com.android.launcher3.ShortcutAndWidgetContainer; import com.android.launcher3.ShortcutInfo; import com.android.launcher3.Utilities; 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; @@ -108,7 +105,6 @@ public class FolderPagedView extends PagedView { mIsRtl = Utilities.isRtl(getResources()); setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); - setEdgeGlowColor(Themes.getAttrColor(context, android.R.attr.colorEdgeEffect)); mFocusIndicatorHelper = new ViewGroupFocusHelper(this); } diff --git a/src/com/android/launcher3/pageindicators/CaretDrawable.java b/src/com/android/launcher3/pageindicators/CaretDrawable.java index 0a00e24e92..32e57a9f62 100644 --- a/src/com/android/launcher3/pageindicators/CaretDrawable.java +++ b/src/com/android/launcher3/pageindicators/CaretDrawable.java @@ -46,7 +46,7 @@ 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.workspace_icon_text_color)); + mCaretPaint.setColor(Themes.getAttrColor(context, android.R.attr.textColorPrimary)); mCaretPaint.setAntiAlias(true); mCaretPaint.setStrokeWidth(strokeWidth); mCaretPaint.setStyle(Paint.Style.STROKE);