• 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.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.IntentFilter;
22 import android.provider.Settings;
23 
24 import com.android.car.settings.R;
25 import com.android.car.settings.common.ListSettingsActivity;
26 import com.android.car.settings.common.TypedPagedListAdapter;
27 
28 import java.util.ArrayList;
29 
30 /**
31  * Configures date time
32  */
33 public class DatetimeSettingsActivity extends ListSettingsActivity {
34     private static final String TAG = "DatetimeSettingsActivity";
35 
36     private static final IntentFilter TIME_CHANGED_FILTER =
37             new IntentFilter(Intent.ACTION_TIME_CHANGED);
38 
39     // Minimum time is Nov 5, 2007, 0:00.
40     public static final long MIN_DATE = 1194220800000L;
41 
42     private final TimeChangedBroadCastReceiver mTimeChangedBroadCastReceiver =
43             new TimeChangedBroadCastReceiver();
44 
45     @Override
getLineItems()46     public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() {
47         ArrayList<TypedPagedListAdapter.LineItem> lineItems = new ArrayList<>();
48         lineItems.add(new DateTimeToggleLineItem(this,
49                 getString(R.string.date_time_auto),
50                 getString(R.string.date_time_auto_summary),
51                 Settings.Global.AUTO_TIME));
52         lineItems.add(new DateTimeToggleLineItem(this,
53                 getString(R.string.zone_auto),
54                 getString(R.string.zone_auto_summary),
55                 Settings.Global.AUTO_TIME_ZONE));
56         lineItems.add(new SetDateLineItem(this));
57         lineItems.add(new SetTimeLineItem(this));
58         lineItems.add(new SetTimeZoneLineItem(this));
59         lineItems.add(new TimeFormatToggleLineItem(this));
60         return lineItems;
61     }
62 
63     @Override
onStart()64     public void onStart() {
65         super.onStart();
66         registerReceiver(mTimeChangedBroadCastReceiver, TIME_CHANGED_FILTER);
67         mPagedListAdapter.notifyDataSetChanged();
68     }
69 
70     @Override
onStop()71     public void onStop() {
72         super.onStop();
73         unregisterReceiver(mTimeChangedBroadCastReceiver);
74     }
75 
76     private class TimeChangedBroadCastReceiver extends BroadcastReceiver {
77         @Override
onReceive(Context context, Intent intent)78         public void onReceive(Context context, Intent intent) {
79             mPagedListAdapter.notifyDataSetChanged();
80         }
81     }
82 }
83