From 1501db3c48ba7a540aeacbc1b895a552b288561c Mon Sep 17 00:00:00 2001 From: Anu6is Date: Sun, 9 Feb 2014 18:03:00 -0600 Subject: [PATCH] Lockscreen Wallpaper Custom lockscreen Accessible via launcher wallpaper selector and Settings - Display - Wallpaper - Lock screen Change-Id: I2e4722d1a6d4ba80a3c656306ceb251d630a8e21 Conflicts: packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java Themes: Keyguard: Fix NPE setting lockscreen wallpaper After boot the view might not be laid out and so getWidth() and getHeight() return 0 and will cause a NullPointerException in createBitmap(). Bug AOSPA-448 Change-Id: Ibacf4199a69709dc34d21695732c2a5360533a23 Signed-off-by: Dirk Rettschlag Keyguard: fix NPE setting lockscreen wallpaper Continue previous patchset (check history) ------- Cherry-picked commit ------- After boot the view might not be laid out and so getWidth() and getHeight() return 0 and will cause a NullPointerException in createBitmap(). Signed-off-by: Dirk Rettschlag --- .../android/keyguard/KeyguardViewManager.java | 58 ++- packages/WallpaperCropper/AndroidManifest.xml | 14 + .../res/layout/actionbar_set_lockscreen.xml | 34 ++ .../res/layout/blur_dialog.xml | 32 ++ .../res/layout/lockscreen_main.xml | 59 +++ .../mipmap-hdpi/ic_lockscreen_wallpaper.png | Bin 0 -> 4418 bytes .../mipmap-mdpi/ic_lockscreen_wallpaper.png | Bin 0 -> 2871 bytes .../mipmap-xhdpi/ic_lockscreen_wallpaper.png | Bin 0 -> 6061 bytes .../mipmap-xxhdpi/ic_lockscreen_wallpaper.png | Bin 0 -> 7596 bytes .../res/values/pa_strings.xml | 25 ++ .../wallpapercropper/LockscreenWallpaper.java | 418 ++++++++++++++++++ 11 files changed, 638 insertions(+), 2 deletions(-) create mode 100644 packages/WallpaperCropper/res/layout/actionbar_set_lockscreen.xml create mode 100644 packages/WallpaperCropper/res/layout/blur_dialog.xml create mode 100644 packages/WallpaperCropper/res/layout/lockscreen_main.xml create mode 100644 packages/WallpaperCropper/res/mipmap-hdpi/ic_lockscreen_wallpaper.png create mode 100644 packages/WallpaperCropper/res/mipmap-mdpi/ic_lockscreen_wallpaper.png create mode 100644 packages/WallpaperCropper/res/mipmap-xhdpi/ic_lockscreen_wallpaper.png create mode 100644 packages/WallpaperCropper/res/mipmap-xxhdpi/ic_lockscreen_wallpaper.png create mode 100644 packages/WallpaperCropper/res/values/pa_strings.xml create mode 100644 packages/WallpaperCropper/src/com/android/wallpapercropper/LockscreenWallpaper.java diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java b/packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java index b09bdc045655..1773c056d683 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java @@ -18,6 +18,7 @@ package com.android.keyguard; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.TransitionDrawable; @@ -31,6 +32,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.content.res.Resources; @@ -68,6 +70,8 @@ import android.view.WindowManager; import android.widget.FrameLayout; +import java.io.File; + /** * Manages creating, showing, hiding and resetting the keyguard. Calls back * via {@link KeyguardViewMediator.ViewMediatorCallback} to poke @@ -78,6 +82,8 @@ public class KeyguardViewManager { private final static boolean DEBUG = KeyguardViewMediator.DEBUG; private static String TAG = "KeyguardViewManager"; public final static String IS_SWITCHING_USER = "is_switching_user"; + private static final String INTENT_LOCKSCREEN_WALLPAPER_CHANGED = "lockscreen_changed"; + private static final String LOCKSCREEN_IMAGE_FILE = "/lockwallpaper.sav"; // Delay dismissing keyguard to allow animations to complete. private static final int HIDE_KEYGUARD_DELAY = 500; @@ -99,7 +105,9 @@ public class KeyguardViewManager { private ViewManagerHost mKeyguardHost; private KeyguardHostView mKeyguardView; + private WallpaperObserver mReceiver; + private boolean mBackgroundInitialized; private boolean mScreenOn = false; private LockPatternUtils mLockPatternUtils; @@ -109,9 +117,37 @@ public class KeyguardViewManager { private boolean mLockscreenNotifications = false; private Bitmap mBlurredImage = null; + private Bitmap mLockscreenBackground; private boolean mRotated = false; private int mLastRotation = 0; + class WallpaperObserver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(INTENT_LOCKSCREEN_WALLPAPER_CHANGED)) { + customLockscreen(); + } + } + } + + private void customLockscreen() { + mLockscreenBackground = null; + String path = mContext.getExternalCacheDir().getAbsolutePath(); + path = path.replace("com.android.keyguard", "com.android.wallpapercropper"); + File file = new File(path + LOCKSCREEN_IMAGE_FILE); + if (file.exists()) { + mLockscreenBackground = BitmapFactory.decodeFile(file.getAbsolutePath()); + } + } + + private void registerWallpaperReceiver() { + IntentFilter filter = new IntentFilter(); + filter.addAction(INTENT_LOCKSCREEN_WALLPAPER_CHANGED); + mReceiver = new WallpaperObserver(); + mContext.registerReceiver(mReceiver, filter); + } + private KeyguardUpdateMonitorCallback mBackgroundChanger = new KeyguardUpdateMonitorCallback() { @Override public void onSetBackground(Bitmap bmp) { @@ -283,6 +319,22 @@ public int getOpacity() { public ViewManagerHost(Context context) { super(context); + registerWallpaperReceiver(); + customLockscreen(); + + if (mLockscreenBackground == null) { + initBackground(); + } else { + Drawable customLockscreen = new BitmapDrawable(mContext.getResources(), + mLockscreenBackground); + setBackground(customLockscreen); + mBackgroundInitialized = false; + } + + } + + public void initBackground() { + mBackgroundInitialized = true; setBackground(mBackgroundDrawable); } @@ -317,6 +369,7 @@ public void drawToCanvas(Canvas canvas, Drawable drawable) { } public void setCustomBackground(Drawable d) { + if (!isLaidOut()) return; if (!ActivityManager.isHighEndGfx() || !mScreenOn) { mCustomBackground = d; if (d != null) { @@ -498,8 +551,8 @@ private void maybeCreateKeyguardLocked(int rotationAngles, boolean force, mKeyguardHost.restoreHierarchyState(mStateContainer); - if (mBlurredImage != null) { - setCustomBackground(mBlurredImage); + if (mBlurredImage != null || mLockscreenBackground != null) { + setCustomBackground(mBlurredImage == null ? mLockscreenBackground : mBlurredImage); } } @@ -724,6 +777,7 @@ public synchronized void hide() { } if (mKeyguardHost != null) { + if (!mBackgroundInitialized) mKeyguardHost.initBackground(); mKeyguardHost.setVisibility(View.GONE); // We really only want to preserve keyguard state for configuration changes. Hence diff --git a/packages/WallpaperCropper/AndroidManifest.xml b/packages/WallpaperCropper/AndroidManifest.xml index 27755bd2c7cc..9fbc23d514c5 100644 --- a/packages/WallpaperCropper/AndroidManifest.xml +++ b/packages/WallpaperCropper/AndroidManifest.xml @@ -2,6 +2,9 @@ package="com.android.wallpapercropper" > + + + + + + + + + diff --git a/packages/WallpaperCropper/res/layout/actionbar_set_lockscreen.xml b/packages/WallpaperCropper/res/layout/actionbar_set_lockscreen.xml new file mode 100644 index 000000000000..f7b9edc61e3b --- /dev/null +++ b/packages/WallpaperCropper/res/layout/actionbar_set_lockscreen.xml @@ -0,0 +1,34 @@ + + + + + + diff --git a/packages/WallpaperCropper/res/layout/blur_dialog.xml b/packages/WallpaperCropper/res/layout/blur_dialog.xml new file mode 100644 index 000000000000..00b223ba4632 --- /dev/null +++ b/packages/WallpaperCropper/res/layout/blur_dialog.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/packages/WallpaperCropper/res/layout/lockscreen_main.xml b/packages/WallpaperCropper/res/layout/lockscreen_main.xml new file mode 100644 index 000000000000..1aa3db6f9065 --- /dev/null +++ b/packages/WallpaperCropper/res/layout/lockscreen_main.xml @@ -0,0 +1,59 @@ + + + + + + + + +