[Android] Make voice search available for TV

Geoffrey Métais git at videolan.org
Thu Mar 2 17:46:25 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar  2 17:08:51 2017 +0100| [73ce52094946dcd1150120cff9a2b69be11ef56c] | committer: Geoffrey Métais

Make voice search available for TV

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

 vlc-android/AndroidManifest.xml                    | 22 ++++++++++-----------
 .../src/org/videolan/vlc/StartActivity.java        | 23 ++++++++++++++++------
 .../org/videolan/vlc/gui/tv/SearchActivity.java    | 22 +++++++++++++--------
 3 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/vlc-android/AndroidManifest.xml b/vlc-android/AndroidManifest.xml
index d5a4728..528a3ab 100644
--- a/vlc-android/AndroidManifest.xml
+++ b/vlc-android/AndroidManifest.xml
@@ -428,6 +428,16 @@
                 <data android:pathPattern=".*\\.xspf" />
                 <data android:pathPattern=".*\\.XSPF" />
             </intent-filter>
+            <!-- Search -->
+            <intent-filter>
+                <action android:name="android.intent.action.SEARCH" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+            <meta-data android:name="android.app.searchable"
+                android:resource="@xml/searchable"/>
         </activity>
         <activity
             android:name=".gui.MainActivity"
@@ -452,17 +462,7 @@
             android:theme="@style/Theme.VLC"/>
         <activity
             android:name=".gui.SearchActivity"
-            android:theme="@style/Theme.VLC">
-            <intent-filter>
-                <action android:name="android.intent.action.SEARCH" />
-            </intent-filter>
-            <intent-filter>
-                <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
-                <category android:name="android.intent.category.DEFAULT"/>
-            </intent-filter>
-            <meta-data android:name="android.app.searchable"
-                android:resource="@xml/searchable"/>
-        </activity>
+            android:theme="@style/Theme.VLC"/>
         <activity
             android:name=".gui.browser.FilePickerActivity"
             android:theme="@style/Theme.VLC.PickerDialog"/>
diff --git a/vlc-android/src/org/videolan/vlc/StartActivity.java b/vlc-android/src/org/videolan/vlc/StartActivity.java
index 1a64499..2572cb4 100644
--- a/vlc-android/src/org/videolan/vlc/StartActivity.java
+++ b/vlc-android/src/org/videolan/vlc/StartActivity.java
@@ -28,11 +28,11 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
-import android.text.TextUtils;
 
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.gui.AudioPlayerContainerActivity;
 import org.videolan.vlc.gui.MainActivity;
+import org.videolan.vlc.gui.SearchActivity;
 import org.videolan.vlc.gui.tv.MainTvActivity;
 import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
 import org.videolan.vlc.gui.video.VideoPlayerActivity;
@@ -51,6 +51,18 @@ public class StartActivity extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        Intent intent = getIntent();
+        boolean tv =  showTvUi();
+        String action = intent != null ? intent.getAction(): null;
+
+        // Route search query
+        if (Intent.ACTION_SEARCH.equals(action) || "com.google.android.gms.actions.SEARCH_ACTION".equals(action)) {
+                startActivity(intent.setClass(this, tv ? org.videolan.vlc.gui.tv.SearchActivity.class : SearchActivity.class));
+            finish();
+            return;
+        }
+
+        // Start application
         /* Get the current version from package */
         SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
         int currentVersionNumber = BuildConfig.VERSION_CODE;
@@ -61,8 +73,7 @@ public class StartActivity extends Activity {
         if (upgrade)
             settings.edit().putInt(PREF_FIRST_RUN, currentVersionNumber).apply();
 
-        Intent intent = getIntent();
-        if (intent != null && TextUtils.equals(intent.getAction(), Intent.ACTION_VIEW) && intent.getData() != null) {
+        if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null) {
             intent.setDataAndType(intent.getData(), intent.getType());
             if (intent.getType() != null && intent.getType().startsWith("video"))
                 startActivity(intent.setClass(this, VideoPlayerActivity.class));
@@ -74,10 +85,10 @@ public class StartActivity extends Activity {
                 serviceInent.putExtra(EXTRA_UPGRADE, upgrade);
                 startService(serviceInent);
             }
-            if (intent != null && TextUtils.equals(intent.getAction(), AudioPlayerContainerActivity.ACTION_SHOW_PLAYER))
-                startActivity(new Intent(this, showTvUi() ? AudioPlayerActivity.class : MainActivity.class));
+            if (AudioPlayerContainerActivity.ACTION_SHOW_PLAYER.equals(action))
+                startActivity(new Intent(this, tv ? AudioPlayerActivity.class : MainActivity.class));
             else {
-                Intent activityIntent = new Intent(this, showTvUi() ? MainTvActivity.class : MainActivity.class);
+                Intent activityIntent = new Intent(this, tv ? MainTvActivity.class : MainActivity.class);
                 if (firstRun)
                     activityIntent.putExtra(EXTRA_FIRST_RUN, true);
                 if (upgrade)
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
index 0e4a595..dfc085b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/SearchActivity.java
@@ -22,6 +22,8 @@ package org.videolan.vlc.gui.tv;
 
 import android.annotation.TargetApi;
 import android.app.Activity;
+import android.app.SearchManager;
+import android.content.Intent;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.v17.leanback.widget.SpeechRecognitionCallback;
@@ -41,15 +43,19 @@ public class SearchActivity extends Activity {
 
         mFragment = (SearchFragment) getFragmentManager()
                 .findFragmentById(R.id.search_fragment);
+        Intent intent = getIntent();
+        if (Intent.ACTION_SEARCH.equals(intent.getAction()) || "com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())) {
+            mFragment.onQueryTextSubmit(intent.getStringExtra(SearchManager.QUERY));
+        } else {
+            SpeechRecognitionCallback speechRecognitionCallback = new SpeechRecognitionCallback() {
 
-        SpeechRecognitionCallback speechRecognitionCallback = new SpeechRecognitionCallback() {
-
-            @Override
-            public void recognizeSpeech() {
-                startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
-            }
-        };
-        mFragment.setSpeechRecognitionCallback(speechRecognitionCallback);
+                @Override
+                public void recognizeSpeech() {
+                    startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
+                }
+            };
+            mFragment.setSpeechRecognitionCallback(speechRecognitionCallback);
+        }
     }
 
     @Override



More information about the Android mailing list