• 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 BluetoothAudioBitsPerSamplePreferenceController extends
26         AbstractBluetoothA2dpPreferenceController {
27 
28     private static final int DEFAULT_INDEX = 0;
29     private static final String BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY =
30             "bluetooth_select_a2dp_bits_per_sample";
31 
BluetoothAudioBitsPerSamplePreferenceController(Context context, Lifecycle lifecycle, BluetoothA2dpConfigStore store)32     public BluetoothAudioBitsPerSamplePreferenceController(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_BITS_PER_SAMPLE_KEY;
40     }
41 
42     @Override
getListValues()43     protected String[] getListValues() {
44         return mContext.getResources().getStringArray(
45                 R.array.bluetooth_a2dp_codec_bits_per_sample_values);
46     }
47 
48     @Override
getListSummaries()49     protected String[] getListSummaries() {
50         return mContext.getResources().getStringArray(
51                 R.array.bluetooth_a2dp_codec_bits_per_sample_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 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE; // default
63         switch (index) {
64             case 0:
65                 // Reset to default
66                 break;
67             case 1:
68                 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_16;
69                 break;
70             case 2:
71                 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_24;
72                 break;
73             case 3:
74                 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_32;
75                 break;
76             default:
77                 break;
78         }
79         mBluetoothA2dpConfigStore.setBitsPerSample(bitsPerSampleValue);
80     }
81 
82     @Override
getCurrentA2dpSettingIndex(BluetoothCodecConfig config)83     protected int getCurrentA2dpSettingIndex(BluetoothCodecConfig config) {
84         final int bitsPerSample = config.getBitsPerSample();
85         int index = DEFAULT_INDEX;
86         switch (bitsPerSample) {
87             case BluetoothCodecConfig.BITS_PER_SAMPLE_16:
88                 index = 1;
89                 break;
90             case BluetoothCodecConfig.BITS_PER_SAMPLE_24:
91                 index = 2;
92                 break;
93             case BluetoothCodecConfig.BITS_PER_SAMPLE_32:
94                 index = 3;
95                 break;
96             case BluetoothCodecConfig.BITS_PER_SAMPLE_NONE:
97             default:
98                 break;
99         }
100         return index;
101     }
102 }
103