• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.car.settings.datetime;
17 
18 
19 import android.content.Intent;
20 import android.os.Bundle;
21 
22 import androidx.car.widget.ListItem;
23 import androidx.car.widget.ListItemProvider;
24 
25 import com.android.car.settings.R;
26 import com.android.car.settings.common.ListItemSettingsFragment;
27 import com.android.settingslib.datetime.ZoneGetter;
28 
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map;
32 
33 /**
34  * Lists all time zone and its offset from GMT.
35  */
36 public class TimeZonePickerFragment extends ListItemSettingsFragment implements
37         TimeZoneLineItem.TimeZoneChangeListener {
38     private List<Map<String, Object>> mZoneList;
39 
getInstance()40     public static TimeZonePickerFragment getInstance() {
41         TimeZonePickerFragment timeZonePickerFragment = new TimeZonePickerFragment();
42         Bundle bundle = ListItemSettingsFragment.getBundle();
43         bundle.putInt(EXTRA_TITLE_ID, R.string.date_time_set_timezone_title);
44         timeZonePickerFragment.setArguments(bundle);
45         return timeZonePickerFragment;
46     }
47 
48     @Override
onActivityCreated(Bundle savedInstanceState)49     public void onActivityCreated(Bundle savedInstanceState) {
50         mZoneList = ZoneGetter.getZonesList(getContext());
51         super.onActivityCreated(savedInstanceState);
52     }
53 
54     @Override
getItemProvider()55     public ListItemProvider getItemProvider() {
56         return new ListItemProvider.ListProvider(getListItems());
57     }
58 
getListItems()59     private List<ListItem> getListItems() {
60         List<ListItem> lineItems = new ArrayList<>();
61         for (Map<String, Object> zone : mZoneList) {
62             lineItems.add(new TimeZoneLineItem(getContext(), this, zone));
63         }
64         return lineItems;
65     }
66 
67     @Override
onTimeZoneChanged()68     public void onTimeZoneChanged() {
69         getContext().sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED));
70         getFragmentController().goBack();
71     }
72 }
73