Merge "[VolumePanel] Fix the Hearable control slice uri parameter" into tm-dev am: fc45c25296
am: 3b2fe3e89e
am: 7fb0500aa8
am: f20d28e0c3
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18638446 Change-Id: I251634e96e47dee560b9031f2122893ec8042a72 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -22,6 +22,7 @@ import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
@@ -50,7 +51,6 @@ import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.IllegalFormatException;
|
||||
import java.util.List;
|
||||
|
||||
public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment {
|
||||
@@ -150,7 +150,6 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
use(BlockingSlicePrefController.class).setSliceUri(sliceEnabled
|
||||
? featureProvider.getBluetoothDeviceSettingsUri(mCachedDevice.getDevice())
|
||||
: null);
|
||||
updateExtraControlUri(/* viewWidth */ 0);
|
||||
}
|
||||
|
||||
private void updateExtraControlUri(int viewWidth) {
|
||||
@@ -162,13 +161,14 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
String uri = featureProvider.getBluetoothDeviceControlUri(mCachedDevice.getDevice());
|
||||
if (!TextUtils.isEmpty(uri)) {
|
||||
try {
|
||||
controlUri = Uri.parse(String.format(uri, viewWidth));
|
||||
} catch (IllegalFormatException | NullPointerException exception) {
|
||||
controlUri = Uri.parse(uri + viewWidth);
|
||||
} catch (NullPointerException exception) {
|
||||
Log.d(TAG, "unable to parse uri");
|
||||
controlUri = null;
|
||||
}
|
||||
}
|
||||
use(SlicePreferenceController.class).setSliceUri(sliceEnabled ? controlUri : null);
|
||||
use(SlicePreferenceController.class).onStart();
|
||||
}
|
||||
|
||||
private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener =
|
||||
@@ -179,7 +179,10 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
updateExtraControlUri(view.getWidth());
|
||||
if (view.getWidth() <= 0) {
|
||||
return;
|
||||
}
|
||||
updateExtraControlUri(view.getWidth() - getPaddingSize());
|
||||
view.getViewTreeObserver().removeOnGlobalLayoutListener(
|
||||
mOnGlobalLayoutListener);
|
||||
}
|
||||
@@ -268,4 +271,17 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
}
|
||||
return controllers;
|
||||
}
|
||||
|
||||
private int getPaddingSize() {
|
||||
TypedArray resolvedAttributes =
|
||||
getContext().obtainStyledAttributes(
|
||||
new int[]{
|
||||
android.R.attr.listPreferredItemPaddingStart,
|
||||
android.R.attr.listPreferredItemPaddingEnd
|
||||
});
|
||||
int width = resolvedAttributes.getDimensionPixelSize(0, 0)
|
||||
+ resolvedAttributes.getDimensionPixelSize(1, 0);
|
||||
resolvedAttributes.recycle();
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import static com.android.settings.slices.CustomSliceRegistry.VOLUME_CALL_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_MEDIA_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_RINGER_URI;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -49,7 +50,6 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.android.settingslib.media.MediaOutputConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.IllegalFormatException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
@@ -64,6 +64,7 @@ public class VolumePanel implements PanelContent, LifecycleObserver {
|
||||
|
||||
private PanelContentCallback mCallback;
|
||||
private LocalBluetoothProfileManager mProfileManager;
|
||||
private int mControlSliceWidth;
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -80,6 +81,14 @@ public class VolumePanel implements PanelContent, LifecycleObserver {
|
||||
|
||||
private VolumePanel(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
if (context instanceof Activity) {
|
||||
int panelWidth =
|
||||
((Activity) context).getWindowManager().getCurrentWindowMetrics().getBounds()
|
||||
.width();
|
||||
// The control slice width = panel width - two left and right horizontal paddings
|
||||
mControlSliceWidth = panelWidth - context.getResources().getDimensionPixelSize(
|
||||
R.dimen.panel_slice_Horizontal_padding) * 2;
|
||||
}
|
||||
|
||||
final FutureTask<LocalBluetoothManager> localBtManagerFutureTask = new FutureTask<>(
|
||||
// Avoid StrictMode ThreadPolicy violation
|
||||
@@ -102,8 +111,7 @@ public class VolumePanel implements PanelContent, LifecycleObserver {
|
||||
public void onResume() {
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(MediaOutputConstants.ACTION_CLOSE_PANEL);
|
||||
mContext.registerReceiver(mReceiver, filter,
|
||||
Context.RECEIVER_EXPORTED_UNAUDITED);
|
||||
mContext.registerReceiver(mReceiver, filter, Context.RECEIVER_EXPORTED_UNAUDITED);
|
||||
}
|
||||
|
||||
/** Invoked when the panel is paused. */
|
||||
@@ -159,13 +167,11 @@ public class VolumePanel implements PanelContent, LifecycleObserver {
|
||||
Uri controlUri = null;
|
||||
final BluetoothDevice bluetoothDevice = findActiveDevice();
|
||||
if (bluetoothDevice != null) {
|
||||
final int width = mContext.getResources().getDimensionPixelSize(
|
||||
R.dimen.settings_panel_width);
|
||||
final String uri = BluetoothUtils.getControlUriMetaData(bluetoothDevice);
|
||||
if (!TextUtils.isEmpty(uri)) {
|
||||
try {
|
||||
controlUri = Uri.parse(String.format(uri, width));
|
||||
} catch (IllegalFormatException | NullPointerException exception) {
|
||||
controlUri = Uri.parse(uri + mControlSliceWidth);
|
||||
} catch (NullPointerException exception) {
|
||||
Log.d(TAG, "unable to parse uri");
|
||||
controlUri = null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user