2 * Copyright (C) 2018 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 package com.android.settings.display;
19 import android.app.UiModeManager;
20 import android.content.Context;
21 import android.provider.Settings;
23 import androidx.annotation.VisibleForTesting;
24 import androidx.fragment.app.Fragment;
26 import com.android.settings.core.TogglePreferenceController;
28 public class DarkUIPreferenceController extends TogglePreferenceController {
30 public static final String DARK_MODE_PREFS = "dark_mode_prefs";
31 public static final String PREF_DARK_MODE_DIALOG_SEEN = "dark_mode_dialog_seen";
32 public static final int DIALOG_SEEN = 1;
33 private UiModeManager mUiModeManager;
34 private Context mContext;
35 private Fragment mFragment;
37 public DarkUIPreferenceController(Context context, String key) {
40 mUiModeManager = context.getSystemService(UiModeManager.class);
44 public boolean isChecked() {
45 return mUiModeManager.getNightMode() == UiModeManager.MODE_NIGHT_YES;
49 public boolean setChecked(boolean isChecked) {
50 final boolean dialogSeen =
51 Settings.Secure.getInt(mContext.getContentResolver(),
52 Settings.Secure.DARK_MODE_DIALOG_SEEN, 0) == DIALOG_SEEN;
53 if (!dialogSeen && isChecked) {
57 mUiModeManager.setNightMode(isChecked
58 ? UiModeManager.MODE_NIGHT_YES
59 : UiModeManager.MODE_NIGHT_NO);
63 private void showDarkModeDialog() {
64 final DarkUIInfoDialogFragment frag = new DarkUIInfoDialogFragment();
65 if (mFragment.getFragmentManager() != null) {
66 frag.show(mFragment.getFragmentManager(), getClass().getName());
71 void setUiModeManager(UiModeManager uiModeManager) {
72 mUiModeManager = uiModeManager;
75 public void setParentFragment(Fragment fragment) {
80 public int getAvailabilityStatus() {