[2/2] OmniGears: lockscreen wallpaper config
Change-Id: Id9b1a8148fe88b6bf3c46271e5c593394df39f1e
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index 317ae84..3f2a38e 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -178,4 +178,10 @@
<string name="omniswitch_title">OmniSwitch</string>
<string name="doze_brightness_level_title">Brightness level</string>
+
+ <!-- Lock screen wallpaper -->
+ <string name="lockscreen_wallpaper_title">Wallpaper</string>
+ <string name="lockscreen_wallpaper_set_title">Set lock screen wallpaper</string>
+ <string name="lockscreen_wallpaper_clear_title">Clear lock screen wallpaper</string>
+
</resources>
diff --git a/res/xml/lockscreen_settings.xml b/res/xml/lockscreen_settings.xml
new file mode 100644
index 0000000..54d0927
--- /dev/null
+++ b/res/xml/lockscreen_settings.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The OmniROM Project
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ -->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+ <PreferenceCategory
+ android:key="lockscreen_wallpaper"
+ android:title="@string/lockscreen_wallpaper_title" >
+
+ <Preference
+ android:key="lockscreen_wallpaper_set"
+ android:title="@string/lockscreen_wallpaper_set_title"
+ android:persistent="false"/>
+
+ <Preference
+ android:key="lockscreen_wallpaper_clear"
+ android:title="@string/lockscreen_wallpaper_clear_title"
+ android:persistent="false"/>
+
+ </PreferenceCategory>
+</PreferenceScreen>
diff --git a/src/org/omnirom/omnigears/LockscreenSettings.java b/src/org/omnirom/omnigears/LockscreenSettings.java
new file mode 100644
index 0000000..e1ee563
--- /dev/null
+++ b/src/org/omnirom/omnigears/LockscreenSettings.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2015 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.omnirom.omnigears;
+
+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 com.android.settings.SettingsPreferenceFragment;
+
+public class LockscreenSettings extends SettingsPreferenceFragment {
+ public static final int IMAGE_PICK = 1;
+ public static final int SET_KEYGUARD_WALLPAPER = 2;
+
+ 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_settings);
+
+ 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();
+ 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);
+ startActivityForResult(intent, SET_KEYGUARD_WALLPAPER);
+ }
+ }
+ if (requestCode == SET_KEYGUARD_WALLPAPER && resultCode == Activity.RESULT_OK) {
+ finish();
+ }
+ }
+
+ 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();
+ }
+}