Use default switch preference view if gesture animations video is not available. am: 08886a0e91

am: 38693095e3

Change-Id: I460835a7e0ba3737e530ae24f6a957ed5ac1e742
This commit is contained in:
Doris Ling
2016-09-23 19:10:06 +00:00
committed by android-build-merger
2 changed files with 12 additions and 12 deletions

View File

@@ -51,6 +51,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/gesture_animation_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/gestures_setting_background_color" android:background="@color/gestures_setting_background_color"
@@ -58,7 +59,6 @@
android:orientation="horizontal"> android:orientation="horizontal">
<com.android.settings.widget.AspectRatioFrameLayout <com.android.settings.widget.AspectRatioFrameLayout
android:id="@+id/gesture_animation_frame"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"

View File

@@ -58,7 +58,6 @@ public final class GesturePreference extends SwitchPreference implements
public GesturePreference(Context context, AttributeSet attrs) { public GesturePreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mContext = context; mContext = context;
setLayoutResource(R.layout.gesture_preference);
TypedArray attributes = context.getTheme().obtainStyledAttributes( TypedArray attributes = context.getTheme().obtainStyledAttributes(
attrs, attrs,
R.styleable.GesturePreference, R.styleable.GesturePreference,
@@ -70,7 +69,8 @@ public final class GesturePreference extends SwitchPreference implements
.appendPath(String.valueOf(animation)) .appendPath(String.valueOf(animation))
.build(); .build();
mMediaPlayer = MediaPlayer.create(mContext, mVideoPath); mMediaPlayer = MediaPlayer.create(mContext, mVideoPath);
if (mMediaPlayer != null) { if (mMediaPlayer != null && mMediaPlayer.getDuration() > 0) {
setLayoutResource(R.layout.gesture_preference);
mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() { mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
@Override @Override
public void onSeekComplete(MediaPlayer mp) { public void onSeekComplete(MediaPlayer mp) {
@@ -84,9 +84,8 @@ public final class GesturePreference extends SwitchPreference implements
mediaPlayer.setLooping(true); mediaPlayer.setLooping(true);
} }
}); });
mAnimationAvailable = true;
} }
mAnimationAvailable = true;
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Animation resource not found. Will not show animation."); Log.w(TAG, "Animation resource not found. Will not show animation.");
} finally { } finally {
@@ -97,15 +96,14 @@ public final class GesturePreference extends SwitchPreference implements
@Override @Override
public void onBindViewHolder(PreferenceViewHolder holder) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder); super.onBindViewHolder(holder);
if (!mAnimationAvailable) {
return;
}
final TextureView video = (TextureView) holder.findViewById(R.id.gesture_video); final TextureView video = (TextureView) holder.findViewById(R.id.gesture_video);
final ImageView imageView = (ImageView) holder.findViewById(R.id.gesture_image); final ImageView imageView = (ImageView) holder.findViewById(R.id.gesture_image);
final ImageView playButton = (ImageView) holder.findViewById(R.id.gesture_play_button); final ImageView playButton = (ImageView) holder.findViewById(R.id.gesture_play_button);
final View animationFrame = holder.findViewById(R.id.gesture_animation_frame);
if (!mAnimationAvailable) {
animationFrame.setVisibility(View.GONE);
return;
}
video.setOnClickListener(new View.OnClickListener() { video.setOnClickListener(new View.OnClickListener() {
@Override @Override
@@ -182,7 +180,9 @@ public final class GesturePreference extends SwitchPreference implements
} }
void loadPreview(LoaderManager manager, int id) { void loadPreview(LoaderManager manager, int id) {
Loader<Bitmap> loader = manager.initLoader(id, Bundle.EMPTY, this); if (mAnimationAvailable) {
Loader<Bitmap> loader = manager.initLoader(id, Bundle.EMPTY, this);
}
} }
void onViewVisible() { void onViewVisible() {