Skip to content

Commit b7febb8

Browse files
committedOct 10, 2020
IME. Add button to switch between keys and mic
This is experimental and not yet available in landscape and watch. Also redesign how the default service is chosen: if the list of selected combos is empty (e.g. after first installation), then we select the first available service from a hard-coded list of services: 1. Kõnele service: best choice if the user has chosen to install it 2. Kõnele (i.e. itself): always available but does not work on Android 11 3. Google: usually available
1 parent 836bb04 commit b7febb8

File tree

9 files changed

+77
-9
lines changed

9 files changed

+77
-9
lines changed
 

‎app/src/main/java/ee/ioc/phon/android/speak/activity/AbstractRecognizerIntentActivity.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,16 @@ protected void setUpActivity(int layout) {
202202

203203
protected void setUpActivity(int layout) {
204204
setContentView(layout);
205+
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
206+
207+
Utils.setUpDefaultCombos(prefs, getResources(), getPackageManager());
205208

206209
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
207210

208211
final Window window = getWindow();
209212
final WindowManager.LayoutParams wlp = window.getAttributes();
210213
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
211214

212-
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
213215
int x = prefs.getInt("keyDialogX", -1);
214216
int y = prefs.getInt("keyDialogY", -1);
215217
if (x != -1 && y != -1) {

‎app/src/main/java/ee/ioc/phon/android/speak/utils/Utils.java

+25
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import ee.ioc.phon.android.speak.model.CallerInfo;
6262
import ee.ioc.phon.android.speak.model.Combo;
6363
import ee.ioc.phon.android.speechutils.Extras;
64+
import ee.ioc.phon.android.speechutils.RecognitionServiceManager;
6465
import ee.ioc.phon.android.speechutils.editor.CommandMatcher;
6566
import ee.ioc.phon.android.speechutils.editor.UtteranceRewriter;
6667
import ee.ioc.phon.android.speechutils.utils.PreferenceUtils;
@@ -331,6 +332,30 @@ public static void publishShortcuts(Context context, List<Combo> selectedCombos,
331332
shortcutManager.setDynamicShortcuts(shortcuts);
332333
}
333334

335+
/**
336+
* TODO: call this in Panel, IME, and Settings
337+
* TODO: take the first language offered by the service (maybe slow?)
338+
*/
339+
public static void setUpDefaultCombos(SharedPreferences prefs, Resources res, PackageManager pm) {
340+
Set<String> combos1 = PreferenceUtils.getPrefStringSet(prefs, res, R.string.keyCombo);
341+
Set<String> combos2 = PreferenceUtils.getPrefStringSet(prefs, res, R.string.keyImeCombo);
342+
if (combos1.isEmpty() || combos2.isEmpty()) {
343+
RecognitionServiceManager mngr = new RecognitionServiceManager();
344+
List<String> services = mngr.getServices(pm);
345+
for (String service : res.getStringArray(R.array.fallbackServices)) {
346+
if (services.contains(service)) {
347+
if (combos1.isEmpty()) {
348+
PreferenceUtils.putPrefStringSet(prefs, res, R.string.keyCombo, Collections.singleton(service));
349+
}
350+
if (combos2.isEmpty()) {
351+
PreferenceUtils.putPrefStringSet(prefs, res, R.string.keyImeCombo, Collections.singleton(service));
352+
}
353+
break;
354+
}
355+
}
356+
}
357+
}
358+
334359
private static Bundle toBundle(EditorInfo attribute) {
335360
Bundle bundle = new Bundle();
336361
bundle.putBundle("extras", attribute.extras);

‎app/src/main/java/ee/ioc/phon/android/speak/view/SpeechInputView.java

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class SpeechInputView extends LinearLayoutCompat {
6464
private MicButton mBImeStartStop;
6565
private ImageButton mBImeKeyboard;
6666
private ImageButton mBImeAction;
67+
private ImageButton mBClipboard;
6768
private Button mBComboSelector;
6869
private TextView mTvInstruction;
6970
private TextView mTvMessage;
@@ -211,6 +212,8 @@ public void setListener(final SpeechInputViewListener listener, EditorInfo edito
211212
toggleClipboardAux();
212213
return true;
213214
});
215+
216+
mBClipboard.setOnClickListener(v -> toggleClipboardAux());
214217
}
215218

216219
ImageButton buttonDelete = findViewById(R.id.bImeDelete);
@@ -350,6 +353,7 @@ public void init(int keys, CallerInfo callerInfo, int swipeType) {
350353
mBImeStartStop = findViewById(R.id.bImeStartStop);
351354
mBImeKeyboard = findViewById(R.id.bImeKeyboard);
352355
mBImeAction = findViewById(R.id.bImeAction);
356+
mBClipboard = findViewById(R.id.bClipboard);
353357
mBComboSelector = findViewById(R.id.tvComboSelector);
354358
mTvInstruction = findViewById(R.id.tvInstruction);
355359
mTvMessage = findViewById(R.id.tvMessage);
@@ -534,10 +538,12 @@ private void showClipboard(boolean b) {
534538
updateTouchListener(0);
535539
setVisibilityKeyboard(View.GONE);
536540
mRlClipboard.setVisibility(View.VISIBLE);
541+
mBClipboard.setImageResource(R.drawable.ic_mic);
537542
} else {
538543
updateTouchListener(mSwipeType);
539544
mRlClipboard.setVisibility(View.GONE);
540545
setVisibilityKeyboard(View.VISIBLE);
546+
mBClipboard.setImageResource(R.drawable.ic_clipboard);
541547
}
542548
}
543549

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
22
android:width="24dp"
33
android:height="24dp"
4-
android:tint="?attr/colorControlNormal"
54
android:viewportWidth="24.0"
65
android:viewportHeight="24.0">
76
<path
8-
android:fillColor="#FF000000"
7+
android:fillColor="?attr/colorControlNormal"
98
android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z" />
109
</vector>

‎app/src/main/res/layout/voice_ime_view.xml

+28-1
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,35 @@
129129
android:textColor="?android:attr/textColorPrimary"
130130
android:textSize="@dimen/textSize3"
131131
tools:text="@string/buttonImeSpeak" />
132+
132133
</RelativeLayout>
133134

134-
<include layout="@layout/button_combo_selector" />
135+
<RelativeLayout
136+
android:layout_width="match_parent"
137+
android:layout_height="wrap_content">
135138

139+
<include
140+
layout="@layout/button_combo_selector"
141+
android:layout_width="wrap_content"
142+
android:layout_height="wrap_content"
143+
android:layout_centerHorizontal="true"
144+
android:layout_centerVertical="true" />
145+
146+
<ImageButton
147+
android:id="@+id/bClipboard"
148+
android:layout_width="wrap_content"
149+
android:layout_height="wrap_content"
150+
android:layout_alignParentEnd="true"
151+
android:layout_alignParentRight="true"
152+
android:layout_centerVertical="true"
153+
android:background="@drawable/button_go"
154+
android:contentDescription="@string/cdChangeInputMethod"
155+
android:minWidth="@dimen/layoutMargin3"
156+
android:minHeight="@dimen/layoutMargin3"
157+
android:padding="@dimen/layoutMargin1"
158+
android:paddingStart="@dimen/layoutMargin2"
159+
android:paddingLeft="@dimen/layoutMargin2"
160+
android:paddingBottom="@dimen/layoutMargin2"
161+
app:srcCompat="@drawable/ic_clipboard" />
162+
</RelativeLayout>
136163
</ee.ioc.phon.android.speak.view.SpeechInputView>

‎app/src/main/res/values-et/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
<string name="dialogTitleCombo">Keeled &amp; teenused</string>
304304
<string name="titleCombo">Kõnetuvastuskeeled &amp; teenused</string>
305305
<string name="summaryImeCombo">Uuendan…</string>
306-
<string name="emptylistImeCombos">Praegu kasutatakse eesti keelt ja Kõnele (kiire tuvastusega) teenust. Keelte ja teenuste lisamiseks või muutmiseks vajutage siia.</string>
306+
<string name="emptylistImeCombos">Keelte ja teenuste lisamiseks või muutmiseks vajutage siia.</string>
307307
<string name="emptylistCombos">@string/emptylistImeCombos</string>
308308
<string name="labelIme">Kõnele kõne &amp; svaip</string>
309309
<string name="titleMaxHypotheses">Tuvastushüpoteeside arv</string>

‎app/src/main/res/values/strings.xml

+10-1
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,23 @@
350350
<item>44100</item>
351351
</string-array>
352352

353+
<string-array name="fallbackServices" translatable="false">
354+
<item>ee.ioc.phon.android.k6neleservice/.service.WebSocketRecognitionService</item>
355+
<item>ee.ioc.phon.android.speak/.service.WebSocketRecognitionService</item>
356+
<item>com.google.android.googlequicksearchbox/com.google.android.voicesearch.serviceapi.GoogleRecognitionService</item>
357+
</string-array>
358+
353359
<!-- When making changes here, you need to change the UI labels as well.
354360
Note also that none of the languages and services are
355361
initially selected in the UI, independent of what is selected here.
356362
We currently use the same language/service for both UIs. -->
357363
<string-array name="defaultImeCombos" translatable="false">
358364
<item>ee.ioc.phon.android.speak/.service.WebSocketRecognitionService;et-EE</item>
359365
</string-array>
360-
<string name="emptylistImeCombos">Currently using Estonian and Kõnele (fast recognition). Tap here to add or change languages and services.</string>
366+
367+
<!-- We try to pre-select a service from the list of fallbackServices. So this message
368+
would be shown only if the device has none of the fallbackServices installed. -->
369+
<string name="emptylistImeCombos">Tap here to add or change languages and services.</string>
361370

362371
<string-array name="defaultCombos" translatable="false">
363372
<item>ee.ioc.phon.android.speak/.service.WebSocketRecognitionService;et-EE</item>

‎build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
buildscript {
2-
ext.kotlin_version = '1.4.0'
2+
ext.kotlin_version = '1.4.10'
33
repositories {
44
google()
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:4.0.1'
8+
classpath 'com.android.tools.build:gradle:4.0.2'
99
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1010
}
1111
}

0 commit comments

Comments
 (0)
Failed to load comments.