mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
StyledPlayerView: Fix calculations to account for margins
Also make some related naming improvements. PiperOrigin-RevId: 347631916
This commit is contained in:
parent
761bd091c3
commit
7ac19ff406
3 changed files with 42 additions and 18 deletions
|
|
@ -24,6 +24,7 @@ import android.content.res.Resources;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnLayoutChangeListener;
|
import android.view.View.OnLayoutChangeListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.view.ViewGroup.MarginLayoutParams;
|
import android.view.ViewGroup.MarginLayoutParams;
|
||||||
import android.view.animation.LinearInterpolator;
|
import android.view.animation.LinearInterpolator;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
@ -477,9 +478,9 @@ import java.util.List;
|
||||||
int oldRight,
|
int oldRight,
|
||||||
int oldBottom) {
|
int oldBottom) {
|
||||||
|
|
||||||
boolean shouldBeMinimalMode = shouldBeMinimalMode();
|
boolean useMinimalMode = useMinimalMode();
|
||||||
if (isMinimalMode != shouldBeMinimalMode) {
|
if (isMinimalMode != useMinimalMode) {
|
||||||
isMinimalMode = shouldBeMinimalMode;
|
isMinimalMode = useMinimalMode;
|
||||||
v.post(this::updateLayoutForSizeChange);
|
v.post(this::updateLayoutForSizeChange);
|
||||||
}
|
}
|
||||||
boolean widthChanged = (right - left) != (oldRight - oldLeft);
|
boolean widthChanged = (right - left) != (oldRight - oldLeft);
|
||||||
|
|
@ -564,7 +565,7 @@ import java.util.List;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldBeMinimalMode() {
|
private boolean useMinimalMode() {
|
||||||
int width =
|
int width =
|
||||||
styledPlayerControlView.getWidth()
|
styledPlayerControlView.getWidth()
|
||||||
- styledPlayerControlView.getPaddingLeft()
|
- styledPlayerControlView.getPaddingLeft()
|
||||||
|
|
@ -573,11 +574,14 @@ import java.util.List;
|
||||||
styledPlayerControlView.getHeight()
|
styledPlayerControlView.getHeight()
|
||||||
- styledPlayerControlView.getPaddingBottom()
|
- styledPlayerControlView.getPaddingBottom()
|
||||||
- styledPlayerControlView.getPaddingTop();
|
- styledPlayerControlView.getPaddingTop();
|
||||||
int defaultModeWidth =
|
int defaultModeMinimumWidth =
|
||||||
Math.max(getWidth(centerControls), getWidth(timeView) + getWidth(overflowShowButton));
|
Math.max(
|
||||||
int defaultModeHeight = getHeight(centerControls) + getHeight(timeBar) + getHeight(bottomBar);
|
getWidthWithMargins(centerControls),
|
||||||
|
getWidthWithMargins(timeView) + getWidthWithMargins(overflowShowButton));
|
||||||
|
int defaultModeMinimumHeight =
|
||||||
|
getHeightWithMargins(centerControls) + 2 * getHeightWithMargins(bottomBar);
|
||||||
|
|
||||||
return (width <= defaultModeWidth || height <= defaultModeHeight);
|
return width <= defaultModeMinimumWidth || height <= defaultModeMinimumHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLayoutForSizeChange() {
|
private void updateLayoutForSizeChange() {
|
||||||
|
|
@ -644,7 +648,7 @@ import java.util.List;
|
||||||
styledPlayerControlView.getWidth()
|
styledPlayerControlView.getWidth()
|
||||||
- styledPlayerControlView.getPaddingLeft()
|
- styledPlayerControlView.getPaddingLeft()
|
||||||
- styledPlayerControlView.getPaddingRight();
|
- styledPlayerControlView.getPaddingRight();
|
||||||
int bottomBarWidth = getWidth(timeView);
|
int bottomBarWidth = getWidthWithMargins(timeView);
|
||||||
for (int i = 0; i < basicControls.getChildCount(); ++i) {
|
for (int i = 0; i < basicControls.getChildCount(); ++i) {
|
||||||
bottomBarWidth += basicControls.getChildAt(i).getWidth();
|
bottomBarWidth += basicControls.getChildAt(i).getWidth();
|
||||||
}
|
}
|
||||||
|
|
@ -707,11 +711,29 @@ import java.util.List;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getWidth(@Nullable View v) {
|
private static int getWidthWithMargins(@Nullable View v) {
|
||||||
return (v != null ? v.getWidth() : 0);
|
if (v == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int width = v.getWidth();
|
||||||
|
LayoutParams layoutParams = v.getLayoutParams();
|
||||||
|
if (layoutParams instanceof MarginLayoutParams) {
|
||||||
|
MarginLayoutParams marginLayoutParams = (MarginLayoutParams) layoutParams;
|
||||||
|
width += marginLayoutParams.leftMargin + marginLayoutParams.rightMargin;
|
||||||
|
}
|
||||||
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getHeight(@Nullable View v) {
|
private static int getHeightWithMargins(@Nullable View v) {
|
||||||
return (v != null ? v.getHeight() : 0);
|
if (v == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int height = v.getHeight();
|
||||||
|
LayoutParams layoutParams = v.getLayoutParams();
|
||||||
|
if (layoutParams instanceof MarginLayoutParams) {
|
||||||
|
MarginLayoutParams marginLayoutParams = (MarginLayoutParams) layoutParams;
|
||||||
|
height += marginLayoutParams.topMargin + marginLayoutParams.bottomMargin;
|
||||||
|
}
|
||||||
|
return height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<FrameLayout android:id="@+id/exo_bottom_bar"
|
<FrameLayout android:id="@+id/exo_bottom_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/exo_styled_bottom_bar_height"
|
android:layout_height="@dimen/exo_styled_bottom_bar_height"
|
||||||
|
android:layout_marginTop="@dimen/exo_styled_bottom_bar_margin_top"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:background="@color/exo_bottom_bar_background"
|
android:background="@color/exo_bottom_bar_background"
|
||||||
android:layoutDirection="ltr">
|
android:layoutDirection="ltr">
|
||||||
|
|
@ -31,10 +32,10 @@
|
||||||
<LinearLayout android:id="@+id/exo_time"
|
<LinearLayout android:id="@+id/exo_time"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="@dimen/exo_styled_time_padding"
|
android:paddingStart="@dimen/exo_styled_bottom_bar_time_padding"
|
||||||
android:paddingEnd="@dimen/exo_styled_time_padding"
|
android:paddingEnd="@dimen/exo_styled_bottom_bar_time_padding"
|
||||||
android:paddingLeft="@dimen/exo_styled_time_padding"
|
android:paddingLeft="@dimen/exo_styled_bottom_bar_time_padding"
|
||||||
android:paddingRight="@dimen/exo_styled_time_padding"
|
android:paddingRight="@dimen/exo_styled_bottom_bar_time_padding"
|
||||||
android:layout_gravity="center_vertical|start"
|
android:layout_gravity="center_vertical|start"
|
||||||
android:layoutDirection="ltr">
|
android:layoutDirection="ltr">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,8 @@
|
||||||
<dimen name="exo_styled_progress_touch_target_height">48dp</dimen>
|
<dimen name="exo_styled_progress_touch_target_height">48dp</dimen>
|
||||||
<dimen name="exo_styled_progress_margin_bottom">52dp</dimen>
|
<dimen name="exo_styled_progress_margin_bottom">52dp</dimen>
|
||||||
<dimen name="exo_styled_bottom_bar_height">60dp</dimen>
|
<dimen name="exo_styled_bottom_bar_height">60dp</dimen>
|
||||||
<dimen name="exo_styled_time_padding">10dp</dimen>
|
<dimen name="exo_styled_bottom_bar_time_padding">10dp</dimen>
|
||||||
|
<dimen name="exo_styled_bottom_bar_margin_top">10dp</dimen>
|
||||||
<dimen name="exo_styled_minimal_controls_margin_bottom">4dp</dimen>
|
<dimen name="exo_styled_minimal_controls_margin_bottom">4dp</dimen>
|
||||||
|
|
||||||
<dimen name="exo_error_message_height">32dp</dimen>
|
<dimen name="exo_error_message_height">32dp</dimen>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue