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 import android.support.v7.widget.RecyclerView; 22 23 import com.android.car.settings.R; 24 import com.android.car.settings.common.ListSettingsFragment; 25 import com.android.car.settings.common.TypedPagedListAdapter; 26 import com.android.car.view.PagedListView; 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 ListSettingsFragment 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 = ListSettingsFragment.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 getLineItems()54 public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() { 55 ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>(); 56 for (Map<String, Object> zone : mZoneList) { 57 lineItems.add(new TimeZoneLineItem(getContext(), this, zone)); 58 } 59 return lineItems; 60 } 61 62 @Override onTimeZoneChanged()63 public void onTimeZoneChanged() { 64 getContext().sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED)); 65 mFragmentController.goBack(); 66 } 67 } 68