[Android] static shortcuts

Geoffrey Métais git at videolan.org
Tue Dec 19 13:23:14 CET 2017


vlc-android | branch: shortcuts | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 19 13:22:51 2017 +0100| [e2359c1d8b49cc9fb0a03396ed7b1522b8d6f32d] | committer: Geoffrey Métais

static shortcuts

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

 vlc-android/AndroidManifest.xml                    |  6 +-
 vlc-android/res/xml/shortcuts.xml                  | 66 ++++++++++++++++++++++
 .../src/org/videolan/vlc/gui/MainActivity.java     | 28 ++++++++-
 3 files changed, 96 insertions(+), 4 deletions(-)

diff --git a/vlc-android/AndroidManifest.xml b/vlc-android/AndroidManifest.xml
index 39af27937..9a3dc17ba 100644
--- a/vlc-android/AndroidManifest.xml
+++ b/vlc-android/AndroidManifest.xml
@@ -74,13 +74,16 @@
             android:name="android.max_aspect"
             android:value="2.1" />
         <activity
-            android:name=".StartActivity">
+            android:name=".StartActivity"
+            android:icon="@drawable/icon">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
                 <category android:name="android.intent.category.LAUNCHER" />
                 <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
             </intent-filter>
+            <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
+
 
             <!-- This filter captures protocols without type info -->
             <intent-filter>
@@ -427,7 +430,6 @@
         </activity>
         <activity
             android:name=".gui.MainActivity"
-            android:icon="@drawable/icon"
             android:label="@string/app_name"
             android:launchMode="singleTask"
             android:windowSoftInputMode="adjustPan"
diff --git a/vlc-android/res/xml/shortcuts.xml b/vlc-android/res/xml/shortcuts.xml
new file mode 100644
index 000000000..e8d31cdb7
--- /dev/null
+++ b/vlc-android/res/xml/shortcuts.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shortcuts xmlns:tools="http://schemas.android.com/tools"
+    xmlns:android="http://schemas.android.com/apk/res/android">
+    <shortcut
+        android:shortcutId="video"
+        android:enabled="true"
+        android:icon="@drawable/ic_menu_video"
+        android:shortcutShortLabel="@string/video"
+        android:shortcutLongLabel="@string/video"
+        tools:targetApi="n_mr1">
+        <intent
+            android:action="vlc.shortcut.video"
+            android:targetPackage="org.videolan.vlc.debug"
+            android:targetClass="org.videolan.vlc.gui.MainActivity" />
+        <!-- If your shortcut is associated with multiple intents, include them
+             here. The last intent in the list determines what the user sees when
+             they launch this shortcut. -->
+        <categories android:name="vlc.shortcut.category" />
+    </shortcut>
+    <shortcut
+        android:shortcutId="audio"
+        android:enabled="true"
+        android:icon="@drawable/ic_menu_audio"
+        android:shortcutShortLabel="@string/audio"
+        android:shortcutLongLabel="@string/audio" >
+        <intent
+            android:action="vlc.shortcut.audio"
+            android:targetPackage="org.videolan.vlc.debug"
+            android:targetClass="org.videolan.vlc.gui.MainActivity" />
+        <!-- If your shortcut is associated with multiple intents, include them
+             here. The last intent in the list determines what the user sees when
+             they launch this shortcut. -->
+        <categories android:name="vlc.shortcut.category" />
+    </shortcut>
+    <shortcut
+        android:shortcutId="browser"
+        android:enabled="true"
+        android:icon="@drawable/ic_menu_folder"
+        android:shortcutShortLabel="@string/directories"
+        android:shortcutLongLabel="@string/directories" >
+        <intent
+            android:action="vlc.shortcut.browser"
+            android:targetPackage="org.videolan.vlc.debug"
+            android:targetClass="org.videolan.vlc.gui.MainActivity" />
+        <!-- If your shortcut is associated with multiple intents, include them
+             here. The last intent in the list determines what the user sees when
+             they launch this shortcut. -->
+        <categories android:name="vlc.shortcut.category" />
+    </shortcut>
+    <shortcut
+        android:shortcutId="network"
+        android:enabled="true"
+        android:icon="@drawable/ic_menu_network"
+        android:shortcutShortLabel="@string/network_browsing"
+        android:shortcutLongLabel="@string/network_browsing" >
+        <intent
+            android:action="vlc.shortcut.network"
+            android:targetPackage="org.videolan.vlc.debug"
+            android:targetClass="org.videolan.vlc.gui.MainActivity" />
+        <!-- If your shortcut is associated with multiple intents, include them
+             here. The last intent in the list determines what the user sees when
+             they launch this shortcut. -->
+        <categories android:name="vlc.shortcut.category" />
+    </shortcut>
+    <!-- Specify more shortcuts here. -->
+</shortcuts>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 8b67e1d78..54d7d812e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -43,6 +43,7 @@ import android.support.v7.app.ActionBar;
 import android.support.v7.app.ActionBarDrawerToggle;
 import android.support.v7.view.ActionMode;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MenuItem;
 import android.view.View;
@@ -231,8 +232,10 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
     @Override
     protected void onStart() {
         super.onStart();
-        if (mCurrentFragment == null && !currentIdIsExtension())
+        if (mCurrentFragment == null && !currentIdIsExtension()) {
+            mCurrentFragmentId = getIdFromShortcut();
             showFragment(mCurrentFragmentId);
+        }
         if (mMediaLibrary.isInitiated()) {
             /* Load media items from database and storage */
             if (mScanNeeded && Permissions.canReadStorage())
@@ -245,6 +248,27 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
             createExtensionServiceConnection();
     }
 
+    private int getIdFromShortcut() {
+        if (!AndroidUtil.isNougatMr1OrLater) return 0;
+        final Intent intent = getIntent();
+        final String action = intent != null ? intent.getAction() : null;
+        if (!TextUtils.isEmpty(action)) {
+            switch (action) {
+                case "vlc.shortcut.video":
+                    return R.id.nav_video;
+                case "vlc.shortcut.audio":
+                    return R.id.nav_audio;
+                case "vlc.shortcut.browser":
+                    return R.id.nav_directories;
+                case "vlc.shortcut.network":
+                    return R.id.nav_network;
+                default:
+                    return 0;
+            }
+        }
+        return 0;
+    }
+
     @Override
     protected void onStop() {
         super.onStop();
@@ -710,7 +734,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
     }
 
     public boolean idIsExtension(int id) {
-        return id <= 100;
+        return id <= 100 && id > 0;
     }
 
     public int getCurrentFragmentId() {



More information about the Android mailing list