• 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 
17 package com.android.car.settings.datetime;
18 
19 import android.content.Context;
20 import android.provider.Settings;
21 
22 import com.android.car.settings.R;
23 import com.android.car.settings.common.BaseFragment;
24 import com.android.car.settings.common.TextLineItem;
25 import com.android.settingslib.datetime.ZoneGetter;
26 
27 import java.util.Calendar;
28 
29 /**
30  * A LineItem that displays and sets time zone.
31  */
32 class SetTimeZoneLineItem extends TextLineItem {
33     private final Context mContext;
34     private final BaseFragment.FragmentController mFragmentController;
35 
SetTimeZoneLineItem(Context context, BaseFragment.FragmentController fragmentController)36     public SetTimeZoneLineItem(Context context, BaseFragment.FragmentController fragmentController) {
37         super(context.getString(R.string.date_time_set_timezone));
38         mContext = context;
39         mFragmentController = fragmentController;
40     }
41 
42     @Override
getDesc()43     public CharSequence getDesc() {
44         Calendar now = Calendar.getInstance();
45         return ZoneGetter.getTimeZoneOffsetAndName(mContext, now.getTimeZone(), now.getTime());
46     }
47 
48     @Override
isEnabled()49     public boolean isEnabled() {
50         return Settings.Global.getInt(mContext.getContentResolver(),
51                 Settings.Global.AUTO_TIME_ZONE, 0) <= 0;
52     }
53 
54     @Override
isExpandable()55     public boolean isExpandable() {
56         return isEnabled();
57     }
58 
59     @Override
isClickable()60     public boolean isClickable() {
61         return isEnabled();
62     }
63 
64     @Override
onClick()65     public void onClick() {
66         mFragmentController.launchFragment(TimeZonePickerFragment.getInstance());
67     }
68 }
69