Updating widget tray theme
Using standard theme attributes rather than custom color codes, so
that it plays nice with system theme changes.
Bug: 34819119
Bug: 34897402
Bug: 21446746
Change-Id: I265fba3ceae8873650fd09e4704838d313155e83
diff --git a/res/drawable/quantum_panel_dark.xml b/res/drawable/quantum_panel_dark.xml
deleted file mode 100644
index b113b37..0000000
--- a/res/drawable/quantum_panel_dark.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2015 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.
--->
-<inset xmlns:android="http://schemas.android.com/apk/res/android"
- android:drawable="@drawable/quantum_panel_shape_dark"
- android:insetBottom="@dimen/quantum_panel_outer_padding"
- android:insetLeft="@dimen/quantum_panel_outer_padding"
- android:insetRight="@dimen/quantum_panel_outer_padding"
- android:insetTop="@dimen/quantum_panel_outer_padding" />
diff --git a/res/drawable/quantum_panel_shape_dark.xml b/res/drawable/round_rect_primary.xml
similarity index 88%
rename from res/drawable/quantum_panel_shape_dark.xml
rename to res/drawable/round_rect_primary.xml
index b299eb8..2c47e06 100644
--- a/res/drawable/quantum_panel_shape_dark.xml
+++ b/res/drawable/round_rect_primary.xml
@@ -16,7 +16,6 @@
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
- <solid android:color="?attr/colorSecondary" />
- <corners
- android:radius="2dp" />
+ <solid android:color="?android:attr/colorPrimary" />
+ <corners android:radius="2dp" />
</shape>
diff --git a/res/layout/add_item_confirmation_activity.xml b/res/layout/add_item_confirmation_activity.xml
index da079da..2aae5bc 100644
--- a/res/layout/add_item_confirmation_activity.xml
+++ b/res/layout/add_item_confirmation_activity.xml
@@ -22,10 +22,10 @@
android:layout_height="match_parent">
<TextView
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:paddingTop="8dp"
- android:paddingBottom="8dp"
+ android:paddingLeft="24dp"
+ android:paddingRight="24dp"
+ android:paddingTop="4dp"
+ android:paddingBottom="20dp"
android:text="@string/add_item_request_drag_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
@@ -33,7 +33,7 @@
<FrameLayout
android:theme="@style/WidgetContainerTheme"
android:layout_width="match_parent"
- android:background="?android:attr/colorPrimary"
+ android:background="?android:attr/colorPrimaryDark"
android:layout_height="wrap_content">
<include
diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml
index 1909f3b..5f5b38b 100644
--- a/res/layout/all_apps.xml
+++ b/res/layout/all_apps.xml
@@ -55,7 +55,7 @@
android:focusable="true"
android:paddingStart="@dimen/container_fastscroll_thumb_max_width"
android:paddingEnd="@dimen/container_fastscroll_thumb_max_width"
- android:theme="@style/CustomOverscroll.Light" />
+ android:theme="@style/AllAppsOverscroll" />
<!-- Fast scroller popup -->
<TextView
diff --git a/res/layout/appwidget_error.xml b/res/layout/appwidget_error.xml
index d6bd0c5..6a459c3 100644
--- a/res/layout/appwidget_error.xml
+++ b/res/layout/appwidget_error.xml
@@ -19,9 +19,10 @@
android:layout_height="match_parent"
android:gravity="center"
android:elevation="2dp"
+ android:padding="4dp"
android:theme="@style/WidgetContainerTheme"
- android:background="@drawable/quantum_panel_dark"
+ android:background="@drawable/round_rect_primary"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
- android:textColor="@color/widgets_view_item_text_color"
+ android:textColor="?android:attr/textColorSecondary"
android:text="@string/gadget_error_text"
/>
diff --git a/res/layout/widget_cell.xml b/res/layout/widget_cell.xml
index c5a6753..b9b098c 100644
--- a/res/layout/widget_cell.xml
+++ b/res/layout/widget_cell.xml
@@ -20,7 +20,7 @@
android:layout_weight="1"
android:orientation="vertical"
android:focusable="true"
- android:background="?android:attr/colorPrimary"
+ android:background="?android:attr/colorPrimaryDark"
android:gravity="center_horizontal">
<LinearLayout
@@ -42,10 +42,9 @@
android:fadingEdge="horizontal"
android:fontFamily="sans-serif-condensed"
android:gravity="start"
- android:shadowColor="#B0000000"
- android:shadowRadius="2.0"
android:singleLine="true"
- android:textColor="@color/widgets_view_item_text_color"
+ android:maxLines="1"
+ android:textColor="?android:attr/textColorSecondary"
android:textSize="14sp" />
<!-- The original dimensions of the widget (can't be the same text as above due to different
@@ -56,11 +55,10 @@
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
- android:textColor="@color/widgets_view_item_text_color"
+ android:textColor="?android:attr/textColorSecondary"
android:textSize="14sp"
android:fontFamily="sans-serif-condensed"
- android:shadowRadius="2.0"
- android:shadowColor="#B0000000" />
+ android:alpha="0.8" />
</LinearLayout>
<!-- The image of the widget. This view does not support padding. Any placement adjustment
diff --git a/res/drawable/widgets_row_divider.xml b/res/layout/widget_list_divider.xml
similarity index 69%
rename from res/drawable/widgets_row_divider.xml
rename to res/layout/widget_list_divider.xml
index 2c3c7a2..68c9a45 100644
--- a/res/drawable/widgets_row_divider.xml
+++ b/res/layout/widget_list_divider.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 The Android Open Source Project
+<!-- 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.
@@ -13,7 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <size android:width="@dimen/widget_row_divider" />
- <solid android:color="?attr/colorSecondary" />
-</shape>
+<View xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="@dimen/widget_row_divider"
+ android:layout_height="match_parent"
+ android:background="?android:attr/colorPrimary" />
\ No newline at end of file
diff --git a/res/layout/widgets_list_row_view.xml b/res/layout/widgets_list_row_view.xml
index 530e856..5c2e230 100644
--- a/res/layout/widgets_list_row_view.xml
+++ b/res/layout/widgets_list_row_view.xml
@@ -19,7 +19,6 @@
android:id="@+id/widgets_cell_list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:background="?android:attr/colorPrimary"
android:orientation="vertical"
android:focusable="true"
android:descendantFocusability="afterDescendants">
@@ -30,7 +29,7 @@
android:id="@+id/section"
android:layout_width="match_parent"
android:layout_height="@dimen/widget_section_height"
- android:background="?attr/colorSecondary"
+ android:background="?android:attr/colorPrimary"
android:drawablePadding="@dimen/widget_section_horizontal_padding"
android:ellipsize="end"
android:focusable="true"
@@ -51,9 +50,9 @@
<HorizontalScrollView
android:id="@+id/widgets_scroll_container"
- android:theme="@style/CustomOverscroll.Dark"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:background="?android:attr/colorPrimaryDark"
android:scrollbars="none">
<LinearLayout
android:id="@+id/widgets_cell_list"
@@ -62,7 +61,6 @@
android:paddingStart="@dimen/widget_row_padding"
android:paddingEnd="0dp"
android:orientation="horizontal"
- android:divider="@drawable/widgets_row_divider"
- android:showDividers="middle"/>
+ android:showDividers="none"/>
</HorizontalScrollView>
</LinearLayout>
diff --git a/res/layout/widgets_view.xml b/res/layout/widgets_view.xml
index d193a5e..2f11c28 100644
--- a/res/layout/widgets_view.xml
+++ b/res/layout/widgets_view.xml
@@ -23,7 +23,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="afterDescendants"
- launcher:revealBackground="@drawable/quantum_panel_shape_dark"
+ launcher:revealBackground="@drawable/round_rect_primary"
android:theme="@style/WidgetContainerTheme">
<View
@@ -45,7 +45,6 @@
<com.android.launcher3.widget.WidgetsRecyclerView
android:id="@+id/widgets_list_view"
- android:theme="@style/CustomOverscroll.Dark"
android:layout_width="match_parent"
android:layout_height="match_parent" />
diff --git a/res/values-v25/styles.xml b/res/values-v26/styles.xml
similarity index 84%
rename from res/values-v25/styles.xml
rename to res/values-v26/styles.xml
index ed670a9..6877623 100644
--- a/res/values-v25/styles.xml
+++ b/res/values-v26/styles.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
-* Copyright (C) 2016 The Android Open Source Project
+* 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.
@@ -19,6 +19,6 @@
<resources>
<!-- Theme for the widget container. -->
<style name="WidgetContainerTheme" parent="@android:style/Theme.DeviceDefault.Settings">
- <item name="colorSecondary">?android:attr/colorSecondary</item>
+ <item name="android:colorEdgeEffect">?android:attr/textColorSecondary</item>
</style>
</resources>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index a259362..18f409f 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -80,9 +80,6 @@
<attr name="hideParentOnDisable" format="boolean" />
</declare-styleable>
- <!-- Fallback attr for pre-API 25 support -->
- <attr name="colorSecondary" format="reference|color" />
-
<declare-styleable name="InvariantDeviceProfile">
<attr name="name" format="string" />
<attr name="minWidthDps" format="float" />
diff --git a/res/values/colors.xml b/res/values/colors.xml
index a7b507c..d166a79 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -45,11 +45,5 @@
<color name="spring_loaded_panel_color">#40FFFFFF</color>
<color name="spring_loaded_highlighted_panel_border_color">#FFF</color>
- <!-- Widgets view -->
- <color name="widgets_view_item_text_color">#3B3B3B</color>
-
- <!-- Used as a fallback since colorSecondary doesn't exist pre-API 25 -->
- <color name="fallback_secondary_color">#FF37474F</color>
-
<color name="notification_icon_default_color">#757575</color> <!-- Gray 600 -->
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 8ffc53f..879c7d8 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -46,20 +46,16 @@
<!-- Theme for the widget container. Overridden on API 25. -->
<style name="WidgetContainerTheme" parent="@android:style/Theme.DeviceDefault.Settings">
- <item name="colorSecondary">@color/fallback_secondary_color</item>
+ <item name="android:colorEdgeEffect">@color/workspace_edge_effect_color</item>
+ <item name="android:textColorPrimary">?android:attr/textColorPrimaryInverse</item>
+ <item name="android:textColorSecondary">?android:attr/textColorSecondaryInverse</item>
</style>
<!-- Overscroll effect -->
- <style name="CustomOverscroll" />
-
- <style name="CustomOverscroll.Light" parent="@android:style/Theme.DeviceDefault.Light">
+ <style name="AllAppsOverscroll" parent="@android:style/Theme.DeviceDefault.Light">
<item name="android:colorEdgeEffect">@color/folder_edge_effect_color</item>
</style>
- <style name="CustomOverscroll.Dark">
- <item name="android:colorEdgeEffect">@color/workspace_edge_effect_color</item>
- </style>
-
<!-- Different icons -->
<style name="Icon">
<item name="android:layout_width">match_parent</item>
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index 5b487b6..6e9820c 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -45,6 +45,7 @@
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;
@@ -132,9 +133,9 @@
mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
mActivityBgColor = context.getResources().getColor(R.color.quantum_panel_bg_color);
- TypedArray ta = context.obtainStyledAttributes(new int[]{R.attr.colorSecondary});
- mPackageBgColor = ta.getColor(0, 0);
- ta.recycle();
+ mPackageBgColor = Utilities.getAttrColor(
+ new ContextThemeWrapper(context, R.style.WidgetContainerTheme),
+ android.R.attr.colorPrimary);
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.
diff --git a/src/com/android/launcher3/PendingAppWidgetHostView.java b/src/com/android/launcher3/PendingAppWidgetHostView.java
index 354cf20..815fd10 100644
--- a/src/com/android/launcher3/PendingAppWidgetHostView.java
+++ b/src/com/android/launcher3/PendingAppWidgetHostView.java
@@ -69,10 +69,10 @@
mDisabledForSafeMode = disabledForSafeMode;
mPaint = new TextPaint();
- mPaint.setColor(0xFFFFFFFF);
+ mPaint.setColor(Utilities.getAttrColor(getContext(), android.R.attr.textColorPrimary));
mPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
mLauncher.getDeviceProfile().iconTextSizePx, getResources().getDisplayMetrics()));
- setBackgroundResource(R.drawable.quantum_panel_dark);
+ setBackgroundResource(R.drawable.round_rect_primary);
setWillNotDraw(false);
setElevation(getResources().getDimension(R.dimen.pending_widget_elevation));
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 267cb2a..839b5e8 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -608,7 +608,11 @@
}
public static int getColorAccent(Context context) {
- TypedArray ta = context.obtainStyledAttributes(new int[]{android.R.attr.colorAccent});
+ 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;
diff --git a/src/com/android/launcher3/widget/WidgetsListAdapter.java b/src/com/android/launcher3/widget/WidgetsListAdapter.java
index 60e6e2a..38210fc 100644
--- a/src/com/android/launcher3/widget/WidgetsListAdapter.java
+++ b/src/com/android/launcher3/widget/WidgetsListAdapter.java
@@ -113,20 +113,27 @@
// Add more views.
// if there are too many, hide them.
- int diff = infoList.size() - row.getChildCount();
+ int expectedChildCount = infoList.size() + Math.max(0, infoList.size() - 1);
+ int childCount = row.getChildCount();
- if (diff > 0) {
- for (int i = 0; i < diff; i++) {
- WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(
- R.layout.widget_cell, row, false);
+ if (expectedChildCount > childCount) {
+ for (int i = childCount ; i < expectedChildCount; i++) {
+ if ((i & 1) == 1) {
+ // Add a divider for odd index
+ mLayoutInflater.inflate(R.layout.widget_list_divider, row);
+ } else {
+ // Add cell for even index
+ WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(
+ R.layout.widget_cell, row, false);
- // set up touch.
- widget.setOnClickListener(mIconClickListener);
- widget.setOnLongClickListener(mIconLongClickListener);
- row.addView(widget);
+ // set up touch.
+ widget.setOnClickListener(mIconClickListener);
+ widget.setOnLongClickListener(mIconLongClickListener);
+ row.addView(widget);
+ }
}
- } else if (diff < 0) {
- for (int i=infoList.size() ; i < row.getChildCount(); i++) {
+ } else if (expectedChildCount < childCount) {
+ for (int i = expectedChildCount ; i < childCount; i++) {
row.getChildAt(i).setVisibility(View.GONE);
}
}
@@ -136,10 +143,14 @@
// Bind the view in the widget horizontal tray region.
for (int i=0; i < infoList.size(); i++) {
- WidgetCell widget = (WidgetCell) row.getChildAt(i);
+ WidgetCell widget = (WidgetCell) row.getChildAt(2*i);
widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
widget.ensurePreview();
widget.setVisibility(View.VISIBLE);
+
+ if (i > 0) {
+ row.getChildAt(2*i - 1).setVisibility(View.VISIBLE);
+ }
}
}
@@ -151,11 +162,10 @@
ViewGroup container = (ViewGroup) mLayoutInflater.inflate(
R.layout.widgets_list_row_view, parent, false);
- LinearLayout cellList = (LinearLayout) container.findViewById(R.id.widgets_cell_list);
// if the end padding is 0, then container view (horizontal scroll view) doesn't respect
// the end of the linear layout width + the start padding and doesn't allow scrolling.
- cellList.setPaddingRelative(mIndent, 0, 1, 0);
+ container.findViewById(R.id.widgets_cell_list).setPaddingRelative(mIndent, 0, 1, 0);
return new WidgetsRowViewHolder(container);
}
@@ -163,7 +173,7 @@
@Override
public void onViewRecycled(WidgetsRowViewHolder holder) {
int total = holder.cellContainer.getChildCount();
- for (int i = 0; i < total; i++) {
+ for (int i = 0; i < total; i+=2) {
WidgetCell widget = (WidgetCell) holder.cellContainer.getChildAt(i);
widget.clear();
}