[Android] Factorize code in Device initialization

Geoffrey Métais git at videolan.org
Mon Sep 4 10:14:34 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Sep  4 10:01:36 2017 +0200| [4c1c411059f3ecacce1bf7c26a436789006463d8] | committer: Geoffrey Métais

Factorize code in Device initialization

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

 vlc-android/src/org/videolan/vlc/util/AndroidDevices.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
index 31e32a683..663f178c4 100644
--- a/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
+++ b/vlc-android/src/org/videolan/vlc/util/AndroidDevices.java
@@ -60,7 +60,7 @@ import java.util.StringTokenizer;
 public class AndroidDevices {
     public final static String TAG = "VLC/UiTools/AndroidDevices";
     public final static String EXTERNAL_PUBLIC_DIRECTORY = Environment.getExternalStorageDirectory().getPath();
-    public static final File SUBTITLES_DIRECTORY = new File(VLCApplication.getAppContext().getExternalFilesDir(null), "subs");
+    public static final File SUBTITLES_DIRECTORY;
 
     public final static boolean isPhone;
     public final static boolean hasCombBar;
@@ -76,21 +76,23 @@ public class AndroidDevices {
 
     static {
         final HashSet<String> devicesWithoutNavBar = new HashSet<>();
+        final Context ctx = VLCApplication.getAppContext();
         devicesWithoutNavBar.add("HTC One V");
         devicesWithoutNavBar.add("HTC One S");
         devicesWithoutNavBar.add("HTC One X");
         devicesWithoutNavBar.add("HTC One XL");
         hasNavBar = AndroidUtil.isICSOrLater && !devicesWithoutNavBar.contains(android.os.Build.MODEL);
-        final PackageManager pm = VLCApplication.getAppContext().getPackageManager();
+        final PackageManager pm = ctx.getPackageManager();
         hasTsp = pm.hasSystemFeature("android.hardware.touchscreen");
         isAndroidTv = pm.hasSystemFeature("android.software.leanback");
         isChromeBook = pm.hasSystemFeature("org.chromium.arc.device_management");
         hasPiP = AndroidUtil.isOOrLater || AndroidUtil.isNougatOrLater && isAndroidTv;
-        isPhone = ((TelephonyManager) VLCApplication.getAppContext().getSystemService(Context.TELEPHONY_SERVICE))
+        isPhone = ((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE))
                 .getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
         // hasCombBar test if device has Combined Bar : only for tablet with Honeycomb or ICS
         hasCombBar = !AndroidDevices.isPhone && AndroidUtil.isHoneycombOrLater
                 && AndroidUtil.isJellyBeanMR1OrLater;
+        SUBTITLES_DIRECTORY = new File(ctx.getExternalFilesDir(null), "subs");
     }
 
     public static boolean hasExternalStorage() {



More information about the Android mailing list