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 17 package com.android.car.settings.datetime; 18 19 import android.annotation.NonNull; 20 import android.app.AlarmManager; 21 import android.content.Context; 22 23 import androidx.car.widget.TextListItem; 24 25 import com.android.settingslib.datetime.ZoneGetter; 26 27 import java.util.Map; 28 29 /** 30 * A LineItem that displays available time zone. 31 */ 32 class TimeZoneLineItem extends TextListItem { 33 34 public interface TimeZoneChangeListener { onTimeZoneChanged()35 void onTimeZoneChanged(); 36 } 37 TimeZoneLineItem( Context context, @NonNull TimeZoneChangeListener listener, Map<String, Object> timeZone)38 public TimeZoneLineItem( 39 Context context, 40 @NonNull TimeZoneChangeListener listener, 41 Map<String, Object> timeZone) { 42 super(context); 43 setTitle(timeZone.get(ZoneGetter.KEY_DISPLAYNAME).toString()); 44 setBody(timeZone.get(ZoneGetter.KEY_GMT).toString()); 45 setOnClickListener(v -> { 46 AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 47 am.setTimeZone((String) timeZone.get(ZoneGetter.KEY_ID)); 48 listener.onTimeZoneChanged(); 49 }); 50 } 51 } 52