Merge "Move rename button next to the device name" into main
This commit is contained in:
@@ -37,12 +37,14 @@ import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -97,6 +99,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
||||
private static final int MAIN_DEVICE_ID = 4;
|
||||
private static final float HALF_ALPHA = 0.5f;
|
||||
|
||||
PreferenceFragmentCompat mFragment;
|
||||
@VisibleForTesting
|
||||
LayoutPreference mLayoutPreference;
|
||||
@VisibleForTesting
|
||||
@@ -170,8 +173,11 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
||||
mIconCache.clear();
|
||||
}
|
||||
|
||||
public void init(CachedBluetoothDevice cachedBluetoothDevice) {
|
||||
/** Initializes the controller. */
|
||||
public void init(
|
||||
CachedBluetoothDevice cachedBluetoothDevice, PreferenceFragmentCompat fragment) {
|
||||
mCachedDevice = cachedBluetoothDevice;
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
private void registerBluetoothDevice() {
|
||||
@@ -325,6 +331,14 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
||||
MAIN_DEVICE_ID);
|
||||
}
|
||||
});
|
||||
if (Flags.enableBluetoothDeviceDetailsPolish()) {
|
||||
ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button);
|
||||
renameButton.setVisibility(View.VISIBLE);
|
||||
renameButton.setOnClickListener(view -> {
|
||||
RemoteDeviceNameDialogFragment.newInstance(mCachedDevice).show(
|
||||
mFragment.getFragmentManager(), RemoteDeviceNameDialogFragment.TAG);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -47,6 +48,9 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (Flags.enableBluetoothDeviceDetailsPolish()) {
|
||||
return false;
|
||||
}
|
||||
boolean hasLeAudio = mCachedDevice.getUiAccessibleProfiles()
|
||||
.stream()
|
||||
.anyMatch(profile -> profile.getProfileId() == BluetoothProfile.LE_AUDIO);
|
||||
|
||||
@@ -50,6 +50,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.connecteddevice.stylus.StylusDevicesController;
|
||||
import com.android.settings.core.SettingsUIDeviceConfig;
|
||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.inputmethod.KeyboardSettingsPreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.slices.SlicePreferenceController;
|
||||
@@ -213,8 +214,8 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
use(AdvancedBluetoothDetailsHeaderController.class).init(mCachedDevice);
|
||||
use(LeAudioBluetoothDetailsHeaderController.class).init(mCachedDevice, mManager);
|
||||
use(AdvancedBluetoothDetailsHeaderController.class).init(mCachedDevice, this);
|
||||
use(LeAudioBluetoothDetailsHeaderController.class).init(mCachedDevice, mManager, this);
|
||||
use(KeyboardSettingsPreferenceController.class).init(mCachedDevice);
|
||||
|
||||
final BluetoothFeatureProvider featureProvider =
|
||||
@@ -338,7 +339,7 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (!mUserManager.isGuestUser()) {
|
||||
if (!Flags.enableBluetoothDeviceDetailsPolish() && !mUserManager.isGuestUser()) {
|
||||
MenuItem item = menu.add(0, EDIT_DEVICE_NAME_ITEM_ID, 0,
|
||||
R.string.bluetooth_rename_button);
|
||||
item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
|
||||
@@ -365,6 +366,9 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
Lifecycle lifecycle = getSettingsLifecycle();
|
||||
controllers.add(new BluetoothDetailsHeaderController(context, this, mCachedDevice,
|
||||
lifecycle));
|
||||
controllers.add(
|
||||
new GeneralBluetoothDetailsHeaderController(
|
||||
context, this, mCachedDevice, lifecycle));
|
||||
controllers.add(new BluetoothDetailsButtonsController(context, this, mCachedDevice,
|
||||
lifecycle));
|
||||
controllers.add(new BluetoothDetailsCompanionAppsController(context, this,
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
/** This class adds a header with device name and status (connected/disconnected, etc.). */
|
||||
public class GeneralBluetoothDetailsHeaderController extends BluetoothDetailsController {
|
||||
private static final String KEY_GENERAL_DEVICE_HEADER = "general_bluetooth_device_header";
|
||||
|
||||
@Nullable
|
||||
private LayoutPreference mLayoutPreference;
|
||||
|
||||
public GeneralBluetoothDetailsHeaderController(
|
||||
Context context,
|
||||
PreferenceFragmentCompat fragment,
|
||||
CachedBluetoothDevice device,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (!Flags.enableBluetoothDeviceDetailsPolish()) {
|
||||
return false;
|
||||
}
|
||||
boolean hasLeAudio =
|
||||
mCachedDevice.getUiAccessibleProfiles().stream()
|
||||
.anyMatch(profile -> profile.getProfileId() == BluetoothProfile.LE_AUDIO);
|
||||
return !BluetoothUtils.isAdvancedDetailsHeader(mCachedDevice.getDevice()) && !hasLeAudio;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(PreferenceScreen screen) {
|
||||
mLayoutPreference = screen.findPreference(KEY_GENERAL_DEVICE_HEADER);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
if (!isAvailable() || mLayoutPreference == null) {
|
||||
return;
|
||||
}
|
||||
ImageView imageView = mLayoutPreference.findViewById(R.id.bt_header_icon);
|
||||
if (imageView != null) {
|
||||
final Pair<Drawable, String> pair =
|
||||
BluetoothUtils.getBtRainbowDrawableWithDescription(mContext, mCachedDevice);
|
||||
imageView.setImageDrawable(pair.first);
|
||||
imageView.setContentDescription(pair.second);
|
||||
}
|
||||
|
||||
TextView title = mLayoutPreference.findViewById(R.id.bt_header_device_name);
|
||||
if (title != null) {
|
||||
title.setText(mCachedDevice.getName());
|
||||
}
|
||||
TextView summary = mLayoutPreference.findViewById(R.id.bt_header_connection_summary);
|
||||
if (summary != null) {
|
||||
summary.setText(mCachedDevice.getConnectionSummary());
|
||||
}
|
||||
ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button);
|
||||
renameButton.setVisibility(View.VISIBLE);
|
||||
renameButton.setOnClickListener(
|
||||
view -> {
|
||||
RemoteDeviceNameDialogFragment.newInstance(mCachedDevice)
|
||||
.show(
|
||||
mFragment.getFragmentManager(),
|
||||
RemoteDeviceNameDialogFragment.TAG);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getPreferenceKey() {
|
||||
return KEY_GENERAL_DEVICE_HEADER;
|
||||
}
|
||||
}
|
||||
@@ -27,14 +27,17 @@ import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.fuelgauge.BatteryMeterView;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -86,6 +89,7 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
||||
@VisibleForTesting
|
||||
static final int INVALID_RESOURCE_ID = -1;
|
||||
|
||||
PreferenceFragmentCompat mFragment;
|
||||
@VisibleForTesting
|
||||
LayoutPreference mLayoutPreference;
|
||||
LocalBluetoothManager mManager;
|
||||
@@ -151,11 +155,12 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
||||
}
|
||||
|
||||
public void init(CachedBluetoothDevice cachedBluetoothDevice,
|
||||
LocalBluetoothManager bluetoothManager) {
|
||||
LocalBluetoothManager bluetoothManager, PreferenceFragmentCompat fragment) {
|
||||
mCachedDevice = cachedBluetoothDevice;
|
||||
mManager = bluetoothManager;
|
||||
mProfileManager = bluetoothManager.getProfileManager();
|
||||
mCachedDeviceGroup = Utils.findAllCachedBluetoothDevicesByGroupId(mManager, mCachedDevice);
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -163,6 +168,14 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
|
||||
if (mLayoutPreference == null || mCachedDevice == null) {
|
||||
return;
|
||||
}
|
||||
if (Flags.enableBluetoothDeviceDetailsPolish()) {
|
||||
ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button);
|
||||
renameButton.setVisibility(View.VISIBLE);
|
||||
renameButton.setOnClickListener(view -> {
|
||||
RemoteDeviceNameDialogFragment.newInstance(mCachedDevice).show(
|
||||
mFragment.getFragmentManager(), RemoteDeviceNameDialogFragment.TAG);
|
||||
});
|
||||
}
|
||||
final ImageView imageView = mLayoutPreference.findViewById(R.id.entity_header_icon);
|
||||
if (imageView != null) {
|
||||
final Pair<Drawable, String> pair =
|
||||
|
||||
Reference in New Issue
Block a user