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.settings.notification;
18 
19 import static com.android.settings.notification.SettingPref.TYPE_GLOBAL;
20 
21 import android.content.Context;
22 import android.content.res.Resources;
23 import android.provider.Settings.Global;
24 
25 import com.android.settings.SettingsPreferenceFragment;
26 import com.android.settingslib.core.lifecycle.Lifecycle;
27 
28 public class DockAudioMediaPreferenceController extends SettingPrefController {
29 
30     private static final String KEY_DOCK_AUDIO_MEDIA = "dock_audio_media";
31 
32     private static final int DOCK_AUDIO_MEDIA_DISABLED = 0;
33     private static final int DOCK_AUDIO_MEDIA_ENABLED = 1;
34     private static final int DEFAULT_DOCK_AUDIO_MEDIA = DOCK_AUDIO_MEDIA_DISABLED;
35 
DockAudioMediaPreferenceController(Context context, SettingsPreferenceFragment parent, Lifecycle lifecycle)36     public DockAudioMediaPreferenceController(Context context, SettingsPreferenceFragment parent,
37             Lifecycle lifecycle) {
38         super(context, parent, lifecycle);
39         mPreference = new SettingPref(
40             TYPE_GLOBAL, KEY_DOCK_AUDIO_MEDIA, Global.DOCK_AUDIO_MEDIA_ENABLED,
41             DEFAULT_DOCK_AUDIO_MEDIA, DOCK_AUDIO_MEDIA_DISABLED, DOCK_AUDIO_MEDIA_ENABLED) {
42             @Override
43             public boolean isApplicable(Context context) {
44                 return context.getResources().getBoolean(
45                     com.android.settings.R.bool.has_dock_settings);
46             }
47 
48             @Override
49             protected String getCaption(Resources res, int value) {
50                 switch(value) {
51                     case DOCK_AUDIO_MEDIA_DISABLED:
52                         return res.getString(
53                             com.android.settings.R.string.dock_audio_media_disabled);
54                     case DOCK_AUDIO_MEDIA_ENABLED:
55                         return res.getString(
56                             com.android.settings.R.string.dock_audio_media_enabled);
57                     default:
58                         throw new IllegalArgumentException();
59                 }
60             }
61         };
62     }
63 }
64