Remove "Night mode" from tuner
Bug: 28887927 Change-Id: Ic1c217152e56db63a87a1f1e772696d97b4b58b3
This commit is contained in:
@@ -1,24 +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.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24.0dp"
|
||||
android:height="24.0dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M20.71,5.63l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0.0l-3.12,3.12 -1.93,-1.91 -1.41,1.41 1.42,1.42L3.0,16.25L3.0,21.0l4.75,0.0l8.92,-8.92 1.42,1.42 1.41,-1.41 -1.92,-1.92 3.12,-3.12c0.4,0.0 0.4,-1.0 0.01,-1.42zM6.92,19.0L5.0,17.08l8.06,-8.06 1.92,1.92L6.92,19.0z"/>
|
||||
</vector>
|
||||
@@ -1,24 +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.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24.0dp"
|
||||
android:height="24.0dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#4DFFFFFF"
|
||||
android:pathData="M20.71,5.63l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0.0l-3.12,3.12 -1.93,-1.91 -1.41,1.41 1.42,1.42L3.0,16.25L3.0,21.0l4.75,0.0l8.92,-8.92 1.42,1.42 1.41,-1.41 -1.92,-1.92 3.12,-3.12c0.4,0.0 0.4,-1.0 0.01,-1.42zM6.92,19.0L5.0,17.08l8.06,-8.06 1.92,1.92L6.92,19.0z"/>
|
||||
</vector>
|
||||
@@ -1,97 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 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="wrap_content"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<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="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/color_modification_r"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<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/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="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/color_modification_g"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<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="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/color_modification_b"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<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>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?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>
|
||||
@@ -1336,59 +1336,6 @@
|
||||
<!-- Notification: Gear: Content description for the gear. [CHAR LIMIT=NONE] -->
|
||||
<string name="notification_gear_accessibility"><xliff:g id="app_name" example="YouTube">%1$s</xliff:g> notification controls</string>
|
||||
|
||||
<!-- SysUI Tuner: Color and appearance screen title [CHAR LIMIT=50] -->
|
||||
<string name="color_and_appearance">Color and appearance</string>
|
||||
|
||||
<!-- SysUI Tuner: Name of the night mode feature [CHAR LIMIT=30] -->
|
||||
<string name="night_mode">Night mode</string>
|
||||
|
||||
<!-- SysUI Tuner: Name of calibrate display dialog [CHAR LIMIT=30] -->
|
||||
<string name="calibrate_display">Calibrate display</string>
|
||||
|
||||
<!-- SysUI Tuner: Summary of night mode when its on [CHAR LIMIT=NONE] -->
|
||||
<string name="night_mode_on">On</string>
|
||||
|
||||
<!-- SysUI Tuner: Summary of night mode when its off [CHAR LIMIT=NONE] -->
|
||||
<string name="night_mode_off">Off</string>
|
||||
|
||||
<!-- SysUI Tuner: Label for switch to turn on night mode automatically [CHAR LIMIT=50] -->
|
||||
<string name="turn_on_automatically">Turn on automatically</string>
|
||||
|
||||
<!-- SysUI Tuner: Summary for switch to turn on night mode automatically [CHAR LIMIT=NONE] -->
|
||||
<string name="turn_on_auto_summary">Switch into Night Mode as appropriate for location and time of day</string>
|
||||
|
||||
<!-- SysUI Tuner: Label for section controlling what night mode does [CHAR LIMIT=60] -->
|
||||
<string name="when_night_mode_on">When Night Mode is on</string>
|
||||
|
||||
<!-- SysUI Tuner: Switch controlling whether dark theme is turned on with night mode [CHAR LIMIT=45] -->
|
||||
<string name="use_dark_theme">Use dark theme for Android OS</string>
|
||||
|
||||
<!-- SysUI Tuner: Switch controlling whether tint is changed with night mode [CHAR LIMIT=45] -->
|
||||
<string name="adjust_tint">Adjust tint</string>
|
||||
|
||||
<!-- SysUI Tuner: Switch controlling whether brightness is changed with night mode [CHAR LIMIT=45] -->
|
||||
<string name="adjust_brightness">Adjust brightness</string>
|
||||
|
||||
<!-- SysUI Tuner: Disclaimer about using dark theme with night mode [CHAR LIMIT=NONE] -->
|
||||
<string name="night_mode_disclaimer">The dark theme is applied to
|
||||
core areas of Android OS that are normally displayed in a light theme,
|
||||
such as Settings.</string>
|
||||
|
||||
<!-- Button to apply settings [CHAR LIMIT=30] -->
|
||||
<string name="color_apply">Apply</string>
|
||||
|
||||
<!-- Title of warning dialog about bad color settings. [CHAR LIMIT=30] -->
|
||||
<string name="color_revert_title">Confirm settings</string>
|
||||
|
||||
<!-- Message warning user about custom color settings [CHAR LIMIT=NONE] -->
|
||||
<string name="color_revert_message">Some color settings can make this
|
||||
device unusable. Click OK to confirm these color settings,
|
||||
otherwise these settings will reset after 10 seconds.</string>
|
||||
|
||||
<string name="color_modification_r" translatable="false">R</string>
|
||||
<string name="color_modification_g" translatable="false">G</string>
|
||||
<string name="color_modification_b" translatable="false">B</string>
|
||||
|
||||
<!-- Title of the battery settings detail panel [CHAR LIMIT=20] -->
|
||||
<string name="battery_panel_title">Battery usage</string>
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:sysui="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/color_and_appearance">
|
||||
|
||||
<Preference
|
||||
android:key="night_mode"
|
||||
android:title="@string/night_mode"
|
||||
android:fragment="com.android.systemui.tuner.NightModeFragment" />
|
||||
|
||||
<com.android.systemui.tuner.CalibratePreference
|
||||
android:key="calibrate"
|
||||
android:title="@string/calibrate_display" />
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -1,39 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:sysui="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/night_mode">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="auto"
|
||||
android:title="@string/turn_on_automatically"
|
||||
android:summary="@string/turn_on_auto_summary" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/when_night_mode_on">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="adjust_tint"
|
||||
android:title="@string/adjust_tint" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="adjust_brightness"
|
||||
android:title="@string/adjust_brightness" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -100,13 +100,6 @@
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
<!--
|
||||
<Preference
|
||||
android:key="color_transform"
|
||||
android:title="@string/color_and_appearance"
|
||||
android:fragment="com.android.systemui.tuner.ColorAndAppearanceFragment" />
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="volume_and_do_not_disturb"
|
||||
android:title="@string/volume_and_do_not_disturb">
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user