[Android] Simplify code

Geoffrey Métais git at videolan.org
Thu May 7 16:29:25 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu May  7 15:08:54 2015 +0200| [1bec8f605c159346beb18a84da9b37fdbe28c39a] | committer: Geoffrey Métais

Simplify code

CID #1297087

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=1bec8f605c159346beb18a84da9b37fdbe28c39a
---

 .../vlc/gui/video/VideoPlayerActivity.java         |   39 ++++++++++----------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index d499dce..44535d2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -58,6 +58,7 @@ import android.support.v7.app.ActionBar;
 import android.support.v7.app.AlertDialog;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.PopupMenu;
+import android.text.TextUtils;
 import android.text.format.DateFormat;
 import android.util.DisplayMetrics;
 import android.util.Log;
@@ -2614,6 +2615,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
         String itemTitle = null;
         long intentPosition = -1; // position passed in by intent (ms)
         long mediaLength = 0l;
+        Intent intent = getIntent();
+        String action = intent.getAction();
+        Bundle extras = getIntent().getExtras();
 
         boolean wasPaused;
         /*
@@ -2631,13 +2635,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
         if (wasPaused)
             Log.d(TAG, "Video was previously paused, resuming in paused mode");
 
-        if (getIntent().getAction() != null
-                && getIntent().getAction().equals(Intent.ACTION_VIEW)) {
+        if (TextUtils.equals(action, Intent.ACTION_VIEW)) {
             /* Started from external application 'content' */
-            data = getIntent().getData();
-            if (data != null
-                    && data.getScheme() != null
-                    && data.getScheme().equals("content")) {
+            data = intent.getData();
+            if (data != null && TextUtils.equals(data.getScheme(), "content")) {
 
 
                 // Mail-based apps - download the stream to a temporary file and play it
@@ -2695,9 +2696,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
                     }
                 }
             } /* External application */
-            else if (getIntent().getDataString() != null) {
+            else if (intent.getDataString() != null) {
                 // Plain URI
-                mLocation = getIntent().getDataString();
+                mLocation = intent.getDataString();
                 // Remove VLC prefix if needed
                 if (mLocation.startsWith("vlc://")) {
                     mLocation = mLocation.substring(6);
@@ -2717,20 +2718,18 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
             }
 
             // Try to get the position
-            if(getIntent().getExtras() != null)
-                intentPosition = getIntent().getExtras().getLong("position", -1);
+            if(extras != null)
+                intentPosition = extras.getLong("position", -1);
         } /* ACTION_VIEW */
         /* Started from VideoListActivity */
-        else if(getIntent().getAction() != null
-                && getIntent().getAction().equals(PLAY_FROM_VIDEOGRID)
-                && getIntent().getExtras() != null) {
-            mLocation = getIntent().getExtras().getString(PLAY_EXTRA_ITEM_LOCATION);
-            itemTitle = getIntent().getExtras().getString(PLAY_EXTRA_ITEM_TITLE);
-            fromStart = getIntent().getExtras().getBoolean(PLAY_EXTRA_FROM_START);
-            if (getIntent().hasExtra(PLAY_EXTRA_SUBTITLES_LOCATION))
-                mSubtitleSelectedFiles.add(getIntent().getExtras().getString(PLAY_EXTRA_SUBTITLES_LOCATION));
+        else if(TextUtils.equals(action, PLAY_FROM_VIDEOGRID) && extras != null) {
+            mLocation = extras.getString(PLAY_EXTRA_ITEM_LOCATION);
+            itemTitle = extras.getString(PLAY_EXTRA_ITEM_TITLE);
+            fromStart = extras.getBoolean(PLAY_EXTRA_FROM_START);
+            if (intent.hasExtra(PLAY_EXTRA_SUBTITLES_LOCATION))
+                mSubtitleSelectedFiles.add(extras.getString(PLAY_EXTRA_SUBTITLES_LOCATION));
             mAskResume &= !fromStart;
-            openedPosition = getIntent().getExtras().getInt(PLAY_EXTRA_OPENED_POSITION, -1);
+            openedPosition = extras.getInt(PLAY_EXTRA_OPENED_POSITION, -1);
         }
 
         if (openedPosition != -1) {
@@ -2774,7 +2773,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
                 }
                 // Consume fromStart option after first use to prevent
                 // restarting again when playback is paused.
-                getIntent().putExtra(PLAY_EXTRA_FROM_START, false);
+                intent.putExtra(PLAY_EXTRA_FROM_START, false);
 
                 mLastAudioTrack = media.getAudioTrack();
                 mLastSpuTrack = media.getSpuTrack();



More information about the Android mailing list