Separate category controller out of HearingDeviceControlsController
We're going to add more different device controls (such as hearing aids presets, volume offset controls or microphone volume controls) into "device_controls_general" PreferenceCategory. It's better to keep the category controller separated from the child controller to better maintain the visibility of the whole category and have a clearer stucture of these controllers. Bug: 300015207 Test: atest BluetoothDetailsHearingDeviceControllerTest Test: atest BluetoothDetailsHearingDeviceSettingsControllerTest Test: atest BluetoothDeviceDetailsFragmentTest Change-Id: I7f35b02a1120aefa8307e500f7abfce3b8055fbf
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The controller of the hearing device controls.
|
||||
*
|
||||
* <p><b>Note:</b> It is responsible for creating the sub-controllers inside this preference
|
||||
* category controller.
|
||||
*/
|
||||
public class BluetoothDetailsHearingDeviceController extends BluetoothDetailsController {
|
||||
static final String KEY_HEARING_DEVICE_GROUP = "hearing_device_group";
|
||||
|
||||
private final List<BluetoothDetailsController> mControllers = new ArrayList<>();
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
public BluetoothDetailsHearingDeviceController(@NonNull Context context,
|
||||
@NonNull PreferenceFragmentCompat fragment,
|
||||
@NonNull CachedBluetoothDevice device,
|
||||
@NonNull Lifecycle lifecycle) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
mLifecycle = lifecycle;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setSubControllers(
|
||||
BluetoothDetailsHearingDeviceSettingsController hearingDeviceSettingsController) {
|
||||
mControllers.clear();
|
||||
mControllers.add(hearingDeviceSettingsController);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mControllers.stream().anyMatch(BluetoothDetailsController::isAvailable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getPreferenceKey() {
|
||||
return KEY_HEARING_DEVICE_GROUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the sub controllers controlled by this group controller.
|
||||
*
|
||||
* <p><b>Note:</b> The caller must call this method when creating this class.
|
||||
*
|
||||
* @param isLaunchFromHearingDevicePage a boolean that determines if the caller is launch from
|
||||
* hearing device page
|
||||
*/
|
||||
void initSubControllers(boolean isLaunchFromHearingDevicePage) {
|
||||
mControllers.clear();
|
||||
// Don't need to show the entrance to hearing device page when launched from the same page
|
||||
if (!isLaunchFromHearingDevicePage) {
|
||||
mControllers.add(new BluetoothDetailsHearingDeviceSettingsController(mContext,
|
||||
mFragment, mCachedDevice, mLifecycle));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<BluetoothDetailsController> getSubControllers() {
|
||||
return mControllers;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.android.settings.bluetooth.BluetoothDetailsHearingDeviceController.KEY_HEARING_DEVICE_GROUP;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@@ -36,15 +38,13 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
/**
|
||||
* The controller of the hearing device settings to launch Hearing device page.
|
||||
*/
|
||||
public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDetailsController
|
||||
public class BluetoothDetailsHearingDeviceSettingsController extends BluetoothDetailsController
|
||||
implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String KEY_DEVICE_CONTROLS_GENERAL_GROUP = "device_controls_general";
|
||||
@VisibleForTesting
|
||||
static final String KEY_HEARING_DEVICE_CONTROLS = "hearing_device_controls";
|
||||
static final String KEY_HEARING_DEVICE_SETTINGS = "hearing_device_settings";
|
||||
|
||||
public BluetoothDetailsHearingDeviceControlsController(Context context,
|
||||
public BluetoothDetailsHearingDeviceSettingsController(Context context,
|
||||
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
lifecycle.addObserver(this);
|
||||
@@ -57,37 +57,39 @@ public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDe
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {
|
||||
if (!mCachedDevice.isHearingAidDevice()) {
|
||||
if (!isAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PreferenceCategory prefCategory = screen.findPreference(getPreferenceKey());
|
||||
final Preference pref = createHearingDeviceControlsPreference(prefCategory.getContext());
|
||||
prefCategory.addPreference(pref);
|
||||
final PreferenceCategory group = screen.findPreference(KEY_HEARING_DEVICE_GROUP);
|
||||
final Preference pref = createHearingDeviceSettingsPreference(group.getContext());
|
||||
group.addPreference(pref);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {}
|
||||
protected void refresh() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_DEVICE_CONTROLS_GENERAL_GROUP;
|
||||
return KEY_HEARING_DEVICE_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (TextUtils.equals(preference.getKey(), KEY_HEARING_DEVICE_CONTROLS)) {
|
||||
if (TextUtils.equals(preference.getKey(), KEY_HEARING_DEVICE_SETTINGS)) {
|
||||
launchAccessibilityHearingDeviceSettings();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Preference createHearingDeviceControlsPreference(Context context) {
|
||||
private Preference createHearingDeviceSettingsPreference(Context context) {
|
||||
final ArrowPreference preference = new ArrowPreference(context);
|
||||
preference.setKey(KEY_HEARING_DEVICE_CONTROLS);
|
||||
preference.setTitle(context.getString(R.string.bluetooth_device_controls_title));
|
||||
preference.setSummary(context.getString(R.string.bluetooth_device_controls_summary));
|
||||
preference.setKey(KEY_HEARING_DEVICE_SETTINGS);
|
||||
preference.setTitle(context.getString(R.string.bluetooth_hearing_device_settings_title));
|
||||
preference.setSummary(
|
||||
context.getString(R.string.bluetooth_hearing_device_settings_summary));
|
||||
preference.setOnPreferenceClickListener(this);
|
||||
|
||||
return preference;
|
||||
@@ -326,16 +326,16 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
lifecycle));
|
||||
controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice,
|
||||
lifecycle));
|
||||
// Don't need to show hearing device again when launched from the same page.
|
||||
if (!isLaunchFromHearingDevicePage()) {
|
||||
controllers.add(new BluetoothDetailsHearingDeviceControlsController(context, this,
|
||||
mCachedDevice, lifecycle));
|
||||
}
|
||||
controllers.add(new BluetoothDetailsDataSyncController(context, this,
|
||||
mCachedDevice, lifecycle));
|
||||
controllers.add(
|
||||
new BluetoothDetailsExtraOptionsController(
|
||||
context, this, mCachedDevice, lifecycle));
|
||||
controllers.add(new BluetoothDetailsDataSyncController(context, this, mCachedDevice,
|
||||
lifecycle));
|
||||
controllers.add(new BluetoothDetailsExtraOptionsController(context, this, mCachedDevice,
|
||||
lifecycle));
|
||||
BluetoothDetailsHearingDeviceController hearingDeviceController =
|
||||
new BluetoothDetailsHearingDeviceController(context, this, mCachedDevice,
|
||||
lifecycle);
|
||||
controllers.add(hearingDeviceController);
|
||||
hearingDeviceController.initSubControllers(isLaunchFromHearingDevicePage());
|
||||
controllers.addAll(hearingDeviceController.getSubControllers());
|
||||
}
|
||||
return controllers;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user