blob: 9c2a9584eb26844b411419e89b2f167d763373fc [file] [log] [blame]
Doris Ling3ca36772017-01-11 15:57:02 -08001/*
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
17package com.android.settings.notification;
18
19import static com.android.settings.notification.SettingPref.TYPE_GLOBAL;
20
21import android.content.Context;
Doris Ling3ca36772017-01-11 15:57:02 -080022import android.content.res.Resources;
23import android.provider.Settings.Global;
24import android.telephony.TelephonyManager;
Fan Zhangc7162cd2018-06-18 15:21:41 -070025
Doris Ling3ca36772017-01-11 15:57:02 -080026import com.android.settings.R;
27import com.android.settings.SettingsPreferenceFragment;
Juan Lang777ed252017-05-09 15:42:36 -070028import com.android.settingslib.core.lifecycle.Lifecycle;
Doris Ling3ca36772017-01-11 15:57:02 -080029
30public class EmergencyTonePreferenceController extends SettingPrefController {
31
32 private static final String KEY_EMERGENCY_TONE = "emergency_tone";
33 private static final int EMERGENCY_TONE_SILENT = 0;
34 private static final int EMERGENCY_TONE_ALERT = 1;
35 private static final int EMERGENCY_TONE_VIBRATE = 2;
36 private static final int DEFAULT_EMERGENCY_TONE = EMERGENCY_TONE_SILENT;
37
38 public EmergencyTonePreferenceController(Context context, SettingsPreferenceFragment parent,
39 Lifecycle lifecycle) {
40 super(context, parent, lifecycle);
41 mPreference = new SettingPref(
42 TYPE_GLOBAL, KEY_EMERGENCY_TONE, Global.EMERGENCY_TONE, DEFAULT_EMERGENCY_TONE,
43 EMERGENCY_TONE_ALERT, EMERGENCY_TONE_VIBRATE, EMERGENCY_TONE_SILENT) {
44
45 @Override
46 public boolean isApplicable(Context context) {
47 final TelephonyManager telephony =
48 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
49 return telephony != null
50 && telephony.getCurrentPhoneType() == TelephonyManager.PHONE_TYPE_CDMA;
51 }
52
53 @Override
54 protected String getCaption(Resources res, int value) {
55 switch(value) {
56 case EMERGENCY_TONE_SILENT:
57 return res.getString(R.string.emergency_tone_silent);
58 case EMERGENCY_TONE_ALERT:
59 return res.getString(R.string.emergency_tone_alert);
60 case EMERGENCY_TONE_VIBRATE:
61 return res.getString(R.string.emergency_tone_vibrate);
62 default:
63 throw new IllegalArgumentException();
64 }
65 }
66 };
67 }
68
69}