summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDanesh Mondegarian <daneshm90@gmail.com>2013-05-30 15:33:51 -0400
committerDanny Baumann <dannybaumann@web.de>2013-07-03 14:57:46 +0200
commitf6b181905d42a0360e612b4655e75253ecfa83bb (patch)
treec67d0994cf60243d69afd617ffbeede20d9e8311 /src
parent5aacfcbbe55f638d1f69933acb0821492c354b48 (diff)
downloadpackages_apps_settings-f6b181905d42a0360e612b4655e75253ecfa83bb.zip
packages_apps_settings-f6b181905d42a0360e612b4655e75253ecfa83bb.tar.gz
packages_apps_settings-f6b181905d42a0360e612b4655e75253ecfa83bb.tar.bz2
Lockscreen options : Camera/widgets toggle
As per https://jira.cyanogenmod.org/browse/CYAN-1243 this commit allows user to control visibility of widgets/camera on lockscreen. Change-Id: Idab2ff4f058e355a1e5936531d9a264b1fea16a1
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/SettingsPreferenceFragment.java7
-rw-r--r--src/com/android/settings/cyanogenmod/LockscreenInterface.java60
2 files changed, 57 insertions, 10 deletions
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index b961bbc..3a225f3 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -29,6 +29,7 @@ import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
+import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.text.TextUtils;
import android.util.Log;
@@ -313,6 +314,10 @@ public class SettingsPreferenceFragment extends PreferenceFragment implements Di
}
public boolean removePreferenceIfPackageNotInstalled(Preference preference) {
+ return removePreferenceIfPackageNotInstalled(preference, getPreferenceScreen());
+ }
+
+ public boolean removePreferenceIfPackageNotInstalled(Preference preference, PreferenceGroup parent) {
String intentUri = ((PreferenceScreen) preference).getIntent().toUri(1);
Pattern pattern = Pattern.compile("component=([^/]+)/");
Matcher matcher = pattern.matcher(intentUri);
@@ -323,7 +328,7 @@ public class SettingsPreferenceFragment extends PreferenceFragment implements Di
getPackageManager().getPackageInfo(packageName, 0);
} catch (NameNotFoundException e) {
Log.e(TAG, "package " + packageName + " not installed, hiding preference.");
- getPreferenceScreen().removePreference(preference);
+ parent.removePreference(preference);
return true;
}
}
diff --git a/src/com/android/settings/cyanogenmod/LockscreenInterface.java b/src/com/android/settings/cyanogenmod/LockscreenInterface.java
index 37d56e8..806a342 100644
--- a/src/com/android/settings/cyanogenmod/LockscreenInterface.java
+++ b/src/com/android/settings/cyanogenmod/LockscreenInterface.java
@@ -21,8 +21,12 @@ import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.admin.DeviceAdminReceiver;
+import android.app.admin.DevicePolicyManager;
import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
import android.content.ContentResolver;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
@@ -34,6 +38,7 @@ import android.os.UserHandle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
+import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.provider.MediaStore;
import android.provider.Settings;
@@ -64,13 +69,22 @@ public class LockscreenInterface extends SettingsPreferenceFragment implements
private static final String KEY_BACKGROUND = "lockscreen_background";
private static final String KEY_SCREEN_SECURITY = "screen_security";
+ private static final String LOCKSCREEN_GENERAL_CATEGORY = "lockscreen_general_category";
+ private static final String LOCKSCREEN_WIDGETS_CATEGORY = "lockscreen_widgets_category";
+ private static final String KEY_LOCKSCREEN_ENABLE_WIDGETS = "lockscreen_enable_widgets";
+ private static final String KEY_LOCKSCREEN_ENABLE_CAMERA = "lockscreen_enable_camera";
+
private ListPreference mCustomBackground;
private ListPreference mBatteryStatus;
private CheckBoxPreference mMaximizeWidgets;
private CheckBoxPreference mMusicControls;
+ private CheckBoxPreference mEnableWidgets;
+ private CheckBoxPreference mEnableCamera;
private File mWallpaperImage;
private File mWallpaperTemporary;
+ private DevicePolicyManager mDPM;
+ private ComponentName mDpmAdminName;
private boolean mIsPrimary;
@@ -83,6 +97,8 @@ public class LockscreenInterface extends SettingsPreferenceFragment implements
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.lockscreen_interface_settings);
+ PreferenceCategory generalCategory = (PreferenceCategory) findPreference(LOCKSCREEN_GENERAL_CATEGORY);
+ PreferenceCategory widgetsCategory = (PreferenceCategory) findPreference(LOCKSCREEN_WIDGETS_CATEGORY);
// Determine which user is logged in
mIsPrimary = UserHandle.myUserId() == UserHandle.USER_OWNER;
@@ -93,9 +109,9 @@ public class LockscreenInterface extends SettingsPreferenceFragment implements
mBatteryStatus.setOnPreferenceChangeListener(this);
}
- mMaximizeWidgets = (CheckBoxPreference)findPreference(KEY_LOCKSCREEN_MAXIMIZE_WIDGETS);
+ mMaximizeWidgets = (CheckBoxPreference) findPreference(KEY_LOCKSCREEN_MAXIMIZE_WIDGETS);
if (!Utils.isPhone(getActivity())) {
- getPreferenceScreen().removePreference(mMaximizeWidgets);
+ widgetsCategory.removePreference(mMaximizeWidgets);
mMaximizeWidgets = null;
} else {
mMaximizeWidgets.setOnPreferenceChangeListener(this);
@@ -106,15 +122,14 @@ public class LockscreenInterface extends SettingsPreferenceFragment implements
PreferenceScreen lockscreenButtons = (PreferenceScreen) findPreference(KEY_LOCKSCREEN_BUTTONS);
if (!hasButtons()) {
- getPreferenceScreen().removePreference(lockscreenButtons);
+ generalCategory.removePreference(lockscreenButtons);
}
} else {
// Secondary user is logged in, remove all primary user specific preferences
- PreferenceScreen prefScreen = getPreferenceScreen();
- prefScreen.removePreference(findPreference(KEY_SCREEN_SECURITY));
- prefScreen.removePreference(findPreference(KEY_ALWAYS_BATTERY));
- prefScreen.removePreference(findPreference(KEY_LOCKSCREEN_BUTTONS));
- prefScreen.removePreference(findPreference(KEY_LOCKSCREEN_MAXIMIZE_WIDGETS));
+ generalCategory.removePreference(findPreference(KEY_SCREEN_SECURITY));
+ widgetsCategory.removePreference(findPreference(KEY_LOCKSCREEN_MAXIMIZE_WIDGETS));
+ generalCategory.removePreference(findPreference(KEY_ALWAYS_BATTERY));
+ generalCategory.removePreference(findPreference(KEY_LOCKSCREEN_BUTTONS));
}
// This applies to all users
@@ -122,11 +137,23 @@ public class LockscreenInterface extends SettingsPreferenceFragment implements
mCustomBackground.setOnPreferenceChangeListener(this);
updateCustomBackgroundSummary();
+ mEnableWidgets = (CheckBoxPreference) findPreference(KEY_LOCKSCREEN_ENABLE_WIDGETS);
+ mEnableWidgets.setOnPreferenceChangeListener(this);
+ mEnableCamera = (CheckBoxPreference) findPreference(KEY_LOCKSCREEN_ENABLE_CAMERA);
+ mEnableCamera.setOnPreferenceChangeListener(this);
+
+ mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
+ mDpmAdminName = new ComponentName(getActivity(), DeviceAdminLockscreenReceiver.class);
+
+ boolean widgetsEnabled = mDPM.getKeyguardDisabledFeatures(null) == 0;
+ mEnableWidgets.setChecked(widgetsEnabled);
+ mEnableCamera.setChecked(!mDPM.getCameraDisabled(null));
+
mWallpaperImage = new File(getActivity().getFilesDir() + "/lockwallpaper");
mWallpaperTemporary = new File(getActivity().getCacheDir() + "/lockwallpaper.tmp");
// Don't display the lock clock preference if its not installed
- removePreferenceIfPackageNotInstalled(findPreference(KEY_LOCK_CLOCK));
+ removePreferenceIfPackageNotInstalled(findPreference(KEY_LOCK_CLOCK), widgetsCategory);
}
private void updateCustomBackgroundSummary() {
@@ -216,7 +243,20 @@ public class LockscreenInterface extends SettingsPreferenceFragment implements
} else if (preference == mCustomBackground) {
int selection = mCustomBackground.findIndexOfValue(objValue.toString());
return handleBackgroundSelection(selection);
+ } else if (preference == mEnableCamera) {
+ boolean value = (Boolean) objValue;
+ mDPM.setActiveAdmin(mDpmAdminName, true);
+ mDPM.setCameraDisabled(mDpmAdminName, !value);
+ return true;
+ } else if (preference == mEnableWidgets) {
+ boolean value = (Boolean) objValue;
+ mDPM.setActiveAdmin(mDpmAdminName, true);
+ mDPM.setKeyguardDisabledFeatures(mDpmAdminName, value
+ ? DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE
+ : DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL);
+ return true;
}
+
return false;
}
@@ -295,4 +335,6 @@ public class LockscreenInterface extends SettingsPreferenceFragment implements
return false;
}
+
+ public static class DeviceAdminLockscreenReceiver extends DeviceAdminReceiver {}
}