Instantiating background image of preview video in
Magnification Gesture screen using ImageView, also set GlobalLayoutListener to adjust its position. Bug: 27992162 Bug: 27901691 Change-Id: I9563eb2776bcde3d7edeb4a420a9b3c02481baf8
This commit is contained in:
@@ -15,13 +15,22 @@
|
||||
-->
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/video_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/video_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/accessibility_screen_magnification_background"
|
||||
android:scaleType="fitXY"
|
||||
android:adjustViewBounds="true" />
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/video"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@id/video_background"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
</RelativeLayout>
|
@@ -30,20 +30,24 @@ import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.MediaController;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.RelativeLayout.LayoutParams;
|
||||
import android.widget.VideoView;
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.ToggleSwitch;
|
||||
import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
|
||||
|
||||
public class ToggleScreenMagnificationPreferenceFragment
|
||||
extends ToggleFeaturePreferenceFragment {
|
||||
public class ToggleScreenMagnificationPreferenceFragment extends ToggleFeaturePreferenceFragment {
|
||||
|
||||
protected class VideoPreference extends Preference {
|
||||
private ImageView mVideoBackgroundView;
|
||||
private OnGlobalLayoutListener mLayoutListener;
|
||||
|
||||
public VideoPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -51,40 +55,19 @@ public class ToggleScreenMagnificationPreferenceFragment
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
Resources res = getPrefContext().getResources();
|
||||
final int backgroundAssetWidth = res.getDimensionPixelSize(
|
||||
R.dimen.screen_magnification_video_background_width);
|
||||
final int videoAssetWidth = res
|
||||
.getDimensionPixelSize(R.dimen.screen_magnification_video_width);
|
||||
final int videoAssetHeight = res
|
||||
.getDimensionPixelSize(R.dimen.screen_magnification_video_height);
|
||||
final int videoAssetMarginTop = res.getDimensionPixelSize(
|
||||
R.dimen.screen_magnification_video_margin_top);
|
||||
view.setDividerAllowedAbove(false);
|
||||
view.setDividerAllowedBelow(false);
|
||||
final RelativeLayout background =
|
||||
(RelativeLayout) view.findViewById(R.id.video_background);
|
||||
VideoView videoView = (VideoView) view.findViewById(R.id.video);
|
||||
|
||||
// Hacky adjustment for using VideoView in recycle view and positioning
|
||||
// it on the background image
|
||||
Resources res = getPrefContext().getResources();
|
||||
final int backgroundWidth = res.getDimensionPixelSize(
|
||||
R.dimen.screen_magnification_video_background_width);
|
||||
final int backgroundHeight = res.getDimensionPixelSize(
|
||||
R.dimen.screen_magnification_video_background_height);
|
||||
final int videoWidth = res.getDimensionPixelSize(
|
||||
R.dimen.screen_magnification_video_width);
|
||||
final int videoHeight = res.getDimensionPixelSize(
|
||||
R.dimen.screen_magnification_video_height);
|
||||
final int videoMarginTop = res.getDimensionPixelSize(
|
||||
R.dimen.screen_magnification_video_margin_top);
|
||||
final int screenWidth = getScreenWidth(getPrefContext());
|
||||
|
||||
RelativeLayout.LayoutParams videoLp = new RelativeLayout.LayoutParams(
|
||||
screenWidth * videoWidth / backgroundWidth,
|
||||
screenWidth * videoHeight / backgroundWidth);
|
||||
videoLp.setMargins(0, screenWidth * videoMarginTop / backgroundWidth, 0, 0);
|
||||
videoView.setLayoutParams(videoLp);
|
||||
|
||||
RelativeLayout.LayoutParams backgroundLp = new RelativeLayout.LayoutParams(
|
||||
screenWidth,
|
||||
screenWidth * backgroundHeight / backgroundWidth);
|
||||
background.setLayoutParams(backgroundLp);
|
||||
background.setBackgroundResource(
|
||||
R.drawable.accessibility_screen_magnification_background);
|
||||
background.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
mVideoBackgroundView = (ImageView) view.findViewById(R.id.video_background);
|
||||
final VideoView videoView = (VideoView) view.findViewById(R.id.video);
|
||||
|
||||
// Loop the video.
|
||||
videoView.setOnPreparedListener(new OnPreparedListener() {
|
||||
@@ -100,7 +83,31 @@ public class ToggleScreenMagnificationPreferenceFragment
|
||||
R.raw.accessibility_screen_magnification)));
|
||||
// Make sure video controls (e.g. for pausing) are not displayed.
|
||||
videoView.setMediaController(null);
|
||||
videoView.start();
|
||||
|
||||
// LayoutListener for adjusting the position of the VideoView on the background image.
|
||||
mLayoutListener = new OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
final int backgroundViewWidth = mVideoBackgroundView.getWidth();
|
||||
|
||||
LayoutParams videoLp = (LayoutParams) videoView.getLayoutParams();
|
||||
videoLp.width = videoAssetWidth * backgroundViewWidth / backgroundAssetWidth;
|
||||
videoLp.height = videoAssetHeight * backgroundViewWidth / backgroundAssetWidth;
|
||||
videoLp.setMargins(0,
|
||||
videoAssetMarginTop * backgroundViewWidth / backgroundAssetWidth, 0, 0);
|
||||
videoView.setLayoutParams(videoLp);
|
||||
videoView.invalidate();
|
||||
videoView.start();
|
||||
}
|
||||
};
|
||||
|
||||
mVideoBackgroundView.getViewTreeObserver().addOnGlobalLayoutListener(mLayoutListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareForRemoval() {
|
||||
mVideoBackgroundView.getViewTreeObserver()
|
||||
.removeOnGlobalLayoutListener(mLayoutListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user