diff options
author | Steve Kondik <steve@cyngn.com> | 2015-02-18 03:44:31 -0800 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-29 17:36:30 -0700 |
commit | e65f2833df18e755c847bc86376253a4b96e73f9 (patch) | |
tree | e61b573057968f05218a0ad697dd38183bf81149 | |
parent | 8f57a61603b7bc2fca99a510cb6c8188fb9612d2 (diff) | |
download | packages_apps_Settings-e65f2833df18e755c847bc86376253a4b96e73f9.zip packages_apps_Settings-e65f2833df18e755c847bc86376253a4b96e73f9.tar.gz packages_apps_Settings-e65f2833df18e755c847bc86376253a4b96e73f9.tar.bz2 |
livedisplay: Add LiveDisplay settings
* Add preference for LiveDisplay mode, and additional supporting
options for auto mode.
* CABC, SRE, CE are all under this umbrella now.
* Manual RGB tweaking is now handled here and the requirement for
CMHW has been removed as it will go thru RenderEngine.
* Moved all related code into the livedisplay package.
Change-Id: I0b00f2bfd8f8227d64ad271bbe0f004f0b4bcf9d
-rw-r--r-- | AndroidManifest.xml | 63 | ||||
-rw-r--r-- | res/drawable/color_temperature_preview.xml | 24 | ||||
-rw-r--r-- | res/layout/display_color_calibration.xml | 29 | ||||
-rw-r--r-- | res/layout/display_temperature.xml | 72 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 16 | ||||
-rw-r--r-- | res/xml/display_settings.xml | 44 | ||||
-rw-r--r-- | res/xml/livedisplay.xml | 97 | ||||
-rw-r--r-- | src/com/android/settings/DisplaySettings.java | 185 | ||||
-rw-r--r-- | src/com/android/settings/Settings.java | 1 | ||||
-rw-r--r-- | src/com/android/settings/SettingsActivity.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/Utils.java | 19 | ||||
-rw-r--r-- | src/com/android/settings/cyanogenmod/BootReceiver.java | 6 | ||||
-rw-r--r-- | src/com/android/settings/livedisplay/DisplayColor.java (renamed from src/com/android/settings/hardware/DisplayColor.java) | 143 | ||||
-rw-r--r-- | src/com/android/settings/livedisplay/DisplayGamma.java (renamed from src/com/android/settings/hardware/DisplayGamma.java) | 4 | ||||
-rw-r--r-- | src/com/android/settings/livedisplay/DisplayTemperature.java | 260 | ||||
-rw-r--r-- | src/com/android/settings/livedisplay/LiveDisplay.java | 350 |
16 files changed, 1009 insertions, 306 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ff771f2..fe1ffb0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2215,7 +2215,70 @@ </intent-filter> </activity> +<<<<<<< HEAD <!-- CyanogenMod activities End --> +======= + <activity android:name=".cyanogenmod.ContributorsCloud" /> + + <activity android:name=".cyanogenmod.SpamList" /> + + <!-- "Blacklist settings" UI, used only on voice-capable phone devices. --> + <activity android:name="Settings$BlacklistSettingsActivity" + android:uiOptions="splitActionBarWhenNarrow" + android:label="@string/blacklist_title" + android:excludeFromRecents="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.blacklist.BlacklistSettings" /> + <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID" + android:resource="@id/security_settings" /> + </activity> + + <activity-alias android:name=".blacklist.BlacklistSettings" + android:taskAffinity="com.android.settings" + android:label="@string/blacklist_title" + android:targetActivity="Settings$BlacklistSettingsActivity" + android:configChanges="orientation|keyboardHidden|screenSize" + android:exported="true"> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.blacklist.BlacklistSettings" /> + <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID" + android:resource="@id/security_settings" /> + </activity-alias> + + <!-- LiveDisplay settings --> + <activity android:name="Settings$LiveDisplayActivity" + android:label="@string/live_display_title" + android:excludeFromRecents="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <action android:name="android.settings.LIVEDISPLAY_SETTINGS" /> + <action android:name="com.android.settings.LIVEDISPLAY_SETTINGS" /> + <category android:name="android.intent.category.VOICE_LAUNCH" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.SHORTCUT" /> + </intent-filter> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.livedisplay.LiveDisplay" /> + <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID" + android:resource="@id/display_and_lights_settings" /> + </activity> + + <activity-alias android:name=".livedisplay.LiveDisplay" + android:taskAffinity="com.android.settings" + android:label="@string/live_display_title" + android:targetActivity="Settings$LiveDisplayActivity" + android:configChanges="orientation|keyboardHidden|screenSize" + android:exported="true"> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.livedisplay.LiveDisplay" /> + <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID" + android:resource="@id/display_and_lights_settings" /> + </activity-alias> +>>>>>>> eda58c5... livedisplay: Add LiveDisplay settings <!-- Pseudo-activity used to provide an intent-filter entry point to encryption settings --> <activity android:name="Settings$CryptKeeperSettingsActivity" diff --git a/res/drawable/color_temperature_preview.xml b/res/drawable/color_temperature_preview.xml new file mode 100644 index 0000000..0a358f6 --- /dev/null +++ b/res/drawable/color_temperature_preview.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2015 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + + <gradient + android:angle="0" + android:startColor="#ff3800" + android:endColor="#bfd3ff" /> +</shape> diff --git a/res/layout/display_color_calibration.xml b/res/layout/display_color_calibration.xml index 72d6ded..31bc1e4 100644 --- a/res/layout/display_color_calibration.xml +++ b/res/layout/display_color_calibration.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2013 The CyanogenMod Project +<!-- + Copyright (C) 2013-2015 The CyanogenMod Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. --> - <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" android:layout_width="match_parent" android:layout_height="match_parent"> @@ -36,11 +37,15 @@ android:layout_height="wrap_content" android:layout_alignParentRight="true" android:paddingTop="10dip" /> - <SeekBar android:id="@+id/color_red_seekbar" + <com.android.settings.IntervalSeekBar android:id="@+id/color_red_seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/color_red_text" - android:paddingTop="2dip" /> + android:paddingTop="2dip" + settings:min="0.01" + settings:max="1.00" + settings:defaultValue="1.00" + settings:digits="4" /> <TextView android:id="@+id/color_green_text" android:layout_width="wrap_content" @@ -54,11 +59,15 @@ android:layout_below="@id/color_red_seekbar" android:layout_alignParentRight="true" android:paddingTop="10dip" /> - <SeekBar android:id="@+id/color_green_seekbar" + <com.android.settings.IntervalSeekBar android:id="@+id/color_green_seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/color_green_text" - android:paddingTop="2dip" /> + android:paddingTop="2dip" + settings:min="0.01" + settings:max="1.00" + settings:defaultValue="1.00" + settings:digits="4" /> <TextView android:id="@+id/color_blue_text" android:layout_width="match_parent" @@ -72,11 +81,15 @@ android:layout_below="@id/color_green_seekbar" android:layout_alignParentRight="true" android:paddingTop="10dip" /> - <SeekBar android:id="@+id/color_blue_seekbar" + <com.android.settings.IntervalSeekBar android:id="@+id/color_blue_seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/color_blue_text" - android:paddingTop="2dip" /> + android:paddingTop="2dip" + settings:min="0.01" + settings:max="1.00" + settings:defaultValue="1.00" + settings:digits="4" /> <ImageView android:id="@+id/black_scale_picture_color" android:src="@drawable/color_tuning_preview" diff --git a/res/layout/display_temperature.xml b/res/layout/display_temperature.xml new file mode 100644 index 0000000..da4e955 --- /dev/null +++ b/res/layout/display_temperature.xml @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2015 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:paddingStart="20dip" + android:paddingEnd="20dip" + android:paddingBottom="20dip"> + + <TextView android:id="@+id/day_temperature_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/live_display_day" + android:paddingTop="10dip" /> + <TextView android:id="@+id/day_temperature_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:paddingTop="10dip" /> + <SeekBar android:id="@+id/day_temperature_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/day_temperature_text" + android:paddingTop="2dip" /> + + <TextView android:id="@+id/night_temperature_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/day_temperature_seekbar" + android:text="@string/live_display_night" + android:paddingTop="10dip" /> + <TextView android:id="@+id/night_temperature_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/day_temperature_seekbar" + android:layout_alignParentRight="true" + android:paddingTop="10dip" /> + <SeekBar android:id="@+id/night_temperature_seekbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/night_temperature_text" + android:paddingTop="2dip" /> + + <ImageView android:id="@+id/black_scale_picture_color" + android:src="@drawable/color_temperature_preview" + android:layout_width="match_parent" + android:layout_height="40dip" + android:layout_below="@id/night_temperature_seekbar" + android:paddingTop="20dip" /> + + </RelativeLayout> +</ScrollView> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index c751d86..1f893b2 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -486,4 +486,20 @@ <string name="saturation_str">Saturation: <xliff:g id="saturation_value">%1$s</xliff:g></string> <string name="contrast_str">Contrast: <xliff:g id="contrast_value">%1$s</xliff:g></string> <string name="intensity_str">Intensity: <xliff:g id="intensity_str_value">%1$s</xliff:g></string> + + <!-- LiveDisplay --> + <string name="live_display_title" translatable="false">LiveDisplay</string> + <string name="live_display_summary">Optimize your screen based on time of day and ambient conditions to improve readibility and reduce eyestrain</string> + <string name="live_display_mode">Display mode</string> + <string name="live_display_color_temperature_title">Color temperature</string> + <string name="live_display_color_temperature_summary">Day: <xliff:g id="day_temperature">%1$d</xliff:g>K Night: <xliff:g id="night_temperature">%2$d</xliff:g>K</string> + <string name="live_display_color_temperature_label"><xliff:g id="degrees">%1$d</xliff:g>K</string> + <string name="live_display_day">Day</string> + <string name="live_display_night">Night</string> + <string name="live_display_outdoor_mode_title">Automatic outdoor mode</string> + <string name="live_display_outdoor_mode_summary">Increase brightness and saturation automatically under bright sunlight</string> + <string name="live_display_low_power_title">Reduce power consumption</string> + <string name="live_display_low_power_summary">Adjust display for lowest power consumption without degradation</string> + <string name="live_display_enhance_color_title">Enhance colors</string> + <string name="live_display_enhance_color_summary">Improve color vibrance of flesh tones, scenery, and other images</string> </resources> diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml index e4f6759..94f2d52 100644 --- a/res/xml/display_settings.xml +++ b/res/xml/display_settings.xml @@ -67,6 +67,13 @@ android:title="@string/screensaver_settings_title" android:fragment="com.android.settings.DreamSettings" /> + <!-- LiveDisplay --> + <PreferenceScreen + android:key="live_display" + android:title="@string/live_display_title" + android:summary="@string/live_display_summary" + android:fragment="com.android.settings.livedisplay.LiveDisplay" /> + <SwitchPreference android:key="lift_to_wake" android:title="@string/lift_to_wake_title" @@ -128,43 +135,6 @@ android:title="@string/adaptive_backlight_title" android:summary="@string/adaptive_backlight_summary" android:defaultValue="true" /> - - <SwitchPreference - android:key="sunlight_enhancement" - android:title="@string/sunlight_enhancement_title" - android:summary="@string/sunlight_enhancement_summary" - android:defaultValue="true" /> - - <SwitchPreference - android:key="color_enhancement" - android:title="@string/color_enhancement_title" - android:summary="@string/color_enhancement_summary" - android:defaultValue="true" /> - - <com.android.settings.hardware.DisplayColor - android:key="color_calibration" - android:title="@string/color_calibration_title" - android:dialogTitle="@string/color_calibration_title" - android:summary="@string/color_calibration_summary" - android:persistent="false" /> - - <com.android.settings.hardware.DisplayGamma - android:key="gamma_tuning" - android:title="@string/gamma_tuning_title_head" - android:dialogTitle="@string/gamma_tuning_title_head" - android:summary="@string/gamma_tuning_summary_head" - android:persistent="false" /> </PreferenceCategory> - <PreferenceScreen - android:persistent="false" - android:key="screencolor_settings" - android:title="@string/screencolor" - android:summary="@string/screencolor_summary"> - <intent - android:action="com.qualcomm.display.PPService" - android:targetPackage="com.android.settings" - android:targetClass="com.android.settings.ScreenColorSettings" /> - </PreferenceScreen> - </PreferenceScreen> diff --git a/res/xml/livedisplay.xml b/res/xml/livedisplay.xml new file mode 100644 index 0000000..54e9870 --- /dev/null +++ b/res/xml/livedisplay.xml @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2015 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"> + + <PreferenceCategory + android:key="live_display_options" + android:title="@string/live_display_title"> + + <ListPreference + android:key="live_display" + android:title="@string/live_display_mode" + android:persistent="false" /> + + <!-- Manual temperature selection --> + <com.android.settings.livedisplay.DisplayTemperature + android:key="live_display_color_temperature" + android:title="@string/live_display_color_temperature_title" + android:dialogTitle="@string/live_display_title" + android:persistent="false" /> + + <!-- Outdoor mode / SRE --> + <com.android.settings.cyanogenmod.SystemSettingSwitchPreference + android:key="live_display_auto_outdoor_mode" + android:title="@string/live_display_outdoor_mode_title" + android:summary="@string/live_display_outdoor_mode_summary" + android:defaultValue="true" /> + + <!-- Adaptive backlight --> + <com.android.settings.cyanogenmod.SystemSettingSwitchPreference + android:key="live_display_low_power" + android:title="@string/live_display_low_power_title" + android:summary="@string/live_display_low_power_summary" + android:defaultValue="true" + settings:advanced="true" /> + + <!-- Color enhancement --> + <com.android.settings.cyanogenmod.SystemSettingSwitchPreference + android:key="live_display_color_enhance" + android:title="@string/live_display_enhance_color_title" + android:summary="@string/live_display_enhance_color_summary" + android:defaultValue="true" + settings:advanced="true" /> + + </PreferenceCategory> + + <PreferenceCategory + android:key="calibration" + android:title="@string/category_calibration" + settings:advanced="true"> + + <!-- screen color --> + <PreferenceScreen + android:persistent="false" + android:key="screencolor_settings" + android:title="@string/screencolor" + android:summary="@string/screencolor_summary" + settings:advanced="true"> + <intent + android:action="com.qualcomm.display.PPService" + android:targetPackage="com.android.settings" + android:targetClass="com.android.settings.ScreenColorSettings" /> + </PreferenceScreen> + + <com.android.settings.livedisplay.DisplayColor + android:key="color_calibration" + android:title="@string/color_calibration_title" + android:dialogTitle="@string/color_calibration_title" + android:summary="@string/color_calibration_summary" + android:persistent="false" + settings:advanced="true"/> + + <com.android.settings.livedisplay.DisplayGamma + android:key="gamma_tuning" + android:title="@string/gamma_tuning_title_head" + android:dialogTitle="@string/gamma_tuning_title_head" + android:summary="@string/gamma_tuning_summary_head" + android:persistent="false" + settings:advanced="true"/> + + </PreferenceCategory> + +</PreferenceScreen> diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java index 718f03d..6340c4e 100644 --- a/src/com/android/settings/DisplaySettings.java +++ b/src/com/android/settings/DisplaySettings.java @@ -18,6 +18,8 @@ package com.android.settings; import com.android.internal.logging.MetricsLogger; import android.preference.CheckBoxPreference; + +import android.os.UserHandle; import com.android.internal.view.RotationPolicy; import com.android.settings.DropDownPreference.Callback; import com.android.settings.search.BaseSearchIndexProvider; @@ -68,12 +70,7 @@ import java.util.ArrayList; import java.util.List; import com.android.settings.Utils; import com.android.settings.cyanogenmod.DisplayRotation; -import com.android.settings.hardware.DisplayColor; -import com.android.settings.hardware.DisplayGamma; -import org.cyanogenmod.hardware.AdaptiveBacklight; -import org.cyanogenmod.hardware.ColorEnhancement; -import org.cyanogenmod.hardware.SunlightEnhancement; import org.cyanogenmod.hardware.TapToWake; public class DisplaySettings extends SettingsPreferenceFragment implements @@ -92,24 +89,17 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness"; private static final String KEY_AUTO_ROTATE = "auto_rotate"; private static final String KEY_NIGHT_MODE = "night_mode"; - private static final String KEY_ADAPTIVE_BACKLIGHT = "adaptive_backlight"; - private static final String KEY_SUNLIGHT_ENHANCEMENT = "sunlight_enhancement"; - private static final String KEY_COLOR_ENHANCEMENT = "color_enhancement"; private static final String KEY_TAP_TO_WAKE = "double_tap_wake_gesture"; private static final String KEY_PROXIMITY_WAKE = "proximity_on_wake"; private static final String KEY_DISPLAY_ROTATION = "display_rotation"; private static final String KEY_WAKE_WHEN_PLUGGED_OR_UNPLUGGED = "wake_when_plugged_or_unplugged"; private static final String CATEGORY_ADVANCED = "advanced_display_prefs"; - private static final String KEY_DISPLAY_COLOR = "color_calibration"; - private static final String KEY_DISPLAY_GAMMA = "gamma_tuning"; - private static final String KEY_SCREEN_COLOR_SETTINGS = "screencolor_settings"; private static final int DLG_GLOBAL_CHANGE_WARNING = 1; private FontDialogPreference mFontSizePref; private PreferenceScreen mDisplayRotationPreference; - private PreferenceScreen mScreenColorSettings; private final Configuration mCurConfig = new Configuration(); @@ -123,10 +113,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private SwitchPreference mTapToWake; private SwitchPreference mWakeWhenPluggedOrUnplugged; - private SwitchPreference mAdaptiveBacklight; - private SwitchPreference mSunlightEnhancement; - private SwitchPreference mColorEnhancement; - private ContentObserver mAccelerometerRotationObserver = new ContentObserver(new Handler()) { @Override @@ -153,7 +139,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements super.onCreate(savedInstanceState); final Activity activity = getActivity(); final ContentResolver resolver = activity.getContentResolver(); - addPreferencesFromResource(R.xml.display_settings); mDisplayRotationPreference = (PreferenceScreen) findPreference(KEY_DISPLAY_ROTATION); @@ -182,8 +167,8 @@ public class DisplaySettings extends SettingsPreferenceFragment implements if (mAutoBrightnessPreference != null && isAutomaticBrightnessAvailable(getResources())) { mAutoBrightnessPreference.setOnPreferenceChangeListener(this); } else { - if (displayPrefs != null && mAutoBrightnessPreference != null) { - displayPrefs.removePreference(mAutoBrightnessPreference); + if (mAutoBrightnessPreference != null) { + removePreference(mAutoBrightnessPreference); mAutoBrightnessPreference = null; } } @@ -192,39 +177,12 @@ public class DisplaySettings extends SettingsPreferenceFragment implements if (mLiftToWakePreference != null && isLiftToWakeAvailable(activity)) { mLiftToWakePreference.setOnPreferenceChangeListener(this); } else { - if (displayPrefs != null && mLiftToWakePreference != null) { - displayPrefs.removePreference(mLiftToWakePreference); + if (mLiftToWakePreference != null) { + removePreference(mLiftToWakePreference); mLiftToWakePreference = null; } } - PreferenceCategory advancedPrefs = (PreferenceCategory) findPreference(CATEGORY_ADVANCED); - - mAdaptiveBacklight = (SwitchPreference) findPreference(KEY_ADAPTIVE_BACKLIGHT); - if (!isAdaptiveBacklightSupported()) { - advancedPrefs.removePreference(mAdaptiveBacklight); - mAdaptiveBacklight = null; - } - - mSunlightEnhancement = (SwitchPreference) findPreference(KEY_SUNLIGHT_ENHANCEMENT); - if (!isSunlightEnhancementSupported()) { - advancedPrefs.removePreference(mSunlightEnhancement); - mSunlightEnhancement = null; - } - - mColorEnhancement = (SwitchPreference) findPreference(KEY_COLOR_ENHANCEMENT); - if (!isColorEnhancementSupported()) { - advancedPrefs.removePreference(mColorEnhancement); - mColorEnhancement = null; - } - - if (!DisplayColor.isSupported()) { - advancedPrefs.removePreference(findPreference(KEY_DISPLAY_COLOR)); - } - if (!DisplayGamma.isSupported()) { - advancedPrefs.removePreference(findPreference(KEY_DISPLAY_GAMMA)); - } - mDozePreference = (SwitchPreference) findPreference(KEY_DOZE); if (mDozePreference != null && Utils.isDozeAvailable(activity)) { mDozePreference.setOnPreferenceChangeListener(this); @@ -263,11 +221,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements mWakeWhenPluggedOrUnplugged = (SwitchPreference) findPreference(KEY_WAKE_WHEN_PLUGGED_OR_UNPLUGGED); - - mScreenColorSettings = (PreferenceScreen) findPreference(KEY_SCREEN_COLOR_SETTINGS); - if (!isPostProcessingSupported()) { - getPreferenceScreen().removePreference(mScreenColorSettings); - } } private static boolean allowAllRotations(Context context) { @@ -407,22 +360,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements public void onResume() { super.onResume(); updateDisplayRotationPreferenceDescription(); - if (mAdaptiveBacklight != null) { - mAdaptiveBacklight.setChecked(AdaptiveBacklight.isEnabled()); - } - - if (mSunlightEnhancement != null) { - if (SunlightEnhancement.isAdaptiveBacklightRequired() && - !AdaptiveBacklight.isEnabled()) { - mSunlightEnhancement.setEnabled(false); - } else { - mSunlightEnhancement.setChecked(SunlightEnhancement.isEnabled()); - } - } - - if (mColorEnhancement != null) { - mColorEnhancement.setChecked(ColorEnhancement.isEnabled()); - } if (mTapToWake != null) { mTapToWake.setChecked(TapToWake.isEnabled()); @@ -438,10 +375,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true, mAccelerometerRotationObserver); - if (mAdaptiveBacklight != null) { - mAdaptiveBacklight.setChecked(AdaptiveBacklight.isEnabled()); - } - // Default value for wake-on-plug behavior from config.xml boolean wakeUpWhenPluggedOrUnpluggedConfig = getResources().getBoolean( com.android.internal.R.bool.config_unplugTurnsOnScreen); @@ -553,16 +486,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (preference == mTapToWake) { return TapToWake.setEnabled(mTapToWake.isChecked()); - } else if (preference == mAdaptiveBacklight) { - if (mSunlightEnhancement != null && - SunlightEnhancement.isAdaptiveBacklightRequired()) { - mSunlightEnhancement.setEnabled(mAdaptiveBacklight.isChecked()); - } - return AdaptiveBacklight.setEnabled(mAdaptiveBacklight.isChecked()); - } else if (preference == mSunlightEnhancement) { - return SunlightEnhancement.setEnabled(mSunlightEnhancement.isChecked()); - } else if (preference == mColorEnhancement) { - return ColorEnhancement.setEnabled(mColorEnhancement.isChecked()); } else if (preference == mWakeWhenPluggedOrUnplugged) { Settings.Global.putInt(getContentResolver(), Settings.Global.WAKE_WHEN_PLUGGED_OR_UNPLUGGED, @@ -652,95 +575,15 @@ public class DisplaySettings extends SettingsPreferenceFragment implements Log.d(TAG, "Tap-to-wake settings restored."); } } - - if (isAdaptiveBacklightSupported()) { - final boolean enabled = prefs.getBoolean(KEY_ADAPTIVE_BACKLIGHT, - AdaptiveBacklight.isEnabled()); - if (!AdaptiveBacklight.setEnabled(enabled)) { - Log.e(TAG, "Failed to restore adaptive backlight settings."); - } else { - Log.d(TAG, "Adaptive backlight settings restored."); - } - } - - if (isSunlightEnhancementSupported()) { - final boolean enabled = prefs.getBoolean(KEY_SUNLIGHT_ENHANCEMENT, - SunlightEnhancement.isEnabled()); - if (SunlightEnhancement.isAdaptiveBacklightRequired() && - !AdaptiveBacklight.isEnabled()) { - SunlightEnhancement.setEnabled(false); - Log.d(TAG, "SRE requires CABC, disabled"); - } else { - if (!SunlightEnhancement.setEnabled(enabled)) { - Log.e(TAG, "Failed to restore SRE settings."); - } else { - Log.d(TAG, "SRE settings restored."); - } - } - } - - if (isColorEnhancementSupported()) { - final boolean enabled = prefs.getBoolean(KEY_COLOR_ENHANCEMENT, - ColorEnhancement.isEnabled()); - if (!ColorEnhancement.setEnabled(enabled)) { - Log.e(TAG, "Failed to restore color enhancement settings."); - } else { - Log.d(TAG, "Color enhancement settings restored."); - } - } - } - - private static boolean isPostProcessingSupported(Context context) { - boolean ret = true; - final PackageManager pm = context.getPackageManager(); - try { - pm.getPackageInfo("com.qualcomm.display", PackageManager.GET_META_DATA); - } catch (NameNotFoundException e) { - ret = false; - } - return ret; - } - - private static boolean isAdaptiveBacklightSupported() { - try { - return AdaptiveBacklight.isSupported(); - } catch (NoClassDefFoundError e) { - // Hardware abstraction framework not installed - return false; - } - } - - private static boolean isSunlightEnhancementSupported() { - try { - return SunlightEnhancement.isSupported(); - } catch (NoClassDefFoundError e) { - // Hardware abstraction framework not installed - return false; - } - } - - private static boolean isColorEnhancementSupported() { - try { - return ColorEnhancement.isSupported(); - } catch (NoClassDefFoundError e) { - // Hardware abstraction framework not installed - return false; - } } public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { private boolean mHasTapToWake; - private boolean mHasSunlightEnhancement, mHasColorEnhancement; - private boolean mHasDisplayGamma, mHasDisplayColor; @Override public void prepare() { mHasTapToWake = isTapToWakeSupported(); - mHasSunlightEnhancement = isSunlightEnhancementSupported(); - mHasColorEnhancement = isColorEnhancementSupported(); - mHasDisplayGamma = DisplayGamma.isSupported(); - mHasDisplayColor = DisplayColor.isSupported(); } @Override @@ -770,21 +613,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements if (!mHasTapToWake) { result.add(KEY_TAP_TO_WAKE); } - if (!mHasSunlightEnhancement) { - result.add(KEY_SUNLIGHT_ENHANCEMENT); - } - if (!mHasColorEnhancement) { - result.add(KEY_COLOR_ENHANCEMENT); - } - if (!isPostProcessingSupported(context)) { - result.add(KEY_SCREEN_COLOR_SETTINGS); - } - if (!mHasDisplayColor) { - result.add(KEY_DISPLAY_COLOR); - } - if (!mHasDisplayGamma) { - result.add(KEY_DISPLAY_GAMMA); - } + if (!isAutomaticBrightnessAvailable(context.getResources())) { result.add(KEY_AUTO_BRIGHTNESS); } diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 7b94d79..727c446 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -118,4 +118,5 @@ public class Settings extends SettingsActivity { public static class WriteSettingsActivity extends SettingsActivity { /* empty */ } public static class AppDrawOverlaySettingsActivity extends SettingsActivity { /* empty */ } public static class AppWriteSettingsActivity extends SettingsActivity { /* empty */ } + public static class LiveDisplayActivity extends SettingsActivity { /* empty */ } } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index d9ff0c3..7f48cc4 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -92,6 +92,7 @@ import com.android.settings.deviceinfo.StorageSettings; import com.android.settings.fuelgauge.BatterySaverSettings; import com.android.settings.fuelgauge.PowerUsageDetail; import com.android.settings.fuelgauge.PowerUsageSummary; +import com.android.settings.livedisplay.LiveDisplay; import com.android.settings.notification.OtherSoundSettings; import com.android.settings.profiles.NFCProfileTagCallback; import com.android.settings.search.DynamicIndexableContentMonitor; @@ -361,6 +362,7 @@ public class SettingsActivity extends Activity ProcessStatsSummary.class.getName(), DrawOverlayDetails.class.getName(), WriteSettingsDetails.class.getName(), + LiveDisplay.class.getName() }; diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 0834c8d..4e945ef 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -760,6 +760,25 @@ public final class Utils { return (deviceKeys & ButtonSettings.KEY_MASK_VOLUME) != 0; } + public static boolean isPackageInstalled(Context context, String pkg, boolean ignoreState) { + if (pkg != null) { + try { + PackageInfo pi = context.getPackageManager().getPackageInfo(pkg, 0); + if (!pi.applicationInfo.enabled && !ignoreState) { + return false; + } + } catch (NameNotFoundException e) { + return false; + } + } + + return true; + } + + public static boolean isPackageInstalled(Context context, String pkg) { + return isPackageInstalled(context, pkg, true); + } + /** * Start a new instance of the activity, showing only the given fragment. * When launched in this mode, the given preference fragment will be instantiated and fill the diff --git a/src/com/android/settings/cyanogenmod/BootReceiver.java b/src/com/android/settings/cyanogenmod/BootReceiver.java index 9d32b02..7454a3e 100644 --- a/src/com/android/settings/cyanogenmod/BootReceiver.java +++ b/src/com/android/settings/cyanogenmod/BootReceiver.java @@ -21,9 +21,10 @@ import android.content.Context; import android.content.Intent; import com.android.settings.ButtonSettings; import com.android.settings.DisplaySettings; -import com.android.settings.hardware.DisplayColor; -import com.android.settings.hardware.DisplayGamma; +import com.android.settings.R; +import com.android.settings.Utils; import com.android.settings.hardware.VibratorIntensity; +import com.android.settings.livedisplay.DisplayGamma; public class BootReceiver extends BroadcastReceiver { @@ -34,7 +35,6 @@ public class BootReceiver extends BroadcastReceiver { /* Restore the hardware tunable values */ DisplaySettings.restore(ctx); ButtonSettings.restoreKeyDisabler(ctx); - DisplayColor.restore(ctx); DisplayGamma.restore(ctx); VibratorIntensity.restore(ctx); DisplaySettings.restore(ctx); diff --git a/src/com/android/settings/hardware/DisplayColor.java b/src/com/android/settings/livedisplay/DisplayColor.java index 8441297..6ca0ac7 100644 --- a/src/com/android/settings/hardware/DisplayColor.java +++ b/src/com/android/settings/livedisplay/DisplayColor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The CyanogenMod Project + * Copyright (C) 2013-2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,35 +14,34 @@ * limitations under the License. */ -package com.android.settings.hardware; +package com.android.settings.livedisplay; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; +import android.os.UserHandle; import android.preference.DialogPreference; -import android.preference.PreferenceManager; -import android.text.TextUtils; +import android.provider.Settings; import android.util.AttributeSet; import android.view.View; +import android.widget.Button; import android.widget.SeekBar; import android.widget.TextView; -import android.widget.Button; +import com.android.settings.IntervalSeekBar; import com.android.settings.R; -import org.cyanogenmod.hardware.DisplayColorCalibration; - /** * Special preference type that allows configuration of Color settings */ public class DisplayColor extends DialogPreference { private static final String TAG = "ColorCalibration"; + private final Context mContext; + // These arrays must all match in length and order private static final int[] SEEKBAR_ID = new int[] { R.id.color_red_seekbar, @@ -57,15 +56,14 @@ public class DisplayColor extends DialogPreference { }; private ColorSeekBar[] mSeekBars = new ColorSeekBar[SEEKBAR_ID.length]; - private String[] mCurrentColors; - private String mOriginalColors; + + private final float[] mCurrentColors = new float[3]; + private final float[] mOriginalColors = new float[3]; public DisplayColor(Context context, AttributeSet attrs) { super(context, attrs); - if (!isSupported()) { - return; - } + mContext = context; setDialogLayoutResource(R.layout.display_color_calibration); } @@ -84,14 +82,31 @@ public class DisplayColor extends DialogPreference { protected void onBindDialogView(View view) { super.onBindDialogView(view); - mOriginalColors = DisplayColorCalibration.getCurColors(); - mCurrentColors = mOriginalColors.split(" "); + String colorAdjustmentTemp = Settings.System.getStringForUser(mContext.getContentResolver(), + Settings.System.DISPLAY_COLOR_ADJUSTMENT, + UserHandle.USER_CURRENT); + String[] colorAdjustment = colorAdjustmentTemp == null ? + null : colorAdjustmentTemp.split(" "); + if (colorAdjustment == null || colorAdjustment.length != 3) { + colorAdjustment = new String[] { "1.0", "1.0", "1.0" }; + } + try { + mOriginalColors[0] = Float.parseFloat(colorAdjustment[0]); + mOriginalColors[1] = Float.parseFloat(colorAdjustment[1]); + mOriginalColors[2] = Float.parseFloat(colorAdjustment[2]); + } catch (NumberFormatException e) { + mOriginalColors[0] = 1.0f; + mOriginalColors[1] = 1.0f; + mOriginalColors[2] = 1.0f; + } + + System.arraycopy(mOriginalColors, 0, mCurrentColors, 0, 3); for (int i = 0; i < SEEKBAR_ID.length; i++) { - SeekBar seekBar = (SeekBar) view.findViewById(SEEKBAR_ID[i]); + IntervalSeekBar seekBar = (IntervalSeekBar) view.findViewById(SEEKBAR_ID[i]); TextView value = (TextView) view.findViewById(SEEKBAR_VALUE_ID[i]); mSeekBars[i] = new ColorSeekBar(seekBar, value, i); - mSeekBars[i].setValueFromString(mCurrentColors[i]); + mSeekBars[i].mSeekBar.setProgressFloat(mCurrentColors[i]); } } @@ -106,12 +121,11 @@ public class DisplayColor extends DialogPreference { defaultsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - int defaultValue = DisplayColorCalibration.getDefValue(); for (int i = 0; i < mSeekBars.length; i++) { - mSeekBars[i].mSeekBar.setProgress(defaultValue); - mCurrentColors[i] = String.valueOf(defaultValue); + mSeekBars[i].mSeekBar.setProgressFloat(1.00f); + mCurrentColors[i] = 1.0f; } - DisplayColorCalibration.setColors(TextUtils.join(" ", mCurrentColors)); + updateColors(mCurrentColors); } }); } @@ -119,14 +133,7 @@ public class DisplayColor extends DialogPreference { @Override protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); - - if (positiveResult) { - Editor editor = getEditor(); - editor.putString("display_color_calibration", DisplayColorCalibration.getCurColors()); - editor.commit(); - } else if (mOriginalColors != null) { - DisplayColorCalibration.setColors(mOriginalColors); - } + updateColors(positiveResult ? mCurrentColors : mOriginalColors); } @Override @@ -142,8 +149,7 @@ public class DisplayColor extends DialogPreference { myState.originalColors = mOriginalColors; // Restore the old state when the activity or dialog is being paused - DisplayColorCalibration.setColors(mOriginalColors); - mOriginalColors = null; + updateColors(mOriginalColors); return myState; } @@ -158,39 +164,18 @@ public class DisplayColor extends DialogPreference { SavedState myState = (SavedState) state; super.onRestoreInstanceState(myState.getSuperState()); - mOriginalColors = myState.originalColors; - mCurrentColors = myState.currentColors; - for (int i = 0; i < mSeekBars.length; i++) { - mSeekBars[i].setValueFromString(mCurrentColors[i]); - } - DisplayColorCalibration.setColors(TextUtils.join(" ", mCurrentColors)); - } - - public static boolean isSupported() { - try { - return DisplayColorCalibration.isSupported(); - } catch (NoClassDefFoundError e) { - // Hardware abstraction framework isn't installed - return false; - } - } - - public static void restore(Context context) { - if (!isSupported()) { - return; - } - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - final String value = prefs.getString("display_color_calibration", null); - - if (value != null) { - DisplayColorCalibration.setColors(value); + System.arraycopy(myState.originalColors, 0, mOriginalColors, 0, 3); + System.arraycopy(myState.currentColors, 0, mCurrentColors, 0, 3); + for (int i = 0; i < mSeekBars.length; i++) { + mSeekBars[i].mSeekBar.setProgressFloat(mCurrentColors[i]); } + updateColors(mCurrentColors); } private static class SavedState extends BaseSavedState { - String originalColors; - String[] currentColors; + float[] originalColors; + float[] currentColors; public SavedState(Parcelable superState) { super(superState); @@ -198,15 +183,15 @@ public class DisplayColor extends DialogPreference { public SavedState(Parcel source) { super(source); - originalColors = source.readString(); - currentColors = source.createStringArray(); + originalColors = source.createFloatArray(); + currentColors = source.createFloatArray(); } @Override public void writeToParcel(Parcel dest, int flags) { super.writeToParcel(dest, flags); - dest.writeString(originalColors); - dest.writeStringArray(currentColors); + dest.writeFloatArray(originalColors); + dest.writeFloatArray(currentColors); } public static final Parcelable.Creator<SavedState> CREATOR = @@ -222,36 +207,38 @@ public class DisplayColor extends DialogPreference { }; } + private void updateColors(float[] colors) { + Settings.System.putStringForUser(mContext.getContentResolver(), + Settings.System.DISPLAY_COLOR_ADJUSTMENT, + new StringBuilder().append(colors[0]).append(" ") + .append(colors[1]).append(" ") + .append(colors[2]).toString(), + UserHandle.USER_CURRENT); + } + private class ColorSeekBar implements SeekBar.OnSeekBarChangeListener { private int mIndex; - private SeekBar mSeekBar; + private final IntervalSeekBar mSeekBar; private TextView mValue; - public ColorSeekBar(SeekBar seekBar, TextView value, int index) { + public ColorSeekBar(IntervalSeekBar seekBar, TextView value, int index) { mSeekBar = seekBar; mValue = value; mIndex = index; - mSeekBar.setMax(DisplayColorCalibration.getMaxValue() - - DisplayColorCalibration.getMinValue()); mSeekBar.setOnSeekBarChangeListener(this); } - public void setValueFromString(String valueString) { - mSeekBar.setProgress(Integer.valueOf(valueString)); - } - @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - int min = DisplayColorCalibration.getMinValue(); - int max = DisplayColorCalibration.getMaxValue(); - + IntervalSeekBar isb = (IntervalSeekBar)seekBar; + float fp = isb.getProgressFloat(); if (fromUser) { - mCurrentColors[mIndex] = String.valueOf(progress + min); - DisplayColorCalibration.setColors(TextUtils.join(" ", mCurrentColors)); + mCurrentColors[mIndex] = fp; + updateColors(mCurrentColors); } - int percent = Math.round(100F * progress / (max - min)); + int percent = Math.round(100F * fp); mValue.setText(String.format("%d%%", percent)); } diff --git a/src/com/android/settings/hardware/DisplayGamma.java b/src/com/android/settings/livedisplay/DisplayGamma.java index b2592ee..38a187b 100644 --- a/src/com/android/settings/hardware/DisplayGamma.java +++ b/src/com/android/settings/livedisplay/DisplayGamma.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The CyanogenMod Project + * Copyright (C) 2013-2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.settings.hardware; +package com.android.settings.livedisplay; import android.app.AlertDialog; import android.content.Context; diff --git a/src/com/android/settings/livedisplay/DisplayTemperature.java b/src/com/android/settings/livedisplay/DisplayTemperature.java new file mode 100644 index 0000000..971bd3e --- /dev/null +++ b/src/com/android/settings/livedisplay/DisplayTemperature.java @@ -0,0 +1,260 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.livedisplay; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; +import android.os.UserHandle; +import android.preference.DialogPreference; +import android.provider.Settings; +import android.util.AttributeSet; +import android.view.View; +import android.widget.Button; +import android.widget.SeekBar; +import android.widget.TextView; + +import com.android.settings.R; + +/** + * Preference for selection of color temperature range for LiveDisplay + */ +public class DisplayTemperature extends DialogPreference { + private static final String TAG = "DisplayTemperature"; + + private final Context mContext; + + private ColorTemperatureSeekBar mDayTemperature; + private ColorTemperatureSeekBar mNightTemperature; + + private int mOriginalDayTemperature; + private int mOriginalNightTemperature; + + private final int mDefaultDayTemperature; + private final int mDefaultNightTemperature; + + public DisplayTemperature(Context context, AttributeSet attrs) { + super(context, attrs); + mContext = context; + + mDefaultDayTemperature = mContext.getResources().getInteger( + com.android.internal.R.integer.config_dayColorTemperature); + mDefaultNightTemperature = mContext.getResources().getInteger( + com.android.internal.R.integer.config_nightColorTemperature); + + setDialogLayoutResource(R.layout.display_temperature); + } + + @Override + protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { + builder.setNeutralButton(R.string.settings_reset_button, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }); + } + + @Override + protected void onBindDialogView(View view) { + super.onBindDialogView(view); + + mOriginalDayTemperature = Settings.System.getIntForUser(mContext.getContentResolver(), + Settings.System.DISPLAY_TEMPERATURE_DAY, + mDefaultDayTemperature, + UserHandle.USER_CURRENT); + mOriginalNightTemperature = Settings.System.getIntForUser(mContext.getContentResolver(), + Settings.System.DISPLAY_TEMPERATURE_NIGHT, + mDefaultNightTemperature, + UserHandle.USER_CURRENT); + + SeekBar day = (SeekBar) view.findViewById(R.id.day_temperature_seekbar); + TextView dayText = (TextView) view.findViewById(R.id.day_temperature_value); + mDayTemperature = new ColorTemperatureSeekBar(day, dayText); + + SeekBar night = (SeekBar) view.findViewById(R.id.night_temperature_seekbar); + TextView nightText = (TextView) view.findViewById(R.id.night_temperature_value); + mNightTemperature = new ColorTemperatureSeekBar(night, nightText); + + mDayTemperature.setProgress(mOriginalDayTemperature); + mNightTemperature.setProgress(mOriginalNightTemperature); + } + + @Override + protected void showDialog(Bundle state) { + super.showDialog(state); + + // Can't use onPrepareDialogBuilder for this as we want the dialog + // to be kept open on click + AlertDialog d = (AlertDialog) getDialog(); + Button defaultsButton = d.getButton(DialogInterface.BUTTON_NEUTRAL); + defaultsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mDayTemperature.setProgress(mDefaultDayTemperature); + mNightTemperature.setProgress(mDefaultNightTemperature); + updateTemperature(true); + } + }); + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + updateTemperature(positiveResult); + } + + @Override + protected Parcelable onSaveInstanceState() { + final Parcelable superState = super.onSaveInstanceState(); + if (getDialog() == null || !getDialog().isShowing()) { + return superState; + } + + // Save the dialog state + final SavedState myState = new SavedState(superState); + myState.originalDayTemperature = mOriginalDayTemperature; + myState.originalNightTemperature = mOriginalNightTemperature; + myState.currentDayTemperature = mDayTemperature.getProgress(); + myState.currentNightTemperature = mNightTemperature.getProgress(); + + // Restore the old state when the activity or dialog is being paused + updateTemperature(false); + + return myState; + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (state == null || !state.getClass().equals(SavedState.class)) { + // Didn't save state for us in onSaveInstanceState + super.onRestoreInstanceState(state); + return; + } + + SavedState myState = (SavedState) state; + super.onRestoreInstanceState(myState.getSuperState()); + + mOriginalDayTemperature = myState.originalDayTemperature; + mOriginalNightTemperature = myState.originalNightTemperature; + mDayTemperature.setProgress(myState.currentDayTemperature); + mNightTemperature.setProgress(myState.currentNightTemperature);; + + updateTemperature(true); + } + + private static class SavedState extends BaseSavedState { + int originalDayTemperature; + int originalNightTemperature; + int currentDayTemperature; + int currentNightTemperature; + + public SavedState(Parcelable superState) { + super(superState); + } + + public SavedState(Parcel source) { + super(source); + originalDayTemperature = source.readInt(); + originalNightTemperature = source.readInt(); + currentDayTemperature = source.readInt(); + currentNightTemperature = source.readInt(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(originalDayTemperature); + dest.writeInt(originalNightTemperature); + dest.writeInt(currentDayTemperature); + dest.writeInt(currentNightTemperature); + } + + public static final Parcelable.Creator<SavedState> CREATOR = + new Parcelable.Creator<SavedState>() { + + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + } + + private void updateTemperature(boolean accept) { + int day = accept ? mDayTemperature.getProgress() : mOriginalDayTemperature; + int night = accept ? mNightTemperature.getProgress() : mOriginalNightTemperature; + callChangeListener(new Integer[] { day, night }); + + Settings.System.putIntForUser(mContext.getContentResolver(), + Settings.System.DISPLAY_TEMPERATURE_DAY, day, + UserHandle.USER_CURRENT); + + Settings.System.putIntForUser(mContext.getContentResolver(), + Settings.System.DISPLAY_TEMPERATURE_NIGHT, night, + UserHandle.USER_CURRENT); + } + + private class ColorTemperatureSeekBar implements SeekBar.OnSeekBarChangeListener { + private final SeekBar mSeekBar; + private final TextView mValue; + + private static final int MIN = 1000; + private static final int MAX = 10000; + + public ColorTemperatureSeekBar(SeekBar seekBar, TextView value) { + mSeekBar = seekBar; + mValue = value; + + mSeekBar.setMax(MAX - MIN); + mSeekBar.setOnSeekBarChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (fromUser) { + updateTemperature(true); + } + mValue.setText(mContext.getResources().getString( + R.string.live_display_color_temperature_label, progress + MIN)); + } + + public void setProgress(int progress) { + int p = progress < MIN ? MIN : progress; + mSeekBar.setProgress(p - MIN); + } + + public int getProgress() { + return mSeekBar.getProgress() + MIN; + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Do nothing here + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Do nothing here + } + } +} diff --git a/src/com/android/settings/livedisplay/LiveDisplay.java b/src/com/android/settings/livedisplay/LiveDisplay.java new file mode 100644 index 0000000..07283a6 --- /dev/null +++ b/src/com/android/settings/livedisplay/LiveDisplay.java @@ -0,0 +1,350 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.livedisplay; + +import android.app.Activity; +import android.content.ContentResolver; +import android.content.Context; +import android.content.res.Resources; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.os.UserHandle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceCategory; +import android.preference.PreferenceScreen; +import android.preference.SwitchPreference; +import android.provider.SearchIndexableResource; +import android.provider.Settings; + +import com.android.internal.util.ArrayUtils; +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.Utils; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settings.search.Indexable; + +import org.cyanogenmod.hardware.AdaptiveBacklight; +import org.cyanogenmod.hardware.ColorEnhancement; +import org.cyanogenmod.hardware.SunlightEnhancement; + +import java.util.ArrayList; +import java.util.List; + +public class LiveDisplay extends SettingsPreferenceFragment implements + Preference.OnPreferenceChangeListener, Indexable { + + private static final String TAG = "LiveDisplay"; + + private static final String KEY_CATEGORY_LIVE_DISPLAY = "live_display_options"; + private static final String KEY_CATEGORY_CALIBRATION = "calibration"; + + private static final String KEY_LIVE_DISPLAY = "live_display"; + private static final String KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE = + "live_display_auto_outdoor_mode"; + private static final String KEY_LIVE_DISPLAY_LOW_POWER = "live_display_low_power"; + private static final String KEY_LIVE_DISPLAY_COLOR_ENHANCE = "live_display_color_enhance"; + private static final String KEY_LIVE_DISPLAY_TEMPERATURE = "live_display_color_temperature"; + + private static final String KEY_DISPLAY_COLOR = "color_calibration"; + private static final String KEY_DISPLAY_GAMMA = "gamma_tuning"; + private static final String KEY_SCREEN_COLOR_SETTINGS = "screencolor_settings"; + + public static final int MODE_DAY = 0; + public static final int MODE_NIGHT = 1; + public static final int MODE_AUTO = 2; + public static final int MODE_OUTDOOR = 3; + + private final Handler mHandler = new Handler(); + private final SettingsObserver mObserver = new SettingsObserver(); + + private ListPreference mLiveDisplay; + + private SwitchPreference mColorEnhancement; + private SwitchPreference mLowPower; + private SwitchPreference mOutdoorMode; + + private PreferenceScreen mScreenColorSettings; + private DisplayTemperature mDisplayTemperature; + + private String[] mModeEntries; + private String[] mModeValues; + private String[] mModeSummaries; + + private int mDefaultDayTemperature; + private int mDefaultNightTemperature; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + final Activity activity = getActivity(); + final ContentResolver resolver = activity.getContentResolver(); + final Resources res = getResources(); + + mDefaultDayTemperature = res.getInteger( + com.android.internal.R.integer.config_dayColorTemperature); + mDefaultNightTemperature = res.getInteger( + com.android.internal.R.integer.config_nightColorTemperature); + + addPreferencesFromResource(R.xml.livedisplay); + + PreferenceCategory liveDisplayPrefs = (PreferenceCategory) + findPreference(KEY_CATEGORY_LIVE_DISPLAY); + PreferenceCategory calibrationPrefs = (PreferenceCategory) + findPreference(KEY_CATEGORY_CALIBRATION); + + int displayMode = Settings.System.getIntForUser(resolver, + Settings.System.DISPLAY_TEMPERATURE_MODE, + 0, UserHandle.USER_CURRENT); + mLiveDisplay = (ListPreference) findPreference(KEY_LIVE_DISPLAY); + mLiveDisplay.setValue(String.valueOf(displayMode)); + + mModeEntries = res.getStringArray( + com.android.internal.R.array.live_display_entries); + mModeValues = res.getStringArray( + com.android.internal.R.array.live_display_values); + mModeSummaries = res.getStringArray( + com.android.internal.R.array.live_display_summaries); + + // Remove outdoor mode from lists if there is no support + if (!SunlightEnhancement.isSupported()) { + int idx = ArrayUtils.indexOf(mModeValues, String.valueOf(MODE_OUTDOOR)); + String[] entriesTemp = new String[mModeEntries.length - 1]; + String[] valuesTemp = new String[mModeValues.length - 1]; + String[] summariesTemp = new String[mModeSummaries.length - 1]; + int j = 0; + for (int i = 0; i < mModeEntries.length; i++) { + if (i == idx) { + continue; + } + entriesTemp[j] = mModeEntries[i]; + valuesTemp[j] = mModeValues[i]; + summariesTemp[j] = mModeSummaries[i]; + j++; + } + mModeEntries = entriesTemp; + mModeValues = valuesTemp; + mModeSummaries = summariesTemp; + } + + mLiveDisplay.setEntries(mModeEntries); + mLiveDisplay.setEntryValues(mModeValues); + mLiveDisplay.setOnPreferenceChangeListener(this); + + mDisplayTemperature = (DisplayTemperature) findPreference(KEY_LIVE_DISPLAY_TEMPERATURE); + + mLowPower = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_LOW_POWER); + if (liveDisplayPrefs != null && mLowPower != null + && !isAdaptiveBacklightSupported()) { + liveDisplayPrefs.removePreference(mLowPower); + mLowPower = null; + } + + mOutdoorMode = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE); + if (liveDisplayPrefs != null && mOutdoorMode != null + && !isSunlightEnhancementSupported()) { + liveDisplayPrefs.removePreference(mOutdoorMode); + mOutdoorMode = null; + } + + mColorEnhancement = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_COLOR_ENHANCE); + if (liveDisplayPrefs != null && mColorEnhancement != null + && !isColorEnhancementSupported()) { + liveDisplayPrefs.removePreference(mColorEnhancement); + mColorEnhancement = null; + } + + if (calibrationPrefs != null && !DisplayGamma.isSupported()) { + Preference gammaPref = findPreference(KEY_DISPLAY_GAMMA); + if (gammaPref != null) { + calibrationPrefs.removePreference(gammaPref); + } + } + + mScreenColorSettings = (PreferenceScreen) findPreference(KEY_SCREEN_COLOR_SETTINGS); + if (calibrationPrefs != null) { + if (!isPostProcessingSupported(getActivity()) && mScreenColorSettings != null) { + calibrationPrefs.removePreference(mScreenColorSettings); + } else if ("user".equals(Build.TYPE)) { + // Remove simple RGB controls if HSIC controls are available + Preference displayColor = findPreference(KEY_DISPLAY_COLOR); + if (displayColor != null) { + calibrationPrefs.removePreference(displayColor); + } + } + } + } + + @Override + public void onResume() { + super.onResume(); + updateModeSummary(); + updateTemperatureSummary(); + mObserver.register(true); + } + + @Override + public void onPause() { + super.onPause(); + mObserver.register(false); + } + + private void updateModeSummary() { + int mode = Settings.System.getIntForUser(getContentResolver(), + Settings.System.DISPLAY_TEMPERATURE_MODE, + MODE_DAY, UserHandle.USER_CURRENT); + + int index = ArrayUtils.indexOf(mModeValues, String.valueOf(mode)); + mLiveDisplay.setSummary(mModeSummaries[index]); + } + + private void updateTemperatureSummary() { + int day = Settings.System.getIntForUser(getContentResolver(), + Settings.System.DISPLAY_TEMPERATURE_DAY, + mDefaultDayTemperature, + UserHandle.USER_CURRENT); + int night = Settings.System.getIntForUser(getContentResolver(), + Settings.System.DISPLAY_TEMPERATURE_NIGHT, + mDefaultNightTemperature, + UserHandle.USER_CURRENT); + + mDisplayTemperature.setSummary(getResources().getString( + R.string.live_display_color_temperature_summary, day, night)); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object objValue) { + if (preference == mLiveDisplay) { + Settings.System.putIntForUser(getContentResolver(), + Settings.System.DISPLAY_TEMPERATURE_MODE, + Integer.valueOf((String)objValue), UserHandle.USER_CURRENT); + } + return true; + } + + private static boolean isAdaptiveBacklightSupported() { + try { + return AdaptiveBacklight.isSupported(); + } catch (NoClassDefFoundError e) { + // Hardware abstraction framework not installed + return false; + } + } + + private static boolean isSunlightEnhancementSupported() { + try { + return SunlightEnhancement.isSupported(); + } catch (NoClassDefFoundError e) { + // Hardware abstraction framework not installed + return false; + } + } + + private static boolean isColorEnhancementSupported() { + try { + return ColorEnhancement.isSupported(); + } catch (NoClassDefFoundError e) { + // Hardware abstraction framework not installed + return false; + } + } + + private static boolean isPostProcessingSupported(Context context) { + return Utils.isPackageInstalled(context, "com.qualcomm.display"); + } + + private final class SettingsObserver extends ContentObserver { + private final Uri DISPLAY_TEMPERATURE_DAY_URI = + Settings.System.getUriFor(Settings.System.DISPLAY_TEMPERATURE_DAY); + private final Uri DISPLAY_TEMPERATURE_NIGHT_URI = + Settings.System.getUriFor(Settings.System.DISPLAY_TEMPERATURE_NIGHT); + private final Uri DISPLAY_TEMPERATURE_MODE_URI = + Settings.System.getUriFor(Settings.System.DISPLAY_TEMPERATURE_MODE); + + public SettingsObserver() { + super(mHandler); + } + + public void register(boolean register) { + final ContentResolver cr = getContentResolver(); + if (register) { + cr.registerContentObserver(DISPLAY_TEMPERATURE_DAY_URI, false, this); + cr.registerContentObserver(DISPLAY_TEMPERATURE_NIGHT_URI, false, this); + cr.registerContentObserver(DISPLAY_TEMPERATURE_MODE_URI, false, this); + } else { + cr.unregisterContentObserver(this); + } + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + super.onChange(selfChange, uri); + updateModeSummary(); + updateTemperatureSummary(); + } + } + + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + private boolean mHasSunlightEnhancement, mHasColorEnhancement, mHasLowPower; + private boolean mHasDisplayGamma; + + @Override + public void prepare() { + mHasSunlightEnhancement = isSunlightEnhancementSupported(); + mHasColorEnhancement = isColorEnhancementSupported(); + mHasLowPower = isAdaptiveBacklightSupported(); + mHasDisplayGamma = DisplayGamma.isSupported(); + } + + @Override + public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, + boolean enabled) { + ArrayList<SearchIndexableResource> result = + new ArrayList<SearchIndexableResource>(); + + SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.livedisplay; + result.add(sir); + + return result; + } + + @Override + public List<String> getNonIndexableKeys(Context context) { + ArrayList<String> result = new ArrayList<String>(); + if (!mHasSunlightEnhancement) { + result.add(KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE); + } + if (!mHasColorEnhancement) { + result.add(KEY_LIVE_DISPLAY_COLOR_ENHANCE); + } + if (!mHasLowPower) { + result.add(KEY_LIVE_DISPLAY_LOW_POWER); + } + if (!isPostProcessingSupported(context)) { + result.add(KEY_SCREEN_COLOR_SETTINGS); + } + if (!mHasDisplayGamma) { + result.add(KEY_DISPLAY_GAMMA); + } + return result; + } + }; +} |