Merge "Add zero state in output switcher" into rvc-dev am: ddd8a8fa92 am: 3e73d0f92c

Change-Id: Ib8b6ff0cd9dfc4ae2fdfd535354fcdd3fac5e261
This commit is contained in:
tim peng
2020-03-30 18:27:22 +00:00
committed by Automerger Merge Worker
6 changed files with 126 additions and 91 deletions

View File

@@ -129,9 +129,9 @@ public class MediaOutputIndicatorSlice implements CustomSliceable {
// Return true if
// 1. AudioMode is not in on-going call
// 2. worker is not null
// 3. Available devices are more than 1
// 3. Available devices are more than 0
return getWorker() != null
&& !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext)
&& getWorker().getMediaDevices().size() > 1;
&& getWorker().getMediaDevices().size() > 0;
}
}

View File

@@ -22,8 +22,11 @@ import static android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
import android.app.PendingIntent;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.SpannableString;
@@ -39,6 +42,8 @@ import androidx.slice.builders.SliceAction;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.bluetooth.BluetoothPairingDetail;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.slices.CustomSliceable;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settings.slices.SliceBroadcastReceiver;
@@ -81,7 +86,6 @@ public class MediaOutputSlice implements CustomSliceable {
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
.setAccentColor(COLOR_NOT_TINTED);
if (!isVisible()) {
Log.d(TAG, "getSlice() is not visible");
return listBuilder.build();
@@ -99,24 +103,53 @@ public class MediaOutputSlice implements CustomSliceable {
}
} else {
final MediaDevice connectedDevice = worker.getCurrentConnectedMediaDevice();
final boolean isTouched = worker.getIsTouched();
// Fix the last top device when user press device to transfer.
final MediaDevice topDevice = isTouched ? worker.getTopDevice() : connectedDevice;
if (devices.size() == 1) {
// Zero state
addRow(connectedDevice, connectedDevice, listBuilder);
listBuilder.addRow(getPairNewRow());
} else {
final boolean isTouched = worker.getIsTouched();
// Fix the last top device when user press device to transfer.
final MediaDevice topDevice = isTouched ? worker.getTopDevice() : connectedDevice;
if (topDevice != null) {
addRow(topDevice, connectedDevice, listBuilder);
worker.setTopDevice(topDevice);
}
if (topDevice != null) {
addRow(topDevice, connectedDevice, listBuilder);
worker.setTopDevice(topDevice);
}
for (MediaDevice device : devices) {
if (topDevice == null || !TextUtils.equals(topDevice.getId(), device.getId())) {
addRow(device, connectedDevice, listBuilder);
for (MediaDevice device : devices) {
if (topDevice == null || !TextUtils.equals(topDevice.getId(), device.getId())) {
addRow(device, connectedDevice, listBuilder);
}
}
}
}
return listBuilder.build();
}
private ListBuilder.RowBuilder getPairNewRow() {
final Drawable d = mContext.getDrawable(R.drawable.ic_add_24dp);
d.setColorFilter(new PorterDuffColorFilter(Utils.getColorAccentDefaultColor(mContext),
PorterDuff.Mode.SRC_IN));
final IconCompat icon = Utils.createIconWithDrawable(d);
final String title = mContext.getString(R.string.bluetooth_pairing_pref_title);
final Intent intent = new SubSettingLauncher(mContext)
.setDestination(BluetoothPairingDetail.class.getName())
.setTitleRes(R.string.bluetooth_pairing_page_title)
.setSourceMetricsCategory(SettingsEnums.PANEL_MEDIA_OUTPUT)
.toIntent();
final SliceAction primarySliceAction = SliceAction.createDeeplink(
PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */),
IconCompat.createWithResource(mContext, R.drawable.ic_add_24dp/*ic_add_blue_24dp*/),
ListBuilder.ICON_IMAGE,
mContext.getText(R.string.bluetooth_pairing_pref_title));
final ListBuilder.RowBuilder builder = new ListBuilder.RowBuilder()
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
.setTitle(title)
.setPrimaryAction(primarySliceAction);
return builder;
}
private ListBuilder.InputRangeBuilder getGroupRow() {
final IconCompat icon = IconCompat.createWithResource(mContext,
R.drawable.ic_speaker_group_black_24dp);
@@ -321,10 +354,10 @@ public class MediaOutputSlice implements CustomSliceable {
// Return true if
// 1. AudioMode is not in on-going call
// 2. worker is not null
// 3. Available devices are more than 1
// 3. Available devices are more than 0
return getWorker() != null
&& !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext)
&& getWorker().getMediaDevices().size() > 1;
&& getWorker().getMediaDevices().size() > 0;
}
}

View File

@@ -23,6 +23,7 @@ import android.media.AudioManager;
import android.text.TextUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.Utils;
@@ -46,6 +47,15 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
super(context, key);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
if (!Utils.isAudioModeOngoingCall(mContext)) {
mPreference.setVisible(true);
}
}
@Override
public void updateState(Preference preference) {
if (preference == null) {
@@ -61,7 +71,6 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
return;
}
boolean deviceConnected = false;
BluetoothDevice activeDevice = null;
// Show preference if there is connected or previously connected device
// Find active device and set its name as the preference's summary
@@ -70,10 +79,8 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
if (mAudioManager.getMode() == AudioManager.MODE_NORMAL
&& ((connectedA2dpDevices != null && !connectedA2dpDevices.isEmpty())
|| (connectedHADevices != null && !connectedHADevices.isEmpty()))) {
deviceConnected = true;
activeDevice = findActiveDevice();
}
mPreference.setVisible(deviceConnected);
mPreference.setSummary((activeDevice == null) ?
mContext.getText(R.string.media_output_default_summary) :
activeDevice.getAlias());