Locale-specific attract loop video files

Depending on user's configuration/locale we may show a different video.
The name of the file is now defined in retail_demo_video_file_name resource.

Bug: 30818319
Change-Id: I1143d2d38b160101db543b01e85db5950886e04f
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 59d782f..6e87646 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -18,8 +18,11 @@
     <!-- Title of the application. Used as a fallback for TalkBack when activity label is not specified (an accessibility service). [CHAR LIMIT=NONE] -->
     <string name="retail_demo_title">Retail demo</string>
 
+    <!-- File name of the demo video in the preloads/demo folder. [DO NOT TRANSLATE] -->
+    <string name="retail_demo_video_file_name">retail_demo.mp4</string>
+
     <!-- URL where the retail demo video can be downloaded from. [DO NOT TRANSLATE] -->
-    <string name="retail_demo_video_download_url" translatable="false"></string>
+    <string name="retail_demo_video_download_url"></string>
 
     <!-- The component name for the demo overlay app. [DO NOT TRANSLATE] -->
     <string name="demo_overlay_app_component" translatable="false"></string>
diff --git a/src/com/android/retaildemo/DemoPlayer.java b/src/com/android/retaildemo/DemoPlayer.java
index 3ebdfc8..320c17a 100644
--- a/src/com/android/retaildemo/DemoPlayer.java
+++ b/src/com/android/retaildemo/DemoPlayer.java
@@ -55,10 +55,6 @@
     private static final String TAG = "DemoPlayer";
     private static final boolean DEBUG = false;
 
-    private static final String VIDEO_FILE_NAME = "retail_demo.mp4";
-    static final String PRELOADED_VIDEO_FILE = Environment.getDataPreloadsDemoDirectory()
-            + File.separator + VIDEO_FILE_NAME;
-
     /**
      * We save the real elapsed time to serve as an indication for downloading the demo video
      * for the next device boot. The device could boot fast at times and could result in
@@ -81,6 +77,7 @@
     private Handler mHandler;
     private boolean mReadyToTap;
     private SettingsObserver mSettingsObserver;
+    private File mPreloadedVideoFile;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -94,7 +91,10 @@
 
         mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
         mHandler = new Handler();
-        mDownloadPath = getObbDir().getPath() + File.separator + VIDEO_FILE_NAME;
+        final String preloadedFileName = getString(R.string.retail_demo_video_file_name);
+        mPreloadedVideoFile = new File(Environment.getDataPreloadsDemoDirectory(),
+                preloadedFileName);
+        mDownloadPath = getObbDir().getPath() + File.separator + preloadedFileName;
         mVideoView = (VideoView) findViewById(R.id.video_content);
 
         // Start playing the video when it is ready
@@ -109,11 +109,11 @@
         mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
             @Override
             public boolean onError(MediaPlayer mp, int what, int extra) {
-                if (mUsingDownloadedVideo && new File(PRELOADED_VIDEO_FILE).exists()) {
+                if (mUsingDownloadedVideo && mPreloadedVideoFile.exists()) {
                     if (DEBUG) Log.d(TAG, "Error using the downloaded video, "
-                            + "falling back to the preloaded video at " + PRELOADED_VIDEO_FILE);
+                            + "falling back to the preloaded video at " + mPreloadedVideoFile);
                     mUsingDownloadedVideo = false;
-                    setVideoPath(PRELOADED_VIDEO_FILE);
+                    setVideoPath(mPreloadedVideoFile.getPath());
                     // And delete the downloaded video so that we don't try to use it
                     // again next time.
                     new File(mDownloadPath).delete();
@@ -159,9 +159,9 @@
             if (DEBUG) Log.d(TAG, "Using the already existing video at " + mDownloadPath);
             setVideoPath(mDownloadPath);
             isVideoSet = true;
-        } else if (new File(PRELOADED_VIDEO_FILE).exists()) {
-            if (DEBUG) Log.d(TAG, "Using the preloaded video at " + PRELOADED_VIDEO_FILE);
-            setVideoPath(PRELOADED_VIDEO_FILE);
+        } else if (mPreloadedVideoFile.exists()) {
+            if (DEBUG) Log.d(TAG, "Using the preloaded video at " + mPreloadedVideoFile);
+            setVideoPath(mPreloadedVideoFile.getPath());
             isVideoSet = true;
         }
 
@@ -181,7 +181,7 @@
             }
             return;
         }
-        new DownloadVideoTask(this, mDownloadPath, this).run();
+        new DownloadVideoTask(this, mDownloadPath, mPreloadedVideoFile, this).run();
     }
 
     private boolean checkIfDownloadingAllowed() {
diff --git a/src/com/android/retaildemo/DownloadVideoTask.java b/src/com/android/retaildemo/DownloadVideoTask.java
index fd211aa..7b664c7 100644
--- a/src/com/android/retaildemo/DownloadVideoTask.java
+++ b/src/com/android/retaildemo/DownloadVideoTask.java
@@ -67,12 +67,14 @@
     private long mVideoUpdateDownloadId;
     private String mDownloadedPath;
     private boolean mVideoAlreadySet;
+    private File mPreloadVideoFile;
 
-    public DownloadVideoTask(Context context, String downloadPath, ResultListener listener) {
+    public DownloadVideoTask(Context context, String downloadPath, File preloadVideoFile,
+            ResultListener listener) {
         mContext = context;
         mDownloadFile = new File(downloadPath);
         mListener = listener;
-
+        mPreloadVideoFile = preloadVideoFile;
         mDlm = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
         mDownloadUrl = mContext.getString(R.string.retail_demo_video_download_url);
     }
@@ -88,11 +90,11 @@
         mHandler = new ThreadHandler(thread.getLooper());
 
         mVideoAlreadySet =
-                mDownloadFile.exists() || new File(DemoPlayer.PRELOADED_VIDEO_FILE).exists();
+                mDownloadFile.exists() || mPreloadVideoFile.exists();
         // If file already exists, no need to download it again.
         if (mVideoAlreadySet) {
             if (DEBUG) Log.d(TAG, "Video already exists at either " + mDownloadFile.getPath()
-                    + " or " + DemoPlayer.PRELOADED_VIDEO_FILE + ", checking for an update... ");
+                    + " or " + mPreloadVideoFile + ", checking for an update... ");
             mHandler.sendMessage(mHandler.obtainMessage(MSG_CHECK_FOR_UPDATE));
         } else {
             if (!isConnectedToNetwork()) {