1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.settings.display.darkmode; 16 17 import android.content.Context; 18 import android.os.Bundle; 19 import android.app.settings.SettingsEnums; 20 import com.android.settings.R; 21 import com.android.settings.dashboard.DashboardFragment; 22 import com.android.settings.search.BaseSearchIndexProvider; 23 import com.android.settingslib.search.SearchIndexable; 24 25 /** 26 * Settings screen for Dark UI Mode 27 */ 28 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 29 public class DarkModeSettingsFragment extends DashboardFragment { 30 31 private static final String TAG = "DarkModeSettingsFragment"; 32 private DarkModeObserver mContentObserver; 33 private Runnable mCallback = () -> { 34 updatePreferenceStates(); 35 }; 36 37 @Override onCreate(Bundle savedInstanceState)38 public void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 41 final Context context = getContext(); 42 mContentObserver = new DarkModeObserver(context); 43 } 44 45 @Override onStart()46 public void onStart() { 47 super.onStart(); 48 // Listen for changes only while visible. 49 mContentObserver.subscribe(mCallback); 50 } 51 52 @Override onStop()53 public void onStop() { 54 super.onStop(); 55 // Stop listening for state changes. 56 mContentObserver.unsubscribe(); 57 } 58 59 @Override getPreferenceScreenResId()60 protected int getPreferenceScreenResId() { 61 return R.xml.dark_mode_settings; 62 } 63 64 @Override getHelpResource()65 public int getHelpResource() { 66 return R.string.help_url_dark_theme; 67 } 68 69 @Override getLogTag()70 protected String getLogTag() { 71 return TAG; 72 } 73 74 @Override getMetricsCategory()75 public int getMetricsCategory() { 76 return SettingsEnums.DARK_UI_SETTINGS; 77 } 78 79 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 80 new BaseSearchIndexProvider(); 81 } 82