Update the static wallpaper Preview screen
am: 25b7b27c8e
Change-Id: I59b742dd620e041eee62990fd85075f31340a18b
diff --git a/res/drawable/btn_transparent.xml b/res/drawable/btn_transparent.xml
new file mode 100644
index 0000000..b8e0d1e
--- /dev/null
+++ b/res/drawable/btn_transparent.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Copyright (C) 2019 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/btn_transparent_background"
+ android:insetBottom="5dp"
+ android:insetTop="5dp"/>
\ No newline at end of file
diff --git a/res/drawable/btn_transparent_background.xml b/res/drawable/btn_transparent_background.xml
new file mode 100644
index 0000000..9eb3bfc
--- /dev/null
+++ b/res/drawable/btn_transparent_background.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Copyright (C) 2019 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.
+-->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <shape android:shape="rectangle">
+ <stroke android:width="1dp" android:color="@android:color/white"/>
+ <corners android:radius="?android:attr/buttonCornerRadius"/>
+ </shape>
+ </item>
+ <item android:drawable="?selectableItemBackground"/>
+</layer-list>
\ No newline at end of file
diff --git a/res/drawable/preview_bottom_sheet_background.xml b/res/drawable/preview_bottom_sheet_background.xml
new file mode 100644
index 0000000..847cbf3
--- /dev/null
+++ b/res/drawable/preview_bottom_sheet_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Copyright (C) 2019 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.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="@color/translucent_black"/>
+ <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" android:topLeftRadius="@dimen/preview_bottom_sheet_corner_radius" android:topRightRadius="@dimen/preview_bottom_sheet_corner_radius"/>
+</shape>
\ No newline at end of file
diff --git a/res/layout/fragment_preview.xml b/res/layout/fragment_preview.xml
index a861213..82c481f 100755
--- a/res/layout/fragment_preview.xml
+++ b/res/layout/fragment_preview.xml
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fitsSystemWindows="false">
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:fitsSystemWindows="false">
<ImageView
android:id="@+id/low_res_image"
@@ -30,107 +31,19 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">
- <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
+ <androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:id="@+id/bottom_sheet"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom"
- android:minHeight="@dimen/preview_attribution_pane_expanded_height"
- android:orientation="vertical"
- android:background="@color/translucent_black"
- app:behavior_peekHeight="@dimen/preview_attribution_pane_collapsed_height"
- app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
-
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="@dimen/preview_attribution_pane_content_side_margin"
- android:layout_marginRight="@dimen/preview_attribution_pane_content_side_margin"
- android:layout_marginBottom="@dimen/preview_attribution_pane_content_bottom_margin">
-
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView
- android:id="@+id/preview_attribution_pane_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="top|start"
- android:layout_marginRight="@dimen/preview_attribution_pane_title_end_margin"
- android:layout_marginEnd="@dimen/preview_attribution_pane_title_end_margin"
- android:layout_marginTop="@dimen/preview_attribution_pane_title_top_margin"
- style="@style/preview_attribution_pane_title"/>
-
- <ImageView
- android:id="@+id/preview_attribution_pane_arrow"
- android:contentDescription="@string/expand_attribution_panel"
- android:layout_gravity="top|end"
- android:layout_width="@dimen/preview_attribution_pane_arrow_size"
- android:layout_height="@dimen/preview_attribution_pane_arrow_size"
- android:layout_marginLeft="@dimen/preview_attribution_pane_arrow_start_margin"
- android:layout_marginStart="@dimen/preview_attribution_pane_arrow_start_margin"
- android:layout_marginTop="@dimen/preview_attribution_pane_arrow_top_bottom_margin"
- android:layout_marginBottom="@dimen/preview_attribution_pane_arrow_top_bottom_margin"
- android:scaleType="center"
- android:focusable="true"
- android:clickable="true"
- android:src="@drawable/material_ic_keyboard_arrow_up_black_24"
- style="?attr/borderlessButtonStyle"/>
-
- </FrameLayout>
-
- <TextView
- android:id="@+id/preview_attribution_pane_subtitle1"
+ <include
+ layout="@layout/preview_page_info"
+ android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/preview_attribution_pane_subtitle1_top_margin"
- android:visibility="gone"
- style="@style/preview_attribution_pane_subtitle"/>
-
- <TextView
- android:id="@+id/preview_attribution_pane_subtitle2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:visibility="gone"
- android:textColor="@color/white_70_alpha"
- android:textSize="@dimen/abc_text_size_caption_material"
- android:layout_marginTop="@dimen/preview_attribution_pane_subtitle2_top_margin"/>
-
- </LinearLayout>
-
- <FrameLayout
- android:id="@+id/preview_attribution_pane_explore_section"
- android:layout_width="match_parent"
- android:layout_height="@dimen/preview_attribution_pane_explore_height"
- android:layout_marginBottom="@dimen/preview_attribution_pane_explore_bottom_margin"
- android:visibility="gone">
-
- <Button
- android:id="@+id/preview_attribution_pane_explore_button"
- android:drawablePadding="@dimen/explore_button_drawable_padding"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="@color/accent_color"
- android:text="@string/explore"
- android:layout_marginLeft="@dimen/preview_attribution_pane_explore_left_margin"
- android:layout_marginStart="@dimen/preview_attribution_pane_explore_left_margin"
- android:layout_gravity="center_vertical"
- style="?attr/borderlessButtonStyle"/>
-
- </FrameLayout>
-
- </LinearLayout>
+ app:behavior_peekHeight="@dimen/preview_attribution_pane_collapsed_height"
+ app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/res/layout/preview_action.xml b/res/layout/preview_action.xml
new file mode 100644
index 0000000..9f5cc6d
--- /dev/null
+++ b/res/layout/preview_action.xml
@@ -0,0 +1,25 @@
+<!-- Copyright (C) 2019 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.
+-->
+
+<CheckBox
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/ActionBarCheckboxStyle"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:background="?android:attr/selectableItemBackgroundBorderless"
+ android:text="@string/preview"
+ android:textAllCaps="false"
+ android:textAppearance="?android:attr/actionMenuTextAppearance"
+ android:theme="@style/PreviewCheckboxDeviceTheme"/>
\ No newline at end of file
diff --git a/res/layout/preview_page_info.xml b/res/layout/preview_page_info.xml
new file mode 100644
index 0000000..587e120
--- /dev/null
+++ b/res/layout/preview_page_info.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Copyright (C) 2019 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/page_info"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:orientation="vertical"
+ android:paddingHorizontal="@dimen/preview_attribution_pane_horizontal_padding"
+ android:background="@drawable/preview_bottom_sheet_background"
+ android:theme="@android:style/Theme.DeviceDefault.Settings">
+
+ <Space
+ android:id="@+id/preview_attribution_pane_title_spacer"
+ android:layout_width="0dp"
+ android:layout_height="@dimen/preview_attribution_pane_inner_spacer_height"/>
+
+ <TextView
+ android:id="@+id/preview_attribution_pane_title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="@dimen/preview_attribution_pane_title_height"
+ android:ellipsize="end"
+ android:forceHasOverlappingRendering="false"
+ android:gravity="center"
+ android:singleLine="true"
+ android:textAppearance="@style/HeaderTextAppearance"
+ android:textColor="@color/material_white_100"/>
+
+ <TextView
+ android:id="@+id/preview_attribution_pane_subtitle1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="@dimen/preview_attribution_pane_author_height"
+ android:layout_marginTop="@dimen/preview_attribution_pane_author_top_margin"
+ android:forceHasOverlappingRendering="false"
+ android:gravity="center"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Subhead"
+ android:textColor="@color/material_white_100"
+ android:visibility="gone"/>
+
+ <TextView
+ android:id="@+id/preview_attribution_pane_subtitle2"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="@dimen/preview_attribution_pane_description_height"
+ android:forceHasOverlappingRendering="false"
+ android:gravity="center_horizontal"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Caption"
+ android:textColor="@color/material_white_100"
+ android:visibility="gone"/>
+
+ <Space
+ android:id="@+id/preview_attribution_pane_spacer"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_marginTop="@dimen/preview_attribution_pane_inner_spacer_height"
+ android:layout_weight="1"/>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="@dimen/preview_attribution_pane_button_bottom_margin"
+ android:gravity="center"
+ android:orientation="horizontal">
+
+ <Button
+ style="@style/OutlinedButtonStyle"
+ android:id="@+id/preview_attribution_pane_explore_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/explore"
+ android:visibility="gone"/>
+
+ <Space
+ android:id="@+id/spacer"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:visibility="gone"/>
+
+ <Button
+ style="@style/ButtonStyle"
+ android:id="@+id/preview_attribution_pane_set_wallpaper_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/set_wallpaper_button_text"
+ android:visibility="gone"/>
+
+ </LinearLayout>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/menu/preview_menu.xml b/res/menu/preview_menu.xml
index d35a16d..7c9d610 100755
--- a/res/menu/preview_menu.xml
+++ b/res/menu/preview_menu.xml
@@ -15,9 +15,9 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
- <item
- android:id="@+id/set_wallpaper"
- android:actionLayout="@layout/set_wallpaper_action"
- android:title="@string/set_wallpaper_button_text"
- app:showAsAction="always|withText" />
+ <item android:id="@+id/preview"
+ android:checkable="true"
+ app:actionLayout="@layout/preview_action"
+ app:showAsAction="always|withText"
+ android:title="@string/preview"/>
</menu>
diff --git a/res/values-notnight-v26/picker_colors.xml b/res/values-notnight-v26/picker_colors.xml
index c8c8424..a21500f 100755
--- a/res/values-notnight-v26/picker_colors.xml
+++ b/res/values-notnight-v26/picker_colors.xml
@@ -50,4 +50,6 @@
<color name="individual_tile_title_text_color">@color/textColorPrimary</color>
<color name="individual_picker_background_color">@color/material_white_100</color>
+
+ <color name="toolbar_icon_color">@color/text_color_dark</color>
</resources>
diff --git a/res/values-notnight-v26/styles.xml b/res/values-notnight-v26/styles.xml
index ae7f7dd..3ca6dcf 100755
--- a/res/values-notnight-v26/styles.xml
+++ b/res/values-notnight-v26/styles.xml
@@ -22,9 +22,7 @@
<item name="android:windowLightStatusBar">true</item>
</style>
- <style name="RegularToolbarStyle" parent="@style/Widget.AppCompat.Toolbar">
- <item name="android:background">@color/primary_color</item>
+ <style name="RegularToolbarStyle" parent="@android:style/Widget.DeviceDefault.Light.ActionBar.Solid">
<item name="android:theme">@style/WallpaperTheme</item>
- <item name="titleTextColor">@color/accent_color</item>
</style>
</resources>
diff --git a/res/values-notnight-v27/styles.xml b/res/values-notnight-v27/styles.xml
index 7c104f7..4de0e9f 100755
--- a/res/values-notnight-v27/styles.xml
+++ b/res/values-notnight-v27/styles.xml
@@ -17,7 +17,7 @@
<style name="WallpaperTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="colorControlActivated">?attr/colorPrimary</item>
- <item name="colorControlNormal">?attr/colorAccent</item>
+ <item name="colorControlNormal">?android:attr/colorPrimary</item>
<item name="android:statusBarColor">?attr/colorPrimary</item>
<item name="android:windowLightStatusBar">true</item>
diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml
index 3289d1b..ece1ff7 100755
--- a/res/values-sw720dp/dimens.xml
+++ b/res/values-sw720dp/dimens.xml
@@ -38,8 +38,7 @@
<!-- Dimensions for the preview attribution pane. -->
- <!-- 48dp + 2 * 8dp margin -->
- <dimen name="preview_attribution_pane_collapsed_height">64dp</dimen>
+ <dimen name="preview_attribution_pane_collapsed_height">0dp</dimen>
<dimen name="preview_attribution_pane_content_side_margin">24dp</dimen>
<dimen name="preview_attribution_pane_explore_left_margin">10dp</dimen>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index d7a149b..5c7a4a9 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -102,8 +102,7 @@
<dimen name="preview_toolbar_up_button_start_padding">0dp</dimen>
<dimen name="preview_toolbar_set_wallpaper_button_end_padding">12dp</dimen>
- <!-- 48dp + 2 * 1dp margin -->
- <dimen name="preview_attribution_pane_collapsed_height">50dp</dimen>
+ <dimen name="preview_attribution_pane_collapsed_height">0dp</dimen>
<dimen name="preview_attribution_pane_expanded_height">96dp</dimen>
<dimen name="preview_attribution_pane_content_side_margin">16dp</dimen>
@@ -118,6 +117,15 @@
<dimen name="preview_attribution_pane_explore_height">48dp</dimen>
<dimen name="preview_attribution_pane_explore_left_margin">2dp</dimen>
<dimen name="preview_attribution_pane_explore_bottom_margin">16dp</dimen>
+ <dimen name="preview_attribution_pane_horizontal_padding">24dp</dimen>
+ <dimen name="preview_attribution_pane_extra_spacer_height">16dp</dimen>
+ <dimen name="preview_attribution_pane_inner_spacer_height">14dp</dimen>
+ <dimen name="preview_attribution_pane_title_height">48dp</dimen>
+ <dimen name="preview_attribution_pane_author_height">24dp</dimen>
+ <dimen name="preview_attribution_pane_author_top_margin">0dp</dimen>
+ <dimen name="preview_attribution_pane_description_height">34dp</dimen>
+ <dimen name="preview_attribution_pane_button_bottom_margin">8dp</dimen>
+
<!-- Dimensions for the "start rotation" dialog. -->
<dimen name="start_rotation_dialog_subhead_margin_top">19dp</dimen>
@@ -168,5 +176,6 @@
<!-- Dimensions for the "disabled by admin" UI in desktop mode. -->
<dimen name="disabled_by_admin_desktop_message_text_size">13sp</dimen>
+ <dimen name="preview_bottom_sheet_corner_radius">?android:attr/dialogCornerRadius</dimen>
</resources>
diff --git a/res/values/picker_colors.xml b/res/values/picker_colors.xml
index f6c85c5..3f6b6af 100755
--- a/res/values/picker_colors.xml
+++ b/res/values/picker_colors.xml
@@ -70,4 +70,6 @@
<color name="individual_picker_background_color">@color/translucent_black</color>
<color name="preview_pane_arrow_color">@color/material_white_100</color>
+
+ <color name="toolbar_icon_color">@color/material_white_text</color>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 83bea72..fe99050 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -297,4 +297,7 @@
<string name="third_party_app_wallpaper_collection_id" translatable="false">
third_party_app_wallpapers
</string>
+
+ <!-- Label for a checkbox which lets user preview the displayed image as wallpaper. [CHAR LIMIT=30] -->
+ <string name="preview">Preview</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 0c66ab1..511f0fb 100755
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -27,6 +27,8 @@
<!-- Set no title and no action bar because we use a toolbar instead. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
+ <item name="android:windowActionBar">false</item>
+ <item name="android:windowNoTitle">true</item>
<!-- Set status bar and navigation buttons to be translucent. -->
<item name="android:colorPrimaryDark">@color/translucent_black</item>
@@ -42,7 +44,7 @@
</style>
<style name="TranslucentToolbarStyle" parent="@style/Widget.AppCompat.Toolbar">
- <item name="android:background">@color/translucent_black</item>
+ <item name="android:background">@android:color/transparent</item>
<item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
@@ -106,4 +108,21 @@
<style name="HeaderTextAppearance" parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title">
<item name="android:textFontWeight">400</item>
</style>
+
+ <style name="ButtonStyle" parent="@android:style/Widget.DeviceDefault.Button.Colored">
+ <item name="android:padding">16dp</item>
+ <item name="android:minHeight">48dp</item>
+ </style>
+
+ <style name="OutlinedButtonStyle" parent="@android:style/Widget.DeviceDefault.Button">
+ <item name="android:background">@drawable/btn_transparent</item>
+ <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
+ <item name="android:textColor">@android:color/white</item>
+ </style>
+
+ <style name="ActionBarCheckboxStyle" parent="@android:style/Widget.DeviceDefault.CompoundButton.CheckBox"/>
+
+ <style name="PreviewCheckboxDeviceTheme" parent="@android:style/Theme.DeviceDefault">
+ <item name="android:colorControlActivated">@*android:color/accent_device_default_light</item>
+ </style>
</resources>
diff --git a/src/com/android/wallpaper/picker/PreviewFragment.java b/src/com/android/wallpaper/picker/PreviewFragment.java
index 0ba9412..dc05fa5 100755
--- a/src/com/android/wallpaper/picker/PreviewFragment.java
+++ b/src/com/android/wallpaper/picker/PreviewFragment.java
@@ -24,6 +24,7 @@
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources.NotFoundException;
+import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Color;
@@ -32,12 +33,11 @@
import android.graphics.PorterDuff.Mode;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
-import android.os.Build;
-import android.os.Build.VERSION;
-import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.util.Log;
+import android.view.ContextThemeWrapper;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -45,11 +45,10 @@
import android.view.MenuItem;
import android.view.Surface;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
-import android.widget.FrameLayout;
+import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -68,8 +67,6 @@
import com.android.wallpaper.asset.Asset.BitmapReceiver;
import com.android.wallpaper.asset.Asset.DimensionsReceiver;
import com.android.wallpaper.compat.BuildCompat;
-import com.android.wallpaper.compat.ButtonDrawableSetterCompat;
-import com.android.wallpaper.config.Flags;
import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.ExploreIntentChecker;
import com.android.wallpaper.module.Injector;
@@ -154,9 +151,7 @@
private TextView mAttributionTitle;
private TextView mAttributionSubtitle1;
private TextView mAttributionSubtitle2;
- private FrameLayout mAttributionExploreSection;
private Button mAttributionExploreButton;
- private ImageView mPreviewPaneArrow;
private int mCurrentScreenOrientation;
private Point mDefaultCropSurfaceSize;
private Point mScreenSize;
@@ -164,6 +159,9 @@
private ImageView mLoadingIndicator;
private MaterialProgressDrawable mProgressDrawable;
private ImageView mLowResImageView;
+ private Button mSetWallpaperButton;
+ private View mSpacer;
+ private CheckBox mPreview;
@SuppressWarnings("RestrictTo")
@State
@@ -194,6 +192,13 @@
return fragment;
}
+ private static int getAttrColor(Context context, int attr) {
+ TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
+ int colorAccent = ta.getColor(0, 0);
+ ta.recycle();
+ return colorAccent;
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -233,10 +238,11 @@
View view = inflater.inflate(R.layout.fragment_preview, container, false);
// Set toolbar as the action bar.
- Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
- ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
- ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
+ Toolbar toolbar = view.findViewById(R.id.toolbar);
+ AppCompatActivity activity = (AppCompatActivity) getActivity();
+ activity.setSupportActionBar(toolbar);
+ activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
// Use updated fancy arrow icon for O+.
if (BuildCompat.isAtLeastO()) {
@@ -267,15 +273,22 @@
mAttributionTitle = view.findViewById(R.id.preview_attribution_pane_title);
mAttributionSubtitle1 = view.findViewById(R.id.preview_attribution_pane_subtitle1);
mAttributionSubtitle2 = view.findViewById(R.id.preview_attribution_pane_subtitle2);
- mAttributionExploreSection = view.findViewById(
- R.id.preview_attribution_pane_explore_section);
mAttributionExploreButton = view.findViewById(
R.id.preview_attribution_pane_explore_button);
- mPreviewPaneArrow = view.findViewById(R.id.preview_attribution_pane_arrow);
mLowResImageView = view.findViewById(R.id.low_res_image);
+ mSetWallpaperButton = view.findViewById(R.id.preview_attribution_pane_set_wallpaper_button);
+ mSpacer = view.findViewById(R.id.spacer);
- mPreviewPaneArrow.setColorFilter(
- getResources().getColor(R.color.preview_pane_arrow_color), Mode.SRC_IN);
+ // Workaround as we don't have access to bottomDialogCornerRadius, mBottomSheet radii are
+ // set to dialogCornerRadius by default.
+ GradientDrawable bottomSheetBackground = (GradientDrawable) mBottomSheet.getBackground();
+ float[] radii = bottomSheetBackground.getCornerRadii();
+ for (int i = 0; i < radii.length; i++) {
+ radii[i]*=2f;
+ }
+ bottomSheetBackground = ((GradientDrawable)bottomSheetBackground.mutate());
+ bottomSheetBackground.setCornerRadii(radii);
+ mBottomSheet.setBackground(bottomSheetBackground);
// Trim some memory from Glide to make room for the full-size image in this fragment.
Glide.get(getActivity()).setMemoryCategory(MemoryCategory.LOW);
@@ -289,7 +302,8 @@
// shown to the user more quickly than the full-sized image.
if (mWallpaperAsset.hasLowResDataSource()) {
mWallpaperAsset.loadLowResDrawable(getActivity(), mLowResImageView, Color.BLACK,
- new WallpaperPreviewBitmapTransformation(getActivity().getApplicationContext(), isRtl()));
+ new WallpaperPreviewBitmapTransformation(getActivity().getApplicationContext(),
+ isRtl()));
}
mWallpaperAsset.decodeRawDimensions(getActivity(), new DimensionsReceiver() {
@@ -332,23 +346,23 @@
mProgressDrawable =
new MaterialProgressDrawable(getActivity().getApplicationContext(), mLoadingIndicator);
mProgressDrawable.setAlpha(255);
- mProgressDrawable.setBackgroundColor(getResources().getColor(R.color.material_white_100));
- mProgressDrawable.setColorSchemeColors(getResources().getColor(R.color.accent_color));
+ mProgressDrawable.setBackgroundColor(getResources().getColor(R.color.material_white_100,
+ getContext().getTheme()));
+ mProgressDrawable.setColorSchemeColors(getAttrColor(
+ new ContextThemeWrapper(getContext(), getDeviceDefaultTheme()),
+ android.R.attr.colorAccent));
mProgressDrawable.updateSizes(MaterialProgressDrawable.LARGE);
mLoadingIndicator.setImageDrawable(mProgressDrawable);
// We don't want to show the spinner every time we load an image if it loads quickly; instead,
// only start showing the spinner if loading the image has taken longer than half of a second.
- mLoadingIndicator.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (mFullResImageView != null && !mFullResImageView.hasImage()
- && !mTestingModeEnabled) {
- mLoadingIndicator.setVisibility(View.VISIBLE);
- mLoadingIndicator.setAlpha(1f);
- if (mProgressDrawable != null) {
- mProgressDrawable.start();
- }
+ mLoadingIndicator.postDelayed(() -> {
+ if (mFullResImageView != null && !mFullResImageView.hasImage()
+ && !mTestingModeEnabled) {
+ mLoadingIndicator.setVisibility(View.VISIBLE);
+ mLoadingIndicator.setAlpha(1f);
+ if (mProgressDrawable != null) {
+ mProgressDrawable.start();
}
}
}, 500);
@@ -363,6 +377,16 @@
return view;
}
+ protected int getDeviceDefaultTheme() {
+ return BuildCompat.isAtLeastQ() ? getDayNightDeviceDefault()
+ : android.R.style.Theme_DeviceDefault;
+ }
+
+ @TargetApi(29)
+ private int getDayNightDeviceDefault() {
+ return R.style.Theme_AppCompat_DayNight;
+ }
+
@Override
public void onResume() {
super.onResume();
@@ -389,32 +413,13 @@
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.preview_menu, menu);
- }
-
- @Override
- public void onPrepareOptionsMenu(Menu menu) {
- super.onPrepareOptionsMenu(menu);
- MenuItem setWallpaperButton = menu.findItem(R.id.set_wallpaper);
-
- if (mPreviewMode == MODE_CROP_AND_SET_WALLPAPER && isWallpaperLoaded()) {
- setWallpaperButton.setVisible(true);
- } else {
- setWallpaperButton.setVisible(false);
- }
+ setupPreviewMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
- if (id == R.id.set_wallpaper) {
- if (BuildCompat.isAtLeastN()) {
- mWallpaperSetter.requestDestination(getContext(), getFragmentManager(), mWallpaper,
- this);
- } else {
- setCurrentWallpaper(WallpaperPersister.DEST_HOME_SCREEN);
- }
- return true;
- } else if (id == android.R.id.home) {
+ if (id == android.R.id.home) {
// The Preview screen has multiple entry points. It could be opened from either
// the IndividualPreviewActivity, the "My photos" selection (by way of
// TopLevelPickerActivity), or from a system "crop and set wallpaper" intent.
@@ -426,6 +431,31 @@
return false;
}
+ protected void setupPreviewMenu(Menu menu) {
+ mPreview = (CheckBox) menu.findItem(R.id.preview).getActionView();
+ mPreview.setOnClickListener(this::setPreviewBehavior);
+ }
+
+ private void setPreviewChecked(boolean checked) {
+ if (mPreview != null) {
+ mPreview.setChecked(checked);
+ int resId = checked ? R.string.expand_attribution_panel
+ : R.string.collapse_attribution_panel;
+ mPreview.setContentDescription(getResources().getString(resId));
+ }
+ }
+
+ private void setPreviewBehavior(final View v) {
+ CheckBox checkbox = (CheckBox) v;
+ BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(mBottomSheet);
+
+ if (checkbox.isChecked()) {
+ behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
+ } else {
+ behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+ }
+ }
+
@Override
public void onSetHomeScreen() {
setCurrentWallpaper(WallpaperPersister.DEST_HOME_SCREEN);
@@ -472,18 +502,13 @@
outState.putInt(KEY_BOTTOM_SHEET_STATE, bottomSheetBehavior.getState());
}
- private void updatePreviewPaneArrow(int bottomSheetState) {
- if (bottomSheetState == BottomSheetBehavior.STATE_COLLAPSED) {
- mPreviewPaneArrow.setImageResource(R.drawable.material_ic_keyboard_arrow_up_black_24);
- mPreviewPaneArrow.setContentDescription(
- getResources().getString(R.string.expand_attribution_panel));
- } else if (bottomSheetState == BottomSheetBehavior.STATE_EXPANDED) {
- mPreviewPaneArrow.setImageResource(R.drawable.material_ic_keyboard_arrow_down_black_24);
- mPreviewPaneArrow.setContentDescription(
- getResources().getString(R.string.collapse_attribution_panel));
+ private void onSetWallpaperClicked(View button) {
+ if (BuildCompat.isAtLeastN()) {
+ mWallpaperSetter.requestDestination(getContext(), getFragmentManager(), mWallpaper,
+ this);
+ } else {
+ setCurrentWallpaper(WallpaperPersister.DEST_HOME_SCREEN);
}
- mPreviewPaneArrow.setColorFilter(
- getResources().getColor(R.color.preview_pane_arrow_color), Mode.SRC_IN);
}
/**
@@ -518,30 +543,23 @@
private void setUpBottomSheetListeners() {
final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(mBottomSheet);
- OnClickListener onClickListener = new OnClickListener() {
- @Override
- public void onClick(View view) {
- if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
- bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
- } else if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
- bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
- }
- }
- };
- mAttributionTitle.setOnClickListener(onClickListener);
- mPreviewPaneArrow.setOnClickListener(onClickListener);
-
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(View bottomSheet, int newState) {
- // Don't respond to lingering state change events occurring after the fragment has already
- // been detached from the activity. Else, IllegalStateException may occur when trying to
- // fetch resources.
+ // Don't respond to lingering state change events occurring after the fragment has
+ // already been detached from the activity. Else, IllegalStateException may occur
+ // when trying to fetch resources.
if (getActivity() == null) {
return;
}
-
- updatePreviewPaneArrow(newState);
+ switch (newState) {
+ case BottomSheetBehavior.STATE_COLLAPSED:
+ setPreviewChecked(true /* checked */);
+ break;
+ case BottomSheetBehavior.STATE_EXPANDED:
+ setPreviewChecked(false /* checked */);
+ break;
+ }
}
@Override
@@ -584,60 +602,57 @@
mAttributionSubtitle2.setText(attributions.get(2));
}
+ if (mPreviewMode == MODE_CROP_AND_SET_WALLPAPER) {
+ mSetWallpaperButton.setVisibility(View.VISIBLE);
+ mSetWallpaperButton.setOnClickListener(this::onSetWallpaperClicked);
+ } else {
+ mSetWallpaperButton.setVisibility(View.GONE);
+ }
+
String actionUrl = mWallpaper.getActionUrl(context);
+
+ mAttributionExploreButton.setVisibility(View.GONE);
if (actionUrl != null && !actionUrl.isEmpty()) {
if (mExploreIntent != null) {
- if (Flags.skipDailyWallpaperButtonEnabled) {
- Drawable exploreButtonDrawable = context.getDrawable(
- mWallpaper.getActionIconRes(context));
+ mAttributionExploreButton.setVisibility(View.VISIBLE);
+ mAttributionExploreButton.setText(context.getString(
+ mWallpaper.getActionLabelRes(context)));
- // This Drawable's state is shared across the app, so make a copy of it before applying a
- // color tint as not to affect other clients elsewhere in the app.
- exploreButtonDrawable = exploreButtonDrawable.getConstantState()
- .newDrawable().mutate();
- // Color the "compass" icon with the accent color.
- exploreButtonDrawable.setColorFilter(
- getResources().getColor(R.color.accent_color), Mode.SRC_IN);
- ButtonDrawableSetterCompat.setDrawableToButtonStart(
- mAttributionExploreButton, exploreButtonDrawable);
- mAttributionExploreButton.setText(context.getString(
- mWallpaper.getActionLabelRes(context)));
- }
+ mAttributionExploreButton.setOnClickListener(view -> {
+ mUserEventLogger.logActionClicked(mWallpaper.getCollectionId(context),
+ mWallpaper.getActionLabelRes(context));
- mAttributionExploreSection.setVisibility(View.VISIBLE);
- mAttributionExploreButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- mUserEventLogger.logActionClicked(mWallpaper.getCollectionId(context),
- mWallpaper.getActionLabelRes(context));
-
- startActivity(mExploreIntent);
- }
+ startActivity(mExploreIntent);
});
}
}
+ if (mAttributionExploreButton.getVisibility() == View.VISIBLE
+ && mSetWallpaperButton.getVisibility() == View.VISIBLE) {
+ mSpacer.setVisibility(View.VISIBLE);
+ } else {
+ mSpacer.setVisibility(View.GONE);
+ }
+
mBottomSheet.setVisibility(View.VISIBLE);
// Initialize the state of the BottomSheet based on the current state because if the initial
// and current state are the same, the state change listener won't fire and set the correct
// arrow asset and text alpha.
- if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
- updatePreviewPaneArrow(BottomSheetBehavior.STATE_EXPANDED);
- } else {
+ if (bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
mAttributionTitle.setAlpha(0f);
mAttributionSubtitle1.setAlpha(0f);
mAttributionSubtitle2.setAlpha(0f);
}
- // Let the state change listener take care of animating a state change to the initial state if
- // there's a state change.
+ // Let the state change listener take care of animating a state change to the initial state
+ // if there's a state change.
bottomSheetBehavior.setState(mBottomSheetInitialState);
}
/**
- * Initializes MosaicView by initializing tiling, setting a fallback page bitmap, and initializing
- * a zoom-scroll observer and click listener.
+ * Initializes MosaicView by initializing tiling, setting a fallback page bitmap, and
+ * initializing a zoom-scroll observer and click listener.
*/
private void initFullResView() {
mFullResImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
@@ -666,7 +681,8 @@
if (mLoadingIndicator != null) {
mLoadingIndicator.setVisibility(View.GONE);
}
- // The page bitmap may be null if there was a decoding error, so show an error dialog.
+ // The page bitmap may be null if there was a decoding error, so show an
+ // error dialog.
if (pageBitmap == null) {
showLoadWallpaperErrorDialog();
return;
@@ -693,7 +709,8 @@
* indicator.
*/
private void crossFadeInMosaicView() {
- long shortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
+ long shortAnimationDuration = getResources().getInteger(
+ android.R.integer.config_shortAnimTime);
mFullResImageView.setAlpha(0f);
mFullResImageView.animate()
@@ -702,7 +719,8 @@
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- // Clear the thumbnail bitmap reference to save memory since it's no longer visible.
+ // Clear the thumbnail bitmap reference to save memory since it's no longer
+ // visible.
if (mLowResImageView != null) {
mLowResImageView.setImageBitmap(null);
}
@@ -773,8 +791,8 @@
rect.set(0, 0, scaledWallpaperWidth, scaledWallpaperHeight);
Point screenSize = ScreenSizeCalculator.getInstance().getScreenSize(
getActivity().getWindowManager().getDefaultDisplay());
- // Crop rect should start off as the visible screen and then include extra width and height if
- // available within wallpaper at the current zoom.
+ // Crop rect should start off as the visible screen and then include extra width and height
+ // if available within wallpaper at the current zoom.
Rect cropRect = new Rect(scrollX, scrollY, scrollX + screenSize.x, scrollY + screenSize.y);
Point defaultCropSurfaceSize = WallpaperCropUtils.getDefaultCropSurfaceSize(
@@ -782,7 +800,8 @@
int extraWidth = defaultCropSurfaceSize.x - screenSize.x;
int extraHeightTopAndBottom = (int) ((defaultCropSurfaceSize.y - screenSize.y) / 2f);
- // Try to increase size of screenRect to include extra width depending on the layout direction.
+ // Try to increase size of screenRect to include extra width depending on the layout
+ // direction.
if (isRtl()) {
cropRect.left = Math.max(cropRect.left - extraWidth, rect.left);
} else {
@@ -843,8 +862,9 @@
R.string.set_wallpaper_error_message, wallpaperDestination);
newFragment.setTargetFragment(this, UNUSED_REQUEST_CODE);
- // Show 'set wallpaper' error dialog now if it's safe to commit fragment transactions, otherwise
- // stage it for later when the hosting activity is in a state to commit fragment transactions.
+ // Show 'set wallpaper' error dialog now if it's safe to commit fragment transactions,
+ // otherwise stage it for later when the hosting activity is in a state to commit fragment
+ // transactions.
BasePreviewActivity activity = (BasePreviewActivity) getActivity();
if (activity.isSafeToCommitFragmentTransaction()) {
newFragment.show(getFragmentManager(), TAG_SET_WALLPAPER_ERROR_DIALOG_FRAGMENT);
@@ -854,8 +874,8 @@
}
/**
- * Shows 'load wallpaper' error dialog now or stage it to be shown when the hosting activity is in
- * a state that allows committing fragment transactions.
+ * Shows 'load wallpaper' error dialog now or stage it to be shown when the hosting activity is
+ * in a state that allows committing fragment transactions.
*/
private void showLoadWallpaperErrorDialog() {
LoadWallpaperErrorDialogFragment dialogFragment =
@@ -923,33 +943,19 @@
case 3:
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
default:
- Log.e(TAG, "Display rotation did not correspond to a valid ActivityInfo orientation with"
- + " display rotation: " + display.getRotation() + " and index offset: " + indexOffset
- + ".");
+ Log.e(TAG, "Display rotation did not correspond to a valid ActivityInfo orientation"
+ + "with display rotation: " + display.getRotation() + " and index offset: "
+ + indexOffset + ".");
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
}
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
- private void saveAndLockScreenOrientation() {
- mCurrentScreenOrientation = getActivity().getRequestedOrientation();
- if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2) {
- getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
- } else {
- getActivity().setRequestedOrientation(getCompatActivityInfoOrientation());
- }
- }
-
- private void restoreScreenOrientation() {
- getActivity().setRequestedOrientation(mCurrentScreenOrientation);
- }
-
/**
- * Returns whether layout direction is RTL (or false for LTR). Since native RTL layout support was
- * added in API 17, returns false for versions lower than 17.
+ * Returns whether layout direction is RTL (or false for LTR). Since native RTL layout support
+ * was added in API 17, returns false for versions lower than 17.
*/
private boolean isRtl() {
- return VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
- && getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
+ return getResources().getConfiguration().getLayoutDirection()
+ == View.LAYOUT_DIRECTION_RTL;
}
}
\ No newline at end of file
diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java b/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java
index 4df59eb..24eb535 100755
--- a/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java
+++ b/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java
@@ -114,7 +114,7 @@
// color tint as not to affect other clients elsewhere in the app.
navigationIcon = navigationIcon.getConstantState().newDrawable().mutate();
navigationIcon.setColorFilter(
- ContextCompat.getColor(this, R.color.accent_color), Mode.SRC_IN);
+ ContextCompat.getColor(this, R.color.toolbar_icon_color), Mode.SRC_IN);
// Need to explicitly check against 19 rather than using BuildCompat in order to avoid a
// NoSuchMethodError here in UI tests running on pre-API 19 emulators.