Add "Broadcast" button at output switcher
1.Add ”Broadcast“ button at output switcher. like the UX mock P9. 2.If the user launches the the broadcast at first time, then the UI shows the educational dialog. like the UX mock P8. Bug: 227109903 Test: manual test Change-Id: Icc4272b3f37e5ed68280a5a5a5efabb766a683e0
This commit is contained in:
@@ -21,6 +21,7 @@ import static android.view.WindowInsets.Type.statusBars;
|
||||
|
||||
import android.app.WallpaperColors;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
@@ -35,6 +36,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -65,6 +67,8 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
||||
|
||||
private static final String TAG = "MediaOutputDialog";
|
||||
private static final String EMPTY_TITLE = " ";
|
||||
private static final String PREF_NAME = "MediaOutputDialog";
|
||||
private static final String PREF_IS_LE_BROADCAST_FIRST_LAUNCH = "PrefIsLeBroadcastFirstLaunch";
|
||||
|
||||
private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
|
||||
private final RecyclerView.LayoutManager mLayoutManager;
|
||||
@@ -252,6 +256,33 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
||||
}
|
||||
// Show when remote media session is available
|
||||
mStopButton.setVisibility(getStopButtonVisibility());
|
||||
if (isBroadcastSupported() && mMediaOutputController.isPlaying()) {
|
||||
mStopButton.setText(R.string.media_output_broadcast);
|
||||
mStopButton.setOnClickListener(v -> {
|
||||
SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
|
||||
if (sharedPref != null
|
||||
&& sharedPref.getBoolean(PREF_IS_LE_BROADCAST_FIRST_LAUNCH, true)) {
|
||||
Log.d(TAG, "PREF_IS_LE_BROADCAST_FIRST_LAUNCH: true");
|
||||
|
||||
mMediaOutputController.launchLeBroadcastNotifyDialog(mDialogView,
|
||||
mBroadcastSender,
|
||||
MediaOutputController.BroadcastNotifyDialog.ACTION_FIRST_LAUNCH);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putBoolean(PREF_IS_LE_BROADCAST_FIRST_LAUNCH, false);
|
||||
editor.apply();
|
||||
} else {
|
||||
mMediaOutputController.launchMediaOutputBroadcastDialog(mDialogView,
|
||||
mBroadcastSender);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mStopButton.setOnClickListener(v -> {
|
||||
mMediaOutputController.releaseSession();
|
||||
dismiss();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable resizeDrawable(Drawable drawable, int size) {
|
||||
@@ -284,6 +315,10 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
||||
|
||||
abstract int getStopButtonVisibility();
|
||||
|
||||
public boolean isBroadcastSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaChanged() {
|
||||
mMainThreadHandler.post(() -> refresh());
|
||||
|
||||
@@ -228,7 +228,7 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
|
||||
* that convert BluetoothLeBroadcastMetadata object to String format.
|
||||
*/
|
||||
private String getBroadcastMetaData() {
|
||||
return "";
|
||||
return "TEST";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,7 +58,9 @@ import androidx.mediarouter.media.MediaRouterParams;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.media.BluetoothMediaDevice;
|
||||
import com.android.settingslib.media.InfoMediaManager;
|
||||
import com.android.settingslib.media.LocalMediaManager;
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
@@ -683,6 +685,20 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback,
|
||||
|| features.contains(MediaRoute2Info.FEATURE_REMOTE_GROUP_PLAYBACK));
|
||||
}
|
||||
|
||||
boolean isBluetoothLeDevice(@NonNull MediaDevice device) {
|
||||
if (device instanceof BluetoothMediaDevice) {
|
||||
final CachedBluetoothDevice cachedDevice =
|
||||
((BluetoothMediaDevice) device).getCachedDevice();
|
||||
boolean isConnectedLeAudioDevice =
|
||||
(cachedDevice != null) ? cachedDevice.isConnectedLeAudioDevice() : false;
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "isConnectedLeAudioDevice=" + isConnectedLeAudioDevice);
|
||||
}
|
||||
return isConnectedLeAudioDevice;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPlayBackInfoLocal() {
|
||||
return mMediaController != null
|
||||
&& mMediaController.getPlaybackInfo() != null
|
||||
@@ -690,6 +706,19 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback,
|
||||
== MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
|
||||
}
|
||||
|
||||
boolean isPlaying() {
|
||||
if (mMediaController == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlaybackState state = mMediaController.getPlaybackState();
|
||||
if (state == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (state.getState() == PlaybackState.STATE_PLAYING);
|
||||
}
|
||||
|
||||
boolean isVolumeControlEnabled(@NonNull MediaDevice device) {
|
||||
return isPlayBackInfoLocal()
|
||||
|| mLocalMediaManager.isMediaSessionAvailableForVolumeControl();
|
||||
|
||||
@@ -27,6 +27,7 @@ import androidx.core.graphics.drawable.IconCompat;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.UiEvent;
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.broadcast.BroadcastSender;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
@@ -87,8 +88,20 @@ public class MediaOutputDialog extends MediaOutputBaseDialog {
|
||||
|
||||
@Override
|
||||
int getStopButtonVisibility() {
|
||||
return mMediaOutputController.isActiveRemoteDevice(
|
||||
mMediaOutputController.getCurrentConnectedMediaDevice()) ? View.VISIBLE : View.GONE;
|
||||
boolean isActiveRemoteDevice = mMediaOutputController.isActiveRemoteDevice(
|
||||
mMediaOutputController.getCurrentConnectedMediaDevice());
|
||||
boolean isBroadCastSupported = isBroadcastSupported();
|
||||
|
||||
return (isActiveRemoteDevice || isBroadCastSupported) ? View.VISIBLE : View.GONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBroadcastSupported() {
|
||||
MediaDevice device = mMediaOutputController.getCurrentConnectedMediaDevice();
|
||||
if (device == null) {
|
||||
return false;
|
||||
}
|
||||
return mMediaOutputController.isBluetoothLeDevice(device);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
Reference in New Issue
Block a user