Use default switch preference view if gesture animations video is not available.
am: 08886a0e91
Change-Id: I813a7b61b49c593d639621194d1e0929a2322605
This commit is contained in:
@@ -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"
|
||||||
|
@@ -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() {
|
||||||
|
Reference in New Issue
Block a user