Skip to content

Commit 66ac945

Browse files
author
Chris Bellew
committed
Added feedback options and redesigned layout of language selector.
1 parent 62d9284 commit 66ac945

File tree

12 files changed

+294
-99
lines changed

12 files changed

+294
-99
lines changed

mobile/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: 'com.android.application'
22

33
repositories {
4+
jcenter()
45
maven {
56
url "https://mint.splunk.com/gradle/"
67
}
@@ -140,4 +141,5 @@ dependencies {
140141
compile project(':shared')
141142
compile files('libs/org.apache.http.legacy.jar')
142143
compile 'de.hdodenhof:circleimageview:2.0.0'
144+
compile 'org.honorato.multistatetogglebutton:multistatetogglebutton:0.2.0'
143145
}

mobile/src/main/java/com/atomjack/vcfp/activities/MainActivity.java

Lines changed: 127 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.os.Bundle;
2323
import android.os.Environment;
2424
import android.os.Handler;
25+
import android.speech.tts.TextToSpeech;
2526
import android.support.design.widget.NavigationView;
2627
import android.support.v4.app.ActivityCompat;
2728
import android.support.v4.app.Fragment;
@@ -105,6 +106,9 @@
105106
import com.google.gson.GsonBuilder;
106107
import com.splunk.mint.Mint;
107108

109+
import org.honorato.multistatetogglebutton.MultiStateToggleButton;
110+
import org.honorato.multistatetogglebutton.ToggleButton;
111+
108112
import java.io.BufferedReader;
109113
import java.io.ByteArrayInputStream;
110114
import java.io.File;
@@ -115,6 +119,7 @@
115119
import java.io.Writer;
116120
import java.net.SocketTimeoutException;
117121
import java.util.ArrayList;
122+
import java.util.Collections;
118123
import java.util.Date;
119124
import java.util.HashMap;
120125
import java.util.List;
@@ -126,7 +131,8 @@
126131

127132
public class MainActivity extends AppCompatActivity
128133
implements VoiceControlForPlexApplication.NetworkChangeListener,
129-
ActivityListener {
134+
ActivityListener,
135+
TextToSpeech.OnInitListener{
130136

131137
public final static int RESULT_VOICE_FEEDBACK_SELECTED = 0;
132138
public final static int RESULT_TASKER_PROJECT_IMPORTED = 1;
@@ -140,6 +146,10 @@ public class MainActivity extends AppCompatActivity
140146

141147
public final static String BUGSENSE_APIKEY = "879458d0";
142148

149+
private ArrayList<String> availableVoices;
150+
private boolean settingErrorFeedback = false;
151+
private TextToSpeech tts;
152+
143153
private DrawerLayout mDrawer;
144154
private Toolbar toolbar;
145155
private NavigationView navigationViewMain;
@@ -542,7 +552,20 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
542552
Logger.d("onActivityResult: %d, %d", requestCode, resultCode);
543553
// Pass on the activity result to the helper for handling
544554
if (VoiceControlForPlexApplication.getInstance().getIabHelper() == null || !VoiceControlForPlexApplication.getInstance().getIabHelper().handleActivityResult(requestCode, resultCode, data)) {
545-
if (requestCode == RESULT_SHORTCUT_CREATED) {
555+
if (requestCode == RESULT_VOICE_FEEDBACK_SELECTED) {
556+
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
557+
// success, create the TTS instance
558+
availableVoices = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
559+
Collections.sort(availableVoices);
560+
// Need this or else voice selection won't show up:
561+
tts = new TextToSpeech(this, this);
562+
} else {
563+
// missing data, install it
564+
Intent installIntent = new Intent();
565+
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
566+
startActivity(installIntent);
567+
}
568+
} else if (requestCode == RESULT_SHORTCUT_CREATED) {
546569
if (resultCode == RESULT_OK) {
547570
data.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
548571
sendBroadcast(data);
@@ -890,7 +913,7 @@ protected void onNewIntent(Intent intent) {
890913
setServer(PlexServer.getScanAllServer());
891914
}
892915
prefs.put(Preferences.SAVED_SERVERS, gsonWrite.toJson(VoiceControlForPlexApplication.servers));
893-
Logger.d("doing first time setup: %s", doingFirstTimeSetup);
916+
Logger.d("doing first time setup: %s, client scan finished: %s", doingFirstTimeSetup, firstTimeSetupClientScanFinished);
894917
if(doingFirstTimeSetup) {
895918
firstTimeSetupServerScanFinished = true;
896919
if(firstTimeSetupClientScanFinished)
@@ -913,16 +936,17 @@ protected void onNewIntent(Intent intent) {
913936
}
914937
}
915938
prefs.put(Preferences.SAVED_CLIENTS, gsonWrite.toJson(VoiceControlForPlexApplication.clients));
916-
if (doingFirstTimeSetup) {
917-
firstTimeSetupClientScanFinished = true;
918-
if(firstTimeSetupServerScanFinished)
919-
onFirstTimeScanFinished();
920-
}
939+
}
940+
if (doingFirstTimeSetup) {
941+
firstTimeSetupClientScanFinished = true;
942+
if(firstTimeSetupServerScanFinished)
943+
onFirstTimeScanFinished();
921944
}
922945
if(onClientRefreshFinished != null) {
923946
onClientRefreshFinished.run();
924947
}
925948

949+
926950
} else if(intent.getAction().equals(ACTION_SHOW_NOW_PLAYING)) {
927951
handleShowNowPlayingIntent(intent);
928952
} else if(intent.getAction() != null && intent.getAction().equals(com.atomjack.shared.Intent.SHOW_WEAR_PURCHASE)) {
@@ -959,6 +983,7 @@ else if(castPlayerManager.isSubscribed())
959983

960984
// This is called after first time setup client & server scan is done.
961985
private void onFirstTimeScanFinished() {
986+
Logger.d("first time scan finished");
962987
doingFirstTimeSetup = false;
963988
prefs.put(Preferences.FIRST_TIME_SETUP_COMPLETED, true);
964989
if(alertDialog != null)
@@ -1540,6 +1565,54 @@ public void donate(MenuItem item) {
15401565
startActivity(intent);
15411566
}
15421567

1568+
public void setFeedback(MenuItem item) {
1569+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
1570+
View view = getLayoutInflater().inflate(R.layout.popup_feedback, null);
1571+
builder.setView(view);
1572+
final AlertDialog dialog = builder.create();
1573+
MultiStateToggleButton feedbackToggleButton = (MultiStateToggleButton)view.findViewById(R.id.feedbackToggleButton);
1574+
boolean[] v = new boolean[2];
1575+
v[prefs.get(Preferences.FEEDBACK, 1) == 0 ? 0 : 1] = true;
1576+
feedbackToggleButton.setStates(v);
1577+
feedbackToggleButton.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() {
1578+
@Override
1579+
public void onValueChanged(int value) {
1580+
prefs.put(Preferences.FEEDBACK, value);
1581+
if(value == 0) {
1582+
onVoiceFeedbackSelected(false);
1583+
}
1584+
}
1585+
});
1586+
MultiStateToggleButton errorsToggleButton = (MultiStateToggleButton)view.findViewById(R.id.errorsToggleButton);
1587+
v = new boolean[2];
1588+
v[prefs.get(Preferences.ERRORS, 1) == 0 ? 0 : 1] = true;
1589+
errorsToggleButton.setStates(v);
1590+
errorsToggleButton.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() {
1591+
@Override
1592+
public void onValueChanged(int value) {
1593+
prefs.put(Preferences.ERRORS, value);
1594+
if(value == 0) {
1595+
onVoiceFeedbackSelected(true);
1596+
}
1597+
}
1598+
});
1599+
dialog.show();
1600+
}
1601+
1602+
private void onVoiceFeedbackSelected(boolean errors) {
1603+
Intent checkIntent = new Intent();
1604+
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
1605+
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
1606+
@Override
1607+
public void onInit(int i) {}
1608+
});
1609+
String engine = tts.getDefaultEngine();
1610+
if (engine != null)
1611+
checkIntent.setPackage(engine);
1612+
settingErrorFeedback = errors;
1613+
startActivityForResult(checkIntent, RESULT_VOICE_FEEDBACK_SELECTED);
1614+
}
1615+
15431616
public void installTasker(MenuItem item) {
15441617
openAppInPlayStore("net.dinglisch.android.taskerm");
15451618
}
@@ -2237,5 +2310,51 @@ public void onSuccess(Bitmap bitmap) {
22372310
}
22382311
}
22392312

2313+
@Override
2314+
public void onInit(int status) {
2315+
if (status == TextToSpeech.SUCCESS) {
2316+
final String pref = settingErrorFeedback ? Preferences.ERRORS_VOICE : Preferences.FEEDBACK_VOICE;
2317+
if (availableVoices != null) {
2318+
AlertDialog.Builder adb = new AlertDialog.Builder(this);
2319+
View view = getLayoutInflater().inflate(R.layout.popup_language_selector, null);
2320+
adb.setView(view);
2321+
final CharSequence items[] = availableVoices.toArray(new CharSequence[availableVoices.size()]);
2322+
int selectedVoice = -1;
2323+
String v = VoiceControlForPlexApplication.getInstance().prefs.get(pref, "Locale.US");
2324+
if (availableVoices.indexOf(v) > -1)
2325+
selectedVoice = availableVoices.indexOf(v);
2326+
2327+
final AlertDialog dialog = adb.create();
2328+
Button languageSelectorCancelButton = (Button)view.findViewById(R.id.languageSelectorCancelButton);
2329+
languageSelectorCancelButton.setOnClickListener(new View.OnClickListener() {
2330+
@Override
2331+
public void onClick(View v) {
2332+
dialog.cancel();
2333+
}
2334+
});
22402335

2336+
RadioGroup languageSelectorRadioGroup = (RadioGroup)view.findViewById(R.id.languageSelectorRadioGroup);
2337+
LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
2338+
RadioGroup.LayoutParams.WRAP_CONTENT,
2339+
RadioGroup.LayoutParams.WRAP_CONTENT);
2340+
for(int i=0;i<items.length;i++) {
2341+
RadioButton button = (RadioButton)getLayoutInflater().inflate(R.layout.popup_chromecast_video_options_button, null);
2342+
button.setText(items[i]);
2343+
button.setId(i);
2344+
languageSelectorRadioGroup.addView(button, layoutParams);
2345+
}
2346+
languageSelectorRadioGroup.check(selectedVoice);
2347+
languageSelectorRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
2348+
@Override
2349+
public void onCheckedChanged(RadioGroup group, int checkedId) {
2350+
VoiceControlForPlexApplication.getInstance().prefs.put(pref, items[checkedId].toString());
2351+
dialog.dismiss();
2352+
}
2353+
});
2354+
dialog.show();
2355+
} else {
2356+
VoiceControlForPlexApplication.getInstance().prefs.put(pref, "Locale.US");
2357+
}
2358+
}
2359+
}
22412360
}

