Commit 7ac19ff4 by olly Committed by Christos Tsilopoulos

StyledPlayerView: Fix calculations to account for margins

Also make some related naming improvements.

PiperOrigin-RevId: 347631916
parent 761bd091
...@@ -24,6 +24,7 @@ import android.content.res.Resources; ...@@ -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; ...@@ -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; ...@@ -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; ...@@ -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));
return (width <= defaultModeWidth || height <= defaultModeHeight); int defaultModeMinimumHeight =
getHeightWithMargins(centerControls) + 2 * getHeightWithMargins(bottomBar);
return width <= defaultModeMinimumWidth || height <= defaultModeMinimumHeight;
} }
private void updateLayoutForSizeChange() { private void updateLayoutForSizeChange() {
...@@ -644,7 +648,7 @@ import java.util.List; ...@@ -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; ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment