From c347ba1d7ea8fa3b981e09f478377531d2fbfa66 Mon Sep 17 00:00:00 2001 From: fusionjack Date: Sun, 16 Aug 2015 22:15:35 +0200 Subject: [PATCH] LockscreenWallpaper: Use FB's WallpaperCropper Thanks to OmniROM for these following commits: * https://gerrit.omnirom.org/#/c/14299/ * https://gerrit.omnirom.org/#/c/14345/ * https://gerrit.omnirom.org/#/c/14354/ FB part: https://github.com/SlimSaber/frameworks_base/commit/9e55ef6c0d1ec6316c20b07d7a425a2929ad33cf Change-Id: I4c70f3ca58afbbf9ddc542bd331bedb4a5cd63df --- res/values/slim_strings.xml | 7 ++ res/xml/lockscreen_wallpaper.xml | 35 ++++++++ res/xml/security_settings_biometric_weak.xml | 8 ++ res/xml/security_settings_chooser.xml | 8 ++ res/xml/security_settings_lockscreen.xml | 8 ++ res/xml/security_settings_password.xml | 8 ++ res/xml/security_settings_pattern.xml | 8 ++ res/xml/security_settings_pin.xml | 8 ++ .../settings/slim/LockscreenWallpaper.java | 90 +++++++++++++++++++ 9 files changed, 180 insertions(+) create mode 100644 res/xml/lockscreen_wallpaper.xml create mode 100644 src/com/android/settings/slim/LockscreenWallpaper.java diff --git a/res/values/slim_strings.xml b/res/values/slim_strings.xml index 577982ec342..eb4ad8d0dbb 100644 --- a/res/values/slim_strings.xml +++ b/res/values/slim_strings.xml @@ -1292,6 +1292,13 @@ Captive portal detection If disabled, a connection to google servers is not required in order to detect data connection. + + Wallpaper + Set lockscreen wallpaper + Set lock screen wallpaper + Clear lock screen wallpaper + Set to default + GPS assisted data download Over any networks diff --git a/res/xml/lockscreen_wallpaper.xml b/res/xml/lockscreen_wallpaper.xml new file mode 100644 index 00000000000..54d092712a7 --- /dev/null +++ b/res/xml/lockscreen_wallpaper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + diff --git a/res/xml/security_settings_biometric_weak.xml b/res/xml/security_settings_biometric_weak.xml index 84da1ca2770..522dcb8f925 100644 --- a/res/xml/security_settings_biometric_weak.xml +++ b/res/xml/security_settings_biometric_weak.xml @@ -76,6 +76,14 @@ + + + diff --git a/res/xml/security_settings_chooser.xml b/res/xml/security_settings_chooser.xml index a28ca582e33..4669186772d 100644 --- a/res/xml/security_settings_chooser.xml +++ b/res/xml/security_settings_chooser.xml @@ -51,6 +51,14 @@ + + + + + + + + + + + + + + + . + * + */ +package com.android.settings.slim; + +import android.app.Activity; +import android.app.WallpaperManager; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.PreferenceScreen; +import android.widget.Toast; + +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; + +public class LockscreenWallpaper extends SettingsPreferenceFragment { + public static final int IMAGE_PICK = 1; + + private static final String KEY_WALLPAPER_SET = "lockscreen_wallpaper_set"; + private static final String KEY_WALLPAPER_CLEAR = "lockscreen_wallpaper_clear"; + + private Preference mSetWallpaper; + private Preference mClearWallpaper; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.lockscreen_wallpaper); + + mSetWallpaper = (Preference) findPreference(KEY_WALLPAPER_SET); + mClearWallpaper = (Preference) findPreference(KEY_WALLPAPER_CLEAR); + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + if (preference == mSetWallpaper) { + setKeyguardWallpaper(); + return true; + } else if (preference == mClearWallpaper) { + clearKeyguardWallpaper(); + Toast.makeText(getView().getContext(), getString(R.string.reset_lockscreen_wallpaper), + Toast.LENGTH_LONG).show(); + return true; + } + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == IMAGE_PICK && resultCode == Activity.RESULT_OK) { + if (data != null && data.getData() != null) { + Uri uri = data.getData(); + Intent intent = new Intent(); + intent.setClassName("com.android.wallpapercropper", "com.android.wallpapercropper.WallpaperCropActivity"); + intent.putExtra("keyguardMode", "1"); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setData(uri); + startActivity(intent); + } + } + } + + private void setKeyguardWallpaper() { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); + startActivityForResult(intent, IMAGE_PICK); + } + + private void clearKeyguardWallpaper() { + WallpaperManager wallpaperManager = null; + wallpaperManager = WallpaperManager.getInstance(getActivity()); + wallpaperManager.clearKeyguardWallpaper(); + } +}