diff options
author | Danesh M <daneshm90@gmail.com> | 2016-03-09 11:49:57 -0800 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2016-03-14 13:37:13 -0700 |
commit | 9c35338443d9d9d84bbfe4c899d82d2da1f85b60 (patch) | |
tree | cc8debc41a1f437cccbdb53e4efc139e9e272bb6 /src/com/android | |
parent | d8c29b8f2327a2df83e606e286d053cfce28ba16 (diff) | |
download | packages_apps_Settings-9c35338443d9d9d84bbfe4c899d82d2da1f85b60.zip packages_apps_Settings-9c35338443d9d9d84bbfe4c899d82d2da1f85b60.tar.gz packages_apps_Settings-9c35338443d9d9d84bbfe4c899d82d2da1f85b60.tar.bz2 |
Settings : Add multiuser support for CMHardware
- Show button for other users
- Use services instead of CMHardware for vibrator and touch sensitivity
- Do a one time restore of tunable settings
CYNGNOS-1166
Change-Id: I0de8eef6bf73c344ee5789e9650dd96b25b1a6bc
Diffstat (limited to 'src/com/android')
6 files changed, 70 insertions, 56 deletions
diff --git a/src/com/android/settings/ButtonSettings.java b/src/com/android/settings/ButtonSettings.java index 30ac090..09c9b7d 100644 --- a/src/com/android/settings/ButtonSettings.java +++ b/src/com/android/settings/ButtonSettings.java @@ -628,25 +628,8 @@ public class ButtonSettings extends SettingsPreferenceFragment implements } private static void writeDisableNavkeysOption(Context context, boolean enabled) { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - final int defaultBrightness = context.getResources().getInteger( - com.android.internal.R.integer.config_buttonBrightnessSettingDefault); - CMSettings.Secure.putInt(context.getContentResolver(), CMSettings.Secure.DEV_FORCE_SHOW_NAVBAR, enabled ? 1 : 0); - CMHardwareManager hardware = CMHardwareManager.getInstance(context); - hardware.set(CMHardwareManager.FEATURE_KEY_DISABLE, enabled); - - /* Save/restore button timeouts to disable them in softkey mode */ - if (enabled) { - CMSettings.Secure.putInt(context.getContentResolver(), - CMSettings.Secure.BUTTON_BRIGHTNESS, 0); - } else { - int oldBright = prefs.getInt(ButtonBacklightBrightness.KEY_BUTTON_BACKLIGHT, - defaultBrightness); - CMSettings.Secure.putInt(context.getContentResolver(), - CMSettings.Secure.BUTTON_BRIGHTNESS, oldBright); - } } private void updateDisableNavkeysOption() { diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index e67c0af..bf3dc84 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -293,7 +293,8 @@ public class SettingsActivity extends Activity R.id.print_settings, R.id.home_settings, R.id.dashboard, - R.id.privacy_settings_cyanogenmod + R.id.privacy_settings_cyanogenmod, + R.id.button_settings }; private static final String[] ENTRY_FRAGMENTS = { diff --git a/src/com/android/settings/cyanogenmod/BootReceiver.java b/src/com/android/settings/cyanogenmod/BootReceiver.java index 14e004d..19c2794 100644 --- a/src/com/android/settings/cyanogenmod/BootReceiver.java +++ b/src/com/android/settings/cyanogenmod/BootReceiver.java @@ -19,6 +19,9 @@ package com.android.settings.cyanogenmod; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + import com.android.settings.ButtonSettings; import com.android.settings.R; import com.android.settings.Utils; @@ -32,14 +35,19 @@ import com.android.settings.DevelopmentSettings; public class BootReceiver extends BroadcastReceiver { private static final String TAG = "BootReceiver"; + private static final String ONE_TIME_TUNABLE_RESTORE = "hardware_tunable_restored"; @Override public void onReceive(Context ctx, Intent intent) { - /* Restore the hardware tunable values */ - ButtonSettings.restoreKeyDisabler(ctx); - DisplayGamma.restore(ctx); - VibratorIntensity.restore(ctx); - InputMethodAndLanguageSettings.restore(ctx); + if (!hasRestoredTunable(ctx)) { + /* Restore the hardware tunable values */ + ButtonSettings.restoreKeyDisabler(ctx); + DisplayGamma.restore(ctx); + VibratorIntensity.restore(ctx); + InputMethodAndLanguageSettings.restore(ctx); + setRestoredTunable(ctx); + } + LocationSettings.restore(ctx); // Extract the contributors database @@ -47,4 +55,14 @@ public class BootReceiver extends BroadcastReceiver { DevelopmentSettings.initializeUpdateRecoveryOption(); } + + private boolean hasRestoredTunable(Context context) { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + return preferences.getBoolean(ONE_TIME_TUNABLE_RESTORE, false); + } + + private void setRestoredTunable(Context context) { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + preferences.edit().putBoolean(ONE_TIME_TUNABLE_RESTORE, true).apply(); + } } diff --git a/src/com/android/settings/hardware/VibratorIntensity.java b/src/com/android/settings/hardware/VibratorIntensity.java index 8bb39ca..e847933 100644 --- a/src/com/android/settings/hardware/VibratorIntensity.java +++ b/src/com/android/settings/hardware/VibratorIntensity.java @@ -37,6 +37,7 @@ import android.widget.TextView; import android.widget.Button; import cyanogenmod.hardware.CMHardwareManager; +import cyanogenmod.providers.CMSettings; import com.android.settings.R; @@ -52,6 +53,7 @@ public class VibratorIntensity extends DialogPreference implements private int mDefaultValue; private int mWarningValue; private CMHardwareManager mHardware; + private final Vibrator mVibrator; private Drawable mProgressDrawable; private Drawable mProgressThumb; @@ -61,6 +63,7 @@ public class VibratorIntensity extends DialogPreference implements super(context, attrs); mHardware = CMHardwareManager.getInstance(context); + mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (!mHardware.isSupported(CMHardwareManager.FEATURE_VIBRATOR)) { return; @@ -116,13 +119,8 @@ public class VibratorIntensity extends DialogPreference implements mRedFilter = new LightingColorFilter(Color.BLACK, getContext().getResources().getColor(android.R.color.holo_red_light)); - // Restore percent value from SharedPreferences object - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - int defaultValue = intensityToPercent(mMinValue, mMaxValue, mDefaultValue); - int percent = prefs.getInt(PREF_NAME, defaultValue); - mSeekBar.setOnSeekBarChangeListener(this); - mSeekBar.setProgress(percent); + mSeekBar.setProgress(intensityToPercent(mMinValue, mMaxValue, mOriginalValue)); } @Override @@ -150,7 +148,8 @@ public class VibratorIntensity extends DialogPreference implements SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); prefs.edit().putInt(PREF_NAME, mSeekBar.getProgress()).commit(); } else { - mHardware.setVibratorIntensity(mHardware.getVibratorIntensity()); + CMSettings.Secure.putInt(getContext().getContentResolver(), + CMSettings.Secure.VIBRATOR_INTENSITY, mOriginalValue); } } @@ -160,14 +159,15 @@ public class VibratorIntensity extends DialogPreference implements return; } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - int vibrator = hardware.getVibratorIntensity(); int min = hardware.getVibratorMinIntensity(); int max = hardware.getVibratorMaxIntensity(); int defaultValue = intensityToPercent(min, max, hardware.getVibratorDefaultIntensity()); int percent = prefs.getInt(PREF_NAME, defaultValue); - hardware.setVibratorIntensity(percentToIntensity(min, max, percent)); + CMSettings.Secure.putInt(context.getContentResolver(), + CMSettings.Secure.VIBRATOR_INTENSITY, percentToIntensity(min, max, + percentToIntensity(min, max, percent))); } @Override @@ -183,8 +183,9 @@ public class VibratorIntensity extends DialogPreference implements mProgressThumb.setColorFilter(shouldWarn ? mRedFilter : null); } - mHardware.setVibratorIntensity(percentToIntensity(mMinValue, mMaxValue, - progress)); + CMSettings.Secure.putInt(getContext().getContentResolver(), + CMSettings.Secure.VIBRATOR_INTENSITY, percentToIntensity(mMinValue, mMaxValue, + progress)); mValue.setText(String.format("%d%%", progress)); } diff --git a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java index 604d75f..1e7b35c 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java +++ b/src/com/android/settings/inputmethod/InputMethodAndLanguageSettings.java @@ -438,11 +438,13 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment CMSettings.System.putInt(getActivity().getContentResolver(), CMSettings.System.HIGH_TOUCH_SENSITIVITY_ENABLE, mHighTouchSensitivityEnable ? 1 : 0); - return mHardware.set(CMHardwareManager.FEATURE_HIGH_TOUCH_SENSITIVITY, - mHighTouchSensitivityEnable); + return true; } else if (preference == mTouchscreenHovering) { - return mHardware.set(CMHardwareManager.FEATURE_TOUCH_HOVERING, - mTouchscreenHovering.isChecked()); + boolean touchHoveringEnable = mTouchscreenHovering.isChecked(); + CMSettings.Secure.putInt(getActivity().getContentResolver(), + CMSettings.Secure.FEATURE_TOUCH_HOVERING, + touchHoveringEnable ? 1 : 0); + return true; } else if (preference instanceof PreferenceScreen) { if (preference.getFragment() != null) { // Fragment will be handled correctly by the super class. @@ -786,21 +788,16 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment if (hardware.isSupported(CMHardwareManager.FEATURE_HIGH_TOUCH_SENSITIVITY)) { final boolean enabled = prefs.getBoolean(KEY_HIGH_TOUCH_SENSITIVITY, hardware.get(CMHardwareManager.FEATURE_HIGH_TOUCH_SENSITIVITY)); - if (!hardware.set(CMHardwareManager.FEATURE_HIGH_TOUCH_SENSITIVITY, - enabled)) { - Log.e(TAG, "Failed to restore high touch sensitivity settings."); - } else { - Log.d(TAG, "High touch sensitivity settings restored."); - } + CMSettings.System.putInt(context.getContentResolver(), + CMSettings.System.HIGH_TOUCH_SENSITIVITY_ENABLE, + enabled ? 1 : 0); } if (hardware.isSupported(CMHardwareManager.FEATURE_TOUCH_HOVERING)) { final boolean enabled = prefs.getBoolean(KEY_TOUCHSCREEN_HOVERING, hardware.get(CMHardwareManager.FEATURE_TOUCH_HOVERING)); - if (!hardware.set(CMHardwareManager.FEATURE_TOUCH_HOVERING, enabled)) { - Log.e(TAG, "Failed to restore touch hovering settings."); - } else { - Log.d(TAG, "Touch hovering settings restored."); - } + CMSettings.Secure.putInt(context.getContentResolver(), + CMSettings.Secure.FEATURE_TOUCH_HOVERING, + enabled ? 1 : 0); } } diff --git a/src/com/android/settings/livedisplay/DisplayGamma.java b/src/com/android/settings/livedisplay/DisplayGamma.java index e75e3a4..2b44cea 100644 --- a/src/com/android/settings/livedisplay/DisplayGamma.java +++ b/src/com/android/settings/livedisplay/DisplayGamma.java @@ -39,7 +39,9 @@ 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; /** @@ -165,7 +167,7 @@ public class DisplayGamma extends DialogPreference { mSeekBars[index][color].setGamma(val); mCurrentColors[index][color] = val; } - mHardware.setDisplayGammaCalibration(index, mCurrentColors[index]); + writeDisplayGamma(getContext(), index, mCurrentColors[index]); } } }); @@ -184,7 +186,7 @@ public class DisplayGamma extends DialogPreference { editor.apply(); } else if (mOriginalColors != null) { for (int i = 0; i < mNumberOfControls; i++) { - mHardware.setDisplayGammaCalibration(i, mOriginalColors[i]); + writeDisplayGamma(getContext(), i, mOriginalColors[i]); } } } @@ -204,7 +206,7 @@ public class DisplayGamma extends DialogPreference { // Restore the old state when the activity or dialog is being paused for (int i = 0; i < mNumberOfControls; i++) { - mHardware.setDisplayGammaCalibration(i, mOriginalColors[i]); + writeDisplayGamma(getContext(), i, mOriginalColors[i]); } mOriginalColors = null; @@ -229,7 +231,7 @@ public class DisplayGamma extends DialogPreference { for (int color = 0; color < BAR_COLORS.length; color++) { mSeekBars[index][color].setGamma(mCurrentColors[index][color]); } - mHardware.setDisplayGammaCalibration(index, mCurrentColors[index]); + writeDisplayGamma(getContext(), index, mCurrentColors[index]); } } @@ -259,7 +261,7 @@ public class DisplayGamma extends DialogPreference { rgb[0] = Integer.valueOf(values[0]); rgb[1] = Integer.valueOf(values[1]); rgb[2] = Integer.valueOf(values[2]); - hardware.setDisplayGammaCalibration(i, rgb); + writeDisplayGamma(context, i, rgb); } } } @@ -311,6 +313,19 @@ public class DisplayGamma extends DialogPreference { }; } + 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; @@ -350,8 +365,7 @@ public class DisplayGamma extends DialogPreference { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { mCurrentColors[mControlIndex][mColorIndex] = progress + mMin; - mHardware.setDisplayGammaCalibration(mControlIndex, - mCurrentColors[mControlIndex]); + writeDisplayGamma(getContext(), mControlIndex, mCurrentColors[mControlIndex]); } mValue.setText(String.valueOf(progress + mMin)); } |