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 import android.text.format.DateFormat; 22 23 import com.android.car.settings.R; 24 import com.android.car.settings.common.BaseFragment; 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 time. 32 */ 33 class SetTimeLineItem extends TextLineItem { 34 private final Context mContext; 35 private final BaseFragment.FragmentController mFragmentController; 36 SetTimeLineItem(Context context, BaseFragment.FragmentController fragmentController)37 public SetTimeLineItem(Context context, BaseFragment.FragmentController fragmentController) { 38 super(context.getString(R.string.date_time_set_time)); 39 mContext = context; 40 mFragmentController = fragmentController; 41 } 42 43 @Override getDesc()44 public CharSequence getDesc() { 45 return DateFormat.getTimeFormat(mContext).format(Calendar.getInstance().getTime()); 46 } 47 48 @Override isEnabled()49 public boolean isEnabled() { 50 return Settings.Global.getInt(mContext.getContentResolver(), 51 Settings.Global.AUTO_TIME, 0) <= 0; 52 } 53 54 @Override isExpandable()55 public boolean isExpandable() { 56 return isEnabled(); 57 } 58 59 @Override onClick()60 public void onClick() { 61 mFragmentController.launchFragment(TimePickerFragment.getInstance()); 62 } 63 } 64