summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2016-03-22 11:07:46 -0700
committerTony Wickham <twickham@google.com>2016-03-22 16:10:29 -0700
commite27899f3d80c45439e487ec3e02549a1df3e48fb (patch)
treec011b6443385873eeebe0b65d976af019b44a839
parente668a081d2e3936a8b9c1fcb418c100374c1f598 (diff)
downloadandroid_packages_wallpapers_LivePicker-e27899f3d80c45439e487ec3e02549a1df3e48fb.tar.gz
android_packages_wallpapers_LivePicker-e27899f3d80c45439e487ec3e02549a1df3e48fb.tar.bz2
android_packages_wallpapers_LivePicker-e27899f3d80c45439e487ec3e02549a1df3e48fb.zip
Prompt to set live wallpaper on home or home and lock screen.
Bug: 27706226 Change-Id: I005063dcb08e2f3840eec6fe7e487855bd823900
-rw-r--r--AndroidManifest.xml1
-rw-r--r--res/values/arrays.xml7
-rw-r--r--res/values/strings.xml4
-rw-r--r--src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java55
4 files changed, 57 insertions, 10 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8c84e0b..af14111 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -26,6 +26,7 @@
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
<uses-permission android:name="android.permission.BIND_WALLPAPER" />
+ <uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:label="@string/application_name"
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
new file mode 100644
index 0000000..06dc2ca
--- /dev/null
+++ b/res/values/arrays.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string-array name="which_wallpaper_options">
+ <item>@string/which_wallpaper_option_home_screen</item>
+ <item>@string/which_wallpaper_option_home_screen_and_lock_screen</item>
+ </string-array>
+</resources> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9c508de..3e9ac84 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -42,4 +42,8 @@
<!-- Message, tells the user the selected live wallpaper is loading. -->
<string name="live_wallpaper_loading">Loading live wallpaper…</string>
+ <!-- Option for setting the wallpaper only on the home screen. -->
+ <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>
</resources>
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
index ab658ca..8eae63c 100644
--- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
+++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
@@ -18,9 +18,11 @@ 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.content.DialogInterface;
import android.graphics.Rect;
import android.service.wallpaper.IWallpaperConnection;
import android.service.wallpaper.IWallpaperService;
@@ -46,6 +48,8 @@ import android.view.LayoutInflater;
import android.util.Log;
import android.widget.TextView;
+import java.io.IOException;
+
public class LiveWallpaperPreview extends Activity {
static final String EXTRA_LIVE_WALLPAPER_INFO = "android.live_wallpaper.info";
@@ -100,16 +104,47 @@ public class LiveWallpaperPreview extends Activity {
return super.onCreateOptionsMenu(menu);
}
- public void setLiveWallpaper(View v) {
- try {
- mWallpaperManager.setWallpaperComponent(mWallpaperIntent.getComponent());
- mWallpaperManager.setWallpaperOffsetSteps(0.5f, 0.0f);
- mWallpaperManager.setWallpaperOffsets(v.getRootView().getWindowToken(), 0.5f, 0.0f);
- setResult(RESULT_OK);
- } catch (RuntimeException e) {
- Log.w(LOG_TAG, "Failure setting wallpaper", e);
+ public void setLiveWallpaper(final View v) {
+ if (mWallpaperManager.getWallpaperId(WallpaperManager.FLAG_SET_LOCK) < 0) {
+ // The lock screen does not have a wallpaper, so no need to prompt; can only set both.
+ try {
+ setLiveWallpaper(v.getRootView().getWindowToken());
+ setResult(RESULT_OK);
+ } catch (RuntimeException e) {
+ Log.w(LOG_TAG, "Failure setting wallpaper", e);
+ }
+ finish();
+ } else {
+ // Otherwise, prompt to either set on home or both home and lock screen.
+ new AlertDialog.Builder(this)
+ .setTitle(R.string.set_live_wallpaper)
+ .setItems(R.array.which_wallpaper_options, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ try {
+ setLiveWallpaper(v.getRootView().getWindowToken());
+ if (which == 1) {
+ // "Home screen and lock screen"; clear the lock screen so it
+ // shows through to the live wallpaper on home.
+ mWallpaperManager.clear(WallpaperManager.FLAG_SET_LOCK);
+ }
+ setResult(RESULT_OK);
+ } catch (RuntimeException e) {
+ Log.w(LOG_TAG, "Failure setting wallpaper", e);
+ } catch (IOException e) {
+ Log.w(LOG_TAG, "Failure setting wallpaper", e);
+ }
+ finish();
+ }
+ })
+ .show();
}
- finish();
+ }
+
+ private void setLiveWallpaper(IBinder windowToken) {
+ mWallpaperManager.setWallpaperComponent(mWallpaperIntent.getComponent());
+ mWallpaperManager.setWallpaperOffsetSteps(0.5f, 0.0f);
+ mWallpaperManager.setWallpaperOffsets(windowToken, 0.5f, 0.0f);
}
@Override
@@ -246,7 +281,7 @@ public class LiveWallpaperPreview extends Activity {
if (!bindService(mIntent, this, Context.BIND_AUTO_CREATE)) {
return false;
}
-
+
mConnected = true;
return true;
}