DO NOT MERGE: Downbranch merge conflict [Output Switcher] Make either transfer or expansion on a single route

When a single route is selectable or selected, make the only option on
it is expansion/shrinkage.
Also customize seekbar to only change progress when tap and move
action, otherwise performs click for the item.

Bug: 223613190
Test: verified on device
Change-Id: I3ceb386f6f851886655b0e8913052b1738550af3
This commit is contained in:
shaoweishen
2022-03-14 10:03:38 +00:00
committed by Shaowei Shen
parent 5169706329
commit 6da04ce007
3 changed files with 74 additions and 11 deletions

View File

@@ -33,7 +33,7 @@
android:layout_height="match_parent"
android:background="@drawable/media_output_item_background"
android:layout_gravity="center_vertical|start">
<SeekBar
<com.android.systemui.media.dialog.MediaOutputSeekbar
android:id="@+id/volume_seekbar"
android:splitTrack="false"
android:visibility="gone"
@@ -127,6 +127,7 @@
android:layout_gravity="right|center"
android:button="@drawable/ic_circle_check_box"
android:visibility="gone"
android:clickable="false"
/>
</FrameLayout>
</LinearLayout>

View File

@@ -169,12 +169,10 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
setSingleLineLayout(getItemTitle(device), true /* bFocused */,
true /* showSeekBar */,
false /* showProgressBar */, false /* showStatus */);
mCheckBox.setOnCheckedChangeListener(null);
mCheckBox.setVisibility(View.VISIBLE);
mCheckBox.setChecked(true);
mCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
onCheckBoxClicked(false, device);
});
mSeekBar.setOnClickListener(null);
mSeekBar.setOnClickListener(v -> onGroupActionTriggered(false, device));
setCheckBoxColor(mCheckBox, mController.getColorItemContent());
initSeekbar(device);
} else if (!mController.hasAdjustVolumeUserRestriction() && currentlyConnected) {
@@ -188,17 +186,13 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
initSeekbar(device);
mCurrentActivePosition = position;
} else if (isDeviceIncluded(mController.getSelectableMediaDevice(), device)) {
mCheckBox.setOnCheckedChangeListener(null);
mCheckBox.setVisibility(View.VISIBLE);
mCheckBox.setChecked(false);
mCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
onCheckBoxClicked(true, device);
});
mContainerLayout.setOnClickListener(v -> onGroupActionTriggered(true, device));
setCheckBoxColor(mCheckBox, mController.getColorItemContent());
setSingleLineLayout(getItemTitle(device), false /* bFocused */,
false /* showSeekBar */,
false /* showProgressBar */, false /* showStatus */);
mContainerLayout.setOnClickListener(v -> onItemClick(v, device));
} else {
setSingleLineLayout(getItemTitle(device), false /* bFocused */);
mContainerLayout.setOnClickListener(v -> onItemClick(v, device));
@@ -228,7 +222,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
}
}
private void onCheckBoxClicked(boolean isChecked, MediaDevice device) {
private void onGroupActionTriggered(boolean isChecked, MediaDevice device) {
if (isChecked && isDeviceIncluded(mController.getSelectableMediaDevice(), device)) {
mController.addDeviceToPlayMedia(device);
} else if (!isChecked && isDeviceIncluded(mController.getDeselectableMediaDevice(),

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.media.dialog;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.SeekBar;
/**
* Customized seekbar used by MediaOutputDialog, which only changes progress when dragging,
* otherwise performs click.
*/
public class MediaOutputSeekbar extends SeekBar {
private static final int DRAGGING_THRESHOLD = 20;
private boolean mIsDragging = false;
public MediaOutputSeekbar(Context context) {
super(context);
}
public MediaOutputSeekbar(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int width = getWidth()
- getPaddingLeft()
- getPaddingRight();
int thumbPos = getPaddingLeft()
+ width
* getProgress()
/ getMax();
if (event.getAction() == MotionEvent.ACTION_DOWN
&& Math.abs(event.getX() - thumbPos) < DRAGGING_THRESHOLD) {
mIsDragging = true;
super.onTouchEvent(event);
} else if (event.getAction() == MotionEvent.ACTION_MOVE && mIsDragging) {
super.onTouchEvent(event);
} else if (event.getAction() == MotionEvent.ACTION_UP && mIsDragging) {
mIsDragging = false;
super.onTouchEvent(event);
} else if (event.getAction() == MotionEvent.ACTION_UP && !mIsDragging) {
performClick();
}
return true;
}
@Override
public boolean performClick() {
return super.performClick();
}
}