mobile/src/main/java/com/atomjack/vcfp/activities/OldMainActivity.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,10 @@ public void logout(MenuItem item) {
550550
}
551551

552552
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.SAVED_SERVERS, gsonWrite.toJson(VoiceControlForPlexApplication.servers));
553-
MenuItem loginItem = menu.findItem(R.id.menu_login);
554-
loginItem.setVisible(true);
555-
MenuItem logoutItem = menu.findItem(R.id.menu_logout);
556-
logoutItem.setVisible(false);
553+
// MenuItem loginItem = menu.findItem(R.id.menu_login);
554+
// loginItem.setVisible(true);
555+
// MenuItem logoutItem = menu.findItem(R.id.menu_logout);
556+
// logoutItem.setVisible(false);
557557

558558
feedback.m(R.string.logged_out);
559559
}
@@ -598,8 +598,8 @@ public void onFailure(Throwable error) {
598598
}
599599

600600
private void switchLogin() {
601-
menu.findItem(R.id.menu_login).setVisible(!menu.findItem(R.id.menu_login).isVisible());
602-
menu.findItem(R.id.menu_logout).setVisible(!menu.findItem(R.id.menu_logout).isVisible());
601+
// menu.findItem(R.id.menu_login).setVisible(!menu.findItem(R.id.menu_login).isVisible());
602+
// menu.findItem(R.id.menu_logout).setVisible(!menu.findItem(R.id.menu_logout).isVisible());
603603
}
604604

605605
private void showPin(final Pin pin) {
@@ -746,10 +746,10 @@ public void onSuccess(PlexUser user) {
746746
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.PLEX_USERNAME, user.username);
747747
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.PLEX_EMAIL, user.email);
748748
feedback.m(R.string.logged_in);
749-
MenuItem loginItem = menu.findItem(R.id.menu_login);
750-
loginItem.setVisible(false);
751-
MenuItem logoutItem = menu.findItem(R.id.menu_logout);
752-
logoutItem.setVisible(true);
749+
// MenuItem loginItem = menu.findItem(R.id.menu_login);
750+
// loginItem.setVisible(false);
751+
// MenuItem logoutItem = menu.findItem(R.id.menu_logout);
752+
// logoutItem.setVisible(true);
753753
alertD.cancel();
754754
}
755755

@@ -1003,7 +1003,7 @@ private void saveSettings() {
10031003
@Override
10041004
public boolean onCreateOptionsMenu(Menu _menu) {
10051005
super.onCreateOptionsMenu(_menu);
1006-
getMenuInflater().inflate(R.menu.menu_main, _menu);
1006+
// getMenuInflater().inflate(R.menu.menu_main, _menu);
10071007
menu = _menu;
10081008

10091009
if(plexSubscription.isSubscribed() || castPlayerManager.isSubscribed())
@@ -1018,8 +1018,8 @@ public boolean onCreateOptionsMenu(Menu _menu) {
10181018
}
10191019

10201020
if(authToken != null) {
1021-
_menu.findItem(R.id.menu_login).setVisible(false);
1022-
_menu.findItem(R.id.menu_logout).setVisible(true);
1021+
// _menu.findItem(R.id.menu_login).setVisible(false);
1022+
// _menu.findItem(R.id.menu_logout).setVisible(true);
10231023
}
10241024
if (!hasValidAutoVoice() && !hasValidUtter()) {
10251025
_menu.findItem(R.id.menu_tasker_import).setVisible(false);
424 Bytes
Loading
291 Bytes
Loading
503 Bytes
Loading
735 Bytes
Loading
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:background="@color/settings_popup_background"
7+
android:padding="20dp">
8+
9+
<TextView
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:textAppearance="?android:attr/textAppearanceLarge"
13+
android:text="@string/help_feedback"
14+
android:id="@+id/textView18"
15+
android:textColor="@color/white"/>
16+
<!--
17+
<RelativeLayout
18+
android:layout_width="match_parent"
19+
android:layout_height="match_parent">
20+
21+
<TextView
22+
android:layout_width="wrap_content"
23+
android:layout_height="wrap_content"
24+
android:textAppearance="?android:attr/textAppearanceLarge"
25+
android:text="Large Text"
26+
android:id="@+id/textView21"/>
27+
28+
<Button
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:text="New Button"
32+
android:id="@+id/button2"
33+
android:layout_alignParentTop="true"
34+
android:layout_alignParentRight="true"
35+
android:layout_alignParentEnd="true"/>
36+
</RelativeLayout>
37+
-->
38+
<RelativeLayout
39+
android:layout_width="match_parent"
40+
android:layout_height="match_parent"
41+
android:layout_marginTop="20dp">
42+
43+
<TextView
44+
android:layout_width="wrap_content"
45+
android:layout_height="wrap_content"
46+
android:textAppearance="?android:attr/textAppearanceMedium"
47+
android:text="@string/feedback"
48+
android:id="@+id/textView19"
49+
android:textColor="@color/white"
50+
android:layout_centerVertical="true"
51+
android:layout_alignParentLeft="true"
52+
android:layout_alignParentStart="true"/>
53+
54+
<org.honorato.multistatetogglebutton.MultiStateToggleButton
55+
xmlns:mstb="http://schemas.android.com/apk/res-auto"
56+
android:layout_width="wrap_content"
57+
android:layout_height="wrap_content"
58+
mstb:values="@array/feedback_options"
59+
android:id="@+id/feedbackToggleButton"
60+
android:layout_alignParentTop="true"
61+
android:layout_alignParentRight="true"
62+
android:layout_alignParentEnd="true"/>
63+
</RelativeLayout>
64+
65+
<RelativeLayout
66+
android:layout_width="match_parent"
67+
android:layout_height="match_parent"
68+
android:layout_marginTop="20dp">
69+
70+
<TextView
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:textAppearance="?android:attr/textAppearanceMedium"
74+
android:text="@string/errors"
75+
android:id="@+id/textView20"
76+
android:textColor="@color/white"
77+
android:layout_centerVertical="true"
78+
android:layout_alignParentLeft="true"
79+
android:layout_alignParentStart="true"/>
80+
81+
<org.honorato.multistatetogglebutton.MultiStateToggleButton
82+
xmlns:mstb="http://schemas.android.com/apk/res-auto"
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
mstb:values="@array/feedback_options"
86+
android:id="@+id/errorsToggleButton"
87+
android:layout_alignParentTop="true"
88+
android:layout_alignParentRight="true"
89+
android:layout_alignParentEnd="true"/>
90+
91+
</RelativeLayout>
92+
</LinearLayout>

0 commit comments

Comments
 (0)