summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/livedisplay
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2016-04-10 18:20:46 -0700
committerSteve Kondik <steve@cyngn.com>2016-04-12 03:13:58 -0700
commit4370045fac8a70750bc6e90ddb2bd8ab51fce90a (patch)
tree583dfb4ee69de4bbd9cb71cc44215eaa15486811 /src/com/android/settings/livedisplay
parent70e9aea5d4bc36ac400e5f7e09c51fe018bb168a (diff)
downloadpackages_apps_Settings-4370045fac8a70750bc6e90ddb2bd8ab51fce90a.zip
packages_apps_Settings-4370045fac8a70750bc6e90ddb2bd8ab51fce90a.tar.gz
packages_apps_Settings-4370045fac8a70750bc6e90ddb2bd8ab51fce90a.tar.bz2
livedisplay: Update Settings for new LiveDisplay API
* LiveDisplay is getting a proper API. This patch refactors the settings to use it. * Also kill off the deprecated "gamma calibration" tunable which nobody should be using at this point. Change-Id: I948b8845cd06c8c634a201cb5d5b93b5766cc51d
Diffstat (limited to 'src/com/android/settings/livedisplay')
-rw-r--r--src/com/android/settings/livedisplay/DisplayColor.java68
-rw-r--r--src/com/android/settings/livedisplay/DisplayGamma.java383
-rw-r--r--src/com/android/settings/livedisplay/DisplayTemperature.java40
-rw-r--r--src/com/android/settings/livedisplay/LiveDisplay.java102
4 files changed, 56 insertions, 537 deletions
diff --git a/src/com/android/settings/livedisplay/DisplayColor.java b/src/com/android/settings/livedisplay/DisplayColor.java
index 5db508f..f6fee82 100644
--- a/src/com/android/settings/livedisplay/DisplayColor.java
+++ b/src/com/android/settings/livedisplay/DisplayColor.java
@@ -16,17 +16,13 @@
package com.android.settings.livedisplay;
-import static cyanogenmod.hardware.CMHardwareManager.FEATURE_DISPLAY_COLOR_CALIBRATION;
-
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;
@@ -36,8 +32,7 @@ import android.widget.TextView;
import com.android.settings.IntervalSeekBar;
import com.android.settings.R;
-import cyanogenmod.hardware.CMHardwareManager;
-import cyanogenmod.providers.CMSettings;
+import cyanogenmod.hardware.LiveDisplayManager;
/**
* Special preference type that allows configuration of Color settings
@@ -46,11 +41,7 @@ public class DisplayColor extends DialogPreference {
private static final String TAG = "ColorCalibration";
private final Context mContext;
-
- private final int minRGB;
- private final int maxRGB;
- private final float defaultRGB;
- private final boolean useCMHW;
+ private final LiveDisplayManager mLiveDisplay;
// These arrays must all match in length and order
private static final int[] SEEKBAR_ID = new int[] {
@@ -74,19 +65,7 @@ public class DisplayColor extends DialogPreference {
super(context, attrs);
mContext = context;
-
- final CMHardwareManager mHardware = CMHardwareManager.getInstance(context);
- useCMHW = mHardware.isSupported(FEATURE_DISPLAY_COLOR_CALIBRATION);
- if (useCMHW) {
- minRGB = mHardware.getDisplayColorCalibrationMin();
- maxRGB = mHardware.getDisplayColorCalibrationMax();
- defaultRGB = (float) mHardware.getDisplayColorCalibrationDefault() / maxRGB;
- } else {
- // Initialize these just to avoid compiler errors.
- minRGB = 20;
- maxRGB = 100;
- defaultRGB = 1.0f;
- }
+ mLiveDisplay = LiveDisplayManager.getInstance(mContext);
setDialogLayoutResource(R.layout.display_color_calibration);
}
@@ -105,38 +84,16 @@ public class DisplayColor extends DialogPreference {
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
- String colorAdjustmentTemp = CMSettings.System.getStringForUser(
- mContext.getContentResolver(),
- CMSettings.System.DISPLAY_COLOR_ADJUSTMENT,
- UserHandle.USER_CURRENT);
- String[] colorAdjustment = colorAdjustmentTemp == null ?
- null : colorAdjustmentTemp.split(" ");
- if (colorAdjustment == null || colorAdjustment.length != 3) {
- colorAdjustment = new String[] { Float.toString(defaultRGB),
- Float.toString(defaultRGB), Float.toString(defaultRGB) };
- }
- try {
- mOriginalColors[0] = Float.parseFloat(colorAdjustment[0]);
- mOriginalColors[1] = Float.parseFloat(colorAdjustment[1]);
- mOriginalColors[2] = Float.parseFloat(colorAdjustment[2]);
- } catch (NumberFormatException e) {
- mOriginalColors[0] = defaultRGB;
- mOriginalColors[1] = defaultRGB;
- mOriginalColors[2] = defaultRGB;
- }
-
+ System.arraycopy(mLiveDisplay.getColorAdjustment(), 0, mOriginalColors, 0, 3);
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);
- if (useCMHW) {
- mSeekBars[i].mSeekBar.setMinimum((float) minRGB / maxRGB);
- /* Maximum hasn't changed but it's relative to the minimum so it needs
- to be reset */
- mSeekBars[i].mSeekBar.setMaximum(1.0f);
- }
+ mSeekBars[i].mSeekBar.setMinimum(0.1f);
+ mSeekBars[i].mSeekBar.setMaximum(1.0f);
+
mSeekBars[i].mSeekBar.setProgressFloat(mCurrentColors[i]);
int percent = Math.round(100F * mCurrentColors[i]);
value.setText(String.format("%d%%", percent));
@@ -155,8 +112,8 @@ public class DisplayColor extends DialogPreference {
@Override
public void onClick(View v) {
for (int i = 0; i < mSeekBars.length; i++) {
- mSeekBars[i].mSeekBar.setProgressFloat(defaultRGB);
- mCurrentColors[i] = defaultRGB;
+ mSeekBars[i].mSeekBar.setProgressFloat(1.0f);
+ mCurrentColors[i] = 1.0f;
}
updateColors(mCurrentColors);
}
@@ -241,12 +198,7 @@ public class DisplayColor extends DialogPreference {
}
private void updateColors(float[] colors) {
- CMSettings.System.putStringForUser(mContext.getContentResolver(),
- CMSettings.System.DISPLAY_COLOR_ADJUSTMENT,
- new StringBuilder().append(colors[0]).append(" ")
- .append(colors[1]).append(" ")
- .append(colors[2]).toString(),
- UserHandle.USER_CURRENT);
+ mLiveDisplay.setColorAdjustment(colors);
}
private class ColorSeekBar implements SeekBar.OnSeekBarChangeListener {
diff --git a/src/com/android/settings/livedisplay/DisplayGamma.java b/src/com/android/settings/livedisplay/DisplayGamma.java
deleted file mode 100644
index 2b44cea..0000000
--- a/src/com/android/settings/livedisplay/DisplayGamma.java
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * 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 cyanogenmod.hardware.CMHardwareManager;
-import cyanogenmod.providers.CMSettings;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-/**
- * 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 int[][] mCurrentColors;
- private int[][] mOriginalColors;
- private int mNumberOfControls;
- private CMHardwareManager mHardware;
-
- public DisplayGamma(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- mHardware = CMHardwareManager.getInstance(context);
- if (!mHardware.isSupported(CMHardwareManager.FEATURE_DISPLAY_GAMMA_CALIBRATION)) {
- return;
- }
-
- mNumberOfControls = mHardware.getNumGammaControls();
- mSeekBars = new GammaSeekBar[mNumberOfControls][BAR_COLORS.length];
-
- mOriginalColors = new int[mNumberOfControls][];
- mCurrentColors = new int[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] = mHardware.getDisplayGammaCalibration(index);
- mCurrentColors[index] = Arrays.copyOf(mOriginalColors[index],
- mOriginalColors[index].length);
-
- final String defaultKey = "display_gamma_default_" + index;
- if (!prefs.contains(defaultKey)) {
- prefs.edit()
- .putString(defaultKey, buildPreferenceValue(mOriginalColors[index]))
- .apply();
- }
-
- 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);
- }
-
- int min = mHardware.getDisplayGammaCalibrationMin();
- int max = mHardware.getDisplayGammaCalibrationMax();
- 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, min, max);
- mSeekBars[index][color].setGamma(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 value = prefs.getString(defaultKey, null);
- final String[] defaultColors = value.split(" ");
-
- for (int color = 0; color < BAR_COLORS.length; color++) {
- int val = Integer.valueOf(defaultColors[color]);
- mSeekBars[index][color].setGamma(val);
- mCurrentColors[index][color] = val;
- }
- writeDisplayGamma(getContext(), index, 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,
- buildPreferenceValue(mHardware.getDisplayGammaCalibration(i)));
- }
- editor.apply();
- } else if (mOriginalColors != null) {
- for (int i = 0; i < mNumberOfControls; i++) {
- writeDisplayGamma(getContext(), 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++) {
- writeDisplayGamma(getContext(), 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(mCurrentColors[index][color]);
- }
- writeDisplayGamma(getContext(), index, mCurrentColors[index]);
- }
- }
-
- private String buildPreferenceValue(int[] colorValues) {
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < colorValues.length; i++) {
- if (i != 0) {
- builder.append(" ");
- }
- builder.append(colorValues[i]);
- }
- return builder.toString();
- }
-
- public static void restore(Context context) {
- final CMHardwareManager hardware = CMHardwareManager.getInstance(context);
- if (!hardware.isSupported(CMHardwareManager.FEATURE_DISPLAY_GAMMA_CALIBRATION)) {
- return;
- }
-
- final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- int[] rgb = new int[3];
- for (int i = 0; i < hardware.getNumGammaControls(); i++) {
- final String value = prefs.getString("display_gamma_" + i, null);
- if (value != null) {
- final String[] values = value.split(" ");
- rgb[0] = Integer.valueOf(values[0]);
- rgb[1] = Integer.valueOf(values[1]);
- rgb[2] = Integer.valueOf(values[2]);
- writeDisplayGamma(context, i, rgb);
- }
- }
- }
-
- private static class SavedState extends BaseSavedState {
- int controlCount;
- int[][] originalColors;
- int[][] currentColors;
-
- public SavedState(Parcelable superState) {
- super(superState);
- }
-
- public SavedState(Parcel source) {
- super(source);
- controlCount = source.readInt();
- originalColors = new int[controlCount][];
- currentColors = new int[controlCount][];
- for (int i = 0; i < controlCount; i++) {
- originalColors[i] = source.createIntArray();
- }
- for (int i = 0; i < controlCount; i++) {
- currentColors[i] = source.createIntArray();
- }
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
- dest.writeInt(controlCount);
- for (int i = 0; i < controlCount; i++) {
- dest.writeIntArray(originalColors[i]);
- }
- for (int i = 0; i < controlCount; i++) {
- dest.writeIntArray(currentColors[i]);
- }
- }
-
- 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 static void writeDisplayGamma(Context context, int index, int[] entries) {
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < entries.length; i++) {
- builder.append(i);
- if (i != entries.length - 1) {
- builder.append("|");
- }
- }
- CMSettings.Secure.putString(context.getContentResolver(),
- CMSettings.Secure.DISPLAY_GAMMA_CALIBRATION_PREFIX + index,
- builder.toString());
- }
-
- private class GammaSeekBar implements SeekBar.OnSeekBarChangeListener {
- private int mControlIndex;
- private int mColorIndex;
- private int mOriginal;
- private int mMin;
- private int mMax;
- private SeekBar mSeekBar;
- private TextView mValue;
-
- public GammaSeekBar(int controlIndex, int colorIndex, ViewGroup container,
- int min, int max) {
- mControlIndex = controlIndex;
- mColorIndex = colorIndex;
-
- mMin = min;
- mMax = max;
-
- 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(mMax - 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] = progress + mMin;
- writeDisplayGamma(getContext(), mControlIndex, 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
index 24ca747..f63204b 100644
--- a/src/com/android/settings/livedisplay/DisplayTemperature.java
+++ b/src/com/android/settings/livedisplay/DisplayTemperature.java
@@ -22,9 +22,7 @@ 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;
@@ -32,7 +30,9 @@ import android.widget.SeekBar;
import android.widget.TextView;
import com.android.settings.R;
-import cyanogenmod.providers.CMSettings;
+
+import cyanogenmod.hardware.LiveDisplayConfig;
+import cyanogenmod.hardware.LiveDisplayManager;
/**
* Preference for selection of color temperature range for LiveDisplay
@@ -48,17 +48,14 @@ public class DisplayTemperature extends DialogPreference {
private int mOriginalDayTemperature;
private int mOriginalNightTemperature;
- private final int mDefaultDayTemperature;
- private final int mDefaultNightTemperature;
+ private final LiveDisplayManager mLiveDisplay;
+ private final LiveDisplayConfig mConfig;
public DisplayTemperature(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
-
- mDefaultDayTemperature = mContext.getResources().getInteger(
- org.cyanogenmod.platform.internal.R.integer.config_dayColorTemperature);
- mDefaultNightTemperature = mContext.getResources().getInteger(
- org.cyanogenmod.platform.internal.R.integer.config_nightColorTemperature);
+ mLiveDisplay = LiveDisplayManager.getInstance(mContext);
+ mConfig = mLiveDisplay.getConfig();
setDialogLayoutResource(R.layout.display_temperature);
}
@@ -77,14 +74,8 @@ public class DisplayTemperature extends DialogPreference {
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
- mOriginalDayTemperature = CMSettings.System.getIntForUser(mContext.getContentResolver(),
- CMSettings.System.DISPLAY_TEMPERATURE_DAY,
- mDefaultDayTemperature,
- UserHandle.USER_CURRENT);
- mOriginalNightTemperature = CMSettings.System.getIntForUser(mContext.getContentResolver(),
- CMSettings.System.DISPLAY_TEMPERATURE_NIGHT,
- mDefaultNightTemperature,
- UserHandle.USER_CURRENT);
+ mOriginalDayTemperature = mLiveDisplay.getDayColorTemperature();
+ mOriginalNightTemperature = mLiveDisplay.getNightColorTemperature();
SeekBar day = (SeekBar) view.findViewById(R.id.day_temperature_seekbar);
TextView dayText = (TextView) view.findViewById(R.id.day_temperature_value);
@@ -109,8 +100,8 @@ public class DisplayTemperature extends DialogPreference {
defaultsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- mDayTemperature.setProgress(mDefaultDayTemperature);
- mNightTemperature.setProgress(mDefaultNightTemperature);
+ mDayTemperature.setProgress(mConfig.getDefaultDayTemperature());
+ mNightTemperature.setProgress(mConfig.getDefaultNightTemperature());
updateTemperature(true);
}
});
@@ -206,13 +197,8 @@ public class DisplayTemperature extends DialogPreference {
int night = accept ? mNightTemperature.getProgress() : mOriginalNightTemperature;
callChangeListener(new Integer[] { day, night });
- CMSettings.System.putIntForUser(mContext.getContentResolver(),
- CMSettings.System.DISPLAY_TEMPERATURE_DAY, day,
- UserHandle.USER_CURRENT);
-
- CMSettings.System.putIntForUser(mContext.getContentResolver(),
- CMSettings.System.DISPLAY_TEMPERATURE_NIGHT, night,
- UserHandle.USER_CURRENT);
+ mLiveDisplay.setDayColorTemperature(day);
+ mLiveDisplay.setNightColorTemperature(night);
}
private class ColorTemperatureSeekBar implements SeekBar.OnSeekBarChangeListener {
diff --git a/src/com/android/settings/livedisplay/LiveDisplay.java b/src/com/android/settings/livedisplay/LiveDisplay.java
index 7000cc8..5cb7aff 100644
--- a/src/com/android/settings/livedisplay/LiveDisplay.java
+++ b/src/com/android/settings/livedisplay/LiveDisplay.java
@@ -15,20 +15,17 @@
*/
package com.android.settings.livedisplay;
-import static cyanogenmod.hardware.CMHardwareManager.FEATURE_ADAPTIVE_BACKLIGHT;
-import static cyanogenmod.hardware.CMHardwareManager.FEATURE_COLOR_ENHANCEMENT;
-import static cyanogenmod.hardware.CMHardwareManager.FEATURE_DISPLAY_MODES;
-import static cyanogenmod.hardware.CMHardwareManager.FEATURE_DISPLAY_GAMMA_CALIBRATION;
-import static cyanogenmod.hardware.CMHardwareManager.FEATURE_SUNLIGHT_ENHANCEMENT;
+import static cyanogenmod.hardware.LiveDisplayManager.FEATURE_CABC;
+import static cyanogenmod.hardware.LiveDisplayManager.FEATURE_COLOR_ENHANCEMENT;
+import static cyanogenmod.hardware.LiveDisplayManager.FEATURE_DISPLAY_MODES;
+import static cyanogenmod.hardware.LiveDisplayManager.MODE_OFF;
+import static cyanogenmod.hardware.LiveDisplayManager.MODE_OUTDOOR;
-import android.app.Activity;
-import android.database.ContentObserver;
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;
@@ -38,7 +35,6 @@ import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.provider.SearchIndexableResource;
-import android.provider.Settings;
import android.util.Log;
import com.android.internal.util.ArrayUtils;
@@ -48,14 +44,17 @@ import com.android.settings.Utils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
-import cyanogenmod.hardware.CMHardwareManager;
-import cyanogenmod.hardware.DisplayMode;
-import cyanogenmod.providers.CMSettings;
import org.cyanogenmod.internal.logging.CMMetricsLogger;
import java.util.ArrayList;
import java.util.List;
+import cyanogenmod.hardware.CMHardwareManager;
+import cyanogenmod.hardware.DisplayMode;
+import cyanogenmod.hardware.LiveDisplayConfig;
+import cyanogenmod.hardware.LiveDisplayManager;
+import cyanogenmod.providers.CMSettings;
+
public class LiveDisplay extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, Indexable {
@@ -72,17 +71,10 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
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";
private static final String KEY_LIVE_DISPLAY_COLOR_PROFILE = "live_display_color_profile";
- public static final int MODE_OFF = 0;
- public static final int MODE_NIGHT = 1;
- public static final int MODE_AUTO = 2;
- public static final int MODE_OUTDOOR = 3;
- public static final int MODE_DAY = 4;
-
private final Handler mHandler = new Handler();
private final SettingsObserver mObserver = new SettingsObserver();
@@ -102,26 +94,21 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
private String[] mModeValues;
private String[] mModeSummaries;
- private int mDefaultDayTemperature;
- private int mDefaultNightTemperature;
-
private boolean mHasDisplayModes = false;
+ private LiveDisplayManager mLiveDisplayManager;
+ private LiveDisplayConfig mConfig;
+
private CMHardwareManager mHardware;
@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(
- org.cyanogenmod.platform.internal.R.integer.config_dayColorTemperature);
- mDefaultNightTemperature = res.getInteger(
- org.cyanogenmod.platform.internal.R.integer.config_nightColorTemperature);
-
- mHardware = CMHardwareManager.getInstance(activity);
+ mHardware = CMHardwareManager.getInstance(getActivity());
+ mLiveDisplayManager = LiveDisplayManager.getInstance(getActivity());
+ mConfig = mLiveDisplayManager.getConfig();
addPreferencesFromResource(R.xml.livedisplay);
@@ -130,9 +117,8 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
PreferenceCategory advancedPrefs = (PreferenceCategory)
findPreference(KEY_CATEGORY_ADVANCED);
- int adaptiveMode = CMSettings.System.getIntForUser(resolver,
- CMSettings.System.DISPLAY_TEMPERATURE_MODE,
- 0, UserHandle.USER_CURRENT);
+ int adaptiveMode = mLiveDisplayManager.getMode();
+
mLiveDisplay = (ListPreference) findPreference(KEY_LIVE_DISPLAY);
mLiveDisplay.setValue(String.valueOf(adaptiveMode));
@@ -144,7 +130,7 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
org.cyanogenmod.platform.internal.R.array.live_display_summaries);
// Remove outdoor mode from lists if there is no support
- if (!mHardware.isSupported(FEATURE_SUNLIGHT_ENHANCEMENT)) {
+ if (!mConfig.hasFeature(LiveDisplayManager.MODE_OUTDOOR)) {
int idx = ArrayUtils.indexOf(mModeValues, String.valueOf(MODE_OUTDOOR));
String[] entriesTemp = new String[mModeEntries.length - 1];
String[] valuesTemp = new String[mModeValues.length - 1];
@@ -172,7 +158,7 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
mColorProfile = (ListPreference) findPreference(KEY_LIVE_DISPLAY_COLOR_PROFILE);
if (liveDisplayPrefs != null && mColorProfile != null
- && (!mHardware.isSupported(FEATURE_DISPLAY_MODES) || !updateDisplayModes())) {
+ && (!mConfig.hasFeature(FEATURE_DISPLAY_MODES) || !updateDisplayModes())) {
liveDisplayPrefs.removePreference(mColorProfile);
} else {
mHasDisplayModes = true;
@@ -181,33 +167,25 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
mOutdoorMode = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE);
if (liveDisplayPrefs != null && mOutdoorMode != null
- && !mHardware.isSupported(FEATURE_SUNLIGHT_ENHANCEMENT)) {
+ && !mConfig.hasFeature(MODE_OUTDOOR)) {
liveDisplayPrefs.removePreference(mOutdoorMode);
mOutdoorMode = null;
}
mLowPower = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_LOW_POWER);
if (advancedPrefs != null && mLowPower != null
- && !mHardware.isSupported(FEATURE_ADAPTIVE_BACKLIGHT)) {
+ && !mConfig.hasFeature(FEATURE_CABC)) {
advancedPrefs.removePreference(mLowPower);
mLowPower = null;
}
mColorEnhancement = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_COLOR_ENHANCE);
if (advancedPrefs != null && mColorEnhancement != null
- && !mHardware.isSupported(FEATURE_COLOR_ENHANCEMENT)) {
+ && !mConfig.hasFeature(FEATURE_COLOR_ENHANCEMENT)) {
advancedPrefs.removePreference(mColorEnhancement);
mColorEnhancement = null;
}
- if (advancedPrefs != null
- && !mHardware.isSupported(FEATURE_DISPLAY_GAMMA_CALIBRATION)) {
- Preference gammaPref = findPreference(KEY_DISPLAY_GAMMA);
- if (gammaPref != null) {
- advancedPrefs.removePreference(gammaPref);
- }
- }
-
mScreenColorSettings = (PreferenceScreen) findPreference(KEY_SCREEN_COLOR_SETTINGS);
if (advancedPrefs != null) {
if (mScreenColorSettings != null &&
@@ -310,9 +288,7 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
}
private void updateModeSummary() {
- int mode = CMSettings.System.getIntForUser(getContentResolver(),
- CMSettings.System.DISPLAY_TEMPERATURE_MODE,
- MODE_OFF, UserHandle.USER_CURRENT);
+ int mode = mLiveDisplayManager.getMode();
int index = ArrayUtils.indexOf(mModeValues, String.valueOf(mode));
if (index < 0) {
@@ -331,14 +307,8 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
}
private void updateTemperatureSummary() {
- int day = CMSettings.System.getIntForUser(getContentResolver(),
- CMSettings.System.DISPLAY_TEMPERATURE_DAY,
- mDefaultDayTemperature,
- UserHandle.USER_CURRENT);
- int night = CMSettings.System.getIntForUser(getContentResolver(),
- CMSettings.System.DISPLAY_TEMPERATURE_NIGHT,
- mDefaultNightTemperature,
- UserHandle.USER_CURRENT);
+ int day = mLiveDisplayManager.getDayColorTemperature();
+ int night = mLiveDisplayManager.getNightColorTemperature();
mDisplayTemperature.setSummary(getResources().getString(
R.string.live_display_color_temperature_summary, day, night));
@@ -347,9 +317,7 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
if (preference == mLiveDisplay) {
- CMSettings.System.putIntForUser(getContentResolver(),
- CMSettings.System.DISPLAY_TEMPERATURE_MODE,
- Integer.valueOf((String)objValue), UserHandle.USER_CURRENT);
+ mLiveDisplayManager.setMode(Integer.valueOf((String)objValue));
} else if (preference == mColorProfile) {
int id = Integer.valueOf((String)objValue);
Log.i("LiveDisplay", "Setting mode: " + id);
@@ -401,8 +369,6 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
- private boolean mHasSunlightEnhancement, mHasColorEnhancement, mHasLowPower;
- private boolean mHasDisplayGamma;
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
@@ -419,19 +385,20 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
@Override
public List<String> getNonIndexableKeys(Context context) {
- CMHardwareManager hardware = CMHardwareManager.getInstance(context);
+ final CMHardwareManager hardware = CMHardwareManager.getInstance(context);
+ final LiveDisplayConfig config = LiveDisplayManager.getInstance(context).getConfig();
ArrayList<String> result = new ArrayList<String>();
if (!hardware.isSupported(FEATURE_DISPLAY_MODES)) {
result.add(KEY_LIVE_DISPLAY_COLOR_PROFILE);
}
- if (!hardware.isSupported(FEATURE_SUNLIGHT_ENHANCEMENT)) {
+ if (!config.hasFeature(MODE_OUTDOOR)) {
result.add(KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE);
}
- if (!hardware.isSupported(FEATURE_COLOR_ENHANCEMENT)) {
+ if (!config.hasFeature(FEATURE_COLOR_ENHANCEMENT)) {
result.add(KEY_LIVE_DISPLAY_COLOR_ENHANCE);
}
- if (!hardware.isSupported(FEATURE_ADAPTIVE_BACKLIGHT)) {
+ if (!config.hasFeature(FEATURE_CABC)) {
result.add(KEY_LIVE_DISPLAY_LOW_POWER);
}
if (!isPostProcessingSupported(context)) {
@@ -439,9 +406,6 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
} else {
result.add(KEY_DISPLAY_COLOR);
}
- if (!hardware.isSupported(FEATURE_DISPLAY_GAMMA_CALIBRATION)) {
- result.add(KEY_DISPLAY_GAMMA);
- }
return result;
}
};