• 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.content.Context;
20 import android.os.SystemProperties;
21 import android.support.annotation.VisibleForTesting;
22 import android.support.v7.preference.ListPreference;
23 import android.support.v7.preference.Preference;
24 import android.text.TextUtils;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.PreferenceControllerMixin;
28 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
29 
30 public class BluetoothAvrcpVersionPreferenceController extends DeveloperOptionsPreferenceController
31         implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
32 
33     private static final String BLUETOOTH_SELECT_AVRCP_VERSION_KEY =
34             "bluetooth_select_avrcp_version";
35 
36     @VisibleForTesting
37     static final String BLUETOOTH_AVRCP_VERSION_PROPERTY = "persist.bluetooth.avrcpversion";
38 
39     private final String[] mListValues;
40     private final String[] mListSummaries;
41 
BluetoothAvrcpVersionPreferenceController(Context context)42     public BluetoothAvrcpVersionPreferenceController(Context context) {
43         super(context);
44 
45         mListValues = context.getResources().getStringArray(R.array.bluetooth_avrcp_version_values);
46         mListSummaries = context.getResources().getStringArray(R.array.bluetooth_avrcp_versions);
47     }
48 
49     @Override
getPreferenceKey()50     public String getPreferenceKey() {
51         return BLUETOOTH_SELECT_AVRCP_VERSION_KEY;
52     }
53 
54     @Override
onPreferenceChange(Preference preference, Object newValue)55     public boolean onPreferenceChange(Preference preference, Object newValue) {
56         SystemProperties.set(BLUETOOTH_AVRCP_VERSION_PROPERTY, newValue.toString());
57         updateState(mPreference);
58         return true;
59     }
60 
61     @Override
updateState(Preference preference)62     public void updateState(Preference preference) {
63         final ListPreference listPreference = (ListPreference) preference;
64         final String currentValue = SystemProperties.get(BLUETOOTH_AVRCP_VERSION_PROPERTY);
65         int index = 0; // Defaults to AVRCP 1.4
66         for (int i = 0; i < mListValues.length; i++) {
67             if (TextUtils.equals(currentValue, mListValues[i])) {
68                 index = i;
69                 break;
70             }
71         }
72         listPreference.setValue(mListValues[index]);
73         listPreference.setSummary(mListSummaries[index]);
74     }
75 }
76