• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.content.Context;
20 import android.support.annotation.VisibleForTesting;
21 import android.support.v7.preference.Preference;
22 
23 import com.android.settings.core.PreferenceController;
24 import com.android.settingslib.datetime.ZoneGetter;
25 
26 import java.util.Calendar;
27 
28 public class TimeZonePreferenceController extends PreferenceController {
29 
30     private static final String KEY_TIMEZONE = "timezone";
31 
32     private final AutoTimeZonePreferenceController mAutoTimeZonePreferenceController;
33 
TimeZonePreferenceController(Context context, AutoTimeZonePreferenceController autoTimeZonePreferenceController)34     public TimeZonePreferenceController(Context context,
35             AutoTimeZonePreferenceController autoTimeZonePreferenceController) {
36         super(context);
37         mAutoTimeZonePreferenceController = autoTimeZonePreferenceController;
38     }
39 
40     @Override
updateState(Preference preference)41     public void updateState(Preference preference) {
42         preference.setSummary(getTimeZoneOffsetAndName());
43         preference.setEnabled(!mAutoTimeZonePreferenceController.isEnabled());
44     }
45 
46     @Override
isAvailable()47     public boolean isAvailable() {
48         return true;
49     }
50 
51     @Override
getPreferenceKey()52     public String getPreferenceKey() {
53         return KEY_TIMEZONE;
54     }
55 
56     @VisibleForTesting
getTimeZoneOffsetAndName()57     CharSequence getTimeZoneOffsetAndName() {
58         final Calendar now = Calendar.getInstance();
59         return ZoneGetter.getTimeZoneOffsetAndName(mContext,
60                 now.getTimeZone(), now.getTime());
61     }
62 }
63