The dark theme preference should have it's own screen rather than being a dialog. This adds some boilerplate code that will be needed for the illustration as well as converting the current list preference to open a new screen. Test: robotests Bug: 128686189 Change-Id: I5b62276353c0d39ad2ad00d21d2280e76cceb09b
87 lines
2.9 KiB
Java
87 lines
2.9 KiB
Java
/*
|
|
* Copyright (C) 2019 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.settings.display;
|
|
|
|
import android.app.UiModeManager;
|
|
import android.content.Context;
|
|
import androidx.preference.Preference;
|
|
import com.android.settings.R;
|
|
import androidx.annotation.VisibleForTesting;
|
|
|
|
public class DarkUISettingsRadioButtonsController {
|
|
|
|
public static final String KEY_DARK = "key_dark_ui_settings_dark";
|
|
public static final String KEY_LIGHT = "key_dark_ui_settings_light";
|
|
|
|
@VisibleForTesting
|
|
UiModeManager mManager;
|
|
|
|
private Preference mFooter;
|
|
|
|
public DarkUISettingsRadioButtonsController(Context context, Preference footer) {
|
|
mManager = context.getSystemService(UiModeManager.class);
|
|
mFooter = footer;
|
|
}
|
|
|
|
public String getDefaultKey() {
|
|
final int mode = mManager.getNightMode();
|
|
updateFooter();
|
|
return mode == UiModeManager.MODE_NIGHT_YES ? KEY_DARK : KEY_LIGHT;
|
|
}
|
|
|
|
public boolean setDefaultKey(String key) {
|
|
switch(key) {
|
|
case KEY_DARK:
|
|
mManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
|
|
break;
|
|
case KEY_LIGHT:
|
|
mManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
|
|
break;
|
|
default:
|
|
throw new IllegalStateException(
|
|
"Not a valid key for " + this.getClass().getSimpleName() + ": " + key);
|
|
}
|
|
updateFooter();
|
|
return true;
|
|
}
|
|
|
|
public void updateFooter() {
|
|
final int mode = mManager.getNightMode();
|
|
switch (mode) {
|
|
case UiModeManager.MODE_NIGHT_YES:
|
|
mFooter.setSummary(R.string.dark_ui_settings_dark_summary);
|
|
break;
|
|
case UiModeManager.MODE_NIGHT_NO:
|
|
case UiModeManager.MODE_NIGHT_AUTO:
|
|
default:
|
|
mFooter.setSummary(R.string.dark_ui_settings_light_summary);
|
|
}
|
|
}
|
|
|
|
public static String modeToDescription(Context context, int mode) {
|
|
final String[] values = context.getResources().getStringArray(R.array.dark_ui_mode_entries);
|
|
switch (mode) {
|
|
case UiModeManager.MODE_NIGHT_YES:
|
|
return values[0];
|
|
case UiModeManager.MODE_NIGHT_NO:
|
|
case UiModeManager.MODE_NIGHT_AUTO:
|
|
default:
|
|
return values[1];
|
|
}
|
|
}
|
|
}
|