Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b8a76ae authored by Steve Kondik's avatar Steve Kondik Committed by Danesh M
Browse files

settings: LiveDisplay color profiles

 * Add support for using the new DisplayMode HAL, which
   configures the display for a preset mode.
 * Clean up the settings a bit, and move advanced stuff
   under an advanced category.

Change-Id: If386c93da99346fbee156b057274b60fd064b49d
parent 5fc6f2e4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -456,4 +456,5 @@
        <item>BR</item>
        <item>IN</item>
    </string-array>

</resources>
+15 −0
Original line number Diff line number Diff line
@@ -554,6 +554,21 @@
    <string name="live_display_low_power_summary">Adjust display for lowest power consumption without degradation</string>
    <string name="live_display_enhance_color_title">Enhance colors</string>
    <string name="live_display_enhance_color_summary">Improve color vibrance of flesh tones, scenery, and other images</string>
    <string name="live_display_color_profile_title">Color profile</string>
    <string name="live_display_color_profile_standard_title">Standard</string>
    <string name="live_display_color_profile_standard_summary">Accurate colors and bright whites</string>
    <string name="live_display_color_profile_natural_title">Natural</string>
    <string name="live_display_color_profile_natural_summary">Realistic colors and flesh tones</string>
    <string name="live_display_color_profile_dynamic_title">Dynamic</string>
    <string name="live_display_color_profile_dynamic_summary">Enhanced colors and bright whites</string>
    <string name="live_display_color_profile_cinema_title">Cinema</string>
    <string name="live_display_color_profile_cinema_summary">Perfect color reproduction for video</string>
    <string name="live_display_color_profile_astronomy_title">Astronomy</string>
    <string name="live_display_color_profile_astronomy_summary">Deep red for preserving night vision</string>
    <string name="live_display_color_profile_photography_title">Photography</string>
    <string name="live_display_color_profile_photography_summary">Perfect color reproduction for photos</string>
    <string name="live_display_color_profile_basic_title">Basic</string>
    <string name="live_display_color_profile_basic_summary">Use the display uncalibrated</string>

    <!-- Whether to display IME switcher notifcation -->
    <string name="ime_switcher_notify">Selector notification</string>
+22 −16
Original line number Diff line number Diff line
@@ -21,6 +21,12 @@
        android:key="live_display_options"
        android:title="@string/live_display_title">

        <!-- Color profile -->
        <ListPreference
                android:key="live_display_color_profile"
                android:title="@string/live_display_color_profile_title"
                android:persistent="false" />

        <ListPreference
                android:key="live_display"
                android:title="@string/live_display_mode"
@@ -40,25 +46,11 @@
                android:summary="@string/live_display_outdoor_mode_summary"
                android:defaultValue="true" />

        <!-- Adaptive backlight -->
        <com.android.settings.cyanogenmod.SystemSettingSwitchPreference
                android:key="display_low_power"
                android:title="@string/live_display_low_power_title"
                android:summary="@string/live_display_low_power_summary"
                android:defaultValue="true" />

        <!-- Color enhancement -->
        <com.android.settings.cyanogenmod.SystemSettingSwitchPreference
                android:key="display_color_enhance"
                android:title="@string/live_display_enhance_color_title"
                android:summary="@string/live_display_enhance_color_summary"
                android:defaultValue="true"/>

    </PreferenceCategory>

    <PreferenceCategory
            android:key="calibration"
            android:title="@string/category_calibration">
            android:key="advanced"
            android:title="@string/advanced">

        <!-- screen color -->
        <PreferenceScreen
@@ -86,6 +78,20 @@
                android:summary="@string/gamma_tuning_summary_head"
                android:persistent="false"/>

        <!-- Adaptive backlight -->
        <com.android.settings.cyanogenmod.SystemSettingSwitchPreference
                android:key="display_low_power"
                android:title="@string/live_display_low_power_title"
                android:summary="@string/live_display_low_power_summary"
                android:defaultValue="true" />

        <!-- Color enhancement -->
        <com.android.settings.cyanogenmod.SystemSettingSwitchPreference
                android:key="display_color_enhance"
                android:title="@string/live_display_enhance_color_title"
                android:summary="@string/live_display_enhance_color_summary"
                android:defaultValue="true" />

    </PreferenceCategory>

</PreferenceScreen>
+127 −23
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ 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;

