diff options
16 files changed, 552 insertions, 238 deletions
diff --git a/packages/SystemUI/res/drawable/switchbar_background.xml b/packages/SystemUI/res/drawable/switchbar_background.xml new file mode 100644 index 000000000000..8d97c46f8870 --- /dev/null +++ b/packages/SystemUI/res/drawable/switchbar_background.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="?android:attr/colorControlHighlight"> + <item android:drawable="@color/switch_bar_background" /> +</ripple> + diff --git a/packages/SystemUI/res/layout/color_matrix_settings.xml b/packages/SystemUI/res/layout/color_matrix_settings.xml new file mode 100644 index 000000000000..3725e78cc481 --- /dev/null +++ b/packages/SystemUI/res/layout/color_matrix_settings.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <include layout="@layout/switch_bar" /> + +</LinearLayout> diff --git a/packages/SystemUI/res/layout/preference_matrix.xml b/packages/SystemUI/res/layout/preference_matrix.xml index ebf486fe2462..1f6066e5eaf0 100644 --- a/packages/SystemUI/res/layout/preference_matrix.xml +++ b/packages/SystemUI/res/layout/preference_matrix.xml @@ -19,82 +19,86 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> - <Space - android:layout_width="0dp" - android:layout_height="wrap_content" - android:layout_weight="1" /> - <GridLayout - android:id="@+id/edit_group" - android:layout_height="wrap_content" - android:layout_width="wrap_content" - android:rowCount="5" - android:columnCount="5"> + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" + android:paddingTop="8dp" + android:paddingBottom="8dp" + android:orientation="vertical"> - <Space android:layout_width="40dp" /> + <LinearLayout + android:id="@+id/r_group" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="4dp" + android:paddingBottom="4dp" + android:orientation="horizontal"> <TextView - android:layout_width="40dp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" android:text="@string/color_modification_r" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" /> - <TextView - android:layout_width="40dp" - android:text="@string/color_modification_g" - android:gravity="center" - android:textAppearance="?android:attr/textAppearanceMedium" /> - - <TextView - android:layout_width="40dp" - android:text="@string/color_modification_b" - android:gravity="center" - android:textAppearance="?android:attr/textAppearanceMedium" /> - - <Space android:layout_width="40dp" /> + <SeekBar android:id="@*android:id/seekbar" + android:layout_marginStart="16dp" + android:layout_gravity="center_vertical" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" /> + </LinearLayout> - <TextView - android:layout_width="40dp" - android:text="@string/color_modification_r" - android:gravity="center" - android:textAppearance="?android:attr/textAppearanceMedium" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> + <LinearLayout + android:id="@+id/g_group" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="4dp" + android:paddingBottom="4dp" + android:orientation="horizontal"> <TextView - android:layout_width="40dp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" android:text="@string/color_modification_g" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> + + <SeekBar android:id="@*android:id/seekbar" + android:layout_marginStart="16dp" + android:layout_gravity="center_vertical" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" /> + </LinearLayout> + + <LinearLayout + android:id="@+id/b_group" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="4dp" + android:paddingBottom="4dp" + android:orientation="horizontal"> <TextView - android:layout_width="40dp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" android:text="@string/color_modification_b" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <Space android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> - <EditText android:inputType="numberDecimal" android:layout_width="40dp" /> + <SeekBar android:id="@*android:id/seekbar" + android:layout_marginStart="16dp" + android:layout_gravity="center_vertical" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" /> + </LinearLayout> - </GridLayout> <Button android:id="@+id/apply" - android:layout_width="0dp" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" - android:layout_gravity="bottom" + android:layout_gravity="end" android:text="@string/color_apply" /> + </LinearLayout> diff --git a/packages/SystemUI/res/layout/switch_bar.xml b/packages/SystemUI/res/layout/switch_bar.xml new file mode 100644 index 000000000000..f98de96a66f9 --- /dev/null +++ b/packages/SystemUI/res/layout/switch_bar.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/switch_bar" + android:layout_width="match_parent" + android:layout_height="?android:attr/actionBarSize" + android:background="@drawable/switchbar_background" + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:clickable="true" + android:gravity="center"> + + <TextView android:id="@+id/switch_text" + android:layout_height="wrap_content" + android:layout_width="0dp" + android:layout_weight="1" + android:layout_gravity="center_vertical" + android:paddingStart="48dp" + android:maxLines="2" + android:ellipsize="end" + android:textAppearance="@android:style/TextAppearance.Material.Title" + android:textColor="?android:attr/textColorPrimaryInverse" + android:textAlignment="viewStart" + android:text="@string/switch_bar_on" /> + + <Switch + android:id="@android:id/switch_widget" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:background="@null" + android:theme="@style/ThemeOverlay.SwitchBar" /> + +</LinearLayout> diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index 5e25d2c9fecb..f0d9949fa90c 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -151,4 +151,7 @@ <color name="qs_tile_tint_unavailable">#40ffffff</color> <color name="qs_tile_tint_inactive">#4dffffff</color> <color name="qs_tile_tint_active">#ffffffff</color> + + <color name="switch_bar_background">#ff37474f</color> + <color name="switch_accent_color">#ff7fcac3</color> </resources> diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 3efa52ffec9c..38572bf3ab20 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1251,6 +1251,9 @@ <!-- Label for custom color transform [CHAR LIMIT=30] --> <string name="color_matrix_custom">Custom colors</string> + <!-- Label for auto color transforms [CHAR LIMIT=30] --> + <string name="color_matrix_auto">Auto</string> + <!-- Label for unknown color transform [CHAR LIMIT=30] --> <string name="color_matrix_unknown">Unknown colors</string> @@ -1345,4 +1348,7 @@ <string name="unpin_target">Unpin</string> <string name="app_info">App info</string> + <!-- Label for feature switch [CHAR LIMIT=30] --> + <string name="switch_bar_on">On</string> + </resources> diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index e40a0f4e3932..6e257d5b79b8 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -345,4 +345,8 @@ <item name="android:textColor">@*android:color/material_deep_teal_500</item> </style> + <style name="ThemeOverlay.SwitchBar" parent="@android:style/ThemeOverlay"> + <item name="android:colorAccent">@color/switch_accent_color</item> + </style> + </resources> diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java index 20e2fa4f0509..789e72e8f276 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java @@ -35,6 +35,7 @@ import com.android.systemui.qs.external.TileServices; 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.DisplayController; import com.android.systemui.statusbar.policy.FlashlightController; import com.android.systemui.statusbar.policy.HotspotController; import com.android.systemui.statusbar.policy.KeyguardMonitor; @@ -389,6 +390,7 @@ public abstract class QSTile<TState extends State> implements Listenable { UserInfoController getUserInfoController(); BatteryController getBatteryController(); TileServices getTileServices(); + DisplayController getDisplayController(); void removeTile(String tileSpec); diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java index 8ae2d7bc50e5..3748a3093a56 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java @@ -72,8 +72,9 @@ public class TileAdapter extends BaseAdapter { } mCurrentTiles = tileSpecs; final TileGroup group = new TileGroup("com.android.settings", mContext); + boolean hasColorMod = host.getDisplayController().isEnabled(); String possible = mContext.getString(R.string.quick_settings_tiles_default) - + ",hotspot,inversion,saver"; + + ",hotspot,inversion,saver" + (hasColorMod ? ",colors" : ""); String[] possibleTiles = possible.split(","); for (int i = 0; i < possibleTiles.length; i++) { final String spec = possibleTiles[i]; 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 9c2159be1b98..b8cd7fb32f23 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java @@ -51,6 +51,7 @@ import com.android.systemui.qs.tiles.WorkModeTile; 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.DisplayController; import com.android.systemui.statusbar.policy.FlashlightController; import com.android.systemui.statusbar.policy.HotspotController; import com.android.systemui.statusbar.policy.KeyguardMonitor; @@ -101,6 +102,7 @@ public final class QSTileHost implements QSTile.Host, Tunable { private final TileServices mServices; private final List<Callback> mCallbacks = new ArrayList<>(); + private final DisplayController mDisplayController; private View mHeader; public QSTileHost(Context context, PhoneStatusBar statusBar, @@ -127,6 +129,7 @@ public final class QSTileHost implements QSTile.Host, Tunable { mSecurity = security; mBattery = battery; mIconController = iconController; + mDisplayController = new DisplayController(mContext); final HandlerThread ht = new HandlerThread(QSTileHost.class.getSimpleName(), Process.THREAD_PRIORITY_BACKGROUND); @@ -277,6 +280,10 @@ public final class QSTileHost implements QSTile.Host, Tunable { return mIconController; } + public DisplayController getDisplayController() { + return mDisplayController; + } + @Override public void onTuningChanged(String key, String newValue) { if (!TILES_SETTING.equals(key)) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DisplayController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DisplayController.java new file mode 100644 index 000000000000..e5d244f5dc88 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DisplayController.java @@ -0,0 +1,191 @@ +/* + * 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.content.res.Configuration; +import android.provider.Settings; +import com.android.systemui.R; +import com.android.systemui.tuner.TunerService; +import libcore.util.Objects; + +import java.util.ArrayList; + +public class DisplayController implements TunerService.Tunable { + + public static final String COLOR_MATRIX_CUSTOM_ENABLED = "tuner_color_custom_enabled"; + public static final String COLOR_MATRIX_CUSTOM_VALUES = "tuner_color_custom_values"; + + public static final String COLOR_STATE = "sysui_color_matrix_state"; + + public static final int COLOR_STATE_DISABLED = 0; + public static final int COLOR_STATE_ENABLED = 1; + public static final int COLOR_STATE_AUTO = 2; + + public static final String AUTO_STRING = "auto_mode"; + public static final String NONE_STRING = "none"; + + public static final int AUTO_INDEX = 2; + public static final int CUSTOM_INDEX = 3; + + // 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; + + private String mCurrentValue; + private boolean mListening; + + public DisplayController(Context context) { + mContext = context; + TunerService.get(mContext).addTunable(this, COLOR_STATE, + Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX); + } + + public void addListener(Listener listener) { + mListeners.add(listener); + listener.onCurrentMatrixChanged(); + } + + public void removeListener(Listener listener) { + mListeners.remove(listener); + } + + public boolean isEnabled() { + return TunerService.get(mContext).getValue(COLOR_STATE, COLOR_STATE_DISABLED) + != COLOR_STATE_DISABLED; + } + + public boolean isAuto() { + return mListening; + } + + public void setAuto(boolean auto) { + TunerService.get(mContext).setValue(COLOR_STATE, auto ? COLOR_STATE_AUTO + : COLOR_STATE_DISABLED); + } + + public boolean isCustomSet() { + return isCustomEnabled() && Objects.equal(getCurrentMatrix(), getCustomValues()); + } + + public String getCurrentMatrix() { + return mCurrentValue; + } + + public String getCustomValues() { + return TunerService.get(mContext).getValue(COLOR_MATRIX_CUSTOM_VALUES); + } + + public boolean isCustomEnabled() { + return TunerService.get(mContext).getValue(COLOR_MATRIX_CUSTOM_ENABLED, 0) != 0; + } + + @Override + public void onTuningChanged(String key, String newValue) { + if (Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX.equals(key)) { + mCurrentValue = newValue; + for (int i = 0; i < mListeners.size(); i++) { + mListeners.get(i).onCurrentMatrixChanged(); + } + } else if (COLOR_STATE.equals(key)) { + final boolean listening = newValue != null + && Integer.parseInt(newValue) == COLOR_STATE_AUTO; + if (listening && !mListening) { + mListening = true; + mContext.registerReceiver(mReceiver, + new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); + updateNightMode(); + } else if (!listening && mListening) { + mListening = false; + mContext.unregisterReceiver(mReceiver); + } + for (int i = 0; i < mListeners.size(); i++) { + mListeners.get(i).onCurrentMatrixChanged(); + } + } + } + + private void updateNightMode() { + final int uiMode = mContext.getResources().getConfiguration().uiMode; + final boolean isNightMode = (uiMode & Configuration.UI_MODE_NIGHT_MASK) + == Configuration.UI_MODE_NIGHT_YES; + String value = null; + if (isNightMode) { + value = toString(NIGHT_VALUES); + } + TunerService.get(mContext).setValue(Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, + value); + } + + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_CONFIGURATION_CHANGED.equals(intent.getAction())) { + updateNightMode(); + } + } + }; + + public interface Listener { + void onCurrentMatrixChanged(); + } + + public static String[] getColorTransforms(Context context) { + return new String[] { + NONE_STRING, + toString(NIGHT_VALUES), + AUTO_STRING, // Blank spot for auto values + null, // Blank spot for custom values + }; + } + + public static CharSequence[] getColorTitles(Context context) { + // TODO: Move to string array resource. + return new CharSequence[]{ + context.getString(R.string.color_matrix_none), + context.getString(R.string.color_matrix_night), + context.getString(R.string.color_matrix_auto), + context.getString(R.string.color_matrix_custom), + }; + } + + 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(); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/tuner/ColorMatrixFragment.java b/packages/SystemUI/src/com/android/systemui/tuner/ColorMatrixFragment.java index 8ed1b069a5ab..dfacd033a90e 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/ColorMatrixFragment.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/ColorMatrixFragment.java @@ -19,6 +19,7 @@ import android.annotation.Nullable; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; +import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; @@ -28,15 +29,15 @@ import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.DropDownPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceViewHolder; -import android.text.Editable; -import android.text.TextUtils; -import android.text.TextWatcher; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.EditText; +import android.widget.SeekBar; +import android.widget.Switch; + import com.android.systemui.R; import com.android.systemui.statusbar.phone.QSTileHost; +import com.android.systemui.statusbar.policy.DisplayController; import java.util.Objects; @@ -44,21 +45,6 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ private static final String TAG = "ColorMatrixFragment"; - public static final int CUSTOM_INDEX = 2; - - // 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 static final long RESET_DELAY = 10000; private boolean mCustomEnabled; @@ -67,20 +53,29 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ private String mCustomValues; private SwitchPreference mEnableCustomPreference; private MatrixPreference mCustomPreference; - private SwitchPreference mShowQs; - private String mTiles; + private int mState; + private Switch mSwitch; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Context context = getContext(); - TunerService.get(context).addTunable(this, ColorMatrixTile.COLOR_MATRIX_CUSTOM_ENABLED, - ColorMatrixTile.COLOR_MATRIX_CUSTOM_VALUES, QSTileHost.TILES_SETTING, + TunerService.get(context).addTunable(this, DisplayController.COLOR_MATRIX_CUSTOM_ENABLED, + DisplayController.COLOR_MATRIX_CUSTOM_VALUES, DisplayController.COLOR_STATE, Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX); } @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + final View view = LayoutInflater.from(getContext()).inflate( + R.layout.color_matrix_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(); setPreferenceScreen(getPreferenceManager().createPreferenceScreen(context)); @@ -88,40 +83,33 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ mSelectPreference = new DropDownPreference(context); mSelectPreference.setTitle(R.string.color_transform); mSelectPreference.setSummary("%s"); - mSelectPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + mSelectPreference.setOnPreferenceChangeListener( + new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - int index = Integer.parseInt((String) newValue); + if (Objects.equals(newValue, DisplayController.AUTO_STRING)) { + Settings.Secure.putInt(context.getContentResolver(), + DisplayController.COLOR_STATE, + DisplayController.COLOR_STATE_AUTO); + return true; + } + if (Objects.equals(newValue, DisplayController.NONE_STRING)) { + Settings.Secure.putString(context.getContentResolver(), + Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, null); + return true; + } + Settings.Secure.putInt(context.getContentResolver(), + DisplayController.COLOR_STATE, + DisplayController.COLOR_STATE_ENABLED); + final String value = (String) newValue; Settings.Secure.putString(context.getContentResolver(), - Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, getValues()[index]); + Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, + value); return true; } }); getPreferenceScreen().addPreference(mSelectPreference); - mShowQs = new SwitchPreference(context); - mShowQs.setTitle(R.string.color_matrix_show_qs); - mShowQs.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - boolean showTile = (Boolean) newValue; - String newTiles; - if (showTile) { - newTiles = mTiles != null ? mTiles + "," + ColorMatrixTile.COLOR_MATRIX_SPEC - : "default," + ColorMatrixTile.COLOR_MATRIX_SPEC; - } else { - newTiles = - mTiles.replace(mTiles.contains(ColorMatrixTile.COLOR_MATRIX_SPEC+ ",") - ? ColorMatrixTile.COLOR_MATRIX_SPEC + "," - : "," + ColorMatrixTile.COLOR_MATRIX_SPEC, ""); - } - Settings.Secure.putString(context.getContentResolver(), QSTileHost.TILES_SETTING, - newTiles); - return true; - } - }); - getPreferenceScreen().addPreference(mShowQs); - mEnableCustomPreference = new SwitchPreference(context); mEnableCustomPreference.setTitle(R.string.color_enable_custom); mEnableCustomPreference.setOnPreferenceChangeListener( @@ -129,8 +117,12 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean enabled = (Boolean) newValue; + if (!enabled && Objects.equals(mCurrentValue, mCustomValues)) { + Settings.Secure.putString(context.getContentResolver(), + Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, null); + } Settings.Secure.putInt(context.getContentResolver(), - ColorMatrixTile.COLOR_MATRIX_CUSTOM_ENABLED, enabled ? 1 : 0); + DisplayController.COLOR_MATRIX_CUSTOM_ENABLED, enabled ? 1 : 0); return true; } }); @@ -141,6 +133,38 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ } @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(mState != DisplayController.COLOR_STATE_DISABLED); + switchBar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int newState = mState != DisplayController.COLOR_STATE_DISABLED + ? DisplayController.COLOR_STATE_DISABLED + : DisplayController.COLOR_STATE_ENABLED; + ContentResolver contentResolver = getContext().getContentResolver(); + if (newState == DisplayController.COLOR_STATE_DISABLED) { + String tiles = Settings.Secure.getString(contentResolver, + QSTileHost.TILES_SETTING); + if (tiles != null) { + if (tiles.contains(",colors")) { + tiles = tiles.replace(",colors", ""); + } else if (tiles.contains("colors,")) { + tiles = tiles.replace("colors,", ""); + } + Settings.Secure.putString(contentResolver, QSTileHost.TILES_SETTING, + tiles); + } + } + Settings.Secure.putInt(contentResolver, + DisplayController.COLOR_STATE, newState); + } + }); + } + + @Override public void onDestroy() { super.onDestroy(); TunerService.get(getContext()).removeTunable(this); @@ -148,20 +172,28 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ @Override public void onTuningChanged(String key, String newValue) { - if (ColorMatrixTile.COLOR_MATRIX_CUSTOM_ENABLED.equals(key)) { + if (DisplayController.COLOR_MATRIX_CUSTOM_ENABLED.equals(key)) { mCustomEnabled = newValue != null && Integer.parseInt(newValue) != 0; mEnableCustomPreference.setChecked(mCustomEnabled); - mCustomPreference.setEnabled(mCustomEnabled); + mCustomPreference.setEnabled(mCustomEnabled + && mState != DisplayController.COLOR_STATE_DISABLED); updateSelectOptions(); - } else if (ColorMatrixTile.COLOR_MATRIX_CUSTOM_VALUES.equals(key)) { + } else if (DisplayController.COLOR_MATRIX_CUSTOM_VALUES.equals(key)) { mCustomValues = newValue; + if (mCustomValues == null) { + mCustomValues = DisplayController.toString(DisplayController.IDENTITY_MATRIX); + } mCustomPreference.setValues(mCustomValues); updateSelectOptions(); - } else if (QSTileHost.TILES_SETTING.equals(key)) { - mTiles = newValue; - boolean hasTile = newValue != null - && newValue.contains(ColorMatrixTile.COLOR_MATRIX_SPEC); - mShowQs.setChecked(hasTile); + } else if (DisplayController.COLOR_STATE.equals(key)) { + mState = newValue != null ? Integer.parseInt(newValue) : 0; + if (mSwitch != null) { + mSwitch.setChecked(mState != DisplayController.COLOR_STATE_DISABLED); + } + mSelectPreference.setEnabled(mState != DisplayController.COLOR_STATE_DISABLED); + mEnableCustomPreference.setEnabled(mState != DisplayController.COLOR_STATE_DISABLED); + mCustomPreference.setEnabled(mCustomEnabled + && mState != DisplayController.COLOR_STATE_DISABLED); } else { mCurrentValue = newValue; updateSelectOptions(); @@ -169,41 +201,38 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ } private void updateSelectOptions() { - final int N = CUSTOM_INDEX + (mCustomEnabled ? 1 : 0); + final int N = DisplayController.CUSTOM_INDEX + (mCustomEnabled ? 1 : 0); String[] values = new String[N]; - CharSequence[] totalNames = getColorTitles(getContext()); CharSequence[] names = new CharSequence[N]; + CharSequence[] totalNames = DisplayController.getColorTitles(getContext()); + String[] entries = DisplayController.getColorTransforms(getContext()); + entries[DisplayController.CUSTOM_INDEX] = mCustomValues != null ? mCustomValues : ""; for (int i = 0; i < N; i++) { - values[i] = String.valueOf(i); + values[i] = entries[i]; names[i] = totalNames[i]; } mSelectPreference.setEntries(names); mSelectPreference.setEntryValues(values); - String[] entries = getValues(); - for (int i = 0; i < values.length; i++) { - if (Objects.equals(entries[i], mCurrentValue)) { - mSelectPreference.setValueIndex(i); - return; - } + int index = 0; + if (mState == DisplayController.COLOR_STATE_AUTO) { + index = DisplayController.AUTO_INDEX; + } else if (mCustomValues != null && Objects.equals(mCurrentValue, mCustomValues)) { + index = DisplayController.CUSTOM_INDEX; + } else if (Objects.equals(mCurrentValue, entries[1])) { + index = 1; } - mSelectPreference.setSummary(R.string.color_matrix_unknown); + mSelectPreference.setValueIndex(index); + mSelectPreference.setSummary("%s"); return; } - private String[] getValues() { - String[] ret = getColorTransforms(); - // Fill in custom based on tuner settings. - ret[CUSTOM_INDEX] = mCustomValues; - return ret; - } - private void startRevertTimer() { getView().postDelayed(mResetColorMatrix, RESET_DELAY); } private void onApply() { Settings.Secure.putString(getContext().getContentResolver(), - ColorMatrixTile.COLOR_MATRIX_CUSTOM_VALUES, mCurrentValue); + DisplayController.COLOR_MATRIX_CUSTOM_VALUES, mCurrentValue); getView().removeCallbacks(mResetColorMatrix); } @@ -212,35 +241,6 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ mResetColorMatrix.run(); } - public static String[] getColorTransforms() { - return new String[] { - null, - toString(NIGHT_VALUES), - null, // Blank spot for custom values - null, // Unknown - }; - } - - public static CharSequence[] getColorTitles(Context context) { - return new CharSequence[] { - context.getString(R.string.color_matrix_none), - context.getString(R.string.color_matrix_night), - context.getString(R.string.color_matrix_custom), - context.getString(R.string.color_matrix_unknown), - }; - } - - private 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(); - } - private final Runnable mResetColorMatrix = new Runnable() { @Override public void run() { @@ -259,14 +259,10 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ } public void setValues(String customValues) { - if (customValues == null) { - mValues = IDENTITY_MATRIX; - } else { - String[] strValues = customValues.split(","); - mValues = new float[strValues.length]; - for (int i = 0; i < mValues.length; i++) { - mValues[i] = Float.parseFloat(strValues[i]); - } + String[] strValues = customValues.split(","); + mValues = new float[strValues.length]; + for (int i = 0; i < mValues.length; i++) { + mValues[i] = Float.parseFloat(strValues[i]); } notifyChanged(); } @@ -274,48 +270,38 @@ public class ColorMatrixFragment extends PreferenceFragment implements TunerServ @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); - ViewGroup vg = (ViewGroup) holder.itemView.findViewById(R.id.edit_group); - if (mValues == null) { - return; - } - int childIndex = 0; - for (int i = 0; i < mValues.length; i++) { - final int index = i; - while (!(vg.getChildAt(childIndex) instanceof EditText)) { - childIndex++; + bindView(holder.findViewById(R.id.r_group), 0); + bindView(holder.findViewById(R.id.g_group), 5); + bindView(holder.findViewById(R.id.b_group), 10); + holder.findViewById(R.id.apply).setOnClickListener(this); + } + + 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; } - final EditText editText = (EditText) vg.getChildAt(childIndex++); - editText.setText(String.valueOf(mValues[i])); - editText.addTextChangedListener(new TextWatcher() { - @Override - public void afterTextChanged(Editable s) { - if (TextUtils.isEmpty(s.toString())) { - return; - } - try { - mValues[index] = Float.parseFloat(s.toString()); - } catch (NumberFormatException e) { - mValues[index] = 0; - } - } - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - }); - } - ((Button) holder.itemView.findViewById(R.id.apply)).setOnClickListener(this); + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); } @Override public void onClick(View v) { + startRevertTimer(); Settings.Secure.putString(getContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, - ColorMatrixFragment.toString(mValues)); + DisplayController.toString(mValues)); RevertWarning.show(ColorMatrixFragment.this); } diff --git a/packages/SystemUI/src/com/android/systemui/tuner/ColorMatrixTile.java b/packages/SystemUI/src/com/android/systemui/tuner/ColorMatrixTile.java index 32068823e4ea..1933c1581188 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/ColorMatrixTile.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/ColorMatrixTile.java @@ -20,15 +20,17 @@ import android.provider.Settings; import com.android.internal.logging.MetricsProto.MetricsEvent; import com.android.systemui.R; import com.android.systemui.qs.QSTile; -import libcore.util.Objects; +import com.android.systemui.statusbar.policy.DisplayController; -public class ColorMatrixTile extends QSTile<QSTile.State> implements TunerService.Tunable { +import java.util.Objects; - public static final String COLOR_MATRIX_CUSTOM_ENABLED = "tuner_color_custom_enabled"; - public static final String COLOR_MATRIX_CUSTOM_VALUES = "tuner_color_custom_values"; + +public class ColorMatrixTile extends QSTile<QSTile.State> implements DisplayController.Listener { public static final String COLOR_MATRIX_SPEC = "colors"; + private final DisplayController mDisplayController; + private int mIndex; private String mCurrentValue; @@ -38,18 +40,17 @@ public class ColorMatrixTile extends QSTile<QSTile.State> implements TunerServic public ColorMatrixTile(Host host) { super(host); + mDisplayController = host.getDisplayController(); } @Override public void setListening(boolean listening) { if (listening) { - mValues = ColorMatrixFragment.getColorTransforms(); - mValueTitles = ColorMatrixFragment.getColorTitles(mContext); - TunerService.get(mContext).addTunable(this, COLOR_MATRIX_CUSTOM_ENABLED, - COLOR_MATRIX_CUSTOM_VALUES, - Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX); + mValues = DisplayController.getColorTransforms(mContext); + mValueTitles = DisplayController.getColorTitles(mContext); + mDisplayController.addListener(this); } else { - TunerService.get(mContext).removeTunable(this); + mDisplayController.removeListener(this); } } @@ -61,46 +62,44 @@ public class ColorMatrixTile extends QSTile<QSTile.State> implements TunerServic @Override protected void handleClick() { mIndex++; - if (!mCustomEnabled && (mIndex == ColorMatrixFragment.CUSTOM_INDEX)) { - mIndex++; - } - if (mIndex == mValues.length - 1) { - mIndex = 0; - } - Settings.Secure.putStringForUser(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, mValues[mIndex], - ActivityManager.getCurrentUser()); - refreshState(); - } - - @Override - public void onTuningChanged(String key, String newValue) { - if (COLOR_MATRIX_CUSTOM_ENABLED.equals(key)) { - mCustomEnabled = newValue != null && Integer.parseInt(newValue) != 0; - } else if (COLOR_MATRIX_CUSTOM_VALUES.equals(key)) { - mValues[ColorMatrixFragment.CUSTOM_INDEX] = newValue; + if (mIndex == DisplayController.AUTO_INDEX) { + mDisplayController.setAuto(true); } else { - mCurrentValue = newValue; - } - // Last value is unknown, default to that. - mIndex = mValues.length - 1; - for (int i = 0; i < mValues.length - 1; i++) { - if (Objects.equal(mCurrentValue, mValues[i])) { - mIndex = i; - break; + mDisplayController.setAuto(false); + if (!mDisplayController.isCustomEnabled() + && (mIndex == DisplayController.CUSTOM_INDEX)) { + mIndex++; + } + if (mIndex == mValues.length - 1) { + mIndex = 0; } + Settings.Secure.putStringForUser(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_DISPLAY_COLOR_MATRIX, mValues[mIndex], + ActivityManager.getCurrentUser()); } refreshState(); } @Override protected void handleUpdateState(State state, Object arg) { + if (mDisplayController.isAuto()) { + mIndex = DisplayController.AUTO_INDEX; + } else if (mDisplayController.isCustomSet()) { + mIndex = DisplayController.CUSTOM_INDEX; + } else { + mIndex = Objects.equals(mDisplayController.getCurrentMatrix(), mValues[1]) ? 1 : 0; + } state.icon = ResourceIcon.get(R.drawable.ic_colorize); state.label = mValueTitles[mIndex]; state.contentDescription = mValueTitles[mIndex]; } @Override + public void onCurrentMatrixChanged() { + refreshState(); + } + + @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 4173ecc2d7fc..f6980e9fa9bf 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerActivity.java @@ -43,6 +43,7 @@ public class TunerActivity extends SettingsDrawerActivity implements Class<?> cls = Class.forName(pref.getFragment()); Fragment fragment = (Fragment) cls.newInstance(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); + setTitle(pref.getTitle()); transaction.replace(R.id.content_frame, fragment); transaction.addToBackStack("PreferenceFragment"); transaction.commit(); diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java index 427b5e8480b2..88f6f4dd2262 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java @@ -81,6 +81,7 @@ public class TunerFragment extends PreferenceFragment { @Override public void onResume() { super.onResume(); + getActivity().setTitle(R.string.system_ui_tuner); updateBatteryPct(); getContext().getContentResolver().registerContentObserver( System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver); diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java index 47a4667f29f0..abaa628145d6 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java @@ -76,6 +76,22 @@ public class TunerService extends SystemUI { mUserTracker.startTracking(); } + public String getValue(String setting) { + return Settings.Secure.getStringForUser(mContentResolver, setting, mCurrentUser); + } + + public void setValue(String setting, String value) { + Settings.Secure.putStringForUser(mContentResolver, setting, value, mCurrentUser); + } + + public int getValue(String setting, int def) { + return Settings.Secure.getIntForUser(mContentResolver, setting, def, mCurrentUser); + } + + public void setValue(String setting, int value) { + Settings.Secure.putIntForUser(mContentResolver, setting, value, mCurrentUser); + } + public void addTunable(Tunable tunable, String... keys) { for (String key : keys) { addTunable(tunable, key); |