Skip to content

Commit

Permalink
Lockscreen Wallpaper
Browse files Browse the repository at this point in the history
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 <[email protected]>

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 <[email protected]>
  • Loading branch information
Anu6is authored and fusionjack committed Sep 8, 2014
1 parent aa731e1 commit 1501db3
Show file tree
Hide file tree
Showing 11 changed files with 638 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions packages/WallpaperCropper/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
package="com.android.wallpapercropper" >
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

<application android:requiredForAllUsers="true">
<activity
Expand All @@ -15,5 +18,16 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="LockscreenWallpaper"
android:theme="@style/Theme.WallpaperCropper"
android:label="@string/pick_lockscreen"
android:icon="@mipmap/ic_lockscreen_wallpaper"
android:finishOnCloseSystemDialogs="true">
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
34 changes: 34 additions & 0 deletions packages/WallpaperCropper/res/layout/actionbar_set_lockscreen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2013, 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"
style="?android:actionButtonStyle"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView style="?android:actionBarTabTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:paddingRight="20dp"
android:drawableLeft="@drawable/ic_actionbar_accept"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:text="@string/lockscreen_instructions" />
</FrameLayout>
32 changes: 32 additions & 0 deletions packages/WallpaperCropper/res/layout/blur_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2014, ParanoidAndroid 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/blur_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SeekBar
android:id="@+id/blur_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:progress="16"
android:max="25" />
</LinearLayout>
59 changes: 59 additions & 0 deletions packages/WallpaperCropper/res/layout/lockscreen_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2014, ParanoidAndroid 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.
*/
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lockscreen_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="@+id/picker_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
/>
</LinearLayout>
<ImageView android:id="@+id/lockscreen_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:id="@+id/lockscreen_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="@string/lockscreen_reset" />
<Button
android:id="@+id/lockscreen_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="@string/lockscreen_select" />
<Button
android:id="@+id/lockscreen_blur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="@string/lockscreen_blur" />
</RelativeLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions packages/WallpaperCropper/res/values/pa_strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 ParanoidAndroid 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 xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="pick_lockscreen">Lock screen</string>
<string name="lockscreen_reset">Reset</string>
<string name="lockscreen_select">Browse</string>
<string name="lockscreen_blur">Blur</string>
<string name="blur_radius">Blur radius</string>
<string name="lockscreen_instructions">Set lockscreen image</string>
<string name="lockscreen_image_set">Lockscreen image updated</string>
<string name="lockscreen_image_reset">Lockscreen image reset</string>
</resources>
Loading

0 comments on commit 1501db3

Please sign in to comment.