Skip to content

Commit 1737a7f

Browse files
author
Chris Bellew
committed
Added option to choose feedback style (voice/toast).
1 parent 466579e commit 1737a7f

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.atomjack.googlesearchplexcontrol"
4-
android:versionCode="1"
5-
android:versionName="1.0" >
4+
android:versionCode="2"
5+
android:versionName="1.1" >
66

77
<uses-permission android:name="com.mohammadag.googlesearchapi.permission.ACCESS_GGOGLE_SEARCH_API" />
88
<uses-permission android:name="android.permission.INTERNET" />

res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@
1818
<string name="menu_about">About</string>
1919
<string name="about_text">Voice Control for Plex Home Theater\n© 2013 Chris Bellew\nLicensed under GPLv3\n\nPlex Home Theater is copyright Plex, Inc.</string>
2020
<string name="menu_donate">Donate</string>
21+
<string name="feedback_voice">Voice</string>
22+
<string name="feedback_toast">Toast</string>
2123

2224
</resources>

src/com/atomjack/vcfpht/GoogleSearchReceiver.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ private void playSpecificEpisode() {
211211
if(videos.size() == 1) {
212212
playVideo(videos.get(0));
213213
} else {
214-
doToast("Sorry, I found more than one match. Try to be more specific?");
215-
GoogleSearchApi.speak(context, "Sorry, I found more than one match. Try to be more specific?");
214+
feedback("Sorry, I found more than one match. Try to be more specific?");
216215
}
217216
}
218217

@@ -257,8 +256,7 @@ private void doEpisodeSearch(String queryTerm, final String season, final String
257256
Log.v(MainActivity.TAG, "Found shows: " + shows.size());
258257

259258
if(shows.size() == 0) {
260-
GoogleSearchApi.speak(context, "Sorry, I couldn't find " + queryTerm);
261-
Log.e(TAG, "Sorry, I couldn't find " + queryTerm);
259+
feedback("Sorry, I couldn't find " + queryTerm);
262260
} else if(shows.size() == 1) {
263261
PlexDirectory show = shows.get(0);
264262
Log.v(TAG, "Show key: " + show.getKey());
@@ -288,8 +286,7 @@ public void onSuccess(String response) {
288286

289287
if(foundSeason == null) {
290288
Log.e(TAG, "Sorry, I couldn't find that season.");
291-
GoogleSearchApi.speak(context, "Sorry, I couldn't find that season.");
292-
doToast("Sorry, I couldn't find that season.");
289+
feedback("Sorry, I couldn't find that season.");
293290
} else {
294291
try {
295292
String url = "http://" + server.getIPAddress() + ":" + server.getPort() + "" + foundSeason.getKey();
@@ -318,8 +315,7 @@ public void onSuccess(String response) {
318315
}
319316
Log.v(TAG, "foundEpisode = " + foundEpisode);
320317
if(foundEpisode == false) {
321-
GoogleSearchApi.speak(context, "Sorry, I couldn't find that episode.");
322-
doToast("Sorry, I couldn't find that episode.");
318+
feedback("Sorry, I couldn't find that episode.");
323319
}
324320
}
325321
});
@@ -376,7 +372,7 @@ public void onSuccess(String response) {
376372

377373
private void onFinishedLatestEpisodeSearch(String queryTerm) {
378374
if(videos.size() == 0) {
379-
GoogleSearchApi.speak(context, "Sorry, I couldn't find " + queryTerm);
375+
feedback("Sorry, I couldn't find " + queryTerm);
380376
} else {
381377
// For now, just take the first one
382378
playVideo(videos.get(0));
@@ -432,19 +428,23 @@ private void onMovieSearchFinished(String queryTerm) {
432428

433429
if(chosenVideo != null) {
434430
Log.v(MainActivity.TAG, "Chosen video: " + chosenVideo.getTitle());
435-
GoogleSearchApi.speak(context, "Now watching " + chosenVideo.getTitle() + " on " + client.getName());
431+
feedback("Now watching " + chosenVideo.getTitle() + " on " + client.getName());
436432

437433
playVideo(chosenVideo);
438434
} else {
439435
Log.v(MainActivity.TAG, "Didn't find a video");
440-
GoogleSearchApi.speak(context, "Sorry, I couldn't find a video to play.");
441-
doToast("Sorry, I couldn't find a video to play.");
436+
feedback("Sorry, I couldn't find a video to play.");
442437
}
443438
}
444439

445-
private void doToast(String text) {
446-
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
440+
private void feedback(String text) {
441+
if(mPrefs.getInt("feedback", MainActivity.FEEDBACK_VOICE) == MainActivity.FEEDBACK_VOICE) {
442+
GoogleSearchApi.speak(context, text);
443+
} else {
444+
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
445+
}
447446
}
447+
448448
private void playVideo(PlexVideo video) {
449449
try {
450450
String url = "http://" + client.getHost() + ":" + client.getPort() + "/player/playback/playMedia?machineIdentifier=" + server.getMachineIdentifier() + "&key=" + video.getKey();

src/com/atomjack/vcfpht/MainActivity.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public class MainActivity extends Activity {
4444
public final static String TAG = "GoogleSearchPlexControl";
4545
public final static String SEARCH_TYPE = "com.atomjack.googlesearchplexcontrol.SEARCH_TYPE";
4646

47+
public final static int FEEDBACK_VOICE = 0;
48+
public final static int FEEDBACK_TOAST = 1;
49+
4750
Button serverSelectButton = null;
4851
Button clientSelectButton = null;
4952

@@ -83,9 +86,6 @@ public void onClick(View view) {
8386
searchForPlexServers();
8487
}
8588
});
86-
87-
88-
8989
} else {
9090
this.server = s;
9191
this.client = (PlexClient)gson.fromJson(mPrefs.getString("Client", ""), PlexClient.class);
@@ -129,7 +129,8 @@ private void initMainWithServer() {
129129

130130
MainSetting setting_data[] = new MainSetting[] {
131131
new MainSetting("Stream from the server", this.server.getName()),
132-
new MainSetting("To the client", this.client.getName())
132+
new MainSetting("To the client", this.client.getName()),
133+
new MainSetting("Feedback", mPrefs.getInt("feedback", 0) == FEEDBACK_VOICE ? "Voice" : "Toast")
133134
};
134135

135136
MainListAdapter adapter = new MainListAdapter(this, R.layout.main_setting_item_row, setting_data);
@@ -145,6 +146,8 @@ public void onItemClick(AdapterView<?> adapter, View view, int position,
145146
searchForPlexServers();
146147
} else if(position == 1) {
147148
getClients();
149+
} else if(position == 2) {
150+
selectFeedback();
148151
}
149152
}
150153
});
@@ -154,6 +157,29 @@ public void onItemClick(AdapterView<?> adapter, View view, int position,
154157
resumeCheckbox.setChecked(mPrefs.getBoolean("resume", false));
155158
}
156159

160+
private void selectFeedback() {
161+
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
162+
builder.setTitle("Feedback");
163+
builder.setCancelable(false)
164+
.setPositiveButton(R.string.feedback_voice, new DialogInterface.OnClickListener() {
165+
public void onClick(DialogInterface dialog, int id) {
166+
mPrefsEditor.putInt("feedback", FEEDBACK_VOICE);
167+
mPrefsEditor.commit();
168+
initMainWithServer();
169+
// dialog.cancel();
170+
}
171+
}).setNegativeButton(R.string.feedback_toast, new DialogInterface.OnClickListener() {
172+
public void onClick(DialogInterface dialog, int id) {
173+
mPrefsEditor.putInt("feedback", FEEDBACK_TOAST);
174+
mPrefsEditor.commit();
175+
initMainWithServer();
176+
// dialog.cancel();
177+
}
178+
});
179+
AlertDialog d = builder.create();
180+
d.show();
181+
}
182+
157183
private void searchForPlexServers() {
158184
searchDialog = new Dialog(this);
159185

0 commit comments

Comments
 (0)