2 * Copyright (C) 2019 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 static com.android.settings.display.DarkUIPreferenceController.DARK_MODE_PREFS;
20 import static com.android.settings.display.DarkUIPreferenceController.PREF_DARK_MODE_DIALOG_SEEN;
22 import android.app.Dialog;
23 import android.app.UiModeManager;
24 import android.content.Context;
25 import android.content.DialogInterface;
26 import android.os.Bundle;
27 import android.provider.Settings;
28 import android.view.LayoutInflater;
29 import android.view.View;
30 import android.widget.ImageView;
31 import android.widget.TextView;
33 import androidx.annotation.NonNull;
34 import androidx.annotation.Nullable;
35 import androidx.appcompat.app.AlertDialog;
37 import com.android.settings.R;
38 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
40 public class DarkUIInfoDialogFragment extends InstrumentedDialogFragment
41 implements DialogInterface.OnClickListener{
44 public int getMetricsCategory() {
45 // TODO(b/130251804): Add metrics constant in followup change to avoid merge conflict in
52 public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
53 Context context = getContext();
54 AlertDialog.Builder dialog = new AlertDialog.Builder(context);
55 LayoutInflater inflater = LayoutInflater.from(dialog.getContext());
56 View titleView = inflater.inflate(R.layout.settings_dialog_title, null);
57 ((ImageView) titleView.findViewById(R.id.settings_icon))
58 .setImageDrawable(context.getDrawable(R.drawable.dark_theme));
59 ((TextView) titleView.findViewById(R.id.settings_title)).setText(R.string.dark_ui_mode);
61 dialog.setCustomTitle(titleView)
62 .setMessage(R.string.dark_ui_settings_dark_summary)
64 R.string.dark_ui_settings_dialog_acknowledge,
66 return dialog.create();
70 public void onDismiss(@NonNull DialogInterface dialog) {
72 super.onDismiss(dialog);
76 public void onClick(DialogInterface dialogInterface, int i) {
77 // We have to manually dismiss the dialog because changing night mode causes it to
79 dialogInterface.dismiss();
83 private void enableDarkTheme() {
84 final Context context = getContext();
85 if (context != null) {
86 Settings.Secure.putInt(context.getContentResolver(),
87 Settings.Secure.DARK_MODE_DIALOG_SEEN,
88 DarkUIPreferenceController.DIALOG_SEEN);
89 context.getSystemService(UiModeManager.class)
90 .setNightMode(UiModeManager.MODE_NIGHT_YES);