@@ -38,6 +39,7 @@ 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;
import com.android.internal.logging.MetricsLogger;
@@ -48,6 +50,7 @@ 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 java.util.ArrayList;
@@ -59,7 +62,7 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
    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_CATEGORY_ADVANCED = "advanced";

    private static final String KEY_LIVE_DISPLAY = "live_display";
    private static final String KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE =
@@ -72,6 +75,8 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
    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;
@@ -90,6 +95,9 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
    private PreferenceScreen mScreenColorSettings;
    private DisplayTemperature mDisplayTemperature;

    private ListPreference mColorProfile;
    private String[] mColorProfileSummaries;

    private String[] mModeEntries;
    private String[] mModeValues;
    private String[] mModeSummaries;
@@ -97,6 +105,8 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
    private int mDefaultDayTemperature;
    private int mDefaultNightTemperature;

    private boolean mHasDisplayModes = false;

    private CMHardwareManager mHardware;

    @Override
@@ -117,14 +127,14 @@ public class LiveDisplay extends SettingsPreferenceFragment implements

        PreferenceCategory liveDisplayPrefs = (PreferenceCategory)
                findPreference(KEY_CATEGORY_LIVE_DISPLAY);
        PreferenceCategory calibrationPrefs = (PreferenceCategory)
                findPreference(KEY_CATEGORY_CALIBRATION);
        PreferenceCategory advancedPrefs = (PreferenceCategory)
                findPreference(KEY_CATEGORY_ADVANCED);

        int displayMode = CMSettings.System.getIntForUser(resolver,
        int adaptiveMode = CMSettings.System.getIntForUser(resolver,
                CMSettings.System.DISPLAY_TEMPERATURE_MODE,
                0, UserHandle.USER_CURRENT);
        mLiveDisplay = (ListPreference) findPreference(KEY_LIVE_DISPLAY);
        mLiveDisplay.setValue(String.valueOf(displayMode));
        mLiveDisplay.setValue(String.valueOf(adaptiveMode));

        mModeEntries = res.getStringArray(
                org.cyanogenmod.platform.internal.R.array.live_display_entries);
@@ -160,11 +170,13 @@ public class LiveDisplay extends SettingsPreferenceFragment implements

        mDisplayTemperature = (DisplayTemperature) findPreference(KEY_LIVE_DISPLAY_TEMPERATURE);

        mLowPower = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_LOW_POWER);
        if (liveDisplayPrefs != null && mLowPower != null
                && !mHardware.isSupported(FEATURE_ADAPTIVE_BACKLIGHT)) {
            liveDisplayPrefs.removePreference(mLowPower);
            mLowPower = null;
        mColorProfile = (ListPreference) findPreference(KEY_LIVE_DISPLAY_COLOR_PROFILE);
        if (liveDisplayPrefs != null && mColorProfile != null
                && (!mHardware.isSupported(FEATURE_DISPLAY_MODES) || !updateDisplayModes())) {
            liveDisplayPrefs.removePreference(mColorProfile);
        } else {
            mHasDisplayModes = true;
            mColorProfile.setOnPreferenceChangeListener(this);
        }

        mOutdoorMode = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE);
@@ -174,31 +186,33 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
            mOutdoorMode = null;
        }

        mLowPower = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_LOW_POWER);
        if (advancedPrefs != null && mLowPower != null
                && !mHardware.isSupported(FEATURE_ADAPTIVE_BACKLIGHT)) {
            advancedPrefs.removePreference(mLowPower);
            mLowPower = null;
        }

        mColorEnhancement = (SwitchPreference) findPreference(KEY_LIVE_DISPLAY_COLOR_ENHANCE);
        if (liveDisplayPrefs != null && mColorEnhancement != null
        if (advancedPrefs != null && mColorEnhancement != null
                && !mHardware.isSupported(FEATURE_COLOR_ENHANCEMENT)) {
            liveDisplayPrefs.removePreference(mColorEnhancement);
            advancedPrefs.removePreference(mColorEnhancement);
            mColorEnhancement = null;
        }

        if (calibrationPrefs != null
        if (advancedPrefs != null
                && !mHardware.isSupported(FEATURE_DISPLAY_GAMMA_CALIBRATION)) {
            Preference gammaPref = findPreference(KEY_DISPLAY_GAMMA);
            if (gammaPref != null) {
                calibrationPrefs.removePreference(gammaPref);
                advancedPrefs.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);
                }
        if (advancedPrefs != null) {
            if (mScreenColorSettings != null &&
                    (mHasDisplayModes ||!isPostProcessingSupported(getActivity()))) {
                advancedPrefs.removePreference(mScreenColorSettings);
            }
        }
    }
@@ -213,6 +227,7 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
        super.onResume();
        updateModeSummary();
        updateTemperatureSummary();
        updateColorProfileSummary(null);
        mObserver.register(true);
    }

@@ -222,12 +237,88 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
        mObserver.register(false);
    }

    private String getStringForResourceName(String resourceName, String defaultValue) {
        Resources res = getResources();
        int resId = res.getIdentifier(resourceName, "string", "com.android.settings");
        if (resId <= 0) {
            Log.e(TAG, "No resource found for " + resourceName);
            return defaultValue;
        } else {
            return res.getString(resId);
        }
    }

    private boolean updateDisplayModes() {
        final DisplayMode[] modes = mHardware.getDisplayModes();
        if (modes == null || modes.length == 0) {
            return false;
        }

        final DisplayMode cur = mHardware.getDefaultDisplayMode();
        int curId = -1;
        String[] entries = new String[modes.length];
        String[] values = new String[modes.length];
        mColorProfileSummaries = new String[modes.length];
        for (int i = 0; i < modes.length; i++) {
            values[i] = String.valueOf(modes[i].id);
            String name = modes[i].name.toLowerCase().replace(" ", "_");
            String nameRes = String.format("live_display_color_profile_%s_title", name);
            entries[i] = getStringForResourceName(nameRes, modes[i].name);

            // Populate summary
            String summaryRes = String.format("live_display_color_profile_%s_summary", name);
            String summary = getStringForResourceName(summaryRes, null);
            if (summary != null) {
                summary = String.format("%s - %s", entries[i], summary);
            }
            mColorProfileSummaries[i] = summary;

            if (cur != null && modes[i].id == cur.id) {
                curId = -1;
            }
        }
        mColorProfile.setEntries(entries);
        mColorProfile.setEntryValues(values);
        if (curId >= 0) {
            mColorProfile.setValue(String.valueOf(curId));
        }

        return true;
    }

    private void updateColorProfileSummary(String value) {
        if (!mHasDisplayModes) {
            return;
        }

        if (value == null) {
            DisplayMode cur = mHardware.getDefaultDisplayMode();
            if (cur != null && cur.id >= 0) {
                value = String.valueOf(cur.id);
            }
        }

        int idx = mColorProfile.findIndexOfValue(value);
        if (idx < 0) {
            Log.e(TAG, "No summary resource found for profile " + value);
            mColorProfile.setSummary(null);
            return;
        }

        mColorProfile.setValue(value);
        mColorProfile.setSummary(mColorProfileSummaries[idx]);
    }

    private void updateModeSummary() {
        int mode = CMSettings.System.getIntForUser(getContentResolver(),
                CMSettings.System.DISPLAY_TEMPERATURE_MODE,
                MODE_OFF, UserHandle.USER_CURRENT);

        int index = ArrayUtils.indexOf(mModeValues, String.valueOf(mode));
        if (index < 0) {
            index = ArrayUtils.indexOf(mModeValues, String.valueOf(MODE_OFF));
        }

        mLiveDisplay.setSummary(mModeSummaries[index]);

        if (mDisplayTemperature != null) {
@@ -258,6 +349,16 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
            CMSettings.System.putIntForUser(getContentResolver(),
                    CMSettings.System.DISPLAY_TEMPERATURE_MODE,
                    Integer.valueOf((String)objValue), UserHandle.USER_CURRENT);
        } else if (preference == mColorProfile) {
            int id = Integer.valueOf((String)objValue);
            Log.i("LiveDisplay", "Setting mode: " + id);
            for (DisplayMode mode : mHardware.getDisplayModes()) {
                if (mode.id == id) {
                    mHardware.setDisplayMode(mode, true);
                    updateColorProfileSummary((String)objValue);
                    break;
                }
            }
        }
        return true;
    }
@@ -320,6 +421,9 @@ public class LiveDisplay extends SettingsPreferenceFragment implements
             CMHardwareManager hardware = CMHardwareManager.getInstance(context);

            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)) {
                result.add(KEY_LIVE_DISPLAY_AUTO_OUTDOOR_MODE);
            }