• 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 
17 package com.android.settings.development;
18 
19 import android.bluetooth.BluetoothCodecConfig;
20 import android.content.Context;
21 
22 import com.android.settings.R;
23 import com.android.settingslib.core.lifecycle.Lifecycle;
24 
25 public class BluetoothAudioChannelModePreferenceController extends
26         AbstractBluetoothA2dpPreferenceController {
27 
28     private static final int DEFAULT_INDEX = 0;
29     private static final String BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY =
30             "bluetooth_select_a2dp_channel_mode";
31 
BluetoothAudioChannelModePreferenceController(Context context, Lifecycle lifecycle, BluetoothA2dpConfigStore store)32     public BluetoothAudioChannelModePreferenceController(Context context, Lifecycle lifecycle,
33             BluetoothA2dpConfigStore store) {
34         super(context, lifecycle, store);
35     }
36 
37     @Override
getPreferenceKey()38     public String getPreferenceKey() {
39         return BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY;
40     }
41 
42     @Override
getListValues()43     protected String[] getListValues() {
44         return mContext.getResources().getStringArray(
45                 R.array.bluetooth_a2dp_codec_channel_mode_values);
46     }
47 
48     @Override
getListSummaries()49     protected String[] getListSummaries() {
50         return mContext.getResources().getStringArray(
51                 R.array.bluetooth_a2dp_codec_channel_mode_summaries);
52     }
53 
54     @Override
getDefaultIndex()55     protected int getDefaultIndex() {
56         return DEFAULT_INDEX;
57     }
58 
59     @Override
writeConfigurationValues(Object newValue)60     protected void writeConfigurationValues(Object newValue) {
61         final int index = mPreference.findIndexOfValue(newValue.toString());
62         int channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_NONE; // default
63         switch (index) {
64             case 0:
65                 // Reset to default
66                 break;
67             case 1:
68                 channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_MONO;
69                 break;
70             case 2:
71                 channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_STEREO;
72                 break;
73             default:
74                 break;
75         }
76         mBluetoothA2dpConfigStore.setChannelMode(channelModeValue);
77     }
78 
79     @Override
getCurrentA2dpSettingIndex(BluetoothCodecConfig config)80     protected int getCurrentA2dpSettingIndex(BluetoothCodecConfig config) {
81         final int channelMode = config.getChannelMode();
82         int index = DEFAULT_INDEX;
83         switch (channelMode) {
84             case BluetoothCodecConfig.CHANNEL_MODE_MONO:
85                 index = 1;
86                 break;
87             case BluetoothCodecConfig.CHANNEL_MODE_STEREO:
88                 index = 2;
89                 break;
90             case BluetoothCodecConfig.CHANNEL_MODE_NONE:
91             default:
92                 break;
93         }
94         return index;
95     }
96 }
97