diff --git a/packages/SystemUI/res/layout/media_output_list_item.xml b/packages/SystemUI/res/layout/media_output_list_item.xml index 20747fad021be..d39b0d53c7431 100644 --- a/packages/SystemUI/res/layout/media_output_list_item.xml +++ b/packages/SystemUI/res/layout/media_output_list_item.xml @@ -33,7 +33,7 @@ android:layout_height="match_parent" android:background="@drawable/media_output_item_background" android:layout_gravity="center_vertical|start"> - \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java index a6464829623fb..f4fcf10e7bb4d 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapter.java @@ -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(), diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputSeekbar.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputSeekbar.java new file mode 100644 index 0000000000000..0a3c5bf24b8bd --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputSeekbar.java @@ -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(); + } +}