• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.android.cellbroadcastreceiver;
18 
19 import android.content.res.Resources;
20 import android.os.Bundle;
21 import android.preference.ListPreference;
22 import android.preference.Preference;
23 import android.preference.PreferenceActivity;
24 
25 /**
26  * Settings activity for the cell broadcast receiver.
27  */
28 public class CellBroadcastSettings extends PreferenceActivity {
29 
30     // Preference key for whether to enable emergency notifications (default enabled).
31     public static final String KEY_ENABLE_EMERGENCY_ALERTS = "enable_emergency_alerts";
32 
33     // Duration of alert sound (in seconds).
34     public static final String KEY_ALERT_SOUND_DURATION = "alert_sound_duration";
35 
36     // Default alert duration (in seconds).
37     public static final String ALERT_SOUND_DEFAULT_DURATION = "4";
38 
39     // Speak contents of alert after playing the alert sound.
40     public static final String KEY_ENABLE_ALERT_SPEECH = "enable_alert_speech";
41 
42     // Preference category for ETWS related settings.
43     public static final String KEY_CATEGORY_ETWS_SETTINGS = "category_etws_settings";
44 
45     // Whether to display ETWS test messages (default is disabled).
46     public static final String KEY_ENABLE_ETWS_TEST_ALERTS = "enable_etws_test_alerts";
47 
48     // Preference category for CMAS related settings.
49     public static final String KEY_CATEGORY_CMAS_SETTINGS = "category_cmas_settings";
50 
51     // Whether to display CMAS imminent threat notifications (default is enabled).
52     public static final String KEY_ENABLE_CMAS_IMMINENT_THREAT_ALERTS =
53             "enable_cmas_imminent_threat_alerts";
54 
55     // Whether to display CMAS amber alert messages (default is disabled).
56     public static final String KEY_ENABLE_CMAS_AMBER_ALERTS = "enable_cmas_amber_alerts";
57 
58     // Whether to display CMAS monthly test messages (default is disabled).
59     public static final String KEY_ENABLE_CMAS_TEST_ALERTS = "enable_cmas_test_alerts";
60 
61     // Preference category for Brazil specific settings.
62     public static final String KEY_CATEGORY_BRAZIL_SETTINGS = "category_brazil_settings";
63 
64     // Preference key for whether to enable channel 50 notifications
65     // Enabled by default for phones sold in Brazil, otherwise this setting may be hidden.
66     public static final String KEY_ENABLE_CHANNEL_50_ALERTS = "enable_channel_50_alerts";
67 
68     @Override
onCreate(Bundle savedInstanceState)69     public void onCreate(Bundle savedInstanceState) {
70         super.onCreate(savedInstanceState);
71         addPreferencesFromResource(R.xml.preferences);
72         Resources res = getResources();
73         if (!res.getBoolean(R.bool.show_etws_settings)) {
74             getPreferenceScreen().removePreference(findPreference(KEY_CATEGORY_ETWS_SETTINGS));
75         }
76         if (!res.getBoolean(R.bool.show_cmas_settings)) {
77             getPreferenceScreen().removePreference(findPreference(KEY_CATEGORY_CMAS_SETTINGS));
78         }
79         if (!res.getBoolean(R.bool.show_brazil_settings)) {
80             getPreferenceScreen().removePreference(findPreference(KEY_CATEGORY_BRAZIL_SETTINGS));
81         }
82 
83         ListPreference duration = (ListPreference) findPreference(KEY_ALERT_SOUND_DURATION);
84         duration.setSummary(duration.getEntry());
85         duration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
86             public boolean onPreferenceChange(Preference pref, Object newValue) {
87                 final ListPreference listPref = (ListPreference) pref;
88                 final int idx = listPref.findIndexOfValue((String) newValue);
89                 listPref.setSummary(listPref.getEntries()[idx]);
90                 return true;
91             }
92         });
93 
94         Preference.OnPreferenceChangeListener startConfigServiceListener =
95                 new Preference.OnPreferenceChangeListener() {
96                     public boolean onPreferenceChange(Preference pref, Object newValue) {
97                         CellBroadcastReceiver.startConfigService(pref.getContext());
98                         return true;
99                     }
100                 };
101         Preference enablePwsAlerts = findPreference(KEY_ENABLE_EMERGENCY_ALERTS);
102         if (enablePwsAlerts != null) {
103             enablePwsAlerts.setOnPreferenceChangeListener(startConfigServiceListener);
104         }
105         Preference enableChannel50Alerts = findPreference(KEY_ENABLE_CHANNEL_50_ALERTS);
106         if (enableChannel50Alerts != null) {
107             enableChannel50Alerts.setOnPreferenceChangeListener(startConfigServiceListener);
108         }
109     }
110 }
111