Browse Source

static shortcuts

shortcuts
Geoffrey Métais 9 years ago
parent
commit
e2359c1d8b
  1. 6
      vlc-android/AndroidManifest.xml
  2. 66
      vlc-android/res/xml/shortcuts.xml
  3. 28
      vlc-android/src/org/videolan/vlc/gui/MainActivity.java

6
vlc-android/AndroidManifest.xml

@ -74,13 +74,16 @@
android:name="android.max_aspect" android:name="android.max_aspect"
android:value="2.1" /> android:value="2.1" />
<activity <activity
android:name=".StartActivity"> android:name=".StartActivity"
android:icon="@drawable/icon">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter> </intent-filter>
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
<!-- This filter captures protocols without type info --> <!-- This filter captures protocols without type info -->
<intent-filter> <intent-filter>
@ -427,7 +430,6 @@
</activity> </activity>
<activity <activity
android:name=".gui.MainActivity" android:name=".gui.MainActivity"
android:icon="@drawable/icon"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTask" android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan" android:windowSoftInputMode="adjustPan"

66
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>

28
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.app.ActionBarDrawerToggle;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -231,8 +232,10 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
if (mCurrentFragment == null && !currentIdIsExtension()) if (mCurrentFragment == null && !currentIdIsExtension()) {
mCurrentFragmentId = getIdFromShortcut();
showFragment(mCurrentFragmentId); showFragment(mCurrentFragmentId);
}
if (mMediaLibrary.isInitiated()) { if (mMediaLibrary.isInitiated()) {
/* Load media items from database and storage */ /* Load media items from database and storage */
if (mScanNeeded && Permissions.canReadStorage()) if (mScanNeeded && Permissions.canReadStorage())
@ -245,6 +248,27 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
createExtensionServiceConnection(); 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 @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
@ -710,7 +734,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
} }
public boolean idIsExtension(int id) { public boolean idIsExtension(int id) {
return id <= 100; return id <= 100 && id > 0;
} }
public int getCurrentFragmentId() { public int getCurrentFragmentId() {

Loading…
Cancel
Save