Merge "[Output Switcher] Adjust casting volume in output switcher cause icons to flicker" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2a96e3f0fd
@@ -46,7 +46,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
|||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
private ViewGroup mConnectedItem;
|
private ViewGroup mConnectedItem;
|
||||||
private boolean mInclueDynamicGroup;
|
private boolean mIncludeDynamicGroup;
|
||||||
|
|
||||||
public MediaOutputAdapter(MediaOutputController controller) {
|
public MediaOutputAdapter(MediaOutputController controller) {
|
||||||
super(controller);
|
super(controller);
|
||||||
@@ -56,7 +56,6 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
|||||||
public MediaDeviceBaseViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
|
public MediaDeviceBaseViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
|
||||||
int viewType) {
|
int viewType) {
|
||||||
super.onCreateViewHolder(viewGroup, viewType);
|
super.onCreateViewHolder(viewGroup, viewType);
|
||||||
|
|
||||||
return new MediaDeviceViewHolder(mHolderView);
|
return new MediaDeviceViewHolder(mHolderView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
|||||||
if (position == size && mController.isZeroMode()) {
|
if (position == size && mController.isZeroMode()) {
|
||||||
viewHolder.onBind(CUSTOMIZED_ITEM_PAIR_NEW, false /* topMargin */,
|
viewHolder.onBind(CUSTOMIZED_ITEM_PAIR_NEW, false /* topMargin */,
|
||||||
true /* bottomMargin */);
|
true /* bottomMargin */);
|
||||||
} else if (mInclueDynamicGroup) {
|
} else if (mIncludeDynamicGroup) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
viewHolder.onBind(CUSTOMIZED_ITEM_DYNAMIC_GROUP, true /* topMargin */,
|
viewHolder.onBind(CUSTOMIZED_ITEM_DYNAMIC_GROUP, true /* topMargin */,
|
||||||
false /* bottomMargin */);
|
false /* bottomMargin */);
|
||||||
@@ -76,11 +75,12 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
|||||||
// from "position - 1".
|
// from "position - 1".
|
||||||
viewHolder.onBind(((List<MediaDevice>) (mController.getMediaDevices()))
|
viewHolder.onBind(((List<MediaDevice>) (mController.getMediaDevices()))
|
||||||
.get(position - 1),
|
.get(position - 1),
|
||||||
false /* topMargin */, position == size /* bottomMargin */);
|
false /* topMargin */, position == size /* bottomMargin */, position);
|
||||||
}
|
}
|
||||||
} else if (position < size) {
|
} else if (position < size) {
|
||||||
viewHolder.onBind(((List<MediaDevice>) (mController.getMediaDevices())).get(position),
|
viewHolder.onBind(((List<MediaDevice>) (mController.getMediaDevices())).get(position),
|
||||||
position == 0 /* topMargin */, position == (size - 1) /* bottomMargin */);
|
position == 0 /* topMargin */, position == (size - 1) /* bottomMargin */,
|
||||||
|
position);
|
||||||
} else if (DEBUG) {
|
} else if (DEBUG) {
|
||||||
Log.d(TAG, "Incorrect position: " + position);
|
Log.d(TAG, "Incorrect position: " + position);
|
||||||
}
|
}
|
||||||
@@ -88,8 +88,8 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
mInclueDynamicGroup = mController.getSelectedMediaDevice().size() > 1;
|
mIncludeDynamicGroup = mController.getSelectedMediaDevice().size() > 1;
|
||||||
if (mController.isZeroMode() || mInclueDynamicGroup) {
|
if (mController.isZeroMode() || mIncludeDynamicGroup) {
|
||||||
// Add extra one for "pair new" or dynamic group
|
// Add extra one for "pair new" or dynamic group
|
||||||
return mController.getMediaDevices().size() + 1;
|
return mController.getMediaDevices().size() + 1;
|
||||||
}
|
}
|
||||||
@@ -120,9 +120,10 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) {
|
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
|
||||||
super.onBind(device, topMargin, bottomMargin);
|
super.onBind(device, topMargin, bottomMargin, position);
|
||||||
final boolean currentlyConnected = !mInclueDynamicGroup && isCurrentlyConnected(device);
|
final boolean currentlyConnected = !mIncludeDynamicGroup
|
||||||
|
&& isCurrentlyConnected(device);
|
||||||
if (currentlyConnected) {
|
if (currentlyConnected) {
|
||||||
mConnectedItem = mContainerLayout;
|
mConnectedItem = mContainerLayout;
|
||||||
}
|
}
|
||||||
@@ -161,6 +162,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
|
|||||||
setTwoLineLayout(device, true /* bFocused */, true /* showSeekBar */,
|
setTwoLineLayout(device, true /* bFocused */, true /* showSeekBar */,
|
||||||
false /* showProgressBar */, false /* showSubtitle */);
|
false /* showProgressBar */, false /* showSubtitle */);
|
||||||
initSeekbar(device);
|
initSeekbar(device);
|
||||||
|
mCurrentActivePosition = position;
|
||||||
} else {
|
} else {
|
||||||
setSingleLineLayout(getItemTitle(device), false /* bFocused */);
|
setSingleLineLayout(getItemTitle(device), false /* bFocused */);
|
||||||
mContainerLayout.setOnClickListener(v -> onItemClick(v, device));
|
mContainerLayout.setOnClickListener(v -> onItemClick(v, device));
|
||||||
|
|||||||
@@ -64,10 +64,12 @@ public abstract class MediaOutputBaseAdapter extends
|
|||||||
Context mContext;
|
Context mContext;
|
||||||
View mHolderView;
|
View mHolderView;
|
||||||
boolean mIsDragging;
|
boolean mIsDragging;
|
||||||
|
int mCurrentActivePosition;
|
||||||
|
|
||||||
public MediaOutputBaseAdapter(MediaOutputController controller) {
|
public MediaOutputBaseAdapter(MediaOutputController controller) {
|
||||||
mController = controller;
|
mController = controller;
|
||||||
mIsDragging = false;
|
mIsDragging = false;
|
||||||
|
mCurrentActivePosition = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,6 +101,10 @@ public abstract class MediaOutputBaseAdapter extends
|
|||||||
return mIsAnimating;
|
return mIsAnimating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getCurrentActivePosition() {
|
||||||
|
return mCurrentActivePosition;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ViewHolder for binding device view.
|
* ViewHolder for binding device view.
|
||||||
*/
|
*/
|
||||||
@@ -136,7 +142,7 @@ public abstract class MediaOutputBaseAdapter extends
|
|||||||
mCheckBox = view.requireViewById(R.id.check_box);
|
mCheckBox = view.requireViewById(R.id.check_box);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) {
|
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
|
||||||
mDeviceId = device.getId();
|
mDeviceId = device.getId();
|
||||||
ThreadUtils.postOnBackgroundThread(() -> {
|
ThreadUtils.postOnBackgroundThread(() -> {
|
||||||
Icon icon = mController.getDeviceIconCompat(device).toIcon(mContext);
|
Icon icon = mController.getDeviceIconCompat(device).toIcon(mContext);
|
||||||
|
|||||||
@@ -174,7 +174,12 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
|
|||||||
mHeaderTitle.setGravity(Gravity.NO_GRAVITY);
|
mHeaderTitle.setGravity(Gravity.NO_GRAVITY);
|
||||||
}
|
}
|
||||||
if (!mAdapter.isDragging() && !mAdapter.isAnimating()) {
|
if (!mAdapter.isDragging() && !mAdapter.isAnimating()) {
|
||||||
mAdapter.notifyDataSetChanged();
|
int currentActivePosition = mAdapter.getCurrentActivePosition();
|
||||||
|
if (currentActivePosition >= 0) {
|
||||||
|
mAdapter.notifyItemChanged(currentActivePosition);
|
||||||
|
} else {
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Show when remote media session is available
|
// Show when remote media session is available
|
||||||
mStopButton.setVisibility(getStopButtonVisibility());
|
mStopButton.setVisibility(getStopButtonVisibility());
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class MediaOutputGroupAdapter extends MediaOutputBaseAdapter {
|
|||||||
final int size = mGroupMediaDevices.size();
|
final int size = mGroupMediaDevices.size();
|
||||||
if (newPosition < size) {
|
if (newPosition < size) {
|
||||||
viewHolder.onBind(mGroupMediaDevices.get(newPosition), false /* topMargin */,
|
viewHolder.onBind(mGroupMediaDevices.get(newPosition), false /* topMargin */,
|
||||||
newPosition == (size - 1) /* bottomMargin */);
|
newPosition == (size - 1) /* bottomMargin */, position);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -94,8 +94,8 @@ public class MediaOutputGroupAdapter extends MediaOutputBaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin) {
|
void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
|
||||||
super.onBind(device, topMargin, bottomMargin);
|
super.onBind(device, topMargin, bottomMargin, position);
|
||||||
mDivider.setVisibility(View.GONE);
|
mDivider.setVisibility(View.GONE);
|
||||||
mAddIcon.setVisibility(View.GONE);
|
mAddIcon.setVisibility(View.GONE);
|
||||||
mBottomDivider.setVisibility(View.GONE);
|
mBottomDivider.setVisibility(View.GONE);
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void refresh_notInDragging_verifyUpdateAdapter() {
|
public void refresh_notInDragging_verifyUpdateAdapter() {
|
||||||
|
when(mMediaOutputBaseAdapter.getCurrentActivePosition()).thenReturn(-1);
|
||||||
when(mMediaOutputBaseAdapter.isDragging()).thenReturn(false);
|
when(mMediaOutputBaseAdapter.isDragging()).thenReturn(false);
|
||||||
mMediaOutputBaseDialogImpl.refresh();
|
mMediaOutputBaseDialogImpl.refresh();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user