summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorim Jaggi <jjaggi@google.com>2016-05-24 00:30:00 -0700
committerJorim Jaggi <jjaggi@google.com>2016-06-02 19:09:51 -0700
commit7d98c8fca6d1edd51178a65847687d81562d7d6e (patch)
treecc8136cfcfb660fb73c026faf9bd1b514fa984fc
parentb30b95f9db068faf294e43fb7927d911ecfaf892 (diff)
downloadandroid_packages_wallpapers_LivePicker-7d98c8fca6d1edd51178a65847687d81562d7d6e.tar.gz
android_packages_wallpapers_LivePicker-7d98c8fca6d1edd51178a65847687d81562d7d6e.tar.bz2
android_packages_wallpapers_LivePicker-7d98c8fca6d1edd51178a65847687d81562d7d6e.zip
Adjust wallpaper picker to match static wallpaper picker
- Implement new action bar - Use BottomSheet behavior from design lib - Fill in values from live wallpaper if desired - Don't use separate dialog for loading state Bug: 28770685 Change-Id: I8dd862fe4c83f702e249f7f3644df89fee771f4f
-rw-r--r--Android.mk14
-rw-r--r--proguard.flags7
-rw-r--r--res/drawable/ic_keyboard_arrow_down_white_24dp.xml24
-rw-r--r--res/drawable/ic_keyboard_arrow_up_white_24dp.xml24
-rw-r--r--res/layout/live_wallpaper_loading.xml24
-rw-r--r--res/layout/live_wallpaper_preview.xml157
-rw-r--r--res/menu/menu_preview.xml5
-rw-r--r--res/values-sw720dp/dimes.xml27
-rw-r--r--res/values-sw720dp/styles.xml21
-rw-r--r--res/values/colors.xml2
-rw-r--r--res/values/dimensions.xml15
-rw-r--r--res/values/strings.xml8
-rw-r--r--res/values/styles.xml32
-rw-r--r--src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java250
14 files changed, 487 insertions, 123 deletions
diff --git a/Android.mk b/Android.mk
index 75b3388..2460ff9 100644
--- a/Android.mk
+++ b/Android.mk
@@ -46,4 +46,18 @@ LOCAL_CERTIFICATE := platform
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+LOCAL_STATIC_JAVA_LIBRARIES := \
+ android-support-v7-appcompat \
+ android-support-v4 \
+ android-support-design
+
+LOCAL_RESOURCE_DIR := \
+ $(LOCAL_PATH)/res \
+ frameworks/support/v7/appcompat/res \
+ frameworks/support/design/res \
+
+LOCAL_AAPT_FLAGS := --auto-add-overlay \
+ --extra-packages android.support.design \
+ --extra-packages android.support.v7.appcompat
+
include $(BUILD_PACKAGE)
diff --git a/proguard.flags b/proguard.flags
index ae1dddc..5320720 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -2,3 +2,10 @@
public void setLiveWallpaper(android.view.View);
public void configureLiveWallpaper(android.view.View);
}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keep class android.support.design.widget.CoordinatorLayout
+-keep class android.support.design.widget.BottomSheetBehavior \ No newline at end of file
diff --git a/res/drawable/ic_keyboard_arrow_down_white_24dp.xml b/res/drawable/ic_keyboard_arrow_down_white_24dp.xml
new file mode 100644
index 0000000..e4c2a23
--- /dev/null
+++ b/res/drawable/ic_keyboard_arrow_down_white_24dp.xml
@@ -0,0 +1,24 @@
+<!--
+ ~ 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
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24.0dp"
+ android:height="24.0dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M7.41,7.84L12.0,12.42l4.59,-4.58L18.0,9.25l-6.0,6.0 -6.0,-6.0z"/>
+</vector>
diff --git a/res/drawable/ic_keyboard_arrow_up_white_24dp.xml b/res/drawable/ic_keyboard_arrow_up_white_24dp.xml
new file mode 100644
index 0000000..d7b3e13
--- /dev/null
+++ b/res/drawable/ic_keyboard_arrow_up_white_24dp.xml
@@ -0,0 +1,24 @@
+<!--
+ ~ 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
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24.0dp"
+ android:height="24.0dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FFFFFF"
+ android:pathData="M7.41,15.41L12.0,10.83l4.59,4.58L18.0,14.0l-6.0,-6.0 -6.0,6.0z"/>
+</vector>
diff --git a/res/layout/live_wallpaper_loading.xml b/res/layout/live_wallpaper_loading.xml
deleted file mode 100644
index dff8b86..0000000
--- a/res/layout/live_wallpaper_loading.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
-
- android:gravity="center"
-
- android:text="@string/live_wallpaper_loading"
- android:textAppearance="?android:attr/textAppearanceMedium" />
diff --git a/res/layout/live_wallpaper_preview.xml b/res/layout/live_wallpaper_preview.xml
index 6dcb644..fb8ab5c 100644
--- a/res/layout/live_wallpaper_preview.xml
+++ b/res/layout/live_wallpaper_preview.xml
@@ -1,25 +1,136 @@
-<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (C) 2009 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.
--->
-<Button xmlns:android="http://schemas.android.com/apk/res/android"
- style="@style/ActionBarSetWallpaperStyle"
+ ~ 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
+ -->
+
+<FrameLayout 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="match_parent"
- android:drawablePadding="8dp"
- android:drawableStart="@drawable/ic_tick"
- android:gravity="start|center_vertical"
- android:onClick="setLiveWallpaper"
- android:text="@string/wallpaper_instructions" />
+ android:layout_height="match_parent">
+
+ <FrameLayout
+ android:id="@+id/loading"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#ff000000"
+ android:forceHasOverlappingRendering="false">
+
+ <ProgressBar
+ style="@android:style/Widget.Material.ProgressBar"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:indeterminate="true"/>
+
+ </FrameLayout>
+
+ <FrameLayout android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:fitsSystemWindows="true">
+
+ <android.support.design.widget.CoordinatorLayout
+ android:id="@+id/coordinator_layout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom">
+
+ <RelativeLayout 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="android.support.design.widget.BottomSheetBehavior">
+
+ <ImageButton android:id="@+id/preview_attribution_pane_arrow"
+ android:contentDescription="@string/expand_attribution_panel"
+ android:layout_width="48dp"
+ android:layout_height="48dp"
+ android:layout_alignParentEnd="true"
+ android:focusable="true"
+ android:clickable="true"
+ android:src="@drawable/ic_keyboard_arrow_up_white_24dp"
+ style="?android:attr/borderlessButtonStyle"/>
+
+ <TextView
+ android:id="@+id/preview_attribution_pane_title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="start"
+ android:layout_marginStart="@dimen/preview_attribution_pane_content_side_margin"
+ android:layout_marginEnd="@dimen/preview_attribution_pane_content_side_margin"
+ android:layout_marginTop="@dimen/preview_attribution_pane_title_top_margin"
+ android:layout_toStartOf="@id/preview_attribution_pane_arrow"
+ android:ellipsize="end"
+ android:textAppearance="@style/AttributionPaneTitle"
+ android:forceHasOverlappingRendering="false"/>
+
+ <TextView android:id="@+id/preview_attribution_pane_subtitle1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/preview_attribution_pane_content_side_margin"
+ android:layout_marginEnd="@dimen/preview_attribution_pane_content_side_margin"
+ android:layout_marginTop="@dimen/preview_attribution_pane_subtitle1_top_margin"
+ android:layout_below="@id/preview_attribution_pane_title"
+ android:layout_toStartOf="@id/preview_attribution_pane_arrow"
+ android:textAppearance="@android:style/TextAppearance.Material.Body1"
+ android:forceHasOverlappingRendering="false"/>
+
+ <TextView android:id="@+id/preview_attribution_pane_subtitle2"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="@dimen/abc_text_size_caption_material"
+ android:layout_marginStart="@dimen/preview_attribution_pane_content_side_margin"
+ android:layout_marginEnd="@dimen/preview_attribution_pane_content_side_margin"
+ android:layout_marginTop="@dimen/preview_attribution_pane_subtitle2_top_margin"
+ android:layout_below="@id/preview_attribution_pane_subtitle1"
+ android:layout_toStartOf="@id/preview_attribution_pane_arrow"
+ android:textAppearance="@android:style/TextAppearance.Material.Caption"
+ android:forceHasOverlappingRendering="false"/>
+
+ <Button android:id="@+id/preview_attribution_pane_explore_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="?android:attr/colorAccent"
+ android:layout_marginLeft="@dimen/preview_attribution_pane_explore_left_margin"
+ android:layout_marginStart="@dimen/preview_attribution_pane_explore_left_margin"
+ android:layout_marginTop="@dimen/preview_attribution_pane_explore_top_margin"
+ android:layout_marginBottom="@dimen/preview_attribution_pane_explore_bottom_margin"
+ android:layout_below="@id/preview_attribution_pane_subtitle2"
+ android:layout_gravity="center_vertical"
+ style="?android:attr/borderlessButtonStyle"
+ android:forceHasOverlappingRendering="false"/>
+
+ <View android:id="@id/spacer"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/preview_attribution_pane_spacer_height"
+ android:layout_below="@id/preview_attribution_pane_subtitle2"
+ android:visibility="gone"/>
+
+ </RelativeLayout>
+
+ </android.support.design.widget.CoordinatorLayout>
+
+ <android.widget.Toolbar android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top"
+ android:paddingStart="@dimen/preview_toolbar_up_button_padding"
+ android:paddingEnd="@dimen/preview_toolbar_set_wallpaper_button_end_padding"
+ style="@style/TranslucentToolbarStyle"/>
+
+ </FrameLayout>
+</FrameLayout>
diff --git a/res/menu/menu_preview.xml b/res/menu/menu_preview.xml
index 26adc2d..8ab2fb3 100644
--- a/res/menu/menu_preview.xml
+++ b/res/menu/menu_preview.xml
@@ -22,4 +22,9 @@
android:showAsAction="ifRoom"
android:title="@string/configure_wallpaper"/>
+ <item
+ android:id="@+id/set_wallpaper"
+ android:title="@string/set_live_wallpaper"
+ android:showAsAction="always|withText" />
+
</menu>
diff --git a/res/values-sw720dp/dimes.xml b/res/values-sw720dp/dimes.xml
new file mode 100644
index 0000000..54380b9
--- /dev/null
+++ b/res/values-sw720dp/dimes.xml
@@ -0,0 +1,27 @@
+<!--
+ ~ 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
+ -->
+
+<resources>
+
+ <!-- Dimensions for the preview fragment. -->
+ <dimen name="preview_toolbar_up_button_padding">8dp</dimen>
+ <dimen name="preview_toolbar_set_wallpaper_button_padding">20dp</dimen>
+
+ <!-- Dimensions for the preview attribution pane. -->
+ <dimen name="preview_attribution_pane_content_side_margin">24dp</dimen>
+ <dimen name="preview_attribution_pane_explore_left_margin">10dp</dimen>
+
+</resources> \ No newline at end of file
diff --git a/res/values-sw720dp/styles.xml b/res/values-sw720dp/styles.xml
new file mode 100644
index 0000000..7e1209c
--- /dev/null
+++ b/res/values-sw720dp/styles.xml
@@ -0,0 +1,21 @@
+<!--
+ ~ 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
+ -->
+
+<resources>
+
+ <style name="AttributionPaneTitle" parent="@android:style/TextAppearance.Material.Headline"/>
+
+</resources> \ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
index d49e104..a81efb6 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -20,5 +20,7 @@
<resources>
<color name="live_wallpaper_thumbnail_background">#CC666666</color>
<color name="live_wallpaper_thumbnail_text_color">#FFFFFFFF</color>
+
+ <color name="translucent_black">#96000000</color>
</resources>
diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml
index d08e573..73792df 100644
--- a/res/values/dimensions.xml
+++ b/res/values/dimensions.xml
@@ -25,4 +25,19 @@
<dimen name="screen_margin_sides">0dip</dimen>
+ <!-- Dimensions for the preview fragment. -->
+ <dimen name="preview_toolbar_up_button_padding">0dp</dimen>
+ <dimen name="preview_toolbar_set_wallpaper_button_end_padding">12dp</dimen>
+
+ <!-- Dimensions for the preview attribution pane. -->
+ <dimen name="preview_attribution_pane_collapsed_height">48dp</dimen>
+ <dimen name="preview_attribution_pane_expanded_height">96dp</dimen>
+ <dimen name="preview_attribution_pane_content_side_margin">16dp</dimen>
+ <dimen name="preview_attribution_pane_title_top_margin">13dp</dimen>
+ <dimen name="preview_attribution_pane_subtitle1_top_margin">12dp</dimen>
+ <dimen name="preview_attribution_pane_subtitle2_top_margin">2dp</dimen>
+ <dimen name="preview_attribution_pane_explore_left_margin">2dp</dimen>
+ <dimen name="preview_attribution_pane_explore_top_margin">12dp</dimen>
+ <dimen name="preview_attribution_pane_explore_bottom_margin">16dp</dimen>
+ <dimen name="preview_attribution_pane_spacer_height">32dp</dimen>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3e9ac84..99e48e6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -46,4 +46,12 @@
<string name="which_wallpaper_option_home_screen">Home screen</string>
<!-- Option for setting the wallpaper on both the home screen and lock screen. -->
<string name="which_wallpaper_option_home_screen_and_lock_screen">Home screen and lock screen</string>
+
+ <!-- Content description for a button letting the user collapse a visual panel showing info
+ about the wallpaper being previewed. [CHAR LIMIT=none] -->
+ <string name="collapse_attribution_panel">Collapse wallpaper info panel</string>
+
+ <!-- Content description for a button letting the user expand a visual panel showing info about
+ the wallpaper being previewed. [CHAR LIMIT=none] -->
+ <string name="expand_attribution_panel">Expand wallpaper info panel</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 01747e7..361d824 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -21,28 +21,24 @@
<style name="LivePickerTheme" parent="@android:style/Theme.DeviceDefault.Settings" />
- <style name="Preview" parent="@android:style/Theme.DeviceDefault">
- <item name="android:actionBarStyle">@style/PreviewActionBar</item>
- <item name="android:windowAnimationStyle">@android:style/Animation.Activity</item>
- <item name="android:windowFullscreen">true</item>
- <item name="android:windowActionBarOverlay">true</item>
- <item name="android:windowTranslucentNavigation">true</item>
+ <style name="Preview" parent="@style/Theme.AppCompat">
+
+ <!-- Set no title and no action bar because we use a toolbar instead. -->
+ <item name="android:windowActionBar">false</item>
+ <item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:colorBackgroundCacheHint">@null</item>
- </style>
+ <item name="android:windowContentOverlay">@null</item>
- <style name="PreviewActionBar" parent="@android:style/Widget.DeviceDefault.ActionBar">
- <item name="android:displayOptions">showCustom</item>
- <item name="android:background">#88000000</item>
- <item name="android:contentInsetEnd">0dp</item>
- <item name="android:contentInsetLeft">0dp</item>
- <item name="android:contentInsetRight">0dp</item>
- <item name="android:contentInsetStart">0dp</item>
+ <!-- Set status bar and navigation buttons to be translucent. -->
+ <item name="android:colorPrimaryDark">@color/translucent_black</item>
+ <item name="android:navigationBarColor">@color/translucent_black</item>
</style>
- <style name="ActionBarSetWallpaperStyle" parent="@android:style/Widget.DeviceDefault.ActionButton">
- <item name="android:textColor">#ffffffff</item>
- <item name="android:background">?android:attr/selectableItemBackgroundBorderless</item>
+ <style name="TranslucentToolbarStyle" parent="@style/Widget.AppCompat.Toolbar">
+ <item name="android:background">@color/translucent_black</item>
+ <item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
+ <style name="AttributionPaneTitle" parent="@android:style/TextAppearance.Material.Subhead"/>
+
</resources> \ No newline at end of file
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
index 85f241f..34e92f1 100644
--- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
+++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
@@ -16,37 +16,43 @@
package com.android.wallpaper.livepicker;
-import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.WallpaperManager;
import android.app.WallpaperInfo;
-import android.app.Dialog;
+import android.app.WallpaperManager;
+import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.DialogInterface;
-import android.graphics.Rect;
-import android.service.wallpaper.IWallpaperConnection;
-import android.service.wallpaper.IWallpaperService;
-import android.service.wallpaper.IWallpaperEngine;
-import android.service.wallpaper.WallpaperSettingsActivity;
-import android.content.ServiceConnection;
import android.content.Intent;
-import android.content.Context;
-import android.content.ComponentName;
-import android.os.RemoteException;
+import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
+import android.content.res.Resources.NotFoundException;
+import android.graphics.Rect;
+import android.net.Uri;
+import android.os.Bundle;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
-import android.os.Bundle;
+import android.os.RemoteException;
+import android.service.wallpaper.IWallpaperConnection;
+import android.service.wallpaper.IWallpaperEngine;
+import android.service.wallpaper.IWallpaperService;
import android.service.wallpaper.WallpaperService;
+import android.service.wallpaper.WallpaperSettingsActivity;
+import android.support.design.widget.BottomSheetBehavior;
+import android.text.TextUtils;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
-import android.view.WindowManager;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.view.LayoutInflater;
-import android.util.Log;
+import android.view.View.OnClickListener;
+import android.view.WindowManager.LayoutParams;
+import android.view.animation.AnimationUtils;
+import android.widget.Button;
+import android.widget.ImageButton;
import android.widget.TextView;
+import android.widget.Toolbar;
import java.io.IOException;
@@ -55,6 +61,9 @@ public class LiveWallpaperPreview extends Activity {
private static final String LOG_TAG = "LiveWallpaperPreview";
+ // TODO: Remove once we have good data for testing.
+ private static final boolean SHOW_DUMMY_DATA = true;
+
private WallpaperManager mWallpaperManager;
private WallpaperConnection mWallpaperConnection;
@@ -62,8 +71,14 @@ public class LiveWallpaperPreview extends Activity {
private String mPackageName;
private Intent mWallpaperIntent;
- private View mView;
- private Dialog mDialog;
+ private TextView mAttributionTitle;
+ private TextView mAttributionSubtitle1;
+ private TextView mAttributionSubtitle2;
+ private Button mAttributionExploreButton;
+ private ImageButton mPreviewPaneArrow;
+ private View mBottomSheet;
+ private View mSpacer;
+ private View mLoading;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -78,29 +93,157 @@ public class LiveWallpaperPreview extends Activity {
setResult(RESULT_CANCELED);
finish();
}
-
initUI(info);
}
protected void initUI(WallpaperInfo info) {
+ getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ setContentView(R.layout.live_wallpaper_preview);
+ mAttributionTitle = (TextView) findViewById(R.id.preview_attribution_pane_title);
+ mAttributionSubtitle1 = (TextView) findViewById(R.id.preview_attribution_pane_subtitle1);
+ mAttributionSubtitle2 = (TextView) findViewById(R.id.preview_attribution_pane_subtitle2);
+ mAttributionExploreButton = (Button) findViewById(
+ R.id.preview_attribution_pane_explore_button);
+ mPreviewPaneArrow = (ImageButton) findViewById(R.id.preview_attribution_pane_arrow);
+ mBottomSheet = findViewById(R.id.bottom_sheet);
+ mSpacer = findViewById(R.id.spacer);
+ mLoading = findViewById(R.id.loading);
+
mSettings = info.getSettingsActivity();
mPackageName = info.getPackageName();
mWallpaperIntent = new Intent(WallpaperService.SERVICE_INTERFACE)
.setClassName(info.getPackageName(), info.getServiceName());
- final ActionBar actionBar = getActionBar();
- actionBar.setCustomView(R.layout.live_wallpaper_preview);
- mView = actionBar.getCustomView();
+ setActionBar((Toolbar) findViewById(R.id.toolbar));
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ getActionBar().setDisplayShowTitleEnabled(false);
mWallpaperManager = WallpaperManager.getInstance(this);
mWallpaperConnection = new WallpaperConnection(mWallpaperIntent);
+
+ populateAttributionPane(info);
+ }
+
+ private void populateAttributionPane(WallpaperInfo info) {
+ if (!info.getShowMetadataInPreview() && !SHOW_DUMMY_DATA) {
+ mBottomSheet.setVisibility(View.GONE);
+ return;
+ }
+ 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);
+ }
+ }
+ };
+ mPreviewPaneArrow.setOnClickListener(onClickListener);
+
+ bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
+ @Override
+ public void onStateChanged(View bottomSheet, int newState) {
+ if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
+ mPreviewPaneArrow.setImageResource(R.drawable.ic_keyboard_arrow_up_white_24dp);
+ mPreviewPaneArrow.setContentDescription(
+ getResources().getString(R.string.expand_attribution_panel));
+ } else if (newState == BottomSheetBehavior.STATE_EXPANDED) {
+ mPreviewPaneArrow.setImageResource(
+ R.drawable.ic_keyboard_arrow_down_white_24dp);
+ mPreviewPaneArrow.setContentDescription(
+ getResources().getString(R.string.collapse_attribution_panel));
+ }
+ }
+
+ @Override
+ public void onSlide(View bottomSheet, float slideOffset) {
+ float alpha;
+ if (slideOffset >= 0) {
+ alpha = slideOffset;
+ } else {
+ alpha = 1f - slideOffset;
+ }
+ mAttributionTitle.setAlpha(slideOffset);
+ mAttributionSubtitle1.setAlpha(slideOffset);
+ mAttributionSubtitle2.setAlpha(slideOffset);
+ mAttributionExploreButton.setAlpha(slideOffset);
+ }
+ });
+
+ bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+ mPreviewPaneArrow.setImageResource(R.drawable.ic_keyboard_arrow_down_white_24dp);
+
+ if (SHOW_DUMMY_DATA) {
+ mAttributionTitle.setText("Diorama, Yosemite");
+ mAttributionSubtitle1.setText("Live Earth Collection - Android Earth");
+ mAttributionSubtitle2.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit."
+ + " Sed imperdiet et mauris molestie laoreet. Proin volutpat elit nec magna"
+ + " tempus, ac aliquet lectus volutpat.");
+ mAttributionExploreButton.setText("Explore");
+ } else {
+ PackageManager pm = getPackageManager();
+
+ CharSequence title = info.loadLabel(pm);
+ if (!TextUtils.isEmpty(title)) {
+ mAttributionTitle.setText(title);
+ } else {
+ mAttributionTitle.setVisibility(View.GONE);
+ }
+
+ try {
+ CharSequence author = info.loadAuthor(pm);
+ if (TextUtils.isEmpty(author)) {
+ throw new NotFoundException();
+ }
+ mAttributionSubtitle1.setText(author);
+ } catch (NotFoundException e) {
+ mAttributionSubtitle1.setVisibility(View.GONE);
+ }
+
+ try {
+ CharSequence description = info.loadDescription(pm);
+ if (TextUtils.isEmpty(description)) {
+ throw new NotFoundException();
+ }
+ mAttributionSubtitle2.setText(description);
+ } catch (NotFoundException e) {
+ mAttributionSubtitle2.setVisibility(View.GONE);
+ }
+
+ try {
+ Uri contextUri = info.loadContextUri(pm);
+ CharSequence contextDescription = info.loadContextDescription(pm);
+ if (contextUri == null) {
+ throw new NotFoundException();
+ }
+ mAttributionExploreButton.setText(contextDescription);
+ mAttributionExploreButton.setOnClickListener(v -> {
+ Intent intent = new Intent(Intent.ACTION_VIEW, contextUri);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Log.e(LOG_TAG, "Couldn't find activity for context link.", e);
+ }
+ });
+ } catch (NotFoundException e) {
+ mAttributionExploreButton.setVisibility(View.GONE);
+ mSpacer.setVisibility(View.VISIBLE);
+ }
+ }
+
+
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- if (mSettings != null) {
- getMenuInflater().inflate(R.menu.menu_preview, menu);
- }
+ getMenuInflater().inflate(R.menu.menu_preview, menu);
+ menu.findItem(R.id.configure).setVisible(mSettings != null);
return super.onCreateOptionsMenu(menu);
}
@@ -116,7 +259,7 @@ public class LiveWallpaperPreview extends Activity {
finish();
} else {
// Otherwise, prompt to either set on home or both home and lock screen.
- new AlertDialog.Builder(this)
+ new AlertDialog.Builder(this, android.R.style.Theme_Material_Light_Dialog)
.setTitle(R.string.set_live_wallpaper)
.setItems(R.array.which_wallpaper_options, new DialogInterface.OnClickListener() {
@Override
@@ -149,12 +292,19 @@ public class LiveWallpaperPreview extends Activity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.configure) {
+ int id = item.getItemId();
+ if (id == R.id.configure) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(mPackageName, mSettings));
intent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true);
startActivity(intent);
return true;
+ } else if (id == R.id.set_wallpaper) {
+ setLiveWallpaper(getWindow().getDecorView());
+ return true;
+ } else if (id == android.R.id.home) {
+ onBackPressed();
+ return true;
}
return super.onOptionsItemSelected(item);
}
@@ -187,9 +337,7 @@ public class LiveWallpaperPreview extends Activity {
public void onAttachedToWindow() {
super.onAttachedToWindow();
- showLoading();
-
- mView.post(new Runnable() {
+ getWindow().getDecorView().post(new Runnable() {
public void run() {
if (!mWallpaperConnection.connect()) {
mWallpaperConnection = null;
@@ -198,31 +346,10 @@ public class LiveWallpaperPreview extends Activity {
});
}
- private void showLoading() {
- LayoutInflater inflater = LayoutInflater.from(this);
- TextView content = (TextView) inflater.inflate(R.layout.live_wallpaper_loading, null);
-
- mDialog = new Dialog(this, android.R.style.Theme_Black);
-
- Window window = mDialog.getWindow();
- WindowManager.LayoutParams lp = window.getAttributes();
-
- lp.width = WindowManager.LayoutParams.MATCH_PARENT;
- lp.height = WindowManager.LayoutParams.MATCH_PARENT;
- window.setType(WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA);
-
- mDialog.setContentView(content, new ViewGroup.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
- ));
- mDialog.show();
- }
-
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
- if (mDialog != null) mDialog.dismiss();
-
if (mWallpaperConnection != null) {
mWallpaperConnection.disconnect();
}
@@ -286,7 +413,7 @@ public class LiveWallpaperPreview extends Activity {
return true;
}
}
-
+
public void disconnect() {
synchronized (this) {
mConnected = false;
@@ -307,10 +434,9 @@ public class LiveWallpaperPreview extends Activity {
if (mWallpaperConnection == this) {
mService = IWallpaperService.Stub.asInterface(service);
try {
- final View view = mView;
- final View root = view.getRootView();
- mService.attach(this, view.getWindowToken(),
- WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY,
+ final View root = getWindow().getDecorView();
+ mService.attach(this, root.getWindowToken(),
+ LayoutParams.TYPE_APPLICATION_MEDIA,
true, root.getWidth(), root.getHeight(),
new Rect(0, 0, 0, 0));
} catch (RemoteException e) {
@@ -352,6 +478,14 @@ public class LiveWallpaperPreview extends Activity {
@Override
public void engineShown(IWallpaperEngine engine) throws RemoteException {
+ mLoading.post(() -> {
+ mLoading.animate()
+ .alpha(0f)
+ .setDuration(220)
+ .setInterpolator(AnimationUtils.loadInterpolator(LiveWallpaperPreview.this,
+ android.R.interpolator.fast_out_linear_in))
+ .withEndAction(() -> mLoading.setVisibility(View.INVISIBLE));
+ });
}
}
}