diff options
author | 2018-08-16 19:56:56 +0800 | |
---|---|---|
committer | 2018-09-11 20:34:00 +0800 | |
commit | 6b77172d5a8831a5b7d388ef09ec4fab1298aebc (patch) | |
tree | fb88a6f62364e3f73714501cf3b31ef2faaedbb9 | |
parent | 254d146dc1bba2ce6e2e017689621c7d2832a193 (diff) |
Support Dark/Light Theme for DocumentsUI (2/N)
1) Define Light Theme and ToolBarTheme to match M2 design
2) Adjust GridItem / ListItem background in Dark Theme
3) Tuning StatusBar and NavigationBar color fulfill design
4) Refactor legacy style definition for GridItem
Test: atest com.android.documentsui.dirlist.ThemeUiTest
atest com.android.documentsui.dirlist.DarkThemeUiTest
manually swich to night mode
Bug: 111862978
Bug: 114369969
Bug: 114805149
Change-Id: I3029a4f25640f83cfd5986f965923656fd01958d
23 files changed, 315 insertions, 67 deletions
diff --git a/res/color/item_title.xml b/res/color/item_doc_grid_tint_dark.xml index d1760d0f1..6c40827ba 100644 --- a/res/color/item_title.xml +++ b/res/color/item_doc_grid_tint_dark.xml @@ -16,9 +16,9 @@ <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item - android:state_enabled="true" - android:color="@color/item_doc_title" /> + android:state_activated="true" + android:color="@color/item_grid_tint_dark" + android:alpha=".15" /> <item - android:state_enabled="false" - android:color="@color/item_doc_title_disabled"/> + android:color="@android:color/transparent" /> </selector> diff --git a/res/drawable/grid_item_background_dark.xml b/res/drawable/grid_item_background_dark.xml new file mode 100644 index 000000000..88becada3 --- /dev/null +++ b/res/drawable/grid_item_background_dark.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2016 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. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:drawable="@color/item_doc_background_selected_dark" + android:state_selected="true" /> + <item android:drawable="@color/item_hover_color_dark" + android:state_drag_hovered="true" /> + <item android:drawable="@color/item_doc_background_dark" + android:state_selected="false" /> +</selector>
\ No newline at end of file diff --git a/res/layout/drag_shadow_layout.xml b/res/layout/drag_shadow_layout.xml index 1917e25f2..f42474254 100644 --- a/res/layout/drag_shadow_layout.xml +++ b/res/layout/drag_shadow_layout.xml @@ -40,7 +40,7 @@ android:maxLines="1" android:ellipsize="end" android:textAlignment="viewStart" - android:textColor="@color/item_title" + android:textAppearance="@android:style/TextAppearance.Material.Subhead" android:paddingStart="6dp" android:paddingBottom="1dp"/> diff --git a/res/layout/inspector_header.xml b/res/layout/inspector_header.xml index d62180170..623ae23f0 100644 --- a/res/layout/inspector_header.xml +++ b/res/layout/inspector_header.xml @@ -29,16 +29,15 @@ android:id="@+id/inspector_file_title" android:layout_width="match_parent" android:layout_height="wrap_content" - android:textSize="20sp" android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingStart="16dp" android:paddingEnd="16dp" - android:textColor="@android:color/white" android:layout_gravity="center_vertical" android:background="@color/inspector_title_background" android:textIsSelectable="true" android:textAlignment="viewStart" - android:layout_alignBottom="@+id/inspector_thumbnail" /> + android:layout_alignBottom="@+id/inspector_thumbnail" + android:textAppearance="@style/InspectorHeaderTitle" /> </RelativeLayout> diff --git a/res/layout/item_dir_grid.xml b/res/layout/item_dir_grid.xml index 7bc949eed..210af6f34 100644 --- a/res/layout/item_dir_grid.xml +++ b/res/layout/item_dir_grid.xml @@ -23,20 +23,17 @@ decide to rip these out, please be sure to check out focus and keyboards. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" + android:layout_margin="4dp" android:focusable="true"> <com.google.android.material.card.MaterialCardView android:layout_width="match_parent" android:layout_height="wrap_content" - android:duplicateParentState="true" - android:background="@drawable/grid_item_background" - app:cardUseCompatPadding="true" - app:cardCornerRadius="@dimen/grid_item_radius" - app:cardElevation="@dimen/grid_item_elevation"> + android:layout_margin="2dp" + android:duplicateParentState="true"> <!-- The height is 48px. paddingTop (9dp) + @dimen/check_icon_size (30dp) + paddingBottom (9dp) --> @@ -44,6 +41,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" + android:background="?attr/colorBackgroundFloating" android:gravity="center_vertical"> <FrameLayout @@ -84,7 +82,6 @@ android:singleLine="true" android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.Material.Subhead" - android:textColor="@color/item_title" android:layout_marginBottom="9dp" android:layout_marginEnd="12dp" android:layout_marginTop="9dp"/> diff --git a/res/layout/item_doc_grid.xml b/res/layout/item_doc_grid.xml index f4163ff2a..c9cd6d14e 100644 --- a/res/layout/item_doc_grid.xml +++ b/res/layout/item_doc_grid.xml @@ -22,20 +22,17 @@ decide to rip these out, please be sure to check out focus and keyboards. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" + android:layout_margin="4dp" android:focusable="true"> <com.google.android.material.card.MaterialCardView android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/grid_item_background" - android:focusable="true" - app:cardUseCompatPadding="true" - app:cardCornerRadius="@dimen/grid_item_radius" - app:cardElevation="@dimen/grid_item_elevation"> + android:layout_margin="2dp" + android:focusable="true"> <RelativeLayout android:layout_width="match_parent" @@ -48,7 +45,6 @@ <FrameLayout android:id="@+id/thumbnail" - android:background="@drawable/grid_item_background" android:layout_width="match_parent" android:layout_height="wrap_content"> @@ -58,7 +54,7 @@ android:layout_height="wrap_content" android:scaleType="centerCrop" android:contentDescription="@null" - android:tint="@color/item_doc_grid_tint" + android:tint="?attr/gridItemTint" android:tintMode="src_over"/> <com.android.documentsui.GridItemThumbnail @@ -76,7 +72,7 @@ <LinearLayout android:id="@+id/nameplate" - android:background="@drawable/grid_item_background" + android:background="?attr/colorBackgroundFloating" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" @@ -140,8 +136,7 @@ android:singleLine="true" android:ellipsize="end" android:textAlignment="viewStart" - android:textAppearance="@android:style/TextAppearance.Material.Caption" - android:textColor="@color/item_details"/> + android:textAppearance="@android:style/TextAppearance.Material.Caption"/> <TextView android:id="@+id/date" @@ -152,8 +147,8 @@ android:singleLine="true" android:ellipsize="end" android:textAlignment="viewStart" - android:textAppearance="@android:style/TextAppearance.Material.Caption" - android:textColor="@color/item_details"/> + android:textAppearance="@android:style/TextAppearance.Material.Caption"/> + </RelativeLayout> </LinearLayout> @@ -174,4 +169,4 @@ </com.google.android.material.card.MaterialCardView> -</LinearLayout>
\ No newline at end of file +</LinearLayout> diff --git a/res/layout/item_doc_list.xml b/res/layout/item_doc_list.xml index 0c190f489..bc23356bd 100644 --- a/res/layout/item_doc_list.xml +++ b/res/layout/item_doc_list.xml @@ -83,7 +83,7 @@ android:ellipsize="end" android:singleLine="true" android:textAlignment="viewStart" - style="?android:attr/textAppearanceListItem" /> + android:textAppearance="?android:attr/textAppearanceListItem" /> <LinearLayout android:id="@+id/line2" diff --git a/res/layout/table_key_value_row.xml b/res/layout/table_key_value_row.xml index b45cda44e..6d0d500be 100644 --- a/res/layout/table_key_value_row.xml +++ b/res/layout/table_key_value_row.xml @@ -30,9 +30,8 @@ android:layout_width="0dp" android:layout_weight="1" android:paddingEnd="5dp" - android:textColor="@android:color/black" - android:textSize="14sp" - android:textAlignment="viewStart"> + android:textAlignment="viewStart" + android:textAppearance="?attr/textAppearanceSubtitle1"> </TextView> <TextView @@ -40,10 +39,9 @@ android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" - android:textColor="@color/inspector_value" - android:textSize="14sp" android:textIsSelectable="true" - android:textAlignment="viewStart"> + android:textAlignment="viewStart" + android:textAppearance="@style/InspectorKeySubTitle"> </TextView> </com.android.documentsui.inspector.KeyValueRow> diff --git a/res/values-night/styles.xml b/res/values-night/styles.xml index fe6659c87..93277aede 100644 --- a/res/values-night/styles.xml +++ b/res/values-night/styles.xml @@ -38,4 +38,11 @@ <style name="ActionBarPopupTheme" parent="@android:style/ThemeOverlay.Material.Dark" /> <style name="ListViewStyle" parent="@android:style/Widget.Material.ListView"></style> + + <style name="CardViewStyle" parent="@style/Widget.MaterialComponents.CardView"> + <item name="colorBackgroundFloating">@drawable/grid_item_background_dark</item> + <item name="cardPreventCornerOverlap">false</item> + <item name="cardCornerRadius">@dimen/grid_item_radius</item> + <item name="cardElevation">@dimen/grid_item_elevation</item> + </style> </resources> diff --git a/res/values-night/themes.xml b/res/values-night/themes.xml index e0c17b921..dd45d3130 100644 --- a/res/values-night/themes.xml +++ b/res/values-night/themes.xml @@ -22,13 +22,14 @@ <item name="actionModeStyle">@style/ActionModeStyle</item> <item name="snackbarButtonStyle">@style/SnackbarButtonStyle</item> - <item name="android:windowBackground">@color/g_dark_grey</item> + <item name="android:windowBackground">?android:attr/colorPrimary</item> <item name="android:colorPrimaryDark">@color/g_grey</item> - <item name="android:colorPrimary">@color/g_grey</item> - <item name="android:colorSecondary">@color/g_grey</item> - <item name="android:colorAccent">@color/accent</item> - <item name="android:colorBackground">@color/g_grey</item> + <item name="android:colorPrimary">@color/g_dark_grey</item> + <item name="android:colorSecondary">@color/g_dark_grey</item> + <item name="android:colorAccent">@color/accent_dark</item> + <item name="android:colorBackground">?android:attr/colorPrimary</item> <item name="android:windowLightStatusBar">false</item> + <item name="android:windowLightNavigationBar">false</item> <item name="android:queryBackground">@color/menu_search_background</item> <item name="android:listDivider">@drawable/list_divider</item> <item name="android:windowActionBar">false</item> @@ -37,9 +38,18 @@ <item name="android:windowSoftInputMode">stateUnspecified|adjustUnspecified</item> <item name="android:actionModeBackground">?android:attr/colorBackground</item> <item name="android:actionModeCloseDrawable">@drawable/ic_action_clear</item> - <item name="android:statusBarColor">@android:color/transparent</item> + <item name="android:statusBarColor">?android:attr/colorPrimary</item> + <item name="android:navigationBarColor">?android:attr/colorPrimary</item> + + <item name="colorControlHighlight">@color/g_grey</item> + <item name="materialCardViewStyle">@style/CardViewStyle</item> <item name="textHandleColor">@color/text_handle_dark</item> <item name="textCursorColor">@color/text_cursor_dark</item> + + <item name="gridItemTint">@color/item_doc_grid_tint_dark</item> + <item name="gridItemColor">@color/item_doc_background_dark</item> + <item name="gridItemSelectedColor">@color/item_doc_background_selected_dark</item> + <item name="gridItemDisableColor">@color/item_doc_background_disabled_dark</item> </style> </resources> diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 84a37b820..f48975668 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -14,8 +14,15 @@ limitations under the License. --> <resources> - <declare-styleable name="HighlightedItemView"> - <attr name="state_highlighted" format="boolean"/> + + <declare-styleable name="ActionBarView"> + <attr name="android:colorPrimary" format="color" /> + <attr name="android:colorControlNormal" format="color" /> + <attr name="android:textColorPrimary" format="color" /> + </declare-styleable> + + <declare-styleable name="CardView"> + <attr name="colorBackgroundFloating" format="color" /> </declare-styleable> <declare-styleable name="DropBadgeView"> @@ -23,12 +30,32 @@ <attr name="state_copy" format="boolean"/> </declare-styleable> - <declare-styleable name="TextHandleView"> - <attr name="textHandleColor" format="reference" /> - <attr name="textCursorColor" format="reference" /> + <declare-styleable name="GridItem"> + <attr name="gridItemTint" format="reference" /> + <attr name="gridItemColor" format="reference" /> + <attr name="gridItemSelectedColor" format="reference" /> + <attr name="gridItemDisableColor" format="reference" /> + </declare-styleable> + + <declare-styleable name="HighlightedItemView"> + <attr name="state_highlighted" format="boolean"/> </declare-styleable> <declare-styleable name="SnackbarView"> <attr name="android:textColor" format="reference" /> </declare-styleable> + + <declare-styleable name="SystemWindow"> + <attr name="android:statusBarColor" format="color" /> + <attr name="android:navigationBarColor" format="color" /> + <attr name="android:windowBackground" format="color" /> + <attr name="android:windowLightStatusBar" format="boolean" /> + <attr name="android:windowLightNavigationBar" format="boolean" /> + </declare-styleable> + + <declare-styleable name="TextHandleView"> + <attr name="textHandleColor" format="reference" /> + <attr name="textCursorColor" format="reference" /> + </declare-styleable> + </resources> diff --git a/res/values/colors.xml b/res/values/colors.xml index ce3f34ad0..c11f08b5e 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -48,22 +48,28 @@ <color name="root_focus_color">#ffe0e0e0</color> <color name="item_hover_color">#ffe0e0e0</color> + <color name="item_hover_color_dark">#ff5f6368</color> - <item name="root_icon_disabled_alpha" format="float" type="dimen">?android:attr/disabledAlpha</item> + <item name="root_icon_disabled_alpha" format="float" type="dimen">?android:attr/disabledAlpha + </item> <color name="doc_icon_color">#ff5a5a5a</color> <color name="tool_bar_color">#ff0e70e8</color> <!--M2 Google Blue 800--> <!-- TODO: Would be nice to move this to a color-set, but not sure how to support animation --> - <color name="item_doc_title">#ff333333</color> + <color name="item_doc_title">?android:attr/textColorSecondary</color> <color name="item_doc_title_disabled">?android:attr/textColorSecondaryInverse</color> - <color name="item_doc_details">#ff333333</color> + <color name="item_doc_details">?android:attr/textColorSecondary</color> <color name="item_doc_background">@android:color/white</color> + <color name="item_doc_background_dark">@color/g_grey</color> <color name="item_doc_background_disabled">#fff4f4f4</color> + <color name="item_doc_background_disabled_dark">@color/g_light_grey</color> <color name="item_doc_background_selected">#4d3367d6</color> + <color name="item_doc_background_selected_dark">#4d2297f0</color> <color name="item_breadcrumb_background_hovered">#1affffff</color> <color name="item_doc_droppable_background">#ffe8f0fb</color> <color name="item_doc_not_droppable_background">#ffe0e0e0</color> - <color name="item_grid_tint">#ff127beb</color> <!--M2 Google Blue 700--> + <color name="item_grid_tint">#ff127beb</color> <!--M2 Google Blue 700--> + <color name="item_grid_tint_dark">@color/primary_dark</color> <!--M2 Google Blue 800--> <color name="item_drag_shadow_background">@android:color/white</color> <color name="item_drag_shadow_container_background">@android:color/transparent</color> @@ -80,8 +86,9 @@ <color name="scroll_track">#fff0f0f0</color> <color name="inspector_value">#ff939393</color> - <color name="inspector_link">#6633b5e5</color> + <color name="inspector_link">?android:attr/colorAccent</color> <color name="inspector_section_title">#ff939393</color> <color name="inspector_section_divider">#E0E0E0</color> <color name="inspector_title_background">#40000000</color> + <color name="inspector_debug_mode_color">#607d8b</color> </resources> diff --git a/res/values/styles.xml b/res/values/styles.xml index 4fd49d5e0..e22d0740f 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -39,6 +39,13 @@ <style name="ListViewStyle" parent="@android:style/Widget.Material.Light.ListView"></style> + <style name="CardViewStyle" parent="@style/Widget.MaterialComponents.CardView"> + <item name="colorBackgroundFloating">@drawable/grid_item_background</item> + <item name="cardPreventCornerOverlap">false</item> + <item name="cardCornerRadius">@dimen/grid_item_radius</item> + <item name="cardElevation">@dimen/grid_item_elevation</item> + </style> + <style name="TrimmedHorizontalProgressBar" parent="android:Widget.Material.ProgressBar.Horizontal"> <item name="android:indeterminateDrawable">@drawable/progress_indeterminate_horizontal_material_trimmed</item> <item name="android:minHeight">3dp</item> @@ -46,10 +53,18 @@ </style> <style name="SortTitle" parent="@style/TextAppearance.MaterialComponents.Headline6" > - <item name="android:textColor">?android:attr/textColorSecondary</item> + <item name="android:textColor">?android:attr/textColorPrimary</item> <item name="android:textSize">16sp</item> </style> + <style name="InspectorHeaderTitle" parent="@style/TextAppearance.MaterialComponents.Headline6"> + <item name="android:textColor">?android:attr/textColorSecondary</item> + </style> + + <style name="InspectorKeySubTitle" parent="@style/TextAppearance.MaterialComponents.Subtitle1"> + <item name="android:textColor">?android:attr/textColorSecondary</item> + </style> + <style name="DrawerMenuPrimary" parent="android:style/TextAppearance.Material.Body2"> <item name="android:textColor">@color/item_root_primary_text</item> </style> diff --git a/res/values/themes.xml b/res/values/themes.xml index 1b8926eb7..4afbcdd8f 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -22,12 +22,14 @@ <item name="actionModeStyle">@style/ActionModeStyle</item> <item name="snackbarButtonStyle">@style/SnackbarButtonStyle</item> - <item name="android:windowBackground">@android:color/white</item> + <item name="android:windowBackground">?android:attr/colorPrimary</item> <item name="android:colorPrimaryDark">@color/g_grey</item> <item name="android:colorPrimary">@android:color/white</item> <item name="android:colorSecondary">@android:color/white</item> - <item name="android:colorBackground">@android:color/white</item> + <item name="android:colorAccent">@color/accent</item> + <item name="android:colorBackground">?android:attr/colorPrimary</item> <item name="android:windowLightStatusBar">true</item> + <item name="android:windowLightNavigationBar">true</item> <item name="android:queryBackground">@color/menu_search_background</item> <item name="android:listDivider">@drawable/list_divider</item> <item name="android:windowActionBar">false</item> @@ -37,8 +39,17 @@ <item name="android:actionModeBackground">?android:attr/colorBackground</item> <item name="android:actionModeCloseDrawable">@drawable/ic_action_clear</item> <item name="android:statusBarColor">?android:attr/colorPrimary</item> + <item name="android:navigationBarColor">?android:attr/colorPrimary</item> + + <item name="colorControlHighlight">@android:color/white</item> + <item name="materialCardViewStyle">@style/CardViewStyle</item> <item name="textHandleColor">@color/text_handle</item> <item name="textCursorColor">@color/text_cursor</item> + + <item name="gridItemTint">@color/item_doc_grid_tint</item> + <item name="gridItemColor">@color/item_doc_background</item> + <item name="gridItemSelectedColor">@color/item_doc_background_selected</item> + <item name="gridItemDisableColor">@color/item_doc_background_disabled</item> </style> </resources>
\ No newline at end of file diff --git a/src/com/android/documentsui/GridItemThumbnail.java b/src/com/android/documentsui/GridItemThumbnail.java index 38d6d725c..6348148fd 100644 --- a/src/com/android/documentsui/GridItemThumbnail.java +++ b/src/com/android/documentsui/GridItemThumbnail.java @@ -17,6 +17,8 @@ package com.android.documentsui; import android.content.Context; +import android.content.res.ColorStateList; +import android.content.res.TypedArray; import android.util.AttributeSet; import android.widget.ImageView; @@ -34,6 +36,10 @@ public class GridItemThumbnail extends ImageView { public GridItemThumbnail(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + TypedArray ta = context.obtainStyledAttributes(R.styleable.GridItem); + ColorStateList color = ta.getColorStateList(R.styleable.GridItem_gridItemTint); + ta.recycle(); + setImageTintList(color); } @Override diff --git a/src/com/android/documentsui/dirlist/DirectoryItemAnimator.java b/src/com/android/documentsui/dirlist/DirectoryItemAnimator.java index f568f3487..14b448a8d 100644 --- a/src/com/android/documentsui/dirlist/DirectoryItemAnimator.java +++ b/src/com/android/documentsui/dirlist/DirectoryItemAnimator.java @@ -23,6 +23,8 @@ import android.content.Context; import androidx.collection.ArrayMap; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.RecyclerView; + +import android.content.res.TypedArray; import android.util.TypedValue; import com.android.documentsui.R; @@ -45,8 +47,12 @@ class DirectoryItemAnimator extends DefaultItemAnimator { private final Integer mSelectedColor; public DirectoryItemAnimator(Context context) { - mDefaultColor = context.getResources().getColor(R.color.item_doc_background); - mSelectedColor = context.getResources().getColor(R.color.item_doc_background_selected); + TypedArray ta = context.obtainStyledAttributes(R.styleable.GridItem); + mSelectedColor = ta.getColor(R.styleable.GridItem_gridItemSelectedColor + , R.color.item_doc_background_selected); + mDefaultColor = ta.getColor(R.styleable.GridItem_gridItemColor + , R.color.item_doc_background); + ta.recycle(); } @Override diff --git a/src/com/android/documentsui/dirlist/GridDocumentHolder.java b/src/com/android/documentsui/dirlist/GridDocumentHolder.java index 3c36d90a2..7d99ed6cb 100644 --- a/src/com/android/documentsui/dirlist/GridDocumentHolder.java +++ b/src/com/android/documentsui/dirlist/GridDocumentHolder.java @@ -21,6 +21,7 @@ import static com.android.documentsui.base.DocumentInfo.getCursorString; import androidx.annotation.ColorInt; import android.content.Context; +import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.Rect; import android.provider.DocumentsContract.Document; @@ -48,17 +49,12 @@ final class GridDocumentHolder extends DocumentHolder { final IconHelper mIconHelper; final View mIconLayout; - private final @ColorInt int mDisabledBgColor; - private final @ColorInt int mDefaultBgColor; // This is used in as a convenience in our bind method. private final DocumentInfo mDoc = new DocumentInfo(); public GridDocumentHolder(Context context, ViewGroup parent, IconHelper iconHelper) { super(context, parent, R.layout.item_doc_grid); - mDisabledBgColor = context.getColor(R.color.item_doc_background_disabled); - mDefaultBgColor = context.getColor(R.color.item_doc_background); - mIconLayout = itemView.findViewById(R.id.icon); mTitle = (TextView) itemView.findViewById(android.R.id.title); mDate = (TextView) itemView.findViewById(R.id.date); @@ -103,8 +99,6 @@ final class GridDocumentHolder extends DocumentHolder { public void setEnabled(boolean enabled) { super.setEnabled(enabled); - // Text colors enabled/disabled is handle via a color set. - itemView.setBackgroundColor(enabled ? mDefaultBgColor : mDisabledBgColor); float imgAlpha = enabled ? 1f : DISABLED_ALPHA; mIconMimeLg.setAlpha(imgAlpha); diff --git a/src/com/android/documentsui/inspector/DebugView.java b/src/com/android/documentsui/inspector/DebugView.java index b4c00bb82..a781ec5de 100644 --- a/src/com/android/documentsui/inspector/DebugView.java +++ b/src/com/android/documentsui/inspector/DebugView.java @@ -64,7 +64,8 @@ public class DebugView extends TableView implements DebugDisplay { void init(Lookup<String, Executor> executors) { assert executors != null; - setBackgroundColor(0xFFFFFFFF); // it's just debug. We do what we want! + // it's just debug. We do what we want! + setBackgroundColor(getResources().getColor(R.color.inspector_debug_mode_color)); mExecutors = executors; } diff --git a/src/com/android/documentsui/inspector/KeyValueRow.java b/src/com/android/documentsui/inspector/KeyValueRow.java index 7fbd5a440..b6a163736 100644 --- a/src/com/android/documentsui/inspector/KeyValueRow.java +++ b/src/com/android/documentsui/inspector/KeyValueRow.java @@ -19,6 +19,7 @@ import androidx.annotation.StringRes; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Paint; import androidx.annotation.Nullable; import android.text.Selection; @@ -90,7 +91,11 @@ public class KeyValueRow extends LinearLayout { public void setOnClickListener(OnClickListener callback) { TextView clickable = ((TextView) findViewById(R.id.table_row_value)); mDefaultTextColor = clickable.getTextColors(); - clickable.setTextColor(R.color.inspector_link); + TypedArray ta = getContext().obtainStyledAttributes(R.styleable.TextAppearance); + int linkColor = ta.getColor(R.styleable.TextAppearance_android_textColorLink, + mDefaultTextColor.getDefaultColor()); + ta.recycle(); + clickable.setTextColor(linkColor); clickable.setPaintFlags(clickable.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); clickable.setOnClickListener(callback); } diff --git a/tests/Android.mk b/tests/Android.mk index 143e6857d..4ff0c8a91 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -17,7 +17,10 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ mockito-target \ ub-uiautomator \ espresso-core \ - guava + guava \ + truth-prebuilt \ + android-support-test + LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt LOCAL_PACKAGE_NAME := DocumentsUITests LOCAL_PRIVATE_PLATFORM_APIS := true diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index 1b6dfba77..082dad68d 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -3,6 +3,7 @@ package="com.android.documentsui.tests"> <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.MODIFY_DAY_NIGHT_MODE" /> <application android:label="DocumentsUI Tests"> <uses-library android:name="android.test.runner" /> diff --git a/tests/functional/com/android/documentsui/ActivityTest.java b/tests/functional/com/android/documentsui/ActivityTest.java index 262ea33ca..a2f48b165 100644 --- a/tests/functional/com/android/documentsui/ActivityTest.java +++ b/tests/functional/com/android/documentsui/ActivityTest.java @@ -18,10 +18,12 @@ package com.android.documentsui; import android.app.Activity; import android.app.UiAutomation; +import android.app.UiModeManager; import android.content.ContentProviderClient; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.res.Configuration; import android.os.Bundle; import android.os.RemoteException; import android.provider.DocumentsContract; @@ -48,6 +50,7 @@ import javax.annotation.Nullable; public abstract class ActivityTest<T extends Activity> extends ActivityInstrumentationTestCase2<T> { static final int TIMEOUT = 5000; + static final int NIGHT_MODE_CHANGE_WAIT_TIME = 1000; // Testing files. For custom ones, override initTestFiles(). public static final String dirName1 = "Dir1"; @@ -69,6 +72,7 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen protected ContentResolver mResolver; protected DocumentsProviderHelper mDocsHelper; protected ContentProviderClient mClient; + protected UiModeManager mUiModeManager; public ActivityTest(Class<T> activityClass) { super(activityClass); @@ -181,4 +185,24 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen bots.directory.waitForDocument(fileName4); bots.directory.assertDocumentsCount(2); } + + /** + * Setup test Activity UI Mode YES or not(AUTO/YES/NO) before start to testing + * @param uiModeNight Constant for {@link #setNightMode(int)} + * 0 - MODE_NIGHT_AUTO + * 1 - MODE_NIGHT_NO + * 2 - MODE_NIGHT_YES + */ + protected void setSystemUiModeNight(int uiModeNight) { + int systemUiMode = getActivity().getResources().getConfiguration().uiMode + & Configuration.UI_MODE_NIGHT_MASK; + if(uiModeNight != systemUiMode) { + /* TODO since ag/4947691 enable config_lockDayNightMode to block app setNightMode() + create b/115315612 to handle the UiModeManager permission deny problem */ + mUiModeManager = (UiModeManager) getActivity() + .getSystemService(Context.UI_MODE_SERVICE); + mUiModeManager.setNightMode(uiModeNight); + device.waitForIdle(NIGHT_MODE_CHANGE_WAIT_TIME); + } + } } diff --git a/tests/unit/com/android/documentsui/dirlist/ThemeUiTest.java b/tests/unit/com/android/documentsui/dirlist/ThemeUiTest.java new file mode 100644 index 000000000..00cf76ca9 --- /dev/null +++ b/tests/unit/com/android/documentsui/dirlist/ThemeUiTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2018 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.documentsui.dirlist; + +import android.app.UiModeManager; +import android.content.res.TypedArray; +import android.graphics.Color; + +import android.support.test.filters.SmallTest; + +import com.android.documentsui.ActivityTest; +import com.android.documentsui.R; +import com.android.documentsui.files.FilesActivity; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** +* This class test default Light Theme (Night Mode Disable) +* Verify ActionBar background, Window background, and GridItem background to meet Light style +*/ +@SmallTest +public class ThemeUiTest extends ActivityTest<FilesActivity> { + public ThemeUiTest() { + super(FilesActivity.class); + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + setSystemUiModeNight(UiModeManager.MODE_NIGHT_NO); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + setSystemUiModeNight(UiModeManager.MODE_NIGHT_NO); + } + + @Test + public void testThemeNightModeEnable_actionBarColor() { + TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.ActionBarView); + int actionBarBackground = ta.getColor(R.styleable.ActionBarView_android_colorPrimary, + Color.RED); + ta.recycle(); + assertEquals(getActivity().getColor(android.R.color.white), actionBarBackground); + } + + @Test + public void testThemeNightModeEnable_gridItemBackgroundColor() { + TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.GridItem); + int gridItemColor = ta.getColor(R.styleable.GridItem_gridItemColor, Color.RED); + ta.recycle(); + assertEquals(getActivity().getColor(R.color.item_doc_background), gridItemColor); + } + + @Test + public void testThemeNightModeEnable_lightNavigationBar() { + TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow); + boolean isLightNavigationBar = ta.getBoolean( + R.styleable.SystemWindow_android_windowLightNavigationBar, false); + ta.recycle(); + assertTrue(isLightNavigationBar); + } + + @Test + public void testThemeNightModeEnable_lightStatusBar() { + TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow); + boolean isLightStatusBar = ta.getBoolean( + R.styleable.SystemWindow_android_windowLightNavigationBar, false); + ta.recycle(); + assertTrue(isLightStatusBar); + } + + @Test + public void testThemeNightModeEnable_navigationBarColor() { + TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow); + int navigationBarColor = ta.getColor(R.styleable.SystemWindow_android_navigationBarColor, + Color.RED); + ta.recycle(); + assertEquals(getActivity().getColor(android.R.color.white), navigationBarColor); + } + + @Test + public void testThemeNightModeEnable_windowBackgroundColor() { + TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow); + int windowBackground = ta.getColor( + R.styleable.SystemWindow_android_windowBackground, Color.RED); + ta.recycle(); + assertEquals(getActivity().getColor(android.R.color.white), windowBackground); + } + + @Test + public void testThemeNightModeEnable_statusBarColor() { + TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.SystemWindow); + int statusBarColor = ta.getColor(R.styleable.SystemWindow_android_statusBarColor, + Color.RED); + ta.recycle(); + assertEquals(getActivity().getColor(android.R.color.white), statusBarColor); + } +} |