Add static preview images to gesture settings.
Set the animation preview image view to the newly added preview image instead of loading it from animation video. Test: manual - launch gesture settings and visually check the animation preview images. Bug: 31636637 Change-Id: If25a0e3501bea0c6343326a143d665ec79e3d7c7
This commit is contained in:
@@ -14,18 +14,12 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.app.LoaderManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Loader;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.media.MediaMetadataRetriever;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.View;
|
||||
@@ -36,15 +30,13 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.utils.AsyncLoader;
|
||||
|
||||
/**
|
||||
* Preference item for a gesture with a switch to signify if it should be enabled.
|
||||
* This shows the title and description of the gesture along with an animation showing how to do
|
||||
* the gesture
|
||||
*/
|
||||
public final class GesturePreference extends SwitchPreference implements
|
||||
LoaderManager.LoaderCallbacks<Bitmap> {
|
||||
public final class GesturePreference extends SwitchPreference {
|
||||
private static final String TAG = "GesturePreference";
|
||||
private final Context mContext;
|
||||
|
||||
@@ -53,7 +45,7 @@ public final class GesturePreference extends SwitchPreference implements
|
||||
private boolean mAnimationAvailable;
|
||||
private boolean mVideoReady;
|
||||
private boolean mScrolling;
|
||||
private BitmapDrawable mPreviewImage;
|
||||
private int mPreviewResource;
|
||||
|
||||
public GesturePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@@ -71,6 +63,10 @@ public final class GesturePreference extends SwitchPreference implements
|
||||
mMediaPlayer = MediaPlayer.create(mContext, mVideoPath);
|
||||
if (mMediaPlayer != null && mMediaPlayer.getDuration() > 0) {
|
||||
setLayoutResource(R.layout.gesture_preference);
|
||||
|
||||
mPreviewResource = attributes.getResourceId(
|
||||
R.styleable.GesturePreference_preview, 0);
|
||||
|
||||
mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
|
||||
@Override
|
||||
public void onSeekComplete(MediaPlayer mp) {
|
||||
@@ -103,6 +99,7 @@ public final class GesturePreference extends SwitchPreference implements
|
||||
|
||||
final TextureView video = (TextureView) holder.findViewById(R.id.gesture_video);
|
||||
final ImageView imageView = (ImageView) holder.findViewById(R.id.gesture_image);
|
||||
imageView.setImageResource(mPreviewResource);
|
||||
final ImageView playButton = (ImageView) holder.findViewById(R.id.gesture_play_button);
|
||||
|
||||
video.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -138,9 +135,6 @@ public final class GesturePreference extends SwitchPreference implements
|
||||
|
||||
@Override
|
||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
|
||||
if (mPreviewImage != null && imageView.getDrawable() == null) {
|
||||
imageView.setImageDrawable(mPreviewImage);
|
||||
}
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
return false;
|
||||
}
|
||||
@@ -159,10 +153,6 @@ public final class GesturePreference extends SwitchPreference implements
|
||||
}
|
||||
});
|
||||
|
||||
if (mPreviewImage != null) {
|
||||
imageView.setImageDrawable(mPreviewImage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,63 +169,10 @@ public final class GesturePreference extends SwitchPreference implements
|
||||
mScrolling = scrolling;
|
||||
}
|
||||
|
||||
void loadPreview(LoaderManager manager, int id) {
|
||||
if (mAnimationAvailable) {
|
||||
Loader<Bitmap> loader = manager.initLoader(id, Bundle.EMPTY, this);
|
||||
}
|
||||
}
|
||||
|
||||
void onViewVisible() {
|
||||
if (mVideoReady && mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.seekTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PreviewRetriever extends AsyncLoader<Bitmap> {
|
||||
private Uri mVideoPath;
|
||||
|
||||
public PreviewRetriever(Context context, Uri videoPath) {
|
||||
super(context);
|
||||
mVideoPath = videoPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap loadInBackground() {
|
||||
MediaMetadataRetriever mediaMetadata = new MediaMetadataRetriever();
|
||||
try {
|
||||
mediaMetadata.setDataSource(getContext(), mVideoPath);
|
||||
return mediaMetadata.getFrameAtTime(0);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Unable to get animation preview.");
|
||||
} finally {
|
||||
mediaMetadata.release();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDiscardResult(final Bitmap result) {
|
||||
if (result != null && !result.isRecycled()) {
|
||||
result.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Bitmap> onCreateLoader(int id, Bundle args) {
|
||||
return new PreviewRetriever(mContext, mVideoPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(final Loader<Bitmap> loader, final Bitmap bitmap) {
|
||||
if (bitmap != null) {
|
||||
mPreviewImage = new BitmapDrawable(mContext.getResources(), bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Bitmap> loader) {
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user