Skip to content

Commit

Permalink
LockscreenWallpaper: Use FB's WallpaperCropper
Browse files Browse the repository at this point in the history
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: SlimSaber/frameworks_base@9e55ef6

Change-Id: I4c70f3ca58afbbf9ddc542bd331bedb4a5cd63df
  • Loading branch information
fusionjack committed Aug 16, 2015
1 parent c633e1b commit c347ba1
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 0 deletions.
7 changes: 7 additions & 0 deletions res/values/slim_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,13 @@
<string name="captive_portal_detection">Captive portal detection</string>
<string name="captive_portal_detection_summary">If disabled, a connection to google servers is not required in order to detect data connection.</string>

<!-- Lockscreen wallpaper -->
<string name="lockscreen_wallpaper_title">Wallpaper</string>
<string name="lockscreen_wallpaper_summary">Set lockscreen wallpaper</string>
<string name="lockscreen_wallpaper_set_title">Set lock screen wallpaper</string>
<string name="lockscreen_wallpaper_clear_title">Clear lock screen wallpaper</string>
<string name="reset_lockscreen_wallpaper">Set to default</string>

<!-- LTO download data over wi-fi only -->
<string name="lto_download_data_wifi_only">GPS assisted data download</string>
<string name="lto_download_data_wifi_only_on">Over any networks</string>
Expand Down
35 changes: 35 additions & 0 deletions res/xml/lockscreen_wallpaper.xml
Original file line number Diff line number Diff line change
@@ -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>
8 changes: 8 additions & 0 deletions res/xml/security_settings_biometric_weak.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
<extra android:name="fragment" android:value="com.android.settings.slim.fragments.LockscreenShortcutFragment" />
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_wallpaper"
android:title="@string/lockscreen_wallpaper_title"
android:summary="@string/lockscreen_wallpaper_summary"
android:persistent="false"
android:fragment="com.android.settings.slim.LockscreenWallpaper">
</PreferenceScreen>

<SwitchPreference
android:key="lockscreen_bottom_shortcuts"
android:title="@string/lockscreen_bottom_shortcuts_title"/>
Expand Down
8 changes: 8 additions & 0 deletions res/xml/security_settings_chooser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
<extra android:name="fragment" android:value="com.android.settings.slim.fragments.LockscreenShortcutFragment" />
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_wallpaper"
android:title="@string/lockscreen_wallpaper_title"
android:summary="@string/lockscreen_wallpaper_summary"
android:persistent="false"
android:fragment="com.android.settings.slim.LockscreenWallpaper">
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_weather"
android:title="@string/lock_screen_weather_settings_title"
Expand Down
8 changes: 8 additions & 0 deletions res/xml/security_settings_lockscreen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
android:title="@string/owner_info_settings_title"
android:summary="@string/owner_info_settings_summary"/>

<PreferenceScreen
android:key="lockscreen_wallpaper"
android:title="@string/lockscreen_wallpaper_title"
android:summary="@string/lockscreen_wallpaper_summary"
android:persistent="false"
android:fragment="com.android.settings.slim.LockscreenWallpaper">
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_weather"
android:title="@string/lock_screen_weather_settings_title"
Expand Down
8 changes: 8 additions & 0 deletions res/xml/security_settings_password.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
<extra android:name="fragment" android:value="com.android.settings.slim.fragments.LockscreenShortcutFragment" />
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_wallpaper"
android:title="@string/lockscreen_wallpaper_title"
android:summary="@string/lockscreen_wallpaper_summary"
android:persistent="false"
android:fragment="com.android.settings.slim.LockscreenWallpaper">
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_weather"
android:title="@string/lock_screen_weather_settings_title"
Expand Down
8 changes: 8 additions & 0 deletions res/xml/security_settings_pattern.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
<extra android:name="fragment" android:value="com.android.settings.slim.fragments.LockscreenShortcutFragment" />
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_wallpaper"
android:title="@string/lockscreen_wallpaper_title"
android:summary="@string/lockscreen_wallpaper_summary"
android:persistent="false"
android:fragment="com.android.settings.slim.LockscreenWallpaper">
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_weather"
android:title="@string/lock_screen_weather_settings_title"
Expand Down
8 changes: 8 additions & 0 deletions res/xml/security_settings_pin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
<extra android:name="fragment" android:value="com.android.settings.slim.fragments.LockscreenShortcutFragment" />
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_wallpaper"
android:title="@string/lockscreen_wallpaper_title"
android:summary="@string/lockscreen_wallpaper_summary"
android:persistent="false"
android:fragment="com.android.settings.slim.LockscreenWallpaper">
</PreferenceScreen>

<PreferenceScreen
android:key="lockscreen_weather"
android:summary="@string/lock_screen_weather_settings_summary"
Expand Down
90 changes: 90 additions & 0 deletions src/com/android/settings/slim/LockscreenWallpaper.java
Original file line number Diff line number Diff line change
@@ -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 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();
}
}

0 comments on commit c347ba1

Please sign in to comment.