• 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.content.Intent;
21 import android.provider.Settings;
22 import android.text.format.DateFormat;
23 
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.Calendar;
29 
30 /**
31  * A LineItem that displays and sets system date.
32  */
33 class SetDateLineItem extends TextLineItem {
34 
35     private Context mContext;
36 
SetDateLineItem(Context context)37     public SetDateLineItem(Context context) {
38         super(context.getString(R.string.date_time_set_date));
39         mContext = context;
40     }
41 
42     @Override
getDesc()43     public CharSequence getDesc() {
44         return DateFormat.getLongDateFormat(mContext).format(Calendar.getInstance().getTime());
45     }
46 
47     @Override
isEnabled()48     public boolean isEnabled() {
49         return Settings.Global.getInt(mContext.getContentResolver(),
50                 Settings.Global.AUTO_TIME, 0) <= 0;
51     }
52 
53     @Override
onClick()54     public void onClick() {
55         Intent intent = new Intent(mContext /* context */, DatePickerActivity.class);
56         mContext.startActivity(intent);
57     }
58 }
59