1 /*
2  * Copyright (C) 2019 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.bluetooth;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.widget.RadioGroup;
22 
23 import com.android.settings.R;
24 
25 /**
26  * Dialog preference to set the Bluetooth A2DP config of codec
27  */
28 public class BluetoothCodecDialogPreference extends BaseBluetoothDialogPreference implements
29         RadioGroup.OnCheckedChangeListener {
30 
BluetoothCodecDialogPreference(Context context)31     public BluetoothCodecDialogPreference(Context context) {
32         super(context);
33         initialize(context);
34     }
35 
BluetoothCodecDialogPreference(Context context, AttributeSet attrs)36     public BluetoothCodecDialogPreference(Context context, AttributeSet attrs) {
37         super(context, attrs);
38         initialize(context);
39     }
40 
BluetoothCodecDialogPreference(Context context, AttributeSet attrs, int defStyleAttr)41     public BluetoothCodecDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
42         super(context, attrs, defStyleAttr);
43         initialize(context);
44     }
45 
BluetoothCodecDialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)46     public BluetoothCodecDialogPreference(Context context, AttributeSet attrs, int defStyleAttr,
47                                           int defStyleRes) {
48         super(context, attrs, defStyleAttr, defStyleRes);
49         initialize(context);
50     }
51 
52     @Override
getRadioButtonGroupId()53     protected int getRadioButtonGroupId() {
54         return R.id.bluetooth_audio_codec_radio_group;
55     }
56 
initialize(Context context)57     private void initialize(Context context) {
58         mRadioButtonIds.add(R.id.bluetooth_audio_codec_default);
59         mRadioButtonIds.add(R.id.bluetooth_audio_codec_sbc);
60         mRadioButtonIds.add(R.id.bluetooth_audio_codec_aac);
61         mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx);
62         mRadioButtonIds.add(R.id.bluetooth_audio_codec_aptx_hd);
63         mRadioButtonIds.add(R.id.bluetooth_audio_codec_ldac);
64         String[] stringArray = context.getResources().getStringArray(
65                 R.array.bluetooth_a2dp_codec_titles);
66         for (int i = 0; i < stringArray.length; i++) {
67             mRadioButtonStrings.add(stringArray[i]);
68         }
69         stringArray = context.getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries);
70         for (int i = 0; i < stringArray.length; i++) {
71             mSummaryStrings.add(stringArray[i]);
72         }
73     }
74 }
75