From ad46c9e0e08da6072c5342eb8ff361b5369c7174 Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
Date: Tue, 30 Apr 2013 18:09:52 +0900
Subject: [PATCH] Catch error while playing welcome video

Bug: 8159728
Change-Id: Ic8eea7993f12395d6eca6db8d5529803251a9fee
---
 java/res/layout/setup_welcome_video.xml               |  6 +++---
 .../inputmethod/latin/setup/SetupActivity.java        | 11 +++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/java/res/layout/setup_welcome_video.xml b/java/res/layout/setup_welcome_video.xml
index 09cef988bd..3cc5f21228 100644
--- a/java/res/layout/setup_welcome_video.xml
+++ b/java/res/layout/setup_welcome_video.xml
@@ -22,7 +22,9 @@
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:orientation="horizontal">
+        android:orientation="horizontal"
+        android:paddingTop="@dimen/setup_welcome_video_vertical_margin"
+        android:paddingBottom="@dimen/setup_welcome_video_vertical_margin">
         <View
             android:layout_weight="@integer/setup_welcome_video_left_padding_weight_in_screen"
             android:layout_width="0dp"
@@ -31,8 +33,6 @@
             android:id="@+id/setup_welcome_video"
             android:background="@color/setup_background"
             android:layout_weight="@integer/setup_welcome_video_weight_in_screen"
-            android:layout_marginTop="@dimen/setup_welcome_video_vertical_margin"
-            android:layout_marginBottom="@dimen/setup_welcome_video_vertical_margin"
             android:layout_width="0dp"
             android:layout_height="wrap_content" />
         <View
diff --git a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
index 651fea6ab2..044180bd60 100644
--- a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
+++ b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
@@ -26,6 +26,7 @@ import android.net.Uri;
 import android.os.Bundle;
 import android.os.Message;
 import android.provider.Settings;
+import android.util.Log;
 import android.view.View;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodManager;
@@ -44,6 +45,8 @@ import java.util.ArrayList;
 
 // TODO: Use Fragment to implement welcome screen and setup steps.
 public final class SetupActivity extends Activity implements View.OnClickListener {
+    private static final String TAG = SetupActivity.class.getSimpleName();
+
     private View mWelcomeScreen;
     private View mSetupScreen;
     private Uri mWelcomeVideoUri;
@@ -198,6 +201,14 @@ public final class SetupActivity extends Activity implements View.OnClickListene
                 mWelcomeVideoView.setBackgroundResource(0);
             }
         });
+        mWelcomeVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
+            @Override
+            public boolean onError(final MediaPlayer mp, final int what, final int extra) {
+                Log.e(TAG, "Playing welcome video causes error: what=" + what + " extra=" + extra);
+                mWelcomeVideoView.setVisibility(View.GONE);
+                return true;
+            }
+        });
 
         mActionStart = findViewById(R.id.setup_start_label);
         mActionStart.setOnClickListener(this);
-- 
GitLab