1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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 15 */ 16 17 package com.android.settings.datetime; 18 19 import android.app.Dialog; 20 import android.app.settings.SettingsEnums; 21 import android.app.timedetector.TimeDetectorHelper; 22 import android.content.Context; 23 24 import com.android.settings.R; 25 import com.android.settings.dashboard.DashboardFragment; 26 import com.android.settings.search.BaseSearchIndexProvider; 27 import com.android.settingslib.search.SearchIndexable; 28 29 import com.google.android.setupcompat.util.WizardManagerHelper; 30 31 @SearchIndexable 32 public class DateTimeSettings extends DashboardFragment implements 33 TimePreferenceController.TimePreferenceHost, DatePreferenceController.DatePreferenceHost { 34 35 private static final String TAG = "DateTimeSettings"; 36 37 // have we been launched from the setup wizard? 38 protected static final String EXTRA_IS_FROM_SUW = "firstRun"; 39 40 @Override getMetricsCategory()41 public int getMetricsCategory() { 42 return SettingsEnums.DATE_TIME; 43 } 44 45 @Override getLogTag()46 protected String getLogTag() { 47 return TAG; 48 } 49 50 @Override getPreferenceScreenResId()51 protected int getPreferenceScreenResId() { 52 return R.xml.date_time_prefs; 53 } 54 55 @Override onAttach(Context context)56 public void onAttach(Context context) { 57 super.onAttach(context); 58 boolean isFromSUW = WizardManagerHelper.isAnySetupWizard(getIntent()); 59 getSettingsLifecycle().addObserver(new TimeChangeListenerMixin(context, this)); 60 use(LocationTimeZoneDetectionPreferenceController.class).setFragment(this); 61 use(AutoTimePreferenceController.class).setDateAndTimeCallback(this); 62 use(DatePreferenceController.class).setHost(this); 63 use(TimePreferenceController.class).setHost(this); 64 use(AutoTimeZonePreferenceController.class) 65 .setTimeAndDateCallback(this) 66 .setFromSUW(isFromSUW); 67 use(TimeFormatPreferenceController.class) 68 .setTimeAndDateCallback(this) 69 .setFromSUW(isFromSUW); 70 71 // All the elements in the category are optional, so we must ensure the category is only 72 // available if any of the elements are available. 73 TimeFeedbackPreferenceCategoryController helpAndFeedbackCategoryController = 74 use(TimeFeedbackPreferenceCategoryController.class); 75 use(TimeFeedbackPreferenceController.class) 76 .registerWithOptionalCategoryController(helpAndFeedbackCategoryController); 77 } 78 79 @Override updateTimeAndDateDisplay(Context context)80 public void updateTimeAndDateDisplay(Context context) { 81 updatePreferenceStates(); 82 } 83 84 @Override onCreateDialog(int id)85 public Dialog onCreateDialog(int id) { 86 switch (id) { 87 case DatePreferenceController.DIALOG_DATEPICKER: 88 return use(DatePreferenceController.class) 89 .buildDatePicker(getActivity(), TimeDetectorHelper.INSTANCE); 90 case TimePreferenceController.DIALOG_TIMEPICKER: 91 return use(TimePreferenceController.class) 92 .buildTimePicker(getActivity()); 93 default: 94 throw new IllegalArgumentException(); 95 } 96 } 97 98 @Override getDialogMetricsCategory(int dialogId)99 public int getDialogMetricsCategory(int dialogId) { 100 switch (dialogId) { 101 case DatePreferenceController.DIALOG_DATEPICKER: 102 return SettingsEnums.DIALOG_DATE_PICKER; 103 case TimePreferenceController.DIALOG_TIMEPICKER: 104 return SettingsEnums.DIALOG_TIME_PICKER; 105 default: 106 return 0; 107 } 108 } 109 110 @Override showTimePicker()111 public void showTimePicker() { 112 removeDialog(TimePreferenceController.DIALOG_TIMEPICKER); 113 showDialog(TimePreferenceController.DIALOG_TIMEPICKER); 114 } 115 116 @Override showDatePicker()117 public void showDatePicker() { 118 showDialog(DatePreferenceController.DIALOG_DATEPICKER); 119 } 120 121 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 122 new BaseSearchIndexProvider(R.xml.date_time_prefs); 123 } 124