Merge "[Audiosharing] UI refinement." into main
This commit is contained in:
@@ -16,22 +16,123 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing;
|
||||
|
||||
import android.bluetooth.BluetoothLeBroadcast;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
public class AudioSharingPreferenceController extends BasePreferenceController {
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class AudioSharingPreferenceController extends BasePreferenceController
|
||||
implements DefaultLifecycleObserver, BluetoothCallback {
|
||||
private static final String TAG = "AudioSharingPreferenceController";
|
||||
|
||||
private Context mContext;
|
||||
private final LocalBluetoothManager mLocalBtManager;
|
||||
private final Executor mExecutor;
|
||||
@Nullable private LocalBluetoothLeBroadcast mBroadcast = null;
|
||||
@Nullable private Preference mPreference;
|
||||
|
||||
private final BluetoothLeBroadcast.Callback mBroadcastCallback =
|
||||
new BluetoothLeBroadcast.Callback() {
|
||||
@Override
|
||||
public void onBroadcastStarted(int reason, int broadcastId) {
|
||||
if (mPreference != null) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroadcastStartFailed(int reason) {}
|
||||
|
||||
@Override
|
||||
public void onBroadcastMetadataChanged(
|
||||
int broadcastId, @NonNull BluetoothLeBroadcastMetadata metadata) {}
|
||||
|
||||
@Override
|
||||
public void onBroadcastStopped(int reason, int broadcastId) {
|
||||
if (mPreference != null) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroadcastStopFailed(int reason) {}
|
||||
|
||||
@Override
|
||||
public void onBroadcastUpdated(int reason, int broadcastId) {}
|
||||
|
||||
@Override
|
||||
public void onBroadcastUpdateFailed(int reason, int broadcastId) {}
|
||||
|
||||
@Override
|
||||
public void onPlaybackStarted(int reason, int broadcastId) {}
|
||||
|
||||
@Override
|
||||
public void onPlaybackStopped(int reason, int broadcastId) {}
|
||||
};
|
||||
|
||||
public AudioSharingPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContext = context;
|
||||
mLocalBtManager = Utils.getLocalBtManager(context);
|
||||
if (mLocalBtManager != null) {
|
||||
mBroadcast = mLocalBtManager.getProfileManager().getLeAudioBroadcastProfile();
|
||||
}
|
||||
mExecutor = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(@NonNull LifecycleOwner owner) {
|
||||
if (mLocalBtManager != null) {
|
||||
mLocalBtManager.getEventManager().registerCallback(this);
|
||||
}
|
||||
if (mBroadcast != null) {
|
||||
mBroadcast.registerServiceCallBack(mExecutor, mBroadcastCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(@NonNull LifecycleOwner owner) {
|
||||
if (mLocalBtManager != null) {
|
||||
mLocalBtManager.getEventManager().unregisterCallback(this);
|
||||
}
|
||||
if (mBroadcast != null) {
|
||||
mBroadcast.unregisterServiceCallBack(mBroadcastCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return AudioSharingUtils.isBroadcasting(mLocalBtManager) ? "On" : "Off";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBluetoothStateChanged(@AdapterState int bluetoothState) {
|
||||
if (mPreference != null) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user