Skip to content

Commit 790600f

Browse files
author
Chris Bellew
committed
Added ability to hardcode client and server into a homescreen shortcut.
1 parent b006c98 commit 790600f

File tree

11 files changed

+515
-246
lines changed

11 files changed

+515
-246
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</intent-filter>
5252
</activity>
5353
<activity android:name=".ShortcutProviderActivity"
54-
android:theme="@android:style/Theme.NoDisplay">
54+
android:theme="@style/Theme.Transparent">
5555
<intent-filter>
5656
<action android:name="android.intent.action.CREATE_SHORTCUT" />
5757
<category android:name="android.intent.category.DEFAULT" />

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public Feedback(SharedPreferences prefs, Context ctx) {
2222
public void onInit(int i) {
2323
Logger.d("Feedback onInit");
2424
if(errorsTts != null)
25-
errorsTts.setLanguage(VoiceControlForPlexApplication.getVoiceLocale(mPrefs.getString(VoiceControlForPlexApplication.PREF_ERRORS_VOICE, "Locale.US")));
25+
errorsTts.setLanguage(VoiceControlForPlexApplication.getVoiceLocale(mPrefs.getString(VoiceControlForPlexApplication.Pref.ERRORS_VOICE, "Locale.US")));
2626
if(feedbackTts != null)
27-
feedbackTts.setLanguage(VoiceControlForPlexApplication.getVoiceLocale(mPrefs.getString(VoiceControlForPlexApplication.PREF_FEEDBACK_VOICE, "Locale.US")));
27+
feedbackTts.setLanguage(VoiceControlForPlexApplication.getVoiceLocale(mPrefs.getString(VoiceControlForPlexApplication.Pref.FEEDBACK_VOICE, "Locale.US")));
2828

2929
if(errorsQueue != null) {
3030
feedback(errorsQueue, true);

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class LocalScan {
3232
private Feedback feedback;
3333
private int serversScanned = 0;
3434
private Map<String, PlexClient> m_clients = new HashMap<String, PlexClient>();
35+
private PlexServer server;
3536

3637
public LocalScan(Context ctx, Class cls, SharedPreferences prefs, LocalScanHandler handler) {
3738
context = ctx;
@@ -47,6 +48,7 @@ public void searchForPlexServers() {
4748
VoiceControlForPlexApplication.showNoWifiDialog(context);
4849
return;
4950
}
51+
5052
searchDialog = new Dialog(context);
5153

5254
searchDialog.setContentView(R.layout.search_popup);
@@ -55,13 +57,17 @@ public void searchForPlexServers() {
5557
searchDialog.show();
5658

5759
Intent mServiceIntent = new Intent(context, GDMService.class);
60+
mServiceIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
5861
mServiceIntent.putExtra("ORIGIN", theClass.getSimpleName());
5962
mServiceIntent.putExtra("class", theClass);
6063
context.startService(mServiceIntent);
6164
}
6265

6366
public void showPlexServers() {
64-
Logger.d("servers: " + VoiceControlForPlexApplication.getPlexMediaServers().size());
67+
showPlexServers(null);
68+
}
69+
70+
public void showPlexServers(ConcurrentHashMap<String, PlexServer> servers) {
6571
if(searchDialog != null)
6672
searchDialog.dismiss();
6773
if(serverSelectDialog == null) {
@@ -72,7 +78,8 @@ public void showPlexServers() {
7278
serverSelectDialog.show();
7379

7480
final ListView serverListView = (ListView)serverSelectDialog.findViewById(R.id.serverListView);
75-
ConcurrentHashMap<String, PlexServer> servers = new ConcurrentHashMap<String, PlexServer>(VoiceControlForPlexApplication.getPlexMediaServers());
81+
if(servers == null)
82+
servers = new ConcurrentHashMap<String, PlexServer>(VoiceControlForPlexApplication.getPlexMediaServers());
7683
final PlexListAdapter adapter = new PlexListAdapter(context, PlexListAdapter.TYPE_SERVER);
7784
adapter.setServers(servers);
7885
serverListView.setAdapter(adapter);
@@ -89,21 +96,27 @@ public void onItemClick(AdapterView<?> parentAdapter, View view, int position, l
8996
}
9097

9198
public void getClients() {
99+
getClients(new PlexServer("none"));
100+
}
101+
102+
public void getClients(PlexServer _server) {
92103
if(!VoiceControlForPlexApplication.isWifiConnected(context)) {
93104
VoiceControlForPlexApplication.showNoWifiDialog(context);
94105
return;
95106
}
96-
PlexServer server = gson.fromJson(mPrefs.getString("Server", ""), PlexServer.class);
107+
server = _server;
108+
if(_server.name.equals("none"))
109+
server = gson.fromJson(mPrefs.getString("Server", ""), PlexServer.class);
97110
if(server == null || server.name.equals(context.getResources().getString(R.string.scan_all))) {
98111
scanForClients();
99112
} else {
100-
getClients(null);
113+
getClients(new MediaContainer());
101114
}
102115
}
103116

104117
public void getClients(MediaContainer mc) {
105118
PlexServer server = gson.fromJson(mPrefs.getString("Server", ""), PlexServer.class);
106-
if(mc != null) {
119+
if(mc.machineIdentifier != null) {
107120
server.machineIdentifier = mc.machineIdentifier;
108121
SharedPreferences.Editor mPrefsEditor = mPrefs.edit();
109122
mPrefsEditor.putString("Server", gson.toJson(server));
@@ -142,6 +155,9 @@ public void onClick(DialogInterface dialog, int id) {
142155
d.show();
143156
} else {
144157
Logger.d("Clients: " + clients.size());
158+
SharedPreferences.Editor mPrefsEditor = mPrefs.edit();
159+
mPrefsEditor.putString(VoiceControlForPlexApplication.Pref.SAVED_CLIENTS, gson.toJson(clients));
160+
mPrefsEditor.commit();
145161
showPlexClients(clients);
146162
}
147163
}

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import java.io.File;
44
import java.io.FileOutputStream;
55
import java.io.InputStream;
6-
import java.math.BigInteger;
7-
import java.security.SecureRandom;
86
import java.util.ArrayList;
97

108
import us.nineworlds.serenity.GDMReceiver;
119
import android.app.Activity;
1210
import android.app.AlertDialog;
1311
import android.app.Dialog;
14-
import android.app.PendingIntent;
1512
import android.content.BroadcastReceiver;
1613
import android.content.DialogInterface;
1714
import android.content.Intent;
@@ -23,7 +20,6 @@
2320
import android.net.Uri;
2421
import android.os.Bundle;
2522
import android.os.Environment;
26-
import android.speech.RecognizerIntent;
2723
import android.speech.tts.TextToSpeech;
2824
import android.support.v4.content.LocalBroadcastManager;
2925
import android.view.Menu;
@@ -54,8 +50,9 @@ public class MainActivity extends Activity implements TextToSpeech.OnInitListene
5450

5551
public final static String BUGSENSE_APIKEY = "879458d0";
5652

57-
private final static int VOICE_FEEDBACK_SELECTED = 0;
58-
private final static int TASKER_PROJECT_IMPORTED = 1;
53+
private final static int RESULT_VOICE_FEEDBACK_SELECTED = 0;
54+
private final static int RESULT_TASKER_PROJECT_IMPORTED = 1;
55+
private final static int RESULT_SHORTCUT_CREATED = 2;
5956

6057
private BroadcastReceiver gdmReceiver = new GDMReceiver();
6158

@@ -196,19 +193,17 @@ public void resumeChecked(View v) {
196193
@Override
197194
public void onActivityResult(int requestCode, int resultCode, Intent data) {
198195
super.onActivityResult(requestCode, resultCode, data);
199-
if (requestCode == VOICE_FEEDBACK_SELECTED) {
196+
if (requestCode == RESULT_VOICE_FEEDBACK_SELECTED) {
200197
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
201198
// success, create the TTS instance
202199
availableVoices = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
203-
TextToSpeech tts = new TextToSpeech(this, this);
204-
// errorsTts = new TextToSpeech(this, this);
205200
} else {
206201
// missing data, install it
207202
Intent installIntent = new Intent();
208203
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
209204
startActivity(installIntent);
210205
}
211-
} else if(requestCode == TASKER_PROJECT_IMPORTED) {
206+
} else if(requestCode == RESULT_TASKER_PROJECT_IMPORTED) {
212207
AlertDialog.Builder usageDialog = new AlertDialog.Builder(MainActivity.this);
213208
usageDialog.setTitle(R.string.import_tasker_project);
214209
usageDialog.setMessage(R.string.import_tasker_instructions);
@@ -234,6 +229,14 @@ public void onClick(DialogInterface dialog, int id) {
234229
}
235230
});
236231
usageDialog.show();
232+
} else if(requestCode == RESULT_SHORTCUT_CREATED) {
233+
if(resultCode == RESULT_OK) {
234+
235+
data.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
236+
sendBroadcast(data);
237+
238+
feedback.m(getString(R.string.shortcut_created));
239+
}
237240
}
238241
}
239242

@@ -322,7 +325,7 @@ public void onInit(int i) {
322325
if (engine != null)
323326
checkIntent.setPackage(engine);
324327
settingErrorFeedback = errors;
325-
startActivityForResult(checkIntent, VOICE_FEEDBACK_SELECTED);
328+
startActivityForResult(checkIntent, RESULT_VOICE_FEEDBACK_SELECTED);
326329
initMainWithServer();
327330
}
328331
}).setNegativeButton(R.string.feedback_toast, new DialogInterface.OnClickListener() {
@@ -337,6 +340,12 @@ public void onClick(DialogInterface dialog, int id) {
337340
}
338341

339342
public void installShortcut(MenuItem item) {
343+
Intent intent = new Intent(this, ShortcutProviderActivity.class);
344+
345+
startActivityForResult(intent, RESULT_SHORTCUT_CREATED);
346+
347+
// startActivity(intent);
348+
/*
340349
Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
341350
342351
Intent launchIntent = new Intent(this, ShortcutActivity.class);
@@ -348,6 +357,7 @@ public void installShortcut(MenuItem item) {
348357
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
349358
350359
sendBroadcast(intent);
360+
*/
351361
}
352362

353363
public void showAbout(MenuItem item) {
@@ -391,7 +401,7 @@ public void importTaskerProject(MenuItem item) {
391401
Intent i = new Intent();
392402
i.setAction(Intent.ACTION_VIEW);
393403
i.setDataAndType(Uri.fromFile(f), "text/xml");
394-
startActivityForResult(i, TASKER_PROJECT_IMPORTED);
404+
startActivityForResult(i, RESULT_TASKER_PROJECT_IMPORTED);
395405
} catch (Exception e) {
396406
Logger.d("Exception opening tasker profile xml: ");
397407
e.printStackTrace();
@@ -443,12 +453,14 @@ public void onNewIntent(Intent intent) {
443453
Logger.d("ON NEW INTENT IN MAINACTIVITY");
444454
String from = intent.getStringExtra("FROM");
445455
Logger.d("From: %s", from);
446-
if(from == null) {
447-
} else if(from.equals("GDMReceiver")) {
456+
if(intent.getAction().equals(VoiceControlForPlexApplication.Intent.GDMRECEIVE)) {
448457
Logger.d("Origin: " + intent.getStringExtra("ORIGIN"));
449458
String origin = intent.getStringExtra("ORIGIN") == null ? "" : intent.getStringExtra("ORIGIN");
450459
if(origin.equals("MainActivity")) {
451460
Logger.d("Got " + VoiceControlForPlexApplication.getPlexMediaServers().size() + " servers");
461+
Gson gson = new Gson();
462+
mPrefsEditor.putString(VoiceControlForPlexApplication.Pref.SAVED_SERVERS, gson.toJson(VoiceControlForPlexApplication.getPlexMediaServers()));
463+
mPrefsEditor.commit();
452464
if(VoiceControlForPlexApplication.getPlexMediaServers().size() > 0) {
453465
localScan.showPlexServers();
454466
} else {
@@ -597,7 +609,7 @@ public void finish() {
597609
@Override
598610
public void onInit(int status) {
599611
if (status == TextToSpeech.SUCCESS) {
600-
final String pref = settingErrorFeedback ? VoiceControlForPlexApplication.PREF_ERRORS_VOICE : VoiceControlForPlexApplication.PREF_FEEDBACK_VOICE;
612+
final String pref = settingErrorFeedback ? VoiceControlForPlexApplication.Pref.ERRORS_VOICE : VoiceControlForPlexApplication.Pref.FEEDBACK_VOICE;
601613
if (availableVoices != null) {
602614
AlertDialog.Builder adb = new AlertDialog.Builder(this);
603615
final CharSequence items[] = availableVoices.toArray(new CharSequence[availableVoices.size()]);

0 commit comments

Comments
 (0)