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.app.AlarmManager; 20 import android.content.Context; 21 import android.provider.Settings; 22 23 import android.annotation.NonNull; 24 import com.android.car.settings.R; 25 import com.android.car.settings.common.TextLineItem; 26 import com.android.settingslib.datetime.ZoneGetter; 27 28 import java.util.Map; 29 30 /** 31 * A LineItem that displays available time zone. 32 */ 33 class TimeZoneLineItem extends TextLineItem { 34 private final Context mContext; 35 private final TimeZoneChangeListener mListener; 36 private final Map<String, Object> mTimeZone; 37 38 public interface TimeZoneChangeListener { onTimeZoneChanged()39 void onTimeZoneChanged(); 40 } 41 TimeZoneLineItem( Context context, @NonNull TimeZoneChangeListener listener, Map<String, Object> timeZone)42 public TimeZoneLineItem( 43 Context context, 44 @NonNull TimeZoneChangeListener listener, 45 Map<String, Object> timeZone) { 46 super((CharSequence) timeZone.get(ZoneGetter.KEY_DISPLAYNAME)); 47 mContext = context; 48 mListener = listener; 49 mTimeZone = timeZone; 50 } 51 52 @Override getDesc()53 public CharSequence getDesc() { 54 return (CharSequence) mTimeZone.get(ZoneGetter.KEY_GMT); 55 } 56 57 @Override isEnabled()58 public boolean isEnabled() { 59 return Settings.Global.getInt(mContext.getContentResolver(), 60 Settings.Global.AUTO_TIME_ZONE, 0) <= 0; 61 } 62 63 @Override isExpandable()64 public boolean isExpandable() { 65 return false; 66 } 67 68 @Override isClickable()69 public boolean isClickable() { 70 return true; 71 } 72 73 @Override onClick()74 public void onClick() { 75 AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); 76 am.setTimeZone((String) mTimeZone.get(ZoneGetter.KEY_ID)); 77 mListener.onTimeZoneChanged(); 78 } 79 } 80