Show overflow button only when there is no enough space

Previously, the overflow button was always shown at the bottom in StyledPlayerControlView
and hided the settings cog even when there is enough space.

With this change, the settings cog moves out from overflow and
the overflow button is shown only when the buttom space is not enough.

PiperOrigin-RevId: 336029179
This commit is contained in:
insun 2020-10-08 08:04:01 +01:00 committed by kim-vde
parent c898e71908
commit 7228b2d718
3 changed files with 32 additions and 19 deletions

View file

@ -56,6 +56,7 @@
with an I-FRAME only variant
([#8025](https://github.com/google/ExoPlayer/issues/8025)).
* IMA extension:
* Fix position reporting after fetch errors
([#7956](https://github.com/google/ExoPlayer/issues/7956)).
* Allow apps to specify a `VideoAdPlayerCallback`
@ -66,6 +67,11 @@
This is in preparation for supporting ads in playlists
([#3750](https://github.com/google/ExoPlayer/issues/3750)).
* UI:
* Show overflow button in `StyledPlayerControlView` only when there is no
enough space.
### 2.12.0 (2020-09-11) ###
To learn more about what's new in 2.12, read the corresponding

View file

@ -677,26 +677,26 @@ import java.util.List;
- styledPlayerControlView.getPaddingLeft()
- styledPlayerControlView.getPaddingRight()
: 0);
int basicBottomBarWidth = getWidth(timeView);
int bottomBarWidth = getWidth(timeView);
for (int i = 0; i < basicControls.getChildCount(); ++i) {
basicBottomBarWidth += basicControls.getChildAt(i).getWidth();
bottomBarWidth += basicControls.getChildAt(i).getWidth();
}
// BasicControls keeps overflow button at least.
int minBasicControlsChildCount = 1;
// ExtraControls keeps overflow button and settings button at least.
int minExtraControlsChildCount = 2;
if (basicBottomBarWidth > width) {
// move control views from basicControls to extraControls
if (bottomBarWidth > width) {
if (overflowShowButton != null && overflowShowButton.getVisibility() != View.VISIBLE) {
overflowShowButton.setVisibility(View.VISIBLE);
bottomBarWidth += overflowShowButton.getWidth();
}
// Move control views from basicControls to extraControls
ArrayList<View> movingChildren = new ArrayList<>();
int movingWidth = 0;
int endIndex = basicControls.getChildCount() - minBasicControlsChildCount;
// The last child is overflow show button which shouldn't move.
int endIndex = basicControls.getChildCount() - 1;
for (int index = 0; index < endIndex; index++) {
View child = basicControls.getChildAt(index);
movingWidth += child.getWidth();
movingChildren.add(child);
if (basicBottomBarWidth - movingWidth <= width) {
if (bottomBarWidth - movingWidth <= width) {
break;
}
}
@ -705,7 +705,9 @@ import java.util.List;
basicControls.removeViews(0, movingChildren.size());
for (View child : movingChildren) {
int index = extraControls.getChildCount() - minExtraControlsChildCount;
// The last child of extra controls should be overflow hide button.
// Adding other buttons before it.
int index = extraControls.getChildCount() - 1;
extraControls.addView(child, index);
}
}
@ -714,23 +716,27 @@ import java.util.List;
// move controls from extraControls to basicControls if possible, else do nothing
ArrayList<View> movingChildren = new ArrayList<>();
int movingWidth = 0;
int startIndex = extraControls.getChildCount() - minExtraControlsChildCount - 1;
for (int index = startIndex; index >= 0; index--) {
// The last child of extra controls is overflow button and it should not move.
int endIndex = extraControls.getChildCount() - 2;
for (int index = endIndex; index >= 0; index--) {
View child = extraControls.getChildAt(index);
movingWidth += child.getWidth();
if (basicBottomBarWidth + movingWidth > width) {
if (bottomBarWidth + movingWidth > width) {
break;
}
movingChildren.add(child);
}
if (!movingChildren.isEmpty()) {
extraControls.removeViews(startIndex - movingChildren.size() + 1, movingChildren.size());
extraControls.removeViews(endIndex - movingChildren.size() + 1, movingChildren.size());
for (View child : movingChildren) {
basicControls.addView(child, 0);
}
}
if (extraControls.getChildCount() == 1 && overflowShowButton != null) {
overflowShowButton.setVisibility(View.GONE);
}
}
}

View file

@ -87,7 +87,11 @@
<ImageButton android:id="@+id/exo_fullscreen"
style="@style/ExoStyledControls.Button.Bottom.FullScreen"/>
<ImageButton android:id="@+id/exo_settings"
style="@style/ExoStyledControls.Button.Bottom.Settings"/>
<ImageButton android:id="@+id/exo_overflow_show"
android:visibility="gone"
style="@style/ExoStyledControls.Button.Bottom.OverflowShow"/>
</LinearLayout>
@ -105,9 +109,6 @@
android:orientation="horizontal"
android:layoutDirection="ltr">
<ImageButton android:id="@+id/exo_settings"
style="@style/ExoStyledControls.Button.Bottom.Settings"/>
<ImageButton android:id="@+id/exo_overflow_hide"
style="@style/ExoStyledControls.Button.Bottom.OverflowHide"/>