[2/2] OmniGears: ActiveDisplay (rework interface)

really fix AD buggy stuff
tested with Music play
tested with No lockscreen
tested with faster screen turn off
check all sensor going off if AD not Showing or Disabled
fix notification posted/removed
make AD using System Window so it will covered all screen
fix Navbar translucent if Lockscreen Blur merged :P
now using Rounded Image
also introduce new RoundedImageView widget
 courtesy of @vinc3m1 (thanks)
fix build
fix sometimes screen turn off after unlock because screen timeout (hopefully)
now using new parser to get Notification data (thanks @Achep for the parser)
rework lightsensor manager
add NotificationUtils
fix brightness sometimes not changing

add support applications privacy mode (will not show content message if enable on each app)
see http://jira.omnirom.org/browse/OMNI-600

allow bypass AD if no notification and lockscreen is secure
see http://jira.omnirom.org/browse/OMNI-594

fix proximity always enable after adding new feature allow bypass AD
fix parsing notification data from app with targetSDK < 17

fix excluded app value (no body notice this broken since AD merged into OmniRom xD )

add option to allow bypass AD

rebased
change string to better explanation for feature
thanks @Pulser and @Jiangyi

Change-Id: Iec1915ec5faeaaa6b599916bd4195ed59f2e1653
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index b533ca3..36199a1 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -237,30 +237,37 @@
     <string name="ad_enable_title">Enable</string>
     <string name="ad_enable_summary_on">Active display enabled</string>
     <string name="ad_enable_summary_off">Active display disabled</string>
+    <string name="ad_bypass_title">Bypass active display</string>
+    <string name="ad_bypass_summary">When no notifications exist, pocket mode will launch the lockscreen</string>
     <string name="ad_text_title">Notification text</string>
     <string name="ad_text_summary">Show the notification text around the ring</string>
-    <string name="ad_all_notifications_title">All notifications</string>
-    <string name="ad_all_notifications_summary">Show all notifications including ongoing, non-clearable notifications</string>
+    <string name="ad_content_title">Use custom notification view</string>
+    <string name="ad_content_summary">Use Active display style for showing notification details, rather than system style</string>
+    <string name="ad_all_notifications_title">Ongoing notifications</string>
+    <string name="ad_all_notifications_summary">Show ongoing, non-clearable notifications</string>
     <string name="ad_hide_low_priority_title">Hide low priority</string>
-    <string name="ad_hide_low_priority_summary">Hide low priority notifications such as those from Google Now</string>
+    <string name="ad_hide_low_priority_summary">Hide notifications marked as low priority</string>
     <string name="ad_pocket_mode_title">Pocket mode</string>
-    <string name="ad_pocket_mode_summary">Show active display notifications when you take the device out of your pocket</string>
-    <string name="ad_redisplay_title">Redisplay notifications</string>
+    <string name="ad_pocket_mode_summary">Show pending notifications after taking the device out of your pocket</string>
+    <string name="ad_redisplay_title">Re-display notifications</string>
     <string name="ad_timeout_title">Display timeout</string>
-    <string name="ad_threshold_title">Threshold to proximity</string>
+    <string name="ad_threshold_title">Proximity time threshold</string>
+    <string name="ad_threshold_summary">Duration the proximity sensor must be covered before Active display is shown</string>
     <string name="ad_brightness_title">Notification brightness</string>
-    <string name="ad_customizations_title">Customizations</string>
-    <string name="ad_excluded_apps_title">Excluded applications</string>
-    <string name="ad_excluded_apps_summary">Excluded applications will not show up in active display</string>
+    <string name="ad_customizations_title">Advanced settings</string>
+    <string name="ad_excluded_apps_title">Excluded apps</string>
+    <string name="ad_excluded_apps_summary">No notifications will be shown for these apps</string>
+    <string name="ad_privacy_apps_title">Privacy mode</string>
+    <string name="ad_privacy_apps_summary">No details will be shown for notifications belonging to these apps</string>
     <string name="ad_show_date_title">Show date</string>
     <string name="ad_show_ampm_title">Show AM/PM</string>
     <string name="ad_sunlight_mode_title">Sunlight mode</string>
-    <string name="ad_brightness_summary">Brightness level for displaying notifications when automatic brightness is not enabled</string>
+    <string name="ad_brightness_summary">Active display brightness (Only applies when automatic brightness is disabled)</string>
     <string name="ad_show_date_summary">Show the date above the clock</string>
