[BT Broadcast Sink] Add the function for leave and scan QRcode buttons

Add function for 'leave broadcast' button
Add function for 'Scan QR code' button
Set 'level broadcast' button gray out when device does not have broadcast source

Bug: 228259065
Test: build pass and manually test
Change-Id: Iab4a45e73f49c3f755b95ea3fa38872daac7e745
This commit is contained in:
SongFerngWang
2022-05-05 16:54:00 +08:00
parent afe6d302e4
commit e8bb9c9be3
2 changed files with 78 additions and 15 deletions

View File

@@ -16,22 +16,24 @@
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.util.Log;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.qrcode.QrCodeScanModeActivity;
import com.android.settingslib.widget.LayoutPreference;
/**
@@ -52,11 +54,12 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
LinearLayout mBtnBroadcastLayout;
Button mBtnLeaveBroadcast;
Button mBtnScanQrCode;
BluetoothFindBroadcastsFragment mBluetoothFindBroadcastsFragment;
public BluetoothFindBroadcastsHeaderController(Context context,
PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle,
LocalBluetoothManager bluetoothManager) {
BluetoothFindBroadcastsFragment fragment, CachedBluetoothDevice device,
Lifecycle lifecycle, LocalBluetoothManager bluetoothManager) {
super(context, fragment, device, lifecycle);
mBluetoothFindBroadcastsFragment = fragment;
}
@Override
@@ -101,20 +104,41 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
mBtnFindBroadcast.setVisibility(View.VISIBLE);
mBtnBroadcastLayout.setVisibility(View.GONE);
}
mBtnLeaveBroadcast.setEnabled(false);
if (mBluetoothFindBroadcastsFragment != null && mCachedDevice != null) {
LocalBluetoothLeBroadcastAssistant broadcastAssistant =
mBluetoothFindBroadcastsFragment.getLeBroadcastAssistant();
if (broadcastAssistant != null
&& broadcastAssistant.getConnectionStatus(mCachedDevice.getDevice())
== BluetoothProfile.STATE_CONNECTED) {
mBtnLeaveBroadcast.setEnabled(true);
}
}
}
private void scanBroadcastSource() {
// TODO(b/228258236) : Call the LocalBluetoothLeBroadcastAssistant
// to start searching for source
// TODO(b/231543455) : Using the BluetoothDeviceUpdater to refactor it.
if (mBluetoothFindBroadcastsFragment == null) {
return;
}
mBluetoothFindBroadcastsFragment.scanBroadcastSource();
}
private void leaveBroadcastSession() {
// TODO(b/228258236) : Call the LocalBluetoothLeBroadcastAssistant
// to leave the broadcast session
if (mBluetoothFindBroadcastsFragment == null) {
return;
}
mBluetoothFindBroadcastsFragment.leaveBroadcastSession();
}
private void launchQrCodeScanner() {
// TODO(b/228259065) : Launch the QR code scanner page by intent
final Intent intent = new Intent(mContext, QrCodeScanModeActivity.class);
intent.setAction(BluetoothBroadcastUtils.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER)
.putExtra(BluetoothBroadcastUtils.EXTRA_BLUETOOTH_SINK_IS_GROUP, false)
.putExtra(BluetoothBroadcastUtils.EXTRA_BLUETOOTH_DEVICE_SINK,
mCachedDevice.getDevice());
mContext.startActivity(intent);
}
@Override
@@ -128,4 +152,11 @@ public class BluetoothFindBroadcastsHeaderController extends BluetoothDetailsCon
public String getPreferenceKey() {
return KEY_BROADCAST_HEADER;
}
/**
* Updates the UI
*/
public void refreshUi() {
updateHeaderLayout();
}
}