Fix not on the top when entering device detail page

Root Cause: Added SpacePreference in xml let the page renders order
incorrectly.

Solution: That SpacePreference should only be visible when the device is
hearing aid.

Bug: 245681095
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsPairOtherControllerTest
Merged-In: Ic0be940c8466b5e1e301255868c29d06bd4428bd
Merged-In: I442445a861898258a73f37ad8f85bcee387fbf58
Change-Id: Icca48d9c2643507638b2b581d052530521cce5df
This commit is contained in:
jasonwshsu
2022-09-21 23:54:15 +08:00
parent e43bf3cd9d
commit 35e20d5ace
3 changed files with 42 additions and 2 deletions

View File

@@ -22,19 +22,25 @@ import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.applications.SpacePreference;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.ButtonPreference;
import com.google.common.annotations.VisibleForTesting;
/**
* This class handles button preference logic to display for hearing aid device.
*/
public class BluetoothDetailsPairOtherController extends BluetoothDetailsController {
private static final String KEY_PAIR_OTHER = "hearing_aid_pair_other_button";
@VisibleForTesting
static final String KEY_SPACE = "hearing_aid_space_layout";
private ButtonPreference mPreference;
private SpacePreference mSpacePreference;
public BluetoothDetailsPairOtherController(Context context,
PreferenceFragmentCompat fragment,
@@ -62,13 +68,20 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
: R.string.bluetooth_pair_left_ear_button;
mPreference = screen.findPreference(getPreferenceKey());
mSpacePreference = screen.findPreference(KEY_SPACE);
mPreference.setTitle(stringRes);
setPreferencesVisibility(getButtonPreferenceVisibility(mCachedDevice));
mPreference.setOnClickListener(v -> launchPairingDetail());
}
@Override
protected void refresh() {
mPreference.setVisible(getButtonPreferenceVisibility(mCachedDevice));
setPreferencesVisibility(getButtonPreferenceVisibility(mCachedDevice));
}
private void setPreferencesVisibility(boolean visible) {
mPreference.setVisible(visible);
mSpacePreference.setVisible(visible);
}
private boolean getButtonPreferenceVisibility(CachedBluetoothDevice cachedDevice) {