Merge "Add ability to adjust height of VideoPreference" into qt-dev
diff --git a/src/com/android/settings/widget/VideoPreference.java b/src/com/android/settings/widget/VideoPreference.java
index ca3e5cc..1af9065 100644
--- a/src/com/android/settings/widget/VideoPreference.java
+++ b/src/com/android/settings/widget/VideoPreference.java
@@ -24,10 +24,12 @@
import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
+import android.util.TypedValue;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -51,11 +53,12 @@
@VisibleForTesting
boolean mVideoReady;
private boolean mVideoPaused;
- private float mAspectRadio = 1.0f;
+ private float mAspectRatio = 1.0f;
private int mPreviewResource;
private boolean mViewVisible;
private Surface mSurface;
private int mAnimationId;
+ private int mHeight = LinearLayout.LayoutParams.MATCH_PARENT - 1; // video height in pixels
public VideoPreference(Context context) {
super(context);
@@ -121,7 +124,11 @@
R.id.video_container);
imageView.setImageResource(mPreviewResource);
- layout.setAspectRatio(mAspectRadio);
+ layout.setAspectRatio(mAspectRatio);
+ if (mHeight >= LinearLayout.LayoutParams.MATCH_PARENT) {
+ layout.setLayoutParams(new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT, mHeight));
+ }
updateViewStates(imageView, playButton);
video.setOnClickListener(v -> updateViewStates(imageView, playButton));
@@ -247,8 +254,17 @@
return mVideoPaused;
}
+ /**
+ * sets the height of the video preference
+ * @param height in dp
+ */
+ public void setHeight(float height) {
+ mHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height,
+ mContext.getResources().getDisplayMetrics());
+ }
+
@VisibleForTesting
void updateAspectRatio() {
- mAspectRadio = mMediaPlayer.getVideoWidth() / (float) mMediaPlayer.getVideoHeight();
+ mAspectRatio = mMediaPlayer.getVideoWidth() / (float) mMediaPlayer.getVideoHeight();
}
}