Show qr code in "Share your audio" dialog

Test: atest
Bug: 381775542
Flag: com.android.settingslib.flags.enable_le_audio_sharing
Change-Id: I6fe339beb50803989d4110fca681e609d2d600c1
This commit is contained in:
chelseahao
2025-01-23 13:35:11 +08:00
parent cc0c66a7ee
commit b6ba9c3bbc
6 changed files with 128 additions and 26 deletions

View File

@@ -17,10 +17,13 @@
package com.android.settings.connecteddevice.audiosharing;
import static com.android.settings.connecteddevice.audiosharing.AudioSharingDashboardFragment.SHARE_THEN_PAIR_REQUEST_CODE;
import static com.android.settings.connecteddevice.audiosharing.audiostreams.AudioStreamsQrCodeFragment.getQrCodeBitmap;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.EXTRA_PAIR_AND_JOIN_SHARING;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.util.Pair;
@@ -48,6 +51,7 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
private static final String TAG = "AudioSharingDialog";
private static final String BUNDLE_KEY_DEVICE_ITEMS = "bundle_key_device_items";
private static final String BUNDLE_KEY_BROADCAST_METADATA = "bundle_key_broadcast_metadata";
// The host creates an instance of this dialog fragment must implement this interface to receive
// event callbacks.
@@ -80,12 +84,14 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
*
* @param host The Fragment this dialog will be hosted.
* @param deviceItems The connected device items eligible for audio sharing.
* @param metadata The audio sharing metadata, nullable.
* @param listener The callback to handle the user action on this dialog.
* @param eventData The eventData to log with for dialog onClick events.
*/
public static void show(
@Nullable Fragment host,
@NonNull List<AudioSharingDeviceItem> deviceItems,
@Nullable BluetoothLeBroadcastMetadata metadata,
@NonNull DialogEventListener listener,
@NonNull Pair<Integer, Object>[] eventData) {
if (host == null) {
@@ -116,6 +122,9 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
Log.d(TAG, "Show up the dialog.");
final Bundle bundle = new Bundle();
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
if (metadata != null) {
bundle.putParcelable(BUNDLE_KEY_BROADCAST_METADATA, metadata);
}
AudioSharingDialogFragment dialogFrag = new AudioSharingDialogFragment();
dialogFrag.setArguments(bundle);
dialogFrag.show(manager, TAG);
@@ -150,7 +159,6 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
}
if (deviceItems.isEmpty()) {
builder.setTitle(R.string.audio_sharing_share_dialog_title)
.setCustomImage(R.drawable.audio_sharing_guidance)
.setCustomMessage(R.string.audio_sharing_dialog_connect_device_content)
.setCustomPositiveButton(
R.string.audio_sharing_pair_button_label,
@@ -172,17 +180,29 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
launcher.setResultListener(sHost, SHARE_THEN_PAIR_REQUEST_CODE);
}
launcher.launch();
})
.setCustomNegativeButton(
R.string.audio_sharing_qrcode_button_label,
v -> {
onCancelClick();
new SubSettingLauncher(getContext())
.setTitleRes(R.string.audio_streams_qr_code_page_title)
.setDestination(AudioStreamsQrCodeFragment.class.getName())
.setSourceMetricsCategory(getMetricsCategory())
.launch();
});
BluetoothLeBroadcastMetadata metadata = arguments.getParcelable(
BUNDLE_KEY_BROADCAST_METADATA, BluetoothLeBroadcastMetadata.class);
Bitmap qrCodeBitmap = metadata == null ? null : getQrCodeBitmap(metadata,
getContext()).orElse(null);
if (qrCodeBitmap != null) {
builder.setCustomImage(qrCodeBitmap)
.setCustomNegativeButton(com.android.settings.R.string.cancel,
v -> onCancelClick());
} else {
builder.setCustomImage(R.drawable.audio_sharing_guidance)
.setCustomNegativeButton(
R.string.audio_sharing_qrcode_button_label,
v -> {
onCancelClick();
new SubSettingLauncher(getContext())
.setTitleRes(R.string.audio_streams_qr_code_page_title)
.setDestination(
AudioStreamsQrCodeFragment.class.getName())
.setSourceMetricsCategory(getMetricsCategory())
.launch();
});
}
} else if (deviceItems.size() == 1) {
AudioSharingDeviceItem deviceItem = Iterables.getOnlyElement(deviceItems);
builder.setTitle(