• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Activity;
20 import android.app.Dialog;
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 import android.content.Intent;
24 
25 import com.android.settings.R;
26 import com.android.settings.dashboard.DashboardFragment;
27 import com.android.settings.search.BaseSearchIndexProvider;
28 import com.android.settingslib.core.AbstractPreferenceController;
29 import com.android.settingslib.search.SearchIndexable;
30 
31 import java.util.ArrayList;
32 import java.util.List;
33 
34 @SearchIndexable
35 public class DateTimeSettings extends DashboardFragment implements
36         TimePreferenceController.TimePreferenceHost, DatePreferenceController.DatePreferenceHost {
37 
38     private static final String TAG = "DateTimeSettings";
39 
40     // have we been launched from the setup wizard?
41     protected static final String EXTRA_IS_FROM_SUW = "firstRun";
42 
43     @Override
getMetricsCategory()44     public int getMetricsCategory() {
45         return SettingsEnums.DATE_TIME;
46     }
47 
48     @Override
getLogTag()49     protected String getLogTag() {
50         return TAG;
51     }
52 
53     @Override
getPreferenceScreenResId()54     protected int getPreferenceScreenResId() {
55         return R.xml.date_time_prefs;
56     }
57 
58     @Override
onAttach(Context context)59     public void onAttach(Context context) {
60         super.onAttach(context);
61         getSettingsLifecycle().addObserver(new TimeChangeListenerMixin(context, this));
62         use(LocationTimeZoneDetectionPreferenceController.class).setFragment(this);
63     }
64 
65     @Override
createPreferenceControllers(Context context)66     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
67         final List<AbstractPreferenceController> controllers = new ArrayList<>();
68         final Activity activity = getActivity();
69         final Intent intent = activity.getIntent();
70         final boolean isFromSUW = intent.getBooleanExtra(EXTRA_IS_FROM_SUW, false);
71 
72         final AutoTimeZonePreferenceController autoTimeZonePreferenceController =
73                 new AutoTimeZonePreferenceController(
74                         activity, this /* UpdateTimeAndDateCallback */, isFromSUW);
75         final AutoTimePreferenceController autoTimePreferenceController =
76                 new AutoTimePreferenceController(
77                         activity, this /* UpdateTimeAndDateCallback */);
78         final AutoTimeFormatPreferenceController autoTimeFormatPreferenceController =
79                 new AutoTimeFormatPreferenceController(
80                         activity, this /* UpdateTimeAndDateCallback */);
81 
82         controllers.add(autoTimeZonePreferenceController);
83         controllers.add(autoTimePreferenceController);
84         controllers.add(autoTimeFormatPreferenceController);
85 
86         controllers.add(new TimeFormatPreferenceController(
87                 activity, this /* UpdateTimeAndDateCallback */, isFromSUW));
88         controllers.add(new TimeZonePreferenceController(
89                 activity, autoTimeZonePreferenceController));
90         controllers.add(new TimePreferenceController(
91                 activity, this /* UpdateTimeAndDateCallback */, autoTimePreferenceController));
92         controllers.add(new DatePreferenceController(
93                 activity, this /* UpdateTimeAndDateCallback */, autoTimePreferenceController));
94         return controllers;
95     }
96 
97     @Override
updateTimeAndDateDisplay(Context context)98     public void updateTimeAndDateDisplay(Context context) {
99         updatePreferenceStates();
100     }
101 
102     @Override
onCreateDialog(int id)103     public Dialog onCreateDialog(int id) {
104         switch (id) {
105             case DatePreferenceController.DIALOG_DATEPICKER:
106                 return use(DatePreferenceController.class)
107                         .buildDatePicker(getActivity());
108             case TimePreferenceController.DIALOG_TIMEPICKER:
109                 return use(TimePreferenceController.class)
110                         .buildTimePicker(getActivity());
111             default:
112                 throw new IllegalArgumentException();
113         }
114     }
115 
116     @Override
getDialogMetricsCategory(int dialogId)117     public int getDialogMetricsCategory(int dialogId) {
118         switch (dialogId) {
119             case DatePreferenceController.DIALOG_DATEPICKER:
120                 return SettingsEnums.DIALOG_DATE_PICKER;
121             case TimePreferenceController.DIALOG_TIMEPICKER:
122                 return SettingsEnums.DIALOG_TIME_PICKER;
123             default:
124                 return 0;
125         }
126     }
127 
128     @Override
showTimePicker()129     public void showTimePicker() {
130         removeDialog(TimePreferenceController.DIALOG_TIMEPICKER);
131         showDialog(TimePreferenceController.DIALOG_TIMEPICKER);
132     }
133 
134     @Override
showDatePicker()135     public void showDatePicker() {
136         showDialog(DatePreferenceController.DIALOG_DATEPICKER);
137     }
138 
139     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
140             new BaseSearchIndexProvider(R.xml.date_time_prefs);
141 }
142