-    <string name="ad_show_ampm_summary">Show AM/PM indicator next to time when using 12hour format</string>
-    <string name="ad_sunlight_mode_summary">Invert the colors when in areas with bright light such as direct sunlight</string>
-    <string name="ad_turnoff_mode_title">Turn off display</string>
-    <string name="ad_turnoff_mode_summary">Turn off display if the device gets pocketed again and was turned on by active display</string>
+    <string name="ad_show_ampm_summary">Show AM/PM indicator when using the 12-hour time format</string>
+    <string name="ad_sunlight_mode_summary">Invert colors when in bright areas such as under direct sunlight</string>
+    <string name="ad_turnoff_mode_title">Auto-sleep display</string>
+    <string name="ad_turnoff_mode_summary">Put device to sleep again if it was woken by Pocket mode, and is returned to the pocket</string>
     <string name="ad_redisplay_never">Never</string>
     <string name="ad_redisplay_1m">1 minute</string>
     <string name="ad_redisplay_5m">5 minutes</string>
@@ -284,7 +291,8 @@
     <string name="ad_pocket_mode_off">Off</string>
     <string name="ad_pocket_mode_notifications">Notifications only</string>
     <string name="ad_pocket_mode_always">Always</string>
-    <string name="bars_and_menus_category_recent_panel_title" >Recents view</string>
+
+    <string name="bars_and_menus_category_recent_panel_title">Recents view</string>
 
     <!-- Recents clear all -->
     <string name="show_recent_clear_all_button_title">Clear all button</string>
diff --git a/res/xml/active_display_settings.xml b/res/xml/active_display_settings.xml
index cc5945b..b7f396d 100644
--- a/res/xml/active_display_settings.xml
+++ b/res/xml/active_display_settings.xml
@@ -25,6 +25,20 @@
         android:summaryOn="@string/ad_enable_summary_on" />
 
     <CheckBoxPreference
+        android:key="ad_content"
+        android:persistent="false"
+        android:title="@string/ad_content_title"
+        android:summary="@string/ad_content_summary"
+        android:dependency="ad_enable"/>
+
+    <CheckBoxPreference
+        android:key="ad_bypass"
+        android:persistent="false"
+        android:title="@string/ad_bypass_title"
+        android:summary="@string/ad_bypass_summary"
+        android:dependency="ad_enable"/>
+
+    <CheckBoxPreference
         android:key="ad_text"
         android:persistent="false"
         android:title="@string/ad_text_title"
@@ -81,6 +95,13 @@
             android:summary="@string/ad_excluded_apps_summary"
             android:dependency="ad_enable" />
 
+        <org.omnirom.omnigears.chameleonos.AppMultiSelectListPreference
+            android:key="ad_privacy_apps"
+            android:persistent="false"
+            android:title="@string/ad_privacy_apps_title"
+            android:summary="@string/ad_privacy_apps_summary"
+            android:dependency="ad_enable" />
+
         <CheckBoxPreference
             android:key="ad_show_date"
             android:persistent="false"
@@ -106,6 +127,7 @@
             android:key="ad_threshold"
             android:persistent="false"
             android:dialogTitle="@string/ad_threshold_title"
+            android:summary="@string/ad_threshold_summary"
             android:title="@string/ad_threshold_title"
             android:entries="@array/ad_threshold_entries"
             android:entryValues="@array/ad_threshold_values"
@@ -125,11 +147,8 @@
             android:persistent="false"
             android:title="@string/ad_brightness_title"
             android:summary="@string/ad_brightness_summary"
-            android:max="100"
-            settings:min="0"
             settings:unitsLeft=""
             settings:unitsRight="%"
-            android:defaultValue="100"
             android:dependency="ad_enable" />
 
 </PreferenceScreen>
diff --git a/src/org/omnirom/omnigears/chameleonos/ActiveDisplaySettings.java b/src/org/omnirom/omnigears/chameleonos/ActiveDisplaySettings.java
index 4d0bed6..6b40642 100644
--- a/src/org/omnirom/omnigears/chameleonos/ActiveDisplaySettings.java
+++ b/src/org/omnirom/omnigears/chameleonos/ActiveDisplaySettings.java
@@ -16,9 +16,12 @@
 
 package org.omnirom.omnigears.chameleonos;
 
+import android.app.Activity;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.hardware.SensorManager;
 import android.os.Bundle;
+import android.os.PowerManager;
 import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
@@ -26,6 +29,7 @@
 import android.preference.PreferenceScreen;
 import android.preference.SwitchPreference;
 import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
 import android.text.TextUtils;
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
@@ -43,12 +47,15 @@
 
     private static final String KEY_ENABLED = "ad_enable";
     private static final String KEY_SHOW_TEXT = "ad_text";
+    private static final String KEY_SHOW_CONTENT = "ad_content";
+    private static final String KEY_BYPASS_CONTENT = "ad_bypass";
     private static final String KEY_ALL_NOTIFICATIONS = "ad_all_notifications";
     private static final String KEY_HIDE_LOW_PRIORITY = "ad_hide_low_priority";
     private static final String KEY_POCKET_MODE = "ad_pocket_mode";
     private static final String KEY_SUNLIGHT_MODE = "ad_sunlight_mode";
     private static final String KEY_REDISPLAY = "ad_redisplay";
     private static final String KEY_EXCLUDED_APPS = "ad_excluded_apps";
+    private static final String KEY_PRIVACY_APPS = "ad_privacy_apps";
     private static final String KEY_SHOW_DATE = "ad_show_date";
     private static final String KEY_SHOW_AMPM = "ad_show_ampm";
     private static final String KEY_BRIGHTNESS = "ad_brightness";
@@ -56,14 +63,20 @@
     private static final String KEY_THRESHOLD = "ad_threshold";
     private static final String KEY_TURNOFF_MODE = "ad_turnoff_mode";
 
+    private ContentResolver mResolver;
+    private Context mContext;
+
     private SwitchPreference mEnabledPref;
     private CheckBoxPreference mShowTextPref;
+    private CheckBoxPreference mShowContentPref;
+    private CheckBoxPreference mBypassPref;
     private CheckBoxPreference mAllNotificationsPref;
     private CheckBoxPreference mHideLowPriorityPref;
     private ListPreference mPocketModePref;
     private CheckBoxPreference mSunlightModePref;
     private ListPreference mRedisplayPref;
     private AppMultiSelectListPreference mExcludedAppsPref;
+    private AppMultiSelectListPreference mPrivacyAppsPref;
     private CheckBoxPreference mShowDatePref;
     private CheckBoxPreference mShowAmPmPref;
     private SeekBarPreference mBrightnessLevel;
@@ -77,43 +90,55 @@
 
         addPreferencesFromResource(R.xml.active_display_settings);
 
+        mContext = getActivity().getApplicationContext();
+        mResolver = mContext.getContentResolver();
+
         mEnabledPref = (SwitchPreference) findPreference(KEY_ENABLED);
-        mEnabledPref.setChecked((Settings.System.getInt(getContentResolver(),
+        mEnabledPref.setChecked((Settings.System.getInt(mResolver,
                 Settings.System.ENABLE_ACTIVE_DISPLAY, 0) == 1));
         mEnabledPref.setOnPreferenceChangeListener(this);
 
         mShowTextPref = (CheckBoxPreference) findPreference(KEY_SHOW_TEXT);
-        mShowTextPref.setChecked((Settings.System.getInt(getContentResolver(),
+        mShowTextPref.setChecked((Settings.System.getInt(mResolver,
                 Settings.System.ACTIVE_DISPLAY_TEXT, 0) == 1));
 
+        mShowContentPref = (CheckBoxPreference) findPreference(KEY_SHOW_CONTENT);
+        mShowContentPref.setChecked((Settings.System.getInt(mResolver,
+                Settings.System.ACTIVE_DISPLAY_CONTENT, 1) != 0));
+
+        mBypassPref = (CheckBoxPreference) findPreference(KEY_BYPASS_CONTENT);
+        mBypassPref.setChecked((Settings.System.getInt(mResolver,
+                Settings.System.ACTIVE_DISPLAY_BYPASS, 1) != 0));
+
         mAllNotificationsPref = (CheckBoxPreference) findPreference(KEY_ALL_NOTIFICATIONS);
-        mAllNotificationsPref.setChecked((Settings.System.getInt(getContentResolver(),
+        mAllNotificationsPref.setChecked((Settings.System.getInt(mResolver,
                 Settings.System.ACTIVE_DISPLAY_ALL_NOTIFICATIONS, 0) == 1));
 
         mHideLowPriorityPref = (CheckBoxPreference) findPreference(KEY_HIDE_LOW_PRIORITY);
-        mHideLowPriorityPref.setChecked((Settings.System.getInt(getContentResolver(),
+        mHideLowPriorityPref.setChecked((Settings.System.getInt(mResolver,
                 Settings.System.ACTIVE_DISPLAY_HIDE_LOW_PRIORITY_NOTIFICATIONS, 0) == 1));
 
         mPocketModePref = (ListPreference) findPreference(KEY_POCKET_MODE);
-            mPocketModePref.setOnPreferenceChangeListener(this);
-            int mode = Settings.System.getInt(getContentResolver(),
+        mPocketModePref.setOnPreferenceChangeListener(this);
+        int mode = Settings.System.getInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_POCKET_MODE, 0);
-            mPocketModePref.setValue(String.valueOf(mode));
-            updatePocketModeSummary(mode);
+        mPocketModePref.setValue(String.valueOf(mode));
+        updatePocketModeSummary(mode);
         if (!hasProximitySensor()) {
             getPreferenceScreen().removePreference(mPocketModePref);
         }
+
         mSunlightModePref = (CheckBoxPreference) findPreference(KEY_SUNLIGHT_MODE);
-        mSunlightModePref.setChecked((Settings.System.getInt(getContentResolver(),
+        mSunlightModePref.setChecked((Settings.System.getInt(mResolver,
                 Settings.System.ACTIVE_DISPLAY_SUNLIGHT_MODE, 0) == 1));
         if (!hasLightSensor()) {
-                getPreferenceScreen().removePreference(mSunlightModePref);
+            getPreferenceScreen().removePreference(mSunlightModePref);
         }
 
         PreferenceScreen prefSet = getPreferenceScreen();
         mRedisplayPref = (ListPreference) prefSet.findPreference(KEY_REDISPLAY);
         mRedisplayPref.setOnPreferenceChangeListener(this);
-        long timeout = Settings.System.getLong(getContentResolver(),
+        long timeout = Settings.System.getLong(mResolver,
                 Settings.System.ACTIVE_DISPLAY_REDISPLAY, 0);
         mRedisplayPref.setValue(String.valueOf(timeout));
         updateRedisplaySummary(timeout);
@@ -123,45 +148,66 @@
         if (excludedApps != null) mExcludedAppsPref.setValues(excludedApps);
         mExcludedAppsPref.setOnPreferenceChangeListener(this);
 
+        mPrivacyAppsPref = (AppMultiSelectListPreference) findPreference(KEY_PRIVACY_APPS);
+        Set<String> privacyApps = getPrivacyApps();
+        if (privacyApps != null) mPrivacyAppsPref.setValues(privacyApps);
+        mPrivacyAppsPref.setOnPreferenceChangeListener(this);
+
         mShowDatePref = (CheckBoxPreference) findPreference(KEY_SHOW_DATE);
-        mShowDatePref.setChecked((Settings.System.getInt(getContentResolver(),
+        mShowDatePref.setChecked((Settings.System.getInt(mResolver,
                 Settings.System.ACTIVE_DISPLAY_SHOW_DATE, 0) == 1));
 
         mShowAmPmPref = (CheckBoxPreference) findPreference(KEY_SHOW_AMPM);
-        mShowAmPmPref.setChecked((Settings.System.getInt(getContentResolver(),
+        mShowAmPmPref.setChecked((Settings.System.getInt(mResolver,
                 Settings.System.ACTIVE_DISPLAY_SHOW_AMPM, 0) == 1));
 
+        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+        int minimumBacklight = pm.getMinimumScreenBrightnessSetting();
+        int maximumBacklight = pm.getMaximumScreenBrightnessSetting();
+
         mBrightnessLevel = (SeekBarPreference) findPreference(KEY_BRIGHTNESS);
-        mBrightnessLevel.setValue(Settings.System.getInt(getContentResolver(),
-                Settings.System.ACTIVE_DISPLAY_BRIGHTNESS, 100));
+        mBrightnessLevel.setMaxValue(maximumBacklight - minimumBacklight);
+        mBrightnessLevel.setMinValue(minimumBacklight);
+        mBrightnessLevel.setValue(Settings.System.getInt(mResolver,
+                Settings.System.ACTIVE_DISPLAY_BRIGHTNESS, maximumBacklight));
         mBrightnessLevel.setOnPreferenceChangeListener(this);
 
+        try {
+            if (Settings.System.getInt(mResolver,
+                    Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
+                mBrightnessLevel.setEnabled(false);
+                mBrightnessLevel.setSummary(R.string.status_bar_toggle_info);
+            }
+        } catch (SettingNotFoundException e) {
+        }
+
         mDisplayTimeout = (ListPreference) prefSet.findPreference(KEY_TIMEOUT);
         mDisplayTimeout.setOnPreferenceChangeListener(this);
-        timeout = Settings.System.getLong(getContentResolver(),
+        timeout = Settings.System.getLong(mResolver,
                 Settings.System.ACTIVE_DISPLAY_TIMEOUT, 8000L);
         mDisplayTimeout.setValue(String.valueOf(timeout));
         updateTimeoutSummary(timeout);
 
         mProximityThreshold = (ListPreference) prefSet.findPreference(KEY_THRESHOLD);
         mProximityThreshold.setOnPreferenceChangeListener(this);
-        long threshold = Settings.System.getLong(getContentResolver(),
+        long threshold = Settings.System.getLong(mResolver,
                 Settings.System.ACTIVE_DISPLAY_THRESHOLD, 5000L);
         mProximityThreshold.setValue(String.valueOf(threshold));
         updateThresholdSummary(threshold);
 
         mTurnOffModePref = (CheckBoxPreference) findPreference(KEY_TURNOFF_MODE);
-        mTurnOffModePref.setChecked((Settings.System.getInt(getContentResolver(),
+        mTurnOffModePref.setChecked((Settings.System.getInt(mResolver,
                 Settings.System.ACTIVE_DISPLAY_TURNOFF_MODE, 0) == 1));
     }
 
+    @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         if (preference == mRedisplayPref) {
             int timeout = Integer.valueOf((String) newValue);
             updateRedisplaySummary(timeout);
             return true;
         } else if (preference == mEnabledPref) {
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ENABLE_ACTIVE_DISPLAY,
                     ((Boolean) newValue).booleanValue() ? 1 : 0);
             return true;
@@ -172,9 +218,12 @@
         } else if (preference == mExcludedAppsPref) {
             storeExcludedApps((Set<String>) newValue);
             return true;
+        } else if (preference == mPrivacyAppsPref) {
+            storePrivacyApps((Set<String>) newValue);
+            return true;
         } else if (preference == mBrightnessLevel) {
             int brightness = ((Integer)newValue).intValue();
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_BRIGHTNESS, brightness);
             return true;
         } else if (preference == mDisplayTimeout) {
@@ -192,40 +241,49 @@
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
         boolean value;
-
         if (preference == mShowTextPref) {
             value = mShowTextPref.isChecked();
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_TEXT,
                     value ? 1 : 0);
+        } else if (preference == mShowContentPref) {
+            value = mShowContentPref.isChecked();
+            Settings.System.putInt(mResolver,
+                    Settings.System.ACTIVE_DISPLAY_CONTENT,
+                    value ? 1 : 0);
+        } else if (preference == mBypassPref) {
+            value = mBypassPref.isChecked();
+            Settings.System.putInt(mResolver,
+                    Settings.System.ACTIVE_DISPLAY_BYPASS,
+                    value ? 1 : 0);
         } else if (preference == mAllNotificationsPref) {
             value = mAllNotificationsPref.isChecked();
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_ALL_NOTIFICATIONS,
                     value ? 1 : 0);
         } else if (preference == mHideLowPriorityPref) {
             value = mHideLowPriorityPref.isChecked();
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_HIDE_LOW_PRIORITY_NOTIFICATIONS,
                     value ? 1 : 0);
         } else if (preference == mSunlightModePref) {
             value = mSunlightModePref.isChecked();
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_SUNLIGHT_MODE,
                     value ? 1 : 0);
         } else if (preference == mShowDatePref) {
             value = mShowDatePref.isChecked();
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_SHOW_DATE,
                     value ? 1 : 0);
         } else if (preference == mShowAmPmPref) {
             value = mShowAmPmPref.isChecked();
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_SHOW_AMPM,
                     value ? 1 : 0);
         } else if (preference == mTurnOffModePref) {
             value = mTurnOffModePref.isChecked();
-            Settings.System.putInt(getContentResolver(),
+            Settings.System.putInt(mResolver,
                     Settings.System.ACTIVE_DISPLAY_TURNOFF_MODE,
                     value ? 1 : 0);
         } else {
@@ -238,20 +296,20 @@
     private void updatePocketModeSummary(int value) {
         mPocketModePref.setSummary(
             mPocketModePref.getEntries()[mPocketModePref.findIndexOfValue("" + value)]);
-        Settings.System.putInt(getContentResolver(),
+        Settings.System.putInt(mResolver,
             Settings.System.ACTIVE_DISPLAY_POCKET_MODE, value);
     }
 
     private void updateRedisplaySummary(long value) {
         mRedisplayPref.setSummary(mRedisplayPref.getEntries()[mRedisplayPref.findIndexOfValue("" + value)]);
-        Settings.System.putLong(getContentResolver(),
+        Settings.System.putLong(mResolver,
                 Settings.System.ACTIVE_DISPLAY_REDISPLAY, value);
     }
 
     private void updateTimeoutSummary(long value) {
         try {
             mDisplayTimeout.setSummary(mDisplayTimeout.getEntries()[mDisplayTimeout.findIndexOfValue("" + value)]);
-            Settings.System.putLong(getContentResolver(),
+            Settings.System.putLong(mResolver,
                     Settings.System.ACTIVE_DISPLAY_TIMEOUT, value);
         } catch (ArrayIndexOutOfBoundsException e) {
         }
@@ -260,24 +318,24 @@
     private void updateThresholdSummary(long value) {
         try {
             mProximityThreshold.setSummary(mProximityThreshold.getEntries()[mProximityThreshold.findIndexOfValue("" + value)]);
-            Settings.System.putLong(getContentResolver(),
+            Settings.System.putLong(mResolver,
                     Settings.System.ACTIVE_DISPLAY_THRESHOLD, value);
         } catch (ArrayIndexOutOfBoundsException e) {
         }
     }
 
     private boolean hasProximitySensor() {
-        SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
+        SensorManager sm = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
         return sm.getDefaultSensor(TYPE_PROXIMITY) != null;
     }
 
     private boolean hasLightSensor() {
-        SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
+        SensorManager sm = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
         return sm.getDefaultSensor(TYPE_LIGHT) != null;
     }
 
     private Set<String> getExcludedApps() {
-        String excluded = Settings.System.getString(getContentResolver(),
+        String excluded = Settings.System.getString(mResolver,
                 Settings.System.ACTIVE_DISPLAY_EXCLUDED_APPS);
         if (TextUtils.isEmpty(excluded))
             return null;
@@ -293,7 +351,28 @@
             builder.append(value);
             delimiter = "|";
         }
-        Settings.System.putString(getContentResolver(),
+        Settings.System.putString(mResolver,
                 Settings.System.ACTIVE_DISPLAY_EXCLUDED_APPS, builder.toString());
     }
+
+    private Set<String> getPrivacyApps() {
+        String privacies = Settings.System.getString(mResolver,
+                Settings.System.ACTIVE_DISPLAY_PRIVACY_APPS);
+        if (TextUtils.isEmpty(privacies))
+            return null;
+
+        return new HashSet<String>(Arrays.asList(privacies.split("\\|")));
+    }
+
+    private void storePrivacyApps(Set<String> values) {
+        StringBuilder builder = new StringBuilder();
+        String delimiter = "";
+        for (String value : values) {
+            builder.append(delimiter);
+            builder.append(value);
+            delimiter = "|";
+        }
+        Settings.System.putString(mResolver,
+                Settings.System.ACTIVE_DISPLAY_PRIVACY_APPS, builder.toString());
+    }
 }
diff --git a/src/org/omnirom/omnigears/chameleonos/AppMultiSelectListPreference.java b/src/org/omnirom/omnigears/chameleonos/AppMultiSelectListPreference.java
index 137a7fa..6600a47 100644
--- a/src/org/omnirom/omnigears/chameleonos/AppMultiSelectListPreference.java
+++ b/src/org/omnirom/omnigears/chameleonos/AppMultiSelectListPreference.java
@@ -101,6 +101,10 @@
         persistStringSet(values);
     }
 
+    public void setClearValues() {
+        mValues.clear();
+    }
+
     /**
      * Retrieves the current value of the key.
      */
diff --git a/src/org/omnirom/omnigears/chameleonos/SeekBarPreference.java b/src/org/omnirom/omnigears/chameleonos/SeekBarPreference.java
index d573cbc..50c83e5 100644
--- a/src/org/omnirom/omnigears/chameleonos/SeekBarPreference.java
+++ b/src/org/omnirom/omnigears/chameleonos/SeekBarPreference.java
@@ -73,17 +73,16 @@
             String newInterval = attrs.getAttributeValue(SETTINGS, "interval");
             if(newInterval != null)
                 mInterval = Integer.parseInt(newInterval);
-        }
-        catch(Exception e) {
+        } catch(Exception e) {
             Log.e(TAG, "Invalid interval value", e);
         }
     }
-    
+
     private String getAttributeStringValue(AttributeSet attrs, String namespace, String name, String defaultValue) {
         String value = attrs.getAttributeValue(namespace, name);
-        if(value == null)
+        if(value == null) {
             value = defaultValue;
-        
+        }
         return value;
     }
 
@@ -91,10 +90,12 @@
     public void onDependencyChanged(Preference dependency, boolean disableDependent) {
         super.onDependencyChanged(dependency, disableDependent);
         this.setShouldDisableView(true);
-        if (mTitle != null)
+        if (mTitle != null) {
             mTitle.setEnabled(!disableDependent);
-        if (mSeekBar != null)
+        }
+        if (mSeekBar != null) {
             mSeekBar.setEnabled(!disableDependent);
+        }
     }
 
     @Override
@@ -105,19 +106,16 @@
             LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             layout = (RelativeLayout)mInflater.inflate(R.layout.seek_bar_preference, parent, false);
             mTitle = (TextView) layout.findViewById(android.R.id.title);
-        }
-        catch(Exception e)
-        {
+        } catch(Exception e) {
             Log.e(TAG, "Error creating seek bar preference", e);
         }
         return layout;
     }
-    
+
     @Override
     public void onBindView(View view) {
         super.onBindView(view);
-        try
-        {
+        try {
             // move our seekbar to the new view we've been given
             ViewParent oldContainer = mSeekBar.getParent();
             ViewGroup newContainer = (ViewGroup) view.findViewById(R.id.seekBarPrefBarContainer);
@@ -132,8 +130,7 @@
                 newContainer.addView(mSeekBar, ViewGroup.LayoutParams.FILL_PARENT,
                         ViewGroup.LayoutParams.WRAP_CONTENT);
             }
-        }
-        catch(Exception ex) {
+        } catch(Exception ex) {
             Log.e(TAG, "Error binding view: " + ex.toString());
         }
         updateView(view);
@@ -156,27 +153,29 @@
             unitsRight.setText(mUnitsRight);
             TextView unitsLeft = (TextView)layout.findViewById(R.id.seekBarPrefUnitsLeft);
             unitsLeft.setText(mUnitsLeft);
-        }
-        catch(Exception e) {
+        } catch(Exception e) {
             Log.e(TAG, "Error updating seek bar preference", e);
         }
     }
-    
+
     @Override
     public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
         int newValue = progress + mMinValue;
-        if(newValue > mMaxValue)
+
+        if(newValue > mMaxValue) {
             newValue = mMaxValue;
-        else if(newValue < mMinValue)
+        } else if(newValue < mMinValue) {
             newValue = mMinValue;
-        else if(mInterval != 1 && newValue % mInterval != 0)
-            newValue = Math.round(((float)newValue)/mInterval)*mInterval;  
-        
+        } else if(mInterval != 1 && newValue % mInterval != 0) {
+            newValue = Math.round(((float)newValue)/mInterval)*mInterval;
+        }
+
         // change rejected, revert to the previous value
-        if(!callChangeListener(newValue)){
-            seekBar.setProgress(mCurrentValue - mMinValue); 
+        if (!callChangeListener(newValue)) {
+            seekBar.setProgress(mCurrentValue - mMinValue);
             return; 
         }
+
         // change accepted, store it
         mCurrentValue = newValue;
         mStatusText.setText(String.valueOf(newValue));
@@ -201,13 +200,11 @@
     protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
         if (restoreValue) {
             mCurrentValue = getPersistedInt(mCurrentValue);
-        }
-        else {
+        } else {
             int temp = 0;
             try {
                 temp = (Integer)defaultValue;
-            }
-            catch(Exception ex) {
+            } catch(Exception ex) {
                 Log.e(TAG, "Invalid default value: " + defaultValue.toString());
             }
             persistInt(temp);