diff options
author | Justin Klaassen <justinklaassen@google.com> | 2016-06-21 08:55:55 -0700 |
---|---|---|
committer | Justin Klaassen <justinklaassen@google.com> | 2016-07-08 11:46:27 -0700 |
commit | e81fa8578284e0eb04009ceade6d0d9d3ef3e7cc (patch) | |
tree | a9b2bb5f86f26e1a0fe5856f934ebf41e28e2ced /packages/SystemUI/src | |
parent | 56177bf81b316f38695457add3a9a822bf6f1104 (diff) |
Remove "Night mode" from tuner
Bug: 28887927
Change-Id: Ic1c217152e56db63a87a1f1e772696d97b4b58b3
Diffstat (limited to 'packages/SystemUI/src')
10 files changed, 1 insertions, 827 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/Prefs.java b/packages/SystemUI/src/com/android/systemui/Prefs.java index 907616c62f29..19ae2954bb2a 100644 --- a/packages/SystemUI/src/com/android/systemui/Prefs.java +++ b/packages/SystemUI/src/com/android/systemui/Prefs.java @@ -47,7 +47,6 @@ public final class Prefs { Key.QS_DATA_SAVER_DIALOG_SHOWN, Key.QS_INVERT_COLORS_ADDED, Key.QS_WORK_ADDED, - Key.QS_NIGHT_ADDED, }) public @interface Key { String OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME = "OverviewLastStackTaskActiveTime"; @@ -67,7 +66,6 @@ public final class Prefs { String QS_DATA_SAVER_DIALOG_SHOWN = "QsDataSaverDialogShown"; String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded"; String QS_WORK_ADDED = "QsWorkAdded"; - String QS_NIGHT_ADDED = "QsNightAdded"; } public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java index 27b079a06c99..ca853feb1a1f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java @@ -39,7 +39,6 @@ import com.android.systemui.statusbar.phone.ManagedProfileController; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.BluetoothController; import com.android.systemui.statusbar.policy.CastController; -import com.android.systemui.statusbar.policy.NightModeController; import com.android.systemui.statusbar.policy.FlashlightController; import com.android.systemui.statusbar.policy.HotspotController; import com.android.systemui.statusbar.policy.KeyguardMonitor; @@ -447,7 +446,6 @@ public abstract class QSTile<TState extends State> { UserInfoController getUserInfoController(); BatteryController getBatteryController(); TileServices getTileServices(); - NightModeController getNightModeController(); void removeTile(String tileSpec); ManagedProfileController getManagedProfileController(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java index 58fbd4c954d2..b74247960fc7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java @@ -24,7 +24,6 @@ import com.android.systemui.statusbar.policy.DataSaverController; import com.android.systemui.statusbar.policy.DataSaverController.Listener; import com.android.systemui.statusbar.policy.HotspotController; import com.android.systemui.statusbar.policy.HotspotController.Callback; -import com.android.systemui.statusbar.policy.NightModeController; /** * Manages which tiles should be automatically added to QS. @@ -67,35 +66,12 @@ public class AutoTileManager { if (!Prefs.getBoolean(context, Key.QS_WORK_ADDED, false)) { host.getManagedProfileController().addCallback(mProfileCallback); } - if (!Prefs.getBoolean(context, Key.QS_NIGHT_ADDED, false)) { - host.getNightModeController().addListener(mNightModeListener); - } } public void destroy() { // TODO: Remove any registered listeners. } - private final NightModeController.Listener mNightModeListener = - new NightModeController.Listener() { - @Override - public void onNightModeChanged() { - if (mHost.getNightModeController().isEnabled()) { - mHost.addTile("night"); - Prefs.putBoolean(mContext, Key.QS_NIGHT_ADDED, true); - mHandler.post(new Runnable() { - @Override - public void run() { - mHost.getNightModeController().removeListener(mNightModeListener); - } - }); - } - } - - @Override - public void onTwilightAutoChanged() { } - }; - private final ManagedProfileController.Callback mProfileCallback = new ManagedProfileController.Callback() { @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java index 011ec22d2b3b..ca7f9051f56d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java @@ -60,7 +60,6 @@ import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.BluetoothController; import com.android.systemui.statusbar.policy.CastController; import com.android.systemui.statusbar.policy.NextAlarmController; -import com.android.systemui.statusbar.policy.NightModeController; import com.android.systemui.statusbar.policy.FlashlightController; import com.android.systemui.statusbar.policy.HotspotController; import com.android.systemui.statusbar.policy.KeyguardMonitor; @@ -71,7 +70,6 @@ import com.android.systemui.statusbar.policy.SecurityController; import com.android.systemui.statusbar.policy.UserInfoController; import com.android.systemui.statusbar.policy.UserSwitcherController; import com.android.systemui.statusbar.policy.ZenModeController; -import com.android.systemui.tuner.NightModeTile; import com.android.systemui.tuner.TunerService; import com.android.systemui.tuner.TunerService.Tunable; @@ -111,7 +109,6 @@ public class QSTileHost implements QSTile.Host, Tunable { private final TileServices mServices; private final List<Callback> mCallbacks = new ArrayList<>(); - private final NightModeController mNightModeController; private final AutoTileManager mAutoTiles; private final ManagedProfileController mProfileController; private final NextAlarmController mNextAlarmController; @@ -144,7 +141,6 @@ public class QSTileHost implements QSTile.Host, Tunable { mBattery = battery; mIconController = iconController; mNextAlarmController = nextAlarmController; - mNightModeController = new NightModeController(mContext, true); mProfileController = new ManagedProfileController(this); final HandlerThread ht = new HandlerThread(QSTileHost.class.getSimpleName(), @@ -308,10 +304,6 @@ public class QSTileHost implements QSTile.Host, Tunable { return mIconController; } - public NightModeController getNightModeController() { - return mNightModeController; - } - public ManagedProfileController getManagedProfileController() { return mProfileController; } @@ -448,8 +440,6 @@ public class QSTileHost implements QSTile.Host, Tunable { else if (tileSpec.equals("user")) return new UserTile(this); else if (tileSpec.equals("battery")) return new BatteryTile(this); else if (tileSpec.equals("saver")) return new DataSaverTile(this); - else if (tileSpec.equals(NightModeTile.NIGHT_MODE_SPEC)) - return new NightModeTile(this); // Intent tiles. else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec); else if (tileSpec.startsWith(CustomTile.PREFIX)) return CustomTile.create(this,tileSpec); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NightModeController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NightModeController.java deleted file mode 100644 index 4611ef9f31db..000000000000 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NightModeController.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source 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.systemui.statusbar.policy; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.opengl.Matrix; -import android.provider.Settings.Secure; -import android.util.MathUtils; -import com.android.systemui.tuner.TunerService; - -import java.util.ArrayList; - -/** - * Listens for changes to twilight from the TwilightService. - * - * Also pushes the current matrix to accessibility based on the current twilight - * and various tuner settings. - */ -public class NightModeController implements TunerService.Tunable { - - public static final String NIGHT_MODE_ADJUST_TINT = "tuner_night_mode_adjust_tint"; - private static final String COLOR_MATRIX_CUSTOM_VALUES = "tuner_color_custom_values"; - - private static final String ACTION_TWILIGHT_CHANGED = "android.intent.action.TWILIGHT_CHANGED"; - - private static final String EXTRA_IS_NIGHT = "isNight"; - private static final String EXTRA_AMOUNT = "amount"; - - // Night mode ~= 3400 K - private static final float[] NIGHT_VALUES = new float[] { - 1, 0, 0, 0, - 0, .754f, 0, 0, - 0, 0, .516f, 0, - 0, 0, 0, 1, - }; - public static final float[] IDENTITY_MATRIX = new float[] { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1, - }; - - private final ArrayList<Listener> mListeners = new ArrayList<>(); - - private final Context mContext; - - // This is whether or not this is the main NightMode controller in SysUI that should be - // updating relevant color matrixes or if its in the tuner process getting current state - // for UI. - private final boolean mUpdateMatrix; - - private float[] mCustomMatrix; - private boolean mListening; - private boolean mAdjustTint; - - private boolean mIsNight; - private float mAmount; - private boolean mIsAuto; - - public NightModeController(Context context) { - this(context, false); - } - - public NightModeController(Context context, boolean updateMatrix) { - mContext = context; - mUpdateMatrix = updateMatrix; - TunerService.get(mContext).addTunable(this, NIGHT_MODE_ADJUST_TINT, - COLOR_MATRIX_CUSTOM_VALUES, Secure.TWILIGHT_MODE); - } - - public void setNightMode(boolean isNight) { - if (mIsAuto) { - if (mIsNight != isNight) { - TunerService.get(mContext).setValue(Secure.TWILIGHT_MODE, isNight - ? Secure.TWILIGHT_MODE_AUTO_OVERRIDE_ON - : Secure.TWILIGHT_MODE_AUTO_OVERRIDE_OFF); - } else { - TunerService.get(mContext).setValue(Secure.TWILIGHT_MODE, - Secure.TWILIGHT_MODE_AUTO); - } - } else { - TunerService.get(mContext).setValue(Secure.TWILIGHT_MODE, isNight - ? Secure.TWILIGHT_MODE_LOCKED_ON : Secure.TWILIGHT_MODE_LOCKED_OFF); - } - } - - public void setAuto(boolean auto) { - mIsAuto = auto; - if (auto) { - TunerService.get(mContext).setValue(Secure.TWILIGHT_MODE, Secure.TWILIGHT_MODE_AUTO); - } else { - // Lock into the current state - TunerService.get(mContext).setValue(Secure.TWILIGHT_MODE, mIsNight - ? Secure.TWILIGHT_MODE_LOCKED_ON : Secure.TWILIGHT_MODE_LOCKED_OFF); - } - } - - public boolean isAuto() { - return mIsAuto; - } - - public void setAdjustTint(Boolean newValue) { - TunerService.get(mContext).setValue(NIGHT_MODE_ADJUST_TINT, ((Boolean) newValue) ? 1 : 0); - } - - public void addListener(Listener listener) { - mListeners.add(listener); - listener.onNightModeChanged(); - updateListening(); - } - - public void removeListener(Listener listener) { - mListeners.remove(listener); - updateListening(); - } - - private void updateListening() { - boolean shouldListen = mListeners.size() != 0 || (mUpdateMatrix && mAdjustTint); - if (shouldListen == mListening) return; - mListening = shouldListen; - if (mListening) { - mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_TWILIGHT_CHANGED)); - } else { - mContext.unregisterReceiver(mReceiver); - } - } - - public boolean isEnabled() { - if (!mListening) { - updateNightMode(mContext.registerReceiver(null, - new IntentFilter(ACTION_TWILIGHT_CHANGED))); - } - return mIsNight; - } - - public String getCustomValues() { - return TunerService.get(mContext).getValue(COLOR_MATRIX_CUSTOM_VALUES); - } - - public void setCustomValues(String values) { - TunerService.get(mContext).setValue(COLOR_MATRIX_CUSTOM_VALUES, values); - } - - @Override - public void onTuningChanged(String key, String newValue) { - if (COLOR_MATRIX_CUSTOM_VALUES.equals(key)) { - mCustomMatrix = newValue != null ? toValues(newValue) : null; - updateCurrentMatrix(); - } else if (NIGHT_MODE_ADJUST_TINT.equals(key)) { - mAdjustTint = newValue == null || Integer.parseInt(newValue) != 0; - updateListening(); - updateCurrentMatrix(); - } else if (Secure.TWILIGHT_MODE.equals(key)) { - mIsAuto = newValue != null && Integer.parseInt(newValue) >= Secure.TWILIGHT_MODE_AUTO; - } - } - - private void updateCurrentMatrix() { - if (!mUpdateMatrix) return; - if ((!mAdjustTint || mAmount == 0) && mCustomMatrix == null) { - TunerService.get(mContext).setValue(Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, null); - return; - } - float[] values = scaleValues(IDENTITY_MATRIX, NIGHT_VALUES, mAdjustTint ? mAmount : 0); - if (mCustomMatrix != null) { - values = multiply(values, mCustomMatrix); - } - TunerService.get(mContext).setValue(Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, - toString(values)); - } - - private void updateNightMode(Intent intent) { - mIsNight = intent != null && intent.getBooleanExtra(EXTRA_IS_NIGHT, false); - mAmount = intent != null ? intent.getFloatExtra(EXTRA_AMOUNT, 0) : 0; - } - - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (ACTION_TWILIGHT_CHANGED.equals(intent.getAction())) { - updateNightMode(intent); - updateCurrentMatrix(); - for (int i = 0; i < mListeners.size(); i++) { - mListeners.get(i).onNightModeChanged(); - } - } - } - }; - - public interface Listener { - void onNightModeChanged(); - void onTwilightAutoChanged(); - } - - private static float[] multiply(float[] matrix, float[] other) { - if (matrix == null) { - return other; - } - float[] result = new float[16]; - Matrix.multiplyMM(result, 0, matrix, 0, other, 0); - return result; - } - - private float[] scaleValues(float[] identityMatrix, float[] nightValues, float amount) { - float[] values = new float[identityMatrix.length]; - for (int i = 0; i < values.length; i++) { - values[i] = MathUtils.lerp(identityMatrix[i], nightValues[i], amount); - } - return values; - } - - public static String toString(float[] values) { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < values.length; i++) { - if (builder.length() != 0) { - builder.append(','); - } - builder.append(values[i]); - } - return builder.toString(); - } - - public static float[] toValues(String customValues) { - String[] strValues = customValues.split(","); - float[] values = new float[strValues.length]; - for (int i = 0; i < values.length; i++) { - values[i] = Float.parseFloat(strValues[i]); - } - return values; - } -} diff --git a/packages/SystemUI/src/com/android/systemui/tuner/CalibratePreference.java b/packages/SystemUI/src/com/android/systemui/tuner/CalibratePreference.java deleted file mode 100644 index ff7be1367388..000000000000 --- a/packages/SystemUI/src/com/android/systemui/tuner/CalibratePreference.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source 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.systemui.tuner; - -import android.content.Context; -import android.support.v7.preference.DialogPreference; -import android.util.AttributeSet; - -public class CalibratePreference extends DialogPreference { - public CalibratePreference(Context context, AttributeSet attrs) { - super(context, attrs); - } -} diff --git a/packages/SystemUI/src/com/android/systemui/tuner/ColorAndAppearanceFragment.java b/packages/SystemUI/src/com/android/systemui/tuner/ColorAndAppearanceFragment.java deleted file mode 100644 index af95cf9354bb..000000000000 --- a/packages/SystemUI/src/com/android/systemui/tuner/ColorAndAppearanceFragment.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source 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.systemui.tuner; - - -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.content.DialogInterface; -import android.os.Bundle; -import android.provider.Settings; -import android.provider.Settings.Secure; -import android.support.v14.preference.PreferenceFragment; -import android.support.v7.preference.Preference; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.SeekBar; - -import com.android.internal.logging.MetricsLogger; -import com.android.internal.logging.MetricsProto.MetricsEvent; -import com.android.systemui.R; -import com.android.systemui.statusbar.policy.NightModeController; - -public class ColorAndAppearanceFragment extends PreferenceFragment { - - private static final String KEY_CALIBRATE = "calibrate"; - - private static final long RESET_DELAY = 10000; - private static final CharSequence KEY_NIGHT_MODE = "night_mode"; - - private NightModeController mNightModeController; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mNightModeController = new NightModeController(getContext()); - } - - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - addPreferencesFromResource(R.xml.color_and_appearance); - } - - @Override - public void onResume() { - super.onResume(); - MetricsLogger.visibility(getContext(), MetricsEvent.TUNER_COLOR_AND_APPEARANCE, true); - // TODO: Figure out better title model for Tuner, to avoid any more of this. - getActivity().setTitle(R.string.color_and_appearance); - - Preference nightMode = findPreference(KEY_NIGHT_MODE); - nightMode.setSummary(mNightModeController.isEnabled() - ? R.string.night_mode_on : R.string.night_mode_off); - } - - @Override - public void onPause() { - super.onPause(); - MetricsLogger.visibility(getContext(), MetricsEvent.TUNER_COLOR_AND_APPEARANCE, false); - } - - @Override - public void onDisplayPreferenceDialog(Preference preference) { - if (preference instanceof CalibratePreference) { - CalibrateDialog.show(this); - } else { - super.onDisplayPreferenceDialog(preference); - } - } - - private void startRevertTimer() { - getView().postDelayed(mResetColorMatrix, RESET_DELAY); - } - - private void onApply() { - MetricsLogger.action(getContext(), MetricsEvent.ACTION_TUNER_CALIBRATE_DISPLAY_CHANGED); - mNightModeController.setCustomValues(Settings.Secure.getString( - getContext().getContentResolver(), Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX)); - getView().removeCallbacks(mResetColorMatrix); - } - - private void onRevert() { - getView().removeCallbacks(mResetColorMatrix); - mResetColorMatrix.run(); - } - - private final Runnable mResetColorMatrix = new Runnable() { - @Override - public void run() { - ((DialogFragment) getFragmentManager().findFragmentByTag("RevertWarning")).dismiss(); - Settings.Secure.putString(getContext().getContentResolver(), - Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, null); - } - }; - - public static class CalibrateDialog extends DialogFragment implements - DialogInterface.OnClickListener { - private float[] mValues; - private NightModeController mNightModeController; - - public static void show(ColorAndAppearanceFragment fragment) { - CalibrateDialog dialog = new CalibrateDialog(); - dialog.setTargetFragment(fragment, 0); - dialog.show(fragment.getFragmentManager(), "Calibrate"); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mNightModeController = new NightModeController(getContext()); - String customValues = mNightModeController.getCustomValues(); - if (customValues == null) { - // Generate this as a string because its the easiest way to generate a copy of the - // identity. - customValues = NightModeController.toString(NightModeController.IDENTITY_MATRIX); - } - mValues = NightModeController.toValues(customValues); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - View v = LayoutInflater.from(getContext()).inflate(R.layout.calibrate_sliders, null); - bindView(v.findViewById(R.id.r_group), 0); - bindView(v.findViewById(R.id.g_group), 5); - bindView(v.findViewById(R.id.b_group), 10); - MetricsLogger.visible(getContext(), MetricsEvent.TUNER_CALIBRATE_DISPLAY); - return new AlertDialog.Builder(getContext()) - .setTitle(R.string.calibrate_display) - .setView(v) - .setPositiveButton(R.string.color_apply, this) - .setNegativeButton(android.R.string.cancel, null) - .create(); - } - - @Override - public void onDismiss(DialogInterface dialog) { - super.onDismiss(dialog); - MetricsLogger.hidden(getContext(), MetricsEvent.TUNER_CALIBRATE_DISPLAY); - } - - private void bindView(View view, final int index) { - SeekBar seekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar); - seekBar.setMax(1000); - seekBar.setProgress((int) (1000 * mValues[index])); - seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - mValues[index] = progress / 1000f; - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - } - }); - } - - @Override - public void onClick(DialogInterface dialog, int which) { - if (mValues[0] == 1 && mValues[5] == 1 && mValues[10] == 1) { - // Allow removal of matrix by all values set to highest. - mNightModeController.setCustomValues(null); - return; - } - ((ColorAndAppearanceFragment) getTargetFragment()).startRevertTimer(); - Settings.Secure.putString(getContext().getContentResolver(), - Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, - NightModeController.toString(mValues)); - RevertWarning.show((ColorAndAppearanceFragment) getTargetFragment()); - } - } - - public static class RevertWarning extends DialogFragment - implements DialogInterface.OnClickListener { - - public static void show(ColorAndAppearanceFragment fragment) { - RevertWarning warning = new RevertWarning(); - warning.setTargetFragment(fragment, 0); - warning.show(fragment.getFragmentManager(), "RevertWarning"); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog alertDialog = new AlertDialog.Builder(getContext()) - .setTitle(R.string.color_revert_title) - .setMessage(R.string.color_revert_message) - .setPositiveButton(R.string.ok, this) - .create(); - alertDialog.setCanceledOnTouchOutside(true); - return alertDialog; - } - - @Override - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - ((ColorAndAppearanceFragment) getTargetFragment()).onRevert(); - } - - @Override - public void onClick(DialogInterface dialog, int which) { - ((ColorAndAppearanceFragment) getTargetFragment()).onApply(); - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/tuner/NightModeFragment.java b/packages/SystemUI/src/com/android/systemui/tuner/NightModeFragment.java deleted file mode 100644 index ae2856cef36f..000000000000 --- a/packages/SystemUI/src/com/android/systemui/tuner/NightModeFragment.java +++ /dev/null @@ -1,188 +0,0 @@ -/** - * Copyright (c) 2016, The Android Open Source 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.systemui.tuner; - -import android.annotation.Nullable; -import android.app.UiModeManager; -import android.content.Context; -import android.os.Bundle; -import android.provider.Settings.Secure; -import android.support.v14.preference.PreferenceFragment; -import android.support.v14.preference.SwitchPreference; -import android.support.v7.preference.Preference; -import android.support.v7.preference.Preference.OnPreferenceChangeListener; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Switch; -import com.android.internal.logging.MetricsLogger; -import com.android.internal.logging.MetricsProto.MetricsEvent; -import com.android.systemui.R; -import com.android.systemui.statusbar.policy.NightModeController; -import com.android.systemui.statusbar.policy.NightModeController.Listener; -import com.android.systemui.tuner.TunerService.Tunable; - -public class NightModeFragment extends PreferenceFragment implements Tunable, - Listener, OnPreferenceChangeListener { - - private static final String TAG = "NightModeFragment"; - - public static final String EXTRA_SHOW_NIGHT_MODE = "show_night_mode"; - - private static final CharSequence KEY_AUTO = "auto"; - private static final CharSequence KEY_ADJUST_TINT = "adjust_tint"; - private static final CharSequence KEY_ADJUST_BRIGHTNESS = "adjust_brightness"; - - private Switch mSwitch; - - private NightModeController mNightModeController; - private SwitchPreference mAutoSwitch; - private SwitchPreference mAdjustTint; - private SwitchPreference mAdjustBrightness; - private UiModeManager mUiModeManager; - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mNightModeController = new NightModeController(getContext()); - mUiModeManager = getContext().getSystemService(UiModeManager.class); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View view = LayoutInflater.from(getContext()).inflate( - R.layout.night_mode_settings, container, false); - ((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState)); - return view; - } - - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - final Context context = getPreferenceManager().getContext(); - - addPreferencesFromResource(R.xml.night_mode); - mAutoSwitch = (SwitchPreference) findPreference(KEY_AUTO); - mAutoSwitch.setOnPreferenceChangeListener(this); - mAdjustTint = (SwitchPreference) findPreference(KEY_ADJUST_TINT); - mAdjustTint.setOnPreferenceChangeListener(this); - mAdjustBrightness = (SwitchPreference) findPreference(KEY_ADJUST_BRIGHTNESS); - mAdjustBrightness.setOnPreferenceChangeListener(this); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - View switchBar = view.findViewById(R.id.switch_bar); - mSwitch = (Switch) switchBar.findViewById(android.R.id.switch_widget); - mSwitch.setChecked(mNightModeController.isEnabled()); - switchBar.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - boolean newState = !mNightModeController.isEnabled(); - MetricsLogger.action(getContext(), MetricsEvent.ACTION_TUNER_NIGHT_MODE, newState); - mNightModeController.setNightMode(newState); - mSwitch.setChecked(newState); - } - }); - } - - @Override - public void onResume() { - super.onResume(); - MetricsLogger.visibility(getContext(), MetricsEvent.TUNER_NIGHT_MODE, true); - mNightModeController.addListener(this); - TunerService.get(getContext()).addTunable(this, Secure.BRIGHTNESS_USE_TWILIGHT, - NightModeController.NIGHT_MODE_ADJUST_TINT); - calculateDisabled(); - } - - @Override - public void onPause() { - super.onPause(); - MetricsLogger.visibility(getContext(), MetricsEvent.TUNER_NIGHT_MODE, false); - mNightModeController.removeListener(this); - TunerService.get(getContext()).removeTunable(this); - } - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - final Boolean value = (Boolean) newValue; - if (mAutoSwitch == preference) { - MetricsLogger.action(getContext(), MetricsEvent.ACTION_TUNER_NIGHT_MODE_AUTO, value); - mNightModeController.setAuto(value); - } else if (mAdjustTint == preference) { - MetricsLogger.action(getContext(), - MetricsEvent.ACTION_TUNER_NIGHT_MODE_ADJUST_TINT, value); - mNightModeController.setAdjustTint(value); - postCalculateDisabled(); - } else if (mAdjustBrightness == preference) { - MetricsLogger.action(getContext(), - MetricsEvent.ACTION_TUNER_NIGHT_MODE_ADJUST_BRIGHTNESS, value); - TunerService.get(getContext()).setValue(Secure.BRIGHTNESS_USE_TWILIGHT, - value ? 1 : 0); - postCalculateDisabled(); - } else { - return false; - } - return true; - } - - private void postCalculateDisabled() { - // Post this because its the easiest way to wait for all state to be calculated. - getView().post(new Runnable() { - @Override - public void run() { - calculateDisabled(); - } - }); - } - - private void calculateDisabled() { - int enabledCount = (mAdjustTint.isChecked() ? 1 : 0) - + (mAdjustBrightness.isChecked() ? 1 : 0); - if (enabledCount == 1) { - if (mAdjustTint.isChecked()) { - mAdjustTint.setEnabled(false); - } else { - mAdjustBrightness.setEnabled(false); - } - } else { - mAdjustTint.setEnabled(true); - mAdjustBrightness.setEnabled(true); - } - } - - @Override - public void onTuningChanged(String key, String newValue) { - if (Secure.BRIGHTNESS_USE_TWILIGHT.equals(key)) { - mAdjustBrightness.setChecked(newValue != null && Integer.parseInt(newValue) != 0); - } else if (NightModeController.NIGHT_MODE_ADJUST_TINT.equals(key)) { - // Default on. - mAdjustTint.setChecked(newValue == null || Integer.parseInt(newValue) != 0); - } - } - - @Override - public void onNightModeChanged() { - mSwitch.setChecked(mNightModeController.isEnabled()); - } - - @Override - public void onTwilightAutoChanged() { - mAutoSwitch.setChecked(mNightModeController.isAuto()); - } -} diff --git a/packages/SystemUI/src/com/android/systemui/tuner/NightModeTile.java b/packages/SystemUI/src/com/android/systemui/tuner/NightModeTile.java deleted file mode 100644 index fe445025854c..000000000000 --- a/packages/SystemUI/src/com/android/systemui/tuner/NightModeTile.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (c) 2016, The Android Open Source 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.systemui.tuner; - -import android.content.Intent; -import com.android.internal.logging.MetricsProto.MetricsEvent; -import com.android.systemui.Prefs; -import com.android.systemui.Prefs.Key; -import com.android.systemui.R; -import com.android.systemui.qs.QSTile; -import com.android.systemui.statusbar.policy.NightModeController; - - -public class NightModeTile extends QSTile<QSTile.State> implements NightModeController.Listener { - - public static final String NIGHT_MODE_SPEC = "night"; - - private final NightModeController mNightModeController; - - private int mIndex; - private String mCurrentValue; - - private boolean mCustomEnabled; - private String[] mValues; - private CharSequence[] mValueTitles; - - public NightModeTile(Host host) { - super(host); - mNightModeController = host.getNightModeController(); - } - - @Override - public boolean isAvailable() { - return Prefs.getBoolean(mContext, Key.QS_NIGHT_ADDED, false) - && TunerService.isTunerEnabled(mContext); - } - - @Override - public void setListening(boolean listening) { - if (listening) { - mNightModeController.addListener(this); - refreshState(); - } else { - mNightModeController.removeListener(this); - } - } - - @Override - public State newTileState() { - return new State(); - } - - @Override - public Intent getLongClickIntent() { - return new Intent(mContext, TunerActivity.class) - .putExtra(NightModeFragment.EXTRA_SHOW_NIGHT_MODE, true); - } - - @Override - protected void handleClick() { - mNightModeController.setNightMode(!mNightModeController.isEnabled()); - refreshState(); - } - - @Override - public CharSequence getTileLabel() { - return mContext.getString(R.string.night_mode); - } - - @Override - protected void handleUpdateState(State state, Object arg) { - // TODO: Right now this is just a dropper, needs an actual night icon. - boolean enabled = mNightModeController.isEnabled(); - state.icon = ResourceIcon.get(enabled ? R.drawable.ic_night_mode - : R.drawable.ic_night_mode_disabled); - state.label = mContext.getString(R.string.night_mode); - state.contentDescription = mContext.getString(R.string.night_mode); - } - - @Override - public void onNightModeChanged() { - refreshState(); - } - - @Override - public void onTwilightAutoChanged() { - // Don't care. - } - - @Override - public int getMetricsCategory() { - return MetricsEvent.QS_COLOR_MATRIX; - } -} diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java index 5e5da7423cb6..5fe92967589e 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java @@ -39,10 +39,7 @@ public class TunerActivity extends SettingsDrawerActivity implements final String action = getIntent().getAction(); boolean showDemoMode = action != null && action.equals( "com.android.settings.action.DEMO_MODE"); - boolean showNightMode = getIntent().getBooleanExtra( - NightModeFragment.EXTRA_SHOW_NIGHT_MODE, false); - final PreferenceFragment fragment = showNightMode ? new NightModeFragment() - : showDemoMode ? new DemoModeFragment() + final PreferenceFragment fragment = showDemoMode ? new DemoModeFragment() : new TunerFragment(); getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment, TAG_TUNER).commit(); |