• 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 package com.android.car.settings.datetime;
17 
18 import android.app.AlarmManager;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.widget.DatePicker;
23 
24 import com.android.car.settings.common.CarSettingActivity;
25 import com.android.car.settings.R;
26 
27 import java.util.Calendar;
28 
29 /**
30  * Sets the system date.
31  */
32 public class DatePickerActivity extends CarSettingActivity {
33     private static final int MILLIS_IN_SECOND = 1000;
34 
35     private DatePicker mDatePicker;
36 
37     @Override
onCreate(Bundle savedInstanceState)38     protected void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40 
41         setContentView(R.layout.date_picker);
42 
43         mDatePicker = (DatePicker) findViewById(R.id.date_picker);
44 
45         findViewById(R.id.confirm).setOnClickListener(v -> {
46             Calendar c = Calendar.getInstance();
47 
48             c.set(Calendar.YEAR, mDatePicker.getYear());
49             c.set(Calendar.MONTH, mDatePicker.getMonth());
50             c.set(Calendar.DAY_OF_MONTH, mDatePicker.getDayOfMonth());
51             long when = Math.max(c.getTimeInMillis(), DatetimeSettingsActivity.MIN_DATE);
52             if (when / MILLIS_IN_SECOND < Integer.MAX_VALUE) {
53                 ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).setTime(when);
54                 sendBroadcast(new Intent(Intent.ACTION_TIME_CHANGED));
55             }
56             finish();
57         });
58     }
59 }
60