[Android] Reduce use of VLCApplication().getAppResources()

Geoffrey Métais git at videolan.org
Tue Feb 5 16:34:28 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb  5 15:40:51 2019 +0100| [a8ed2d978918f22ece6f180d453b43445b22ce90] | committer: Geoffrey Métais

Reduce use of VLCApplication().getAppResources()

> https://code.videolan.org/videolan/vlc-android/commit/a8ed2d978918f22ece6f180d453b43445b22ce90
---

 .../src/org/videolan/vlc/gui/DebugLogActivity.java |  3 +-
 .../src/org/videolan/vlc/gui/InfoActivity.java     |  2 +-
 .../src/org/videolan/vlc/gui/audio/AudioPlayer.kt  |  2 +-
 .../org/videolan/vlc/media/BrowserProvider.java    |  7 ++--
 .../src/org/videolan/vlc/util/VLCOptions.java      | 37 ++++++++--------------
 5 files changed, 20 insertions(+), 31 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/DebugLogActivity.java b/vlc-android/src/org/videolan/vlc/gui/DebugLogActivity.java
index f308d1224..4d229cff8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DebugLogActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DebugLogActivity.java
@@ -31,7 +31,6 @@ import com.google.android.material.snackbar.Snackbar;
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.DebugLogService;
 import org.videolan.vlc.R;
-import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.util.Permissions;
 
@@ -181,7 +180,7 @@ public class DebugLogActivity extends FragmentActivity implements DebugLogServic
     public void onSaved(boolean success, String path) {
         if (success) {
             Snackbar.make(mLogView, String.format(
-                    VLCApplication.getAppResources().getString(R.string.dump_logcat_success),
+                    getString(R.string.dump_logcat_success),
                     path), Snackbar.LENGTH_LONG).show();
         } else {
             UiTools.snacker(getWindow().getDecorView().findViewById(android.R.id.content), R.string.dump_logcat_failure);
diff --git a/vlc-android/src/org/videolan/vlc/gui/InfoActivity.java b/vlc-android/src/org/videolan/vlc/gui/InfoActivity.java
index d9be0cf4d..52e67857e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/InfoActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/InfoActivity.java
@@ -224,7 +224,7 @@ public class InfoActivity extends AudioPlayerContainerActivity implements View.O
                 files = newFiles;
                 filesLength = files.length;
             }
-            for (int i = 0; i<filesLength ; ++i){
+            if (files != null) for (int i = 0; i<filesLength ; ++i){
                 filename = Uri.decode(files[i]);
                 int index = filename.lastIndexOf('.');
                 if (index <= 0)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 2fa454bdd..ab3b0f61c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -170,7 +170,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher {
                 CTX_REMOVE_FROM_PLAYLIST -> view?.let {
                     val mw = playlistAdapter.getItem(position)
                     val cancelAction = Runnable { playlistModel.insertMedia(position, mw) }
-                    val message = String.format(VLCApplication.getAppResources().getString(R.string.remove_playlist_item), mw.title)
+                    val message = String.format(getString(R.string.remove_playlist_item), mw.title)
                     UiTools.snackerWithCancel(it, message, null, cancelAction)
                     playlistModel.remove(position)
                 }
diff --git a/vlc-android/src/org/videolan/vlc/media/BrowserProvider.java b/vlc-android/src/org/videolan/vlc/media/BrowserProvider.java
index a3a6d60fa..5ec1293f3 100644
--- a/vlc-android/src/org/videolan/vlc/media/BrowserProvider.java
+++ b/vlc-android/src/org/videolan/vlc/media/BrowserProvider.java
@@ -35,8 +35,6 @@ import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.net.Uri;
 import android.os.IBinder;
-import androidx.annotation.NonNull;
-import androidx.annotation.WorkerThread;
 import android.support.v4.media.MediaBrowserCompat;
 import android.support.v4.media.MediaDescriptionCompat;
 
@@ -57,6 +55,9 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Semaphore;
 
+import androidx.annotation.NonNull;
+import androidx.annotation.WorkerThread;
+
 
 public class BrowserProvider implements ExtensionManagerService.ExtensionManagerActivity {
 
@@ -92,7 +93,7 @@ public class BrowserProvider implements ExtensionManagerService.ExtensionManager
         List<MediaBrowserCompat.MediaItem> results = new ArrayList<>();
         MediaLibraryItem[] list = null;
         boolean limitSize = false;
-        Resources res = VLCApplication.getAppResources();
+        final Resources res = context.getResources();
 
         //Extensions
         if (parentId.startsWith(ExtensionsManager.EXTENSION_PREFIX)) {
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
index 6b303312b..b9142f301 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
@@ -69,13 +69,13 @@ public class VLCOptions {
             AUDIOTRACK_SESSION_ID = audioManager.generateAudioSessionId();
         }
 
-        ArrayList<String> options = new ArrayList<String>(50);
+        final ArrayList<String> options = new ArrayList<String>(50);
 
-        final boolean timeStrechingDefault = VLCApplication.getAppResources().getBoolean(R.bool.time_stretching_default);
+        final boolean timeStrechingDefault = context.getResources().getBoolean(R.bool.time_stretching_default);
         final boolean timeStreching = pref.getBoolean("enable_time_stretching_audio", timeStrechingDefault);
         final String subtitlesEncoding = pref.getString("subtitle_text_encoding", "");
         final boolean frameSkip = pref.getBoolean("enable_frame_skip", false);
-        String chroma = pref.getString("chroma_format", VLCApplication.getAppResources().getString(R.string.chroma_format_default));
+        final String chroma = pref.getString("chroma_format", context.getResources().getString(R.string.chroma_format_default));
         final boolean verboseMode = pref.getBoolean("enable_verbose_mode", true);
 
         int deblocking = -1;
@@ -84,10 +84,8 @@ public class VLCOptions {
         } catch (NumberFormatException ignored) {}
 
         int networkCaching = pref.getInt("network_caching_value", 0);
-        if (networkCaching > 60000)
-            networkCaching = 60000;
-        else if (networkCaching < 0)
-            networkCaching = 0;
+        if (networkCaching > 60000) networkCaching = 60000;
+        else if (networkCaching < 0) networkCaching = 0;
 
         final String freetypeRelFontsize = pref.getString("subtitles_size", "16");
         final boolean freetypeBold = pref.getBoolean("subtitles_bold", false);
@@ -107,8 +105,7 @@ public class VLCOptions {
         options.add(subtitlesEncoding);
         options.add("--stats");
         /* XXX: why can't the default be fine ? #7792 */
-        if (networkCaching > 0)
-            options.add("--network-caching=" + networkCaching);
+        if (networkCaching > 0) options.add("--network-caching=" + networkCaching);
         options.add("--android-display-chroma");
         options.add(chroma);
         options.add("--audio-resampler");
@@ -116,24 +113,17 @@ public class VLCOptions {
         options.add("--audiotrack-session-id=" + AUDIOTRACK_SESSION_ID);
 
         options.add("--freetype-rel-fontsize=" + freetypeRelFontsize);
-        if (freetypeBold)
-            options.add("--freetype-bold");
+        if (freetypeBold) options.add("--freetype-bold");
         options.add("--freetype-color=" + freetypeColor);
-        if (freetypeBackground)
-            options.add("--freetype-background-opacity=128");
-        else
-            options.add("--freetype-background-opacity=0");
-        if (opengl == 1)
-            options.add("--vout=gles2,none");
-        else if (opengl == 0)
-            options.add("--vout=android_display,none");
+        if (freetypeBackground) options.add("--freetype-background-opacity=128");
+        else options.add("--freetype-background-opacity=0");
+        if (opengl == 1) options.add("--vout=gles2,none");
+        else if (opengl == 0) options.add("--vout=android_display,none");
 
         /* Configure keystore */
         options.add("--keystore");
-        if (AndroidUtil.isMarshMallowOrLater)
-            options.add("file_crypt,none");
-        else
-            options.add("file_plaintext,none");
+        if (AndroidUtil.isMarshMallowOrLater) options.add("file_crypt,none");
+        else options.add("file_plaintext,none");
         options.add("--keystore-file");
         options.add(new File(context.getDir("keystore", Context.MODE_PRIVATE), "file").getAbsolutePath());
 
@@ -149,7 +139,6 @@ public class VLCOptions {
             final String optionsArray[] = customOptions.split("\\r?\\n", -1);
             if (!Util.isArrayEmpty(optionsArray)) Collections.addAll(options, optionsArray);
         }
-
         return options;
     }
 



More information about the Android mailing list