From e65f2833df18e755c847bc86376253a4b96e73f9 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Wed, 18 Feb 2015 03:44:31 -0800 Subject: 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 --- AndroidManifest.xml | 63 ++++ res/drawable/color_temperature_preview.xml | 24 ++ res/layout/display_color_calibration.xml | 29 +- res/layout/display_temperature.xml | 72 +++++ res/values/cm_strings.xml | 16 + res/xml/display_settings.xml | 44 +-- res/xml/livedisplay.xml | 97 ++++++ src/com/android/settings/DisplaySettings.java | 185 +---------- src/com/android/settings/Settings.java | 1 + src/com/android/settings/SettingsActivity.java | 2 + src/com/android/settings/Utils.java | 19 ++ .../android/settings/cyanogenmod/BootReceiver.java | 6 +- .../android/settings/hardware/DisplayColor.java | 268 ---------------- .../android/settings/hardware/DisplayGamma.java | 341 -------------------- .../android/settings/livedisplay/DisplayColor.java | 255 +++++++++++++++ .../android/settings/livedisplay/DisplayGamma.java | 341 ++++++++++++++++++++ .../settings/livedisplay/DisplayTemperature.java | 260 +++++++++++++++ .../android/settings/livedisplay/LiveDisplay.java | 350 +++++++++++++++++++++ 18 files changed, 1538 insertions(+), 835 deletions(-) create mode 100644 res/drawable/color_temperature_preview.xml create mode 100644 res/layout/display_temperature.xml create mode 100644 res/xml/livedisplay.xml delete mode 100644 src/com/android/settings/hardware/DisplayColor.java delete mode 100644 src/com/android/settings/hardware/DisplayGamma.java create mode 100644 src/com/android/settings/livedisplay/DisplayColor.java create mode 100644 src/com/android/settings/livedisplay/DisplayGamma.java create mode 100644 src/com/android/settings/livedisplay/DisplayTemperature.java create mode 100644 src/com/android/settings/livedisplay/LiveDisplay.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ff771f2..fe1ffb0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2215,7 +2215,70 @@ +<<<<<<< HEAD +======= + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +>>>>>>> eda58c5... livedisplay: Add LiveDisplay settings + + + + + 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 @@ - - @@ -36,11 +37,15 @@ android:layout_height="wrap_content" android:layout_alignParentRight="true" android:paddingTop="10dip" /> - + android:paddingTop="2dip" + settings:min="0.01" + settings:max="1.00" + settings:defaultValue="1.00" + settings:digits="4" /> - + android:paddingTop="2dip" + settings:min="0.01" + settings:max="1.00" + settings:defaultValue="1.00" + settings:digits="4" /> - + android:paddingTop="2dip" + settings:min="0.01" + settings:max="1.00" + settings:defaultValue="1.00" + settings:digits="4" /> + + + + + + + + + + + + + + + + + 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 @@ Saturation: %1$s Contrast: %1$s Intensity: %1$s + + + LiveDisplay + Optimize your screen based on time of day and ambient conditions to improve readibility and reduce eyestrain + Display mode + Color temperature + Day: %1$dK Night: %2$dK + %1$dK + Day + Night + Automatic outdoor mode + Increase brightness and saturation automatically under bright sunlight + Reduce power consumption + Adjust display for lowest power consumption without degradation + Enhance colors + Improve color vibrance of flesh tones, scenery, and other images 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" /> + + + - - - - - - - - - - - - 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/hardware/DisplayColor.java deleted file mode 100644 index 8441297..0000000 --- a/src/com/android/settings/hardware/DisplayColor.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (C) 2013 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.hardware; - -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.preference.DialogPreference; -import android.preference.PreferenceManager; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.View; -import android.widget.SeekBar; -import android.widget.TextView; -import android.widget.Button; - -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"; - - // These arrays must all match in length and order - private static final int[] SEEKBAR_ID = new int[] { - R.id.color_red_seekbar, - R.id.color_green_seekbar, - R.id.color_blue_seekbar - }; - - private static final int[] SEEKBAR_VALUE_ID = new int[] { - R.id.color_red_value, - R.id.color_green_value, - R.id.color_blue_value - }; - - private ColorSeekBar[] mSeekBars = new ColorSeekBar[SEEKBAR_ID.length]; - private String[] mCurrentColors; - private String mOriginalColors; - - public DisplayColor(Context context, AttributeSet attrs) { - super(context, attrs); - - if (!isSupported()) { - return; - } - - setDialogLayoutResource(R.layout.display_color_calibration); - } - - @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); - - mOriginalColors = DisplayColorCalibration.getCurColors(); - mCurrentColors = mOriginalColors.split(" "); - - for (int i = 0; i < SEEKBAR_ID.length; i++) { - SeekBar seekBar = (SeekBar) 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]); - } - } - - @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) { - int defaultValue = DisplayColorCalibration.getDefValue(); - for (int i = 0; i < mSeekBars.length; i++) { - mSeekBars[i].mSeekBar.setProgress(defaultValue); - mCurrentColors[i] = String.valueOf(defaultValue); - } - DisplayColorCalibration.setColors(TextUtils.join(" ", mCurrentColors)); - } - }); - } - - @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); - } - } - - @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.currentColors = mCurrentColors; - myState.originalColors = mOriginalColors; - - // Restore the old state when the activity or dialog is being paused - DisplayColorCalibration.setColors(mOriginalColors); - mOriginalColors = null; - - 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()); - 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); - } - } - - private static class SavedState extends BaseSavedState { - String originalColors; - String[] currentColors; - - public SavedState(Parcelable superState) { - super(superState); - } - - public SavedState(Parcel source) { - super(source); - originalColors = source.readString(); - currentColors = source.createStringArray(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeString(originalColors); - dest.writeStringArray(currentColors); - } - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } - - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; - } - - private class ColorSeekBar implements SeekBar.OnSeekBarChangeListener { - private int mIndex; - private SeekBar mSeekBar; - private TextView mValue; - - public ColorSeekBar(SeekBar 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(); - - if (fromUser) { - mCurrentColors[mIndex] = String.valueOf(progress + min); - DisplayColorCalibration.setColors(TextUtils.join(" ", mCurrentColors)); - } - - int percent = Math.round(100F * progress / (max - min)); - mValue.setText(String.format("%d%%", percent)); - } - - @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/hardware/DisplayGamma.java b/src/com/android/settings/hardware/DisplayGamma.java deleted file mode 100644 index b2592ee..0000000 --- a/src/com/android/settings/hardware/DisplayGamma.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (C) 2013 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.hardware; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.content.res.Resources; -import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; -import android.preference.DialogPreference; -import android.preference.PreferenceManager; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.SeekBar; -import android.widget.TextView; - -import com.android.settings.R; -import org.cyanogenmod.hardware.DisplayGammaCalibration; - -/** - * Special preference type that allows configuration of Gamma settings - */ -public class DisplayGamma extends DialogPreference { - private static final String TAG = "GammaCalibration"; - - private static final int[] BAR_COLORS = new int[] { - R.string.color_red_title, - R.string.color_green_title, - R.string.color_blue_title - }; - - private GammaSeekBar[][] mSeekBars; - - private String[][] mCurrentColors; - private String[] mOriginalColors; - private int mNumberOfControls; - - public DisplayGamma(Context context, AttributeSet attrs) { - super(context, attrs); - - if (!isSupported()) { - return; - } - - mNumberOfControls = DisplayGammaCalibration.getNumberOfControls(); - mSeekBars = new GammaSeekBar[mNumberOfControls][BAR_COLORS.length]; - - mOriginalColors = new String[mNumberOfControls]; - mCurrentColors = new String[mNumberOfControls][]; - - setDialogLayoutResource(R.layout.display_gamma_calibration); - } - - @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); - - final ViewGroup container = (ViewGroup) view.findViewById(R.id.gamma_container); - final LayoutInflater inflater = LayoutInflater.from(getContext()); - final SharedPreferences prefs = getSharedPreferences(); - final Resources res = container.getResources(); - final String[] gammaDescriptors = res.getStringArray(R.array.gamma_descriptors); - - // Create multiple sets of seekbars, depending on the - // number of controls the device has - for (int index = 0; index < mNumberOfControls; index++) { - mOriginalColors[index] = DisplayGammaCalibration.getCurGamma(index); - mCurrentColors[index] = mOriginalColors[index].split(" "); - - final String defaultKey = "display_gamma_default_" + index; - if (!prefs.contains(defaultKey)) { - prefs.edit().putString(defaultKey, mOriginalColors[index]).commit(); - } - - if (mNumberOfControls != 1) { - TextView header = (TextView) inflater.inflate( - R.layout.display_gamma_calibration_header, container, false); - - if (index < gammaDescriptors.length) { - header.setText(gammaDescriptors[index]); - } else { - header.setText(res.getString( - R.string.gamma_tuning_control_set_header, index + 1)); - } - container.addView(header); - } - - for (int color = 0; color < BAR_COLORS.length; color++) { - ViewGroup item = (ViewGroup) inflater.inflate( - R.layout.display_gamma_calibration_item, container, false); - - mSeekBars[index][color] = new GammaSeekBar(index, color, item); - mSeekBars[index][color].setGamma(Integer.valueOf(mCurrentColors[index][color])); - // make sure to add the seekbar group to the container _after_ - // creating GammaSeekBar, so that GammaSeekBar has a chance to - // get the correct subviews without getting confused by duplicate IDs - container.addView(item); - } - } - } - - @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) { - for (int index = 0; index < mSeekBars.length; index++) { - final SharedPreferences prefs = getSharedPreferences(); - final String defaultKey = "display_gamma_default_" + index; - // this key is guaranteed to be present, as we have - // created it in onBindDialogView() - final String[] defaultColors = prefs.getString(defaultKey, null).split(" "); - - for (int color = 0; color < BAR_COLORS.length; color++) { - mSeekBars[index][color].setGamma(Integer.valueOf(defaultColors[color])); - mCurrentColors[index][color] = defaultColors[color]; - } - DisplayGammaCalibration.setGamma(index, - TextUtils.join(" ", mCurrentColors[index])); - } - } - }); - } - - @Override - protected void onDialogClosed(boolean positiveResult) { - super.onDialogClosed(positiveResult); - - if (positiveResult) { - Editor editor = getEditor(); - for (int i = 0; i < mNumberOfControls; i++) { - editor.putString("display_gamma_" + i, DisplayGammaCalibration.getCurGamma(i)); - } - editor.commit(); - } else if (mOriginalColors != null) { - for (int i = 0; i < mNumberOfControls; i++) { - DisplayGammaCalibration.setGamma(i, mOriginalColors[i]); - } - } - } - - @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.controlCount = mNumberOfControls; - myState.currentColors = mCurrentColors; - myState.originalColors = mOriginalColors; - - // Restore the old state when the activity or dialog is being paused - for (int i = 0; i < mNumberOfControls; i++) { - DisplayGammaCalibration.setGamma(i, mOriginalColors[i]); - } - mOriginalColors = null; - - 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()); - mNumberOfControls = myState.controlCount; - mOriginalColors = myState.originalColors; - mCurrentColors = myState.currentColors; - - for (int index = 0; index < mNumberOfControls; index++) { - for (int color = 0; color < BAR_COLORS.length; color++) { - mSeekBars[index][color].setGamma(Integer.valueOf(mCurrentColors[index][color])); - } - DisplayGammaCalibration.setGamma(index, TextUtils.join(" ", mCurrentColors[index])); - } - } - - public static boolean isSupported() { - try { - return DisplayGammaCalibration.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); - for (int i = 0; i < DisplayGammaCalibration.getNumberOfControls(); i++) { - final String values = prefs.getString("display_gamma_" + i, null); - if (values != null) { - DisplayGammaCalibration.setGamma(i, values); - } - } - } - - private static class SavedState extends BaseSavedState { - int controlCount; - String[] originalColors; - String[][] currentColors; - - public SavedState(Parcelable superState) { - super(superState); - } - - public SavedState(Parcel source) { - super(source); - controlCount = source.readInt(); - originalColors = source.createStringArray(); - currentColors = new String[controlCount][]; - for (int i = 0; i < controlCount; i++) { - currentColors[i] = source.createStringArray(); - } - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(controlCount); - dest.writeStringArray(originalColors); - for (int i = 0; i < controlCount; i++) { - dest.writeStringArray(currentColors[i]); - } - } - - public static final Parcelable.Creator CREATOR = - new Parcelable.Creator() { - - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } - - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; - } - - private class GammaSeekBar implements SeekBar.OnSeekBarChangeListener { - private int mControlIndex; - private int mColorIndex; - private int mOriginal; - private int mMin; - private SeekBar mSeekBar; - private TextView mValue; - - public GammaSeekBar(int controlIndex, int colorIndex, ViewGroup container) { - mControlIndex = controlIndex; - mColorIndex = colorIndex; - - mMin = DisplayGammaCalibration.getMinValue(controlIndex); - - mValue = (TextView) container.findViewById(R.id.color_value); - mSeekBar = (SeekBar) container.findViewById(R.id.color_seekbar); - - TextView label = (TextView) container.findViewById(R.id.color_text); - label.setText(container.getContext().getString(BAR_COLORS[colorIndex])); - - mSeekBar.setMax(DisplayGammaCalibration.getMaxValue(controlIndex) - mMin); - mSeekBar.setProgress(0); - mValue.setText(String.valueOf(mSeekBar.getProgress() + mMin)); - - // this must be done last, we don't want to apply our initial value to the hardware - mSeekBar.setOnSeekBarChangeListener(this); - } - - public void setGamma(int gamma) { - mSeekBar.setProgress(gamma - mMin); - } - - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - if (fromUser) { - mCurrentColors[mControlIndex][mColorIndex] = String.valueOf(progress + mMin); - DisplayGammaCalibration.setGamma(mControlIndex, - TextUtils.join(" ", mCurrentColors[mControlIndex])); - } - mValue.setText(String.valueOf(progress + mMin)); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - // Do nothing - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - // Do nothing - } - } -} diff --git a/src/com/android/settings/livedisplay/DisplayColor.java b/src/com/android/settings/livedisplay/DisplayColor.java new file mode 100644 index 0000000..6ca0ac7 --- /dev/null +++ b/src/com/android/settings/livedisplay/DisplayColor.java @@ -0,0 +1,255 @@ +/* + * 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. + * 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.IntervalSeekBar; +import com.android.settings.R; + +/** + * 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, + R.id.color_green_seekbar, + R.id.color_blue_seekbar + }; + + private static final int[] SEEKBAR_VALUE_ID = new int[] { + R.id.color_red_value, + R.id.color_green_value, + R.id.color_blue_value + }; + + private ColorSeekBar[] mSeekBars = new ColorSeekBar[SEEKBAR_ID.length]; + + private final float[] mCurrentColors = new float[3]; + private final float[] mOriginalColors = new float[3]; + + public DisplayColor(Context context, AttributeSet attrs) { + super(context, attrs); + + mContext = context; + + setDialogLayoutResource(R.layout.display_color_calibration); + } + + @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); + + 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++) { + 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].mSeekBar.setProgressFloat(mCurrentColors[i]); + } + } + + @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) { + for (int i = 0; i < mSeekBars.length; i++) { + mSeekBars[i].mSeekBar.setProgressFloat(1.00f); + mCurrentColors[i] = 1.0f; + } + updateColors(mCurrentColors); + } + }); + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + updateColors(positiveResult ? mCurrentColors : mOriginalColors); + } + + @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.currentColors = mCurrentColors; + myState.originalColors = mOriginalColors; + + // Restore the old state when the activity or dialog is being paused + updateColors(mOriginalColors); + + 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()); + + 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 { + float[] originalColors; + float[] currentColors; + + public SavedState(Parcelable superState) { + super(superState); + } + + public SavedState(Parcel source) { + super(source); + originalColors = source.createFloatArray(); + currentColors = source.createFloatArray(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeFloatArray(originalColors); + dest.writeFloatArray(currentColors); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + } + + 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 final IntervalSeekBar mSeekBar; + private TextView mValue; + + public ColorSeekBar(IntervalSeekBar seekBar, TextView value, int index) { + mSeekBar = seekBar; + mValue = value; + mIndex = index; + + mSeekBar.setOnSeekBarChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + IntervalSeekBar isb = (IntervalSeekBar)seekBar; + float fp = isb.getProgressFloat(); + if (fromUser) { + mCurrentColors[mIndex] = fp; + updateColors(mCurrentColors); + } + + int percent = Math.round(100F * fp); + mValue.setText(String.format("%d%%", percent)); + } + + @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/DisplayGamma.java b/src/com/android/settings/livedisplay/DisplayGamma.java new file mode 100644 index 0000000..38a187b --- /dev/null +++ b/src/com/android/settings/livedisplay/DisplayGamma.java @@ -0,0 +1,341 @@ +/* + * 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. + * 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.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.content.res.Resources; +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; +import android.preference.DialogPreference; +import android.preference.PreferenceManager; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.SeekBar; +import android.widget.TextView; + +import com.android.settings.R; +import org.cyanogenmod.hardware.DisplayGammaCalibration; + +/** + * Special preference type that allows configuration of Gamma settings + */ +public class DisplayGamma extends DialogPreference { + private static final String TAG = "GammaCalibration"; + + private static final int[] BAR_COLORS = new int[] { + R.string.color_red_title, + R.string.color_green_title, + R.string.color_blue_title + }; + + private GammaSeekBar[][] mSeekBars; + + private String[][] mCurrentColors; + private String[] mOriginalColors; + private int mNumberOfControls; + + public DisplayGamma(Context context, AttributeSet attrs) { + super(context, attrs); + + if (!isSupported()) { + return; + } + + mNumberOfControls = DisplayGammaCalibration.getNumberOfControls(); + mSeekBars = new GammaSeekBar[mNumberOfControls][BAR_COLORS.length]; + + mOriginalColors = new String[mNumberOfControls]; + mCurrentColors = new String[mNumberOfControls][]; + + setDialogLayoutResource(R.layout.display_gamma_calibration); + } + + @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); + + final ViewGroup container = (ViewGroup) view.findViewById(R.id.gamma_container); + final LayoutInflater inflater = LayoutInflater.from(getContext()); + final SharedPreferences prefs = getSharedPreferences(); + final Resources res = container.getResources(); + final String[] gammaDescriptors = res.getStringArray(R.array.gamma_descriptors); + + // Create multiple sets of seekbars, depending on the + // number of controls the device has + for (int index = 0; index < mNumberOfControls; index++) { + mOriginalColors[index] = DisplayGammaCalibration.getCurGamma(index); + mCurrentColors[index] = mOriginalColors[index].split(" "); + + final String defaultKey = "display_gamma_default_" + index; + if (!prefs.contains(defaultKey)) { + prefs.edit().putString(defaultKey, mOriginalColors[index]).commit(); + } + + if (mNumberOfControls != 1) { + TextView header = (TextView) inflater.inflate( + R.layout.display_gamma_calibration_header, container, false); + + if (index < gammaDescriptors.length) { + header.setText(gammaDescriptors[index]); + } else { + header.setText(res.getString( + R.string.gamma_tuning_control_set_header, index + 1)); + } + container.addView(header); + } + + for (int color = 0; color < BAR_COLORS.length; color++) { + ViewGroup item = (ViewGroup) inflater.inflate( + R.layout.display_gamma_calibration_item, container, false); + + mSeekBars[index][color] = new GammaSeekBar(index, color, item); + mSeekBars[index][color].setGamma(Integer.valueOf(mCurrentColors[index][color])); + // make sure to add the seekbar group to the container _after_ + // creating GammaSeekBar, so that GammaSeekBar has a chance to + // get the correct subviews without getting confused by duplicate IDs + container.addView(item); + } + } + } + + @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) { + for (int index = 0; index < mSeekBars.length; index++) { + final SharedPreferences prefs = getSharedPreferences(); + final String defaultKey = "display_gamma_default_" + index; + // this key is guaranteed to be present, as we have + // created it in onBindDialogView() + final String[] defaultColors = prefs.getString(defaultKey, null).split(" "); + + for (int color = 0; color < BAR_COLORS.length; color++) { + mSeekBars[index][color].setGamma(Integer.valueOf(defaultColors[color])); + mCurrentColors[index][color] = defaultColors[color]; + } + DisplayGammaCalibration.setGamma(index, + TextUtils.join(" ", mCurrentColors[index])); + } + } + }); + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + + if (positiveResult) { + Editor editor = getEditor(); + for (int i = 0; i < mNumberOfControls; i++) { + editor.putString("display_gamma_" + i, DisplayGammaCalibration.getCurGamma(i)); + } + editor.commit(); + } else if (mOriginalColors != null) { + for (int i = 0; i < mNumberOfControls; i++) { + DisplayGammaCalibration.setGamma(i, mOriginalColors[i]); + } + } + } + + @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.controlCount = mNumberOfControls; + myState.currentColors = mCurrentColors; + myState.originalColors = mOriginalColors; + + // Restore the old state when the activity or dialog is being paused + for (int i = 0; i < mNumberOfControls; i++) { + DisplayGammaCalibration.setGamma(i, mOriginalColors[i]); + } + mOriginalColors = null; + + 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()); + mNumberOfControls = myState.controlCount; + mOriginalColors = myState.originalColors; + mCurrentColors = myState.currentColors; + + for (int index = 0; index < mNumberOfControls; index++) { + for (int color = 0; color < BAR_COLORS.length; color++) { + mSeekBars[index][color].setGamma(Integer.valueOf(mCurrentColors[index][color])); + } + DisplayGammaCalibration.setGamma(index, TextUtils.join(" ", mCurrentColors[index])); + } + } + + public static boolean isSupported() { + try { + return DisplayGammaCalibration.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); + for (int i = 0; i < DisplayGammaCalibration.getNumberOfControls(); i++) { + final String values = prefs.getString("display_gamma_" + i, null); + if (values != null) { + DisplayGammaCalibration.setGamma(i, values); + } + } + } + + private static class SavedState extends BaseSavedState { + int controlCount; + String[] originalColors; + String[][] currentColors; + + public SavedState(Parcelable superState) { + super(superState); + } + + public SavedState(Parcel source) { + super(source); + controlCount = source.readInt(); + originalColors = source.createStringArray(); + currentColors = new String[controlCount][]; + for (int i = 0; i < controlCount; i++) { + currentColors[i] = source.createStringArray(); + } + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(controlCount); + dest.writeStringArray(originalColors); + for (int i = 0; i < controlCount; i++) { + dest.writeStringArray(currentColors[i]); + } + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + } + + private class GammaSeekBar implements SeekBar.OnSeekBarChangeListener { + private int mControlIndex; + private int mColorIndex; + private int mOriginal; + private int mMin; + private SeekBar mSeekBar; + private TextView mValue; + + public GammaSeekBar(int controlIndex, int colorIndex, ViewGroup container) { + mControlIndex = controlIndex; + mColorIndex = colorIndex; + + mMin = DisplayGammaCalibration.getMinValue(controlIndex); + + mValue = (TextView) container.findViewById(R.id.color_value); + mSeekBar = (SeekBar) container.findViewById(R.id.color_seekbar); + + TextView label = (TextView) container.findViewById(R.id.color_text); + label.setText(container.getContext().getString(BAR_COLORS[colorIndex])); + + mSeekBar.setMax(DisplayGammaCalibration.getMaxValue(controlIndex) - mMin); + mSeekBar.setProgress(0); + mValue.setText(String.valueOf(mSeekBar.getProgress() + mMin)); + + // this must be done last, we don't want to apply our initial value to the hardware + mSeekBar.setOnSeekBarChangeListener(this); + } + + public void setGamma(int gamma) { + mSeekBar.setProgress(gamma - mMin); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (fromUser) { + mCurrentColors[mControlIndex][mColorIndex] = String.valueOf(progress + mMin); + DisplayGammaCalibration.setGamma(mControlIndex, + TextUtils.join(" ", mCurrentColors[mControlIndex])); + } + mValue.setText(String.valueOf(progress + mMin)); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Do nothing + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Do nothing + } + } +} 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 CREATOR = + new Parcelable.Creator() { + + 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 getXmlResourcesToIndex(Context context, + boolean enabled) { + ArrayList result = + new ArrayList(); + + SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.livedisplay; + result.add(sir); + + return result; + } + + @Override + public List getNonIndexableKeys(Context context) { + ArrayList result = new ArrayList(); + 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; + } + }; +} -- cgit v1.1