From f5cecb08fbdde6506e14f72a2ea5c2c6a0efac2f Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Fri, 17 Jun 2016 11:22:59 -0700 Subject: [PATCH] Add play icon to the gesture settings videos. 1. Add a play button icon to show on top of the gesture videos when the video is not playing. 2. Dynamically split the gesture video and description text in half instead of using the hard coded value. 3. Hide the video view if animation is not available. 4. Delay removing the animation preview till the video starts drawing on the surface texture. Bug: 28565958 Change-Id: I8b954828d16286014404172d29efa4d2e00432b3 --- res/drawable/ic_gesture_play_button.xml | 25 +++++++++ res/layout/gesture_preference.xml | 22 +++++--- res/values/dimens.xml | 6 +-- .../settings/gestures/GesturePreference.java | 53 +++++++++++++------ 4 files changed, 79 insertions(+), 27 deletions(-) create mode 100644 res/drawable/ic_gesture_play_button.xml diff --git a/res/drawable/ic_gesture_play_button.xml b/res/drawable/ic_gesture_play_button.xml new file mode 100644 index 00000000000..e2fa6e0ceaf --- /dev/null +++ b/res/drawable/ic_gesture_play_button.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/res/layout/gesture_preference.xml b/res/layout/gesture_preference.xml index 9a388c592b9..5f413fe95a3 100644 --- a/res/layout/gesture_preference.xml +++ b/res/layout/gesture_preference.xml @@ -26,7 +26,6 @@ + android:id="@+id/gesture_animation_frame" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1"> + + 16dp - 56dp - 206dp - 206dp - 206dp - 206dp 20dp + 36dp diff --git a/src/com/android/settings/gestures/GesturePreference.java b/src/com/android/settings/gestures/GesturePreference.java index 1541aece094..ba7ce75f8dd 100644 --- a/src/com/android/settings/gestures/GesturePreference.java +++ b/src/com/android/settings/gestures/GesturePreference.java @@ -14,6 +14,7 @@ package com.android.settings.gestures; +import android.content.ContentResolver; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Bitmap; @@ -29,6 +30,7 @@ import android.view.View; import android.view.Surface; import android.view.TextureView; import android.widget.ImageView; +import android.widget.LinearLayout; import android.util.AttributeSet; import android.util.Log; @@ -39,12 +41,14 @@ import com.android.settings.R; * This shows the title and description of the gesture along with an animation showing how to do * the gesture */ -public class GesturePreference extends SwitchPreference { +public final class GesturePreference extends SwitchPreference { private static final String TAG = "GesturePreference"; + private final Context mContext; + private Uri mVideoPath; - private Context mContext; private MediaPlayer mMediaPlayer; private MediaMetadataRetriever mMediaMetadata; + private boolean animationAvailable; public GesturePreference(Context context, AttributeSet attrs) { super(context, attrs); @@ -56,12 +60,15 @@ public class GesturePreference extends SwitchPreference { 0, 0); try { int animation = attributes.getResourceId(R.styleable.GesturePreference_animation, 0); - mVideoPath = Uri.parse( - "android.resource://" + context.getPackageName() + "/" + animation); + mVideoPath = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) + .authority(context.getPackageName()) + .appendPath(String.valueOf(animation)) + .build(); mMediaMetadata = new MediaMetadataRetriever(); mMediaMetadata.setDataSource(mContext, mVideoPath); + animationAvailable = true; } catch (Exception e) { - // resource not available, show blank view + Log.w(TAG, "Animation resource not found. Will not show animation."); } finally { attributes.recycle(); } @@ -72,6 +79,21 @@ public class GesturePreference extends SwitchPreference { super.onBindViewHolder(holder); final TextureView video = (TextureView) holder.findViewById(R.id.gesture_video); final ImageView imageView = (ImageView) holder.findViewById(R.id.gesture_image); + final ImageView playButton = (ImageView) holder.findViewById(R.id.gesture_play_button); + final View detailView = holder.findViewById(R.id.gesture_detail); + final View animationFrame = holder.findViewById(R.id.gesture_animation_frame); + + if (!animationAvailable) { + animationFrame.setVisibility(View.GONE); + return; + } + + Bitmap bitmap = mMediaMetadata.getFrameAtTime(0); + if (bitmap != null) { + imageView.setImageDrawable(new BitmapDrawable(bitmap)); + } + imageView.setVisibility(View.VISIBLE); + playButton.setVisibility(View.VISIBLE); video.setOnTouchListener(new View.OnTouchListener() { @Override @@ -80,9 +102,10 @@ public class GesturePreference extends SwitchPreference { if (mMediaPlayer != null) { if (mMediaPlayer.isPlaying()) { mMediaPlayer.pause(); + playButton.setVisibility(View.VISIBLE); } else { mMediaPlayer.start(); - imageView.setVisibility(View.GONE); + playButton.setVisibility(View.GONE); } } return true; @@ -93,7 +116,9 @@ public class GesturePreference extends SwitchPreference { video.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { @Override - public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) { + public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, + int height) { + animationFrame.setLayoutParams(new LinearLayout.LayoutParams(width, width)); mMediaPlayer = MediaPlayer.create(mContext, mVideoPath); if (mMediaPlayer != null) { mMediaPlayer.setSurface(new Surface(surfaceTexture)); @@ -107,7 +132,8 @@ public class GesturePreference extends SwitchPreference { } @Override - public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) { + public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, + int height) { } @Override @@ -123,17 +149,12 @@ public class GesturePreference extends SwitchPreference { @Override public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) { + if (mMediaPlayer.isPlaying() && imageView.getVisibility() == View.VISIBLE) { + imageView.setVisibility(View.GONE); + } } }); - if (mMediaPlayer == null) { - Bitmap bitmap = mMediaMetadata.getFrameAtTime(0); - if (bitmap != null) { - imageView.setImageDrawable(new BitmapDrawable(bitmap)); - } - imageView.setVisibility(View.VISIBLE); - } - } }