Merge "Add battery illustration" into pi-dev am: 3035d45a8f
am: 0c43bd4c36
Change-Id: Id80603471c5ac9d1ea68417bc27b5f2c77dd1dcf
This commit is contained in:
@@ -16,6 +16,7 @@ package com.android.settings.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
@@ -30,7 +31,8 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
||||
|
||||
private static final float ASPECT_RATIO_CHANGE_THREASHOLD = 0.01f;
|
||||
|
||||
private float mAspectRatio = 1.0f;
|
||||
@VisibleForTesting
|
||||
float mAspectRatio = 1.0f;
|
||||
|
||||
public AspectRatioFrameLayout(Context context) {
|
||||
this(context, null);
|
||||
@@ -51,6 +53,10 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
public void setAspectRatio(float aspectRadio) {
|
||||
mAspectRatio = aspectRadio;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
@@ -65,11 +71,9 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
||||
// Close enough, skip.
|
||||
return;
|
||||
}
|
||||
if (aspectRatioDiff > 0) {
|
||||
width = (int) (height * mAspectRatio);
|
||||
} else {
|
||||
height = (int) (width / mAspectRatio);
|
||||
}
|
||||
|
||||
width = (int) (height * mAspectRatio);
|
||||
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import android.content.res.TypedArray;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
@@ -42,10 +43,13 @@ public class VideoPreference extends Preference {
|
||||
private final Context mContext;
|
||||
|
||||
private Uri mVideoPath;
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private boolean mAnimationAvailable;
|
||||
@VisibleForTesting
|
||||
MediaPlayer mMediaPlayer;
|
||||
@VisibleForTesting
|
||||
boolean mAnimationAvailable;
|
||||
private boolean mVideoReady;
|
||||
private boolean mVideoPaused;
|
||||
private float mAspectRadio = 1.0f;
|
||||
private int mPreviewResource;
|
||||
|
||||
public VideoPreference(Context context, AttributeSet attrs) {
|
||||
@@ -73,6 +77,7 @@ public class VideoPreference extends Preference {
|
||||
|
||||
mMediaPlayer.setOnPreparedListener(mediaPlayer -> mediaPlayer.setLooping(true));
|
||||
mAnimationAvailable = true;
|
||||
updateAspectRatio();
|
||||
} else {
|
||||
setVisible(false);
|
||||
}
|
||||
@@ -94,7 +99,11 @@ public class VideoPreference extends Preference {
|
||||
final TextureView video = (TextureView) holder.findViewById(R.id.video_texture_view);
|
||||
final ImageView imageView = (ImageView) holder.findViewById(R.id.video_preview_image);
|
||||
final ImageView playButton = (ImageView) holder.findViewById(R.id.video_play_button);
|
||||
final AspectRatioFrameLayout layout = (AspectRatioFrameLayout) holder.findViewById(
|
||||
R.id.video_container);
|
||||
|
||||
imageView.setImageResource(mPreviewResource);
|
||||
layout.setAspectRatio(mAspectRadio);
|
||||
|
||||
video.setOnClickListener(v -> {
|
||||
if (mMediaPlayer != null) {
|
||||
@@ -178,4 +187,9 @@ public class VideoPreference extends Preference {
|
||||
return mVideoPaused;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateAspectRatio() {
|
||||
mAspectRadio = mMediaPlayer.getVideoWidth() / (float)mMediaPlayer.getVideoHeight();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user