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 27 import java.util.Calendar; 28 29 /** 30 * A LineItem that displays and sets system date. 31 */ 32 class SetDateLineItem extends TextLineItem { 33 private final Context mContext; 34 private final BaseFragment.FragmentController mFragmentController; 35 SetDateLineItem(Context context, BaseFragment.FragmentController fragmentController)36 public SetDateLineItem(Context context, BaseFragment.FragmentController fragmentController) { 37 super(context.getString(R.string.date_time_set_date)); 38 mContext = context; 39 mFragmentController = fragmentController; 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 isExpandable()54 public boolean isExpandable() { 55 return isEnabled(); 56 } 57 58 @Override onClick()59 public void onClick() { 60 mFragmentController.launchFragment(DatePickerFragment.getInstance()); 61 } 62 } 63