Skip to content

Commit 1d15994

Browse files
author
Chris Bellew
committed
Added shortcut capability.
1 parent 43e9f4e commit 1d15994

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

Voice Control For Plex/src/main/AndroidManifest.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,20 @@
4949
<action android:name="android.intent.action.SEND" />
5050
</intent-filter>
5151
</activity>
52-
52+
<activity android:name=".ShortcutProviderActivity"
53+
android:theme="@android:style/Theme.NoDisplay">
54+
<intent-filter>
55+
<action android:name="android.intent.action.CREATE_SHORTCUT" />
56+
<category android:name="android.intent.category.DEFAULT" />
57+
</intent-filter>
58+
</activity>
59+
<activity android:name=".ShortcutActivity"
60+
android:theme="@android:style/Theme.NoDisplay"
61+
android:launchMode="singleInstance">
62+
<intent-filter>
63+
<action android:name="android.intent.action.MAIN"/>
64+
</intent-filter>
65+
</activity>
5366
<service
5467
android:name=".GDMService"
5568
android:exported="false" />

Voice Control For Plex/src/main/java/com/atomjack/vcfp/ListenerWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] ap
3535
listenerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "voice.recognition.test");
3636
listenerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
3737
listenerIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, resultsPendingIntent);
38-
listenerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice Control for Plex is listening");
38+
listenerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, context.getResources().getString(R.string.voice_prompt));
3939

4040
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, listenerIntent, 0);
4141
remoteViews.setOnClickPendingIntent(R.id.listenButton, pendingIntent);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.atomjack.vcfp;
2+
3+
import android.app.Activity;
4+
import android.app.PendingIntent;
5+
import android.content.Intent;
6+
import android.net.Uri;
7+
import android.os.Bundle;
8+
import android.speech.RecognizerIntent;
9+
10+
import java.math.BigInteger;
11+
import java.security.SecureRandom;
12+
13+
public class ShortcutActivity extends Activity {
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
Intent serviceIntent = new Intent(getApplicationContext(), PlexSearch.class);
18+
SecureRandom random = new SecureRandom();
19+
serviceIntent.setData(Uri.parse(new BigInteger(130, random).toString(32)));
20+
PendingIntent resultsPendingIntent = PendingIntent.getService(getApplicationContext(), 0, serviceIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
21+
22+
Intent listenerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
23+
listenerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
24+
listenerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "voice.recognition.test");
25+
listenerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
26+
listenerIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, resultsPendingIntent);
27+
listenerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, getResources().getString(R.string.voice_prompt));
28+
29+
startActivity(listenerIntent);
30+
finish();
31+
}
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.atomjack.vcfp;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
7+
public class ShortcutProviderActivity extends Activity {
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
12+
13+
Intent sendIntent = new Intent();
14+
15+
Intent launchIntent = new Intent(this, ShortcutActivity.class);
16+
17+
sendIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
18+
sendIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "");
19+
sendIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
20+
21+
setResult(RESULT_OK, sendIntent);
22+
finish();
23+
}
24+
}

Voice Control For Plex/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@
6262
<string name="changelog_close">Close</string>
6363
<string name="no_wifi_connection">No WiFi Connection</string>
6464
<string name="no_wifi_connection_message">A WiFi connection is required. Please check your WiFi settings and try again.</string>
65+
<string name="voice_prompt">Voice Control for Plex is listening</string>
6566
</resources>

0 commit comments

Comments
 (0)