3
3
import java .io .File ;
4
4
import java .io .FileOutputStream ;
5
5
import java .io .InputStream ;
6
- import java .math .BigInteger ;
7
- import java .security .SecureRandom ;
8
6
import java .util .ArrayList ;
9
7
10
8
import us .nineworlds .serenity .GDMReceiver ;
11
9
import android .app .Activity ;
12
10
import android .app .AlertDialog ;
13
11
import android .app .Dialog ;
14
- import android .app .PendingIntent ;
15
12
import android .content .BroadcastReceiver ;
16
13
import android .content .DialogInterface ;
17
14
import android .content .Intent ;
23
20
import android .net .Uri ;
24
21
import android .os .Bundle ;
25
22
import android .os .Environment ;
26
- import android .speech .RecognizerIntent ;
27
23
import android .speech .tts .TextToSpeech ;
28
24
import android .support .v4 .content .LocalBroadcastManager ;
29
25
import android .view .Menu ;
@@ -54,8 +50,9 @@ public class MainActivity extends Activity implements TextToSpeech.OnInitListene
54
50
55
51
public final static String BUGSENSE_APIKEY = "879458d0" ;
56
52
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 ;
59
56
60
57
private BroadcastReceiver gdmReceiver = new GDMReceiver ();
61
58
@@ -196,19 +193,17 @@ public void resumeChecked(View v) {
196
193
@ Override
197
194
public void onActivityResult (int requestCode , int resultCode , Intent data ) {
198
195
super .onActivityResult (requestCode , resultCode , data );
199
- if (requestCode == VOICE_FEEDBACK_SELECTED ) {
196
+ if (requestCode == RESULT_VOICE_FEEDBACK_SELECTED ) {
200
197
if (resultCode == TextToSpeech .Engine .CHECK_VOICE_DATA_PASS ) {
201
198
// success, create the TTS instance
202
199
availableVoices = data .getStringArrayListExtra (TextToSpeech .Engine .EXTRA_AVAILABLE_VOICES );
203
- TextToSpeech tts = new TextToSpeech (this , this );
204
- // errorsTts = new TextToSpeech(this, this);
205
200
} else {
206
201
// missing data, install it
207
202
Intent installIntent = new Intent ();
208
203
installIntent .setAction (TextToSpeech .Engine .ACTION_INSTALL_TTS_DATA );
209
204
startActivity (installIntent );
210
205
}
211
- } else if (requestCode == TASKER_PROJECT_IMPORTED ) {
206
+ } else if (requestCode == RESULT_TASKER_PROJECT_IMPORTED ) {
212
207
AlertDialog .Builder usageDialog = new AlertDialog .Builder (MainActivity .this );
213
208
usageDialog .setTitle (R .string .import_tasker_project );
214
209
usageDialog .setMessage (R .string .import_tasker_instructions );
@@ -234,6 +229,14 @@ public void onClick(DialogInterface dialog, int id) {
234
229
}
235
230
});
236
231
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
+ }
237
240
}
238
241
}
239
242
@@ -322,7 +325,7 @@ public void onInit(int i) {
322
325
if (engine != null )
323
326
checkIntent .setPackage (engine );
324
327
settingErrorFeedback = errors ;
325
- startActivityForResult (checkIntent , VOICE_FEEDBACK_SELECTED );
328
+ startActivityForResult (checkIntent , RESULT_VOICE_FEEDBACK_SELECTED );
326
329
initMainWithServer ();
327
330
}
328
331
}).setNegativeButton (R .string .feedback_toast , new DialogInterface .OnClickListener () {
@@ -337,6 +340,12 @@ public void onClick(DialogInterface dialog, int id) {
337
340
}
338
341
339
342
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
+ /*
340
349
Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
341
350
342
351
Intent launchIntent = new Intent(this, ShortcutActivity.class);
@@ -348,6 +357,7 @@ public void installShortcut(MenuItem item) {
348
357
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
349
358
350
359
sendBroadcast(intent);
360
+ */
351
361
}
352
362
353
363
public void showAbout (MenuItem item ) {
@@ -391,7 +401,7 @@ public void importTaskerProject(MenuItem item) {
391
401
Intent i = new Intent ();
392
402
i .setAction (Intent .ACTION_VIEW );
393
403
i .setDataAndType (Uri .fromFile (f ), "text/xml" );
394
- startActivityForResult (i , TASKER_PROJECT_IMPORTED );
404
+ startActivityForResult (i , RESULT_TASKER_PROJECT_IMPORTED );
395
405
} catch (Exception e ) {
396
406
Logger .d ("Exception opening tasker profile xml: " );
397
407
e .printStackTrace ();
@@ -443,12 +453,14 @@ public void onNewIntent(Intent intent) {
443
453
Logger .d ("ON NEW INTENT IN MAINACTIVITY" );
444
454
String from = intent .getStringExtra ("FROM" );
445
455
Logger .d ("From: %s" , from );
446
- if (from == null ) {
447
- } else if (from .equals ("GDMReceiver" )) {
456
+ if (intent .getAction ().equals (VoiceControlForPlexApplication .Intent .GDMRECEIVE )) {
448
457
Logger .d ("Origin: " + intent .getStringExtra ("ORIGIN" ));
449
458
String origin = intent .getStringExtra ("ORIGIN" ) == null ? "" : intent .getStringExtra ("ORIGIN" );
450
459
if (origin .equals ("MainActivity" )) {
451
460
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 ();
452
464
if (VoiceControlForPlexApplication .getPlexMediaServers ().size () > 0 ) {
453
465
localScan .showPlexServers ();
454
466
} else {
@@ -597,7 +609,7 @@ public void finish() {
597
609
@ Override
598
610
public void onInit (int status ) {
599
611
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 ;
601
613
if (availableVoices != null ) {
602
614
AlertDialog .Builder adb = new AlertDialog .Builder (this );
603
615
final CharSequence items [] = availableVoices .toArray (new CharSequence [availableVoices .size ()]);
0 commit comments