• 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 BluetoothAudioSampleRatePreferenceController extends
26         AbstractBluetoothA2dpPreferenceController {
27 
28     private static final int DEFAULT_INDEX = 0;
29     private static final String BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY =
30             "bluetooth_select_a2dp_sample_rate";
31 
BluetoothAudioSampleRatePreferenceController(Context context, Lifecycle lifecycle, BluetoothA2dpConfigStore store)32     public BluetoothAudioSampleRatePreferenceController(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_SAMPLE_RATE_KEY;
40     }
41 
42     @Override
getListValues()43     protected String[] getListValues() {
44         return mContext.getResources().getStringArray(
45                 R.array.bluetooth_a2dp_codec_sample_rate_values);
46     }
47 
48     @Override
getListSummaries()49     protected String[] getListSummaries() {
50         return mContext.getResources().getStringArray(
51                 R.array.bluetooth_a2dp_codec_sample_rate_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 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_NONE; // default
63         switch (index) {
64             case 0:
65                 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_NONE;
66                 break;
67             case 1:
68                 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_44100;
69                 break;
70             case 2:
71                 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_48000;
72                 break;
73             case 3:
74                 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_88200;
75                 break;
76             case 4:
77                 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_96000;
78                 break;
79             default:
80                 break;
81         }
82         mBluetoothA2dpConfigStore.setSampleRate(sampleRateValue);
83     }
84 
85     @Override
getCurrentA2dpSettingIndex(BluetoothCodecConfig config)86     protected int getCurrentA2dpSettingIndex(BluetoothCodecConfig config) {
87         final int sampleRate = config.getSampleRate();
88         int index = DEFAULT_INDEX;
89         switch (sampleRate) {
90             case BluetoothCodecConfig.SAMPLE_RATE_44100:
91                 index = 1;
92                 break;
93             case BluetoothCodecConfig.SAMPLE_RATE_48000:
94                 index = 2;
95                 break;
96             case BluetoothCodecConfig.SAMPLE_RATE_88200:
97                 index = 3;
98                 break;
99             case BluetoothCodecConfig.SAMPLE_RATE_96000:
100                 index = 4;
101                 break;
102             case BluetoothCodecConfig.SAMPLE_RATE_176400:
103             case BluetoothCodecConfig.SAMPLE_RATE_192000:
104             case BluetoothCodecConfig.SAMPLE_RATE_NONE:
105             default:
106                 break;
107         }
108         return index;
109     }
110 }
111