[Audiosharing] Impl audio sharing main switch.
Start/stop broadcast when no eligible buds connected. Flagged with enable_le_audio_sharing Bug: 305620450 Test: Manual Change-Id: I04359c0954e336ceb1a89a7836199b5be0b5e0c5
This commit is contained in:
@@ -38,6 +38,26 @@ import java.util.ArrayList;
|
||||
public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
|
||||
private static final String TAG = "AudioSharingDialog";
|
||||
|
||||
private static final String BUNDLE_KEY_DEVICE_NAMES = "bundle_key_device_names";
|
||||
|
||||
// The host creates an instance of this dialog fragment must implement this interface to receive
|
||||
// event callbacks.
|
||||
public interface DialogEventListener {
|
||||
/**
|
||||
* Called when users click the device item for sharing in the dialog.
|
||||
*
|
||||
* @param position The position of the item clicked.
|
||||
*/
|
||||
void onItemClick(int position);
|
||||
|
||||
/**
|
||||
* Called when users click the cancel button in the dialog.
|
||||
*/
|
||||
void onCancelClick();
|
||||
}
|
||||
|
||||
private static DialogEventListener sListener;
|
||||
|
||||
private View mRootView;
|
||||
|
||||
@Override
|
||||
@@ -50,40 +70,59 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
|
||||
*
|
||||
* @param host The Fragment this dialog will be hosted.
|
||||
*/
|
||||
public static void show(Fragment host) {
|
||||
public static void show(
|
||||
Fragment host, ArrayList<String> deviceNames, DialogEventListener listener) {
|
||||
if (!Flags.enableLeAudioSharing()) return;
|
||||
final FragmentManager manager = host.getChildFragmentManager();
|
||||
sListener = listener;
|
||||
if (manager.findFragmentByTag(TAG) == null) {
|
||||
final AudioSharingDialogFragment dialog = new AudioSharingDialogFragment();
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putStringArrayList(BUNDLE_KEY_DEVICE_NAMES, deviceNames);
|
||||
AudioSharingDialogFragment dialog = new AudioSharingDialogFragment();
|
||||
dialog.setArguments(bundle);
|
||||
dialog.show(manager, TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Bundle arguments = requireArguments();
|
||||
ArrayList<String> deviceNames = arguments.getStringArrayList(BUNDLE_KEY_DEVICE_NAMES);
|
||||
final AlertDialog.Builder builder =
|
||||
new AlertDialog.Builder(getActivity()).setTitle("Share audio");
|
||||
new AlertDialog.Builder(getActivity()).setTitle("Share audio").setCancelable(false);
|
||||
mRootView =
|
||||
LayoutInflater.from(builder.getContext())
|
||||
.inflate(R.layout.dialog_audio_sharing, /* parent= */ null);
|
||||
// TODO: use real subtitle according to device count.
|
||||
TextView subTitle1 = mRootView.findViewById(R.id.share_audio_subtitle1);
|
||||
TextView subTitle2 = mRootView.findViewById(R.id.share_audio_subtitle2);
|
||||
subTitle1.setText("2 devices connected");
|
||||
subTitle2.setText("placeholder");
|
||||
if (deviceNames.isEmpty()) {
|
||||
subTitle1.setVisibility(View.INVISIBLE);
|
||||
subTitle2.setText("To start sharing audio, connect headphones that support LE audio");
|
||||
builder.setNegativeButton(
|
||||
"Close",
|
||||
(dialog, which) -> {
|
||||
sListener.onCancelClick();
|
||||
});
|
||||
} else if (deviceNames.size() == 1) {
|
||||
// TODO: add real impl
|
||||
subTitle1.setText("1 devices connected");
|
||||
subTitle2.setText("placeholder");
|
||||
} else {
|
||||
// TODO: add real impl
|
||||
subTitle1.setText("2 devices connected");
|
||||
subTitle2.setText("placeholder");
|
||||
}
|
||||
RecyclerView recyclerView = mRootView.findViewById(R.id.btn_list);
|
||||
// TODO: use real audio sharing device list.
|
||||
ArrayList<String> devices = new ArrayList<>();
|
||||
devices.add("Buds 1");
|
||||
devices.add("Buds 2");
|
||||
recyclerView.setAdapter(
|
||||
new AudioSharingDeviceAdapter(
|
||||
devices,
|
||||
deviceNames,
|
||||
(int position) -> {
|
||||
// TODO: add on click callback.
|
||||
sListener.onItemClick(position);
|
||||
}));
|
||||
recyclerView.setLayoutManager(
|
||||
new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
|
||||
return builder.setView(mRootView).create();
|
||||
AlertDialog dialog = builder.setView(mRootView).create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user