Skip to content

Commit 206e822

Browse files
authoredApr 8, 2023
Require minSdkVersion 23 (was 21) to simply code (#105)
Require minSdkVersion 23 (was 21) to simply code
1 parent 616f9e7 commit 206e822

22 files changed

+61
-66
lines changed
 

‎app/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ android {
2727
// API level 21: Jetpack Compose
2828
defaultConfig {
2929
applicationId 'ee.ioc.phon.android.speak'
30-
minSdkVersion 21
30+
minSdkVersion 23
3131
targetSdkVersion 33
32-
versionCode 1817
33-
versionName '1.8.17'
32+
versionCode 1900
33+
versionName '1.9.00'
3434
vectorDrawables.useSupportLibrary = true
3535
// Keep only en and et resources
3636
resConfigs 'en', 'et'

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
*/
4444
public class AppListCursorAdapter extends CursorAdapter {
4545

46-
private String mDefaultServerUrl;
47-
private PackageManager mPm;
46+
private final String mDefaultServerUrl;
47+
private final PackageManager mPm;
4848

4949
public AppListCursorAdapter(Context context, Cursor c, boolean autoRequery) {
5050
super(context, c, autoRequery);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Caller(PendingIntent pendingIntent, Bundle bundle) {
7070
if (pendingIntent == null) {
7171
mPrimaryCaller = bundle.getString(RecognizerIntent.EXTRA_CALLING_PACKAGE);
7272
} else {
73-
mPrimaryCaller = pendingIntent.getTargetPackage();
73+
mPrimaryCaller = pendingIntent.getCreatorPackage();
7474
}
7575
mSecondaryCaller = getPackageName(bundle);
7676
}
@@ -120,7 +120,7 @@ public static String getCaller(ComponentName callingActivity, PendingIntent pend
120120
return callingActivity.getPackageName();
121121
}
122122
} else {
123-
return pendingIntent.getTargetPackage();
123+
return pendingIntent.getCreatorPackage();
124124
}
125125
return null;
126126
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class QuickSettingsManager {
2121
COMBOS_MULTILINGUAL = Collections.unmodifiableSet(set);
2222
}
2323

24-
private SharedPreferences mPrefs;
25-
private Resources mRes;
24+
private final SharedPreferences mPrefs;
25+
private final Resources mRes;
2626

2727
public QuickSettingsManager(SharedPreferences prefs, Resources res) {
2828
mPrefs = prefs;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public abstract class AbstractRecognizerIntentActivity extends AppCompatActivity
8686

8787
private Iterable<UtteranceRewriter> mRewriters;
8888

89-
private static SparseIntArray mErrorCodesServiceToIntent = IntentUtils.createErrorCodesServiceToIntent();
89+
private static final SparseIntArray mErrorCodesServiceToIntent = IntentUtils.createErrorCodesServiceToIntent();
9090

9191
private List<byte[]> mBufferList = new ArrayList<>();
9292

@@ -580,7 +580,7 @@ private SparseArray<String> createErrorMessages() {
580580
*/
581581
protected void setResultError(int errorCode) {
582582
if (mIsReturnErrors) {
583-
Integer errorCodeIntent = mErrorCodesServiceToIntent.get(errorCode);
583+
int errorCodeIntent = mErrorCodesServiceToIntent.get(errorCode);
584584
setResult(errorCodeIntent);
585585
finish();
586586
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void onCreate(Bundle savedInstanceState) {
5454
Bundle extras = intent.getExtras();
5555

5656
if (extras == null) {
57-
requestWindowFeature(Window.FEATURE_NO_TITLE);
57+
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
5858
mIsFinishAfterPlayAudio = true;
5959
}
6060

@@ -66,7 +66,7 @@ public void onCreate(Bundle savedInstanceState) {
6666
if (extras != null) {
6767
String title = extras.getString(EXTRA_TITLE);
6868
if (title == null) {
69-
requestWindowFeature(Window.FEATURE_NO_TITLE);
69+
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
7070
} else {
7171
setTitle(title);
7272
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import androidx.appcompat.app.AppCompatActivity;
3232

3333
import java.io.IOException;
34-
import java.io.UnsupportedEncodingException;
34+
import java.nio.charset.StandardCharsets;
3535
import java.util.ArrayList;
3636
import java.util.Collections;
3737
import java.util.List;
@@ -113,11 +113,7 @@ public void onCreate(Bundle savedInstanceState) {
113113
if (uri != null) {
114114
if ("k6".equals(uri.getScheme())) {
115115
byte[] data = Base64.decode(uri.getSchemeSpecificPart().substring(2), Base64.NO_WRAP | Base64.URL_SAFE);
116-
try {
117-
utteranceRewriter = new UtteranceRewriter(new String(data, "UTF-8"));
118-
} catch (UnsupportedEncodingException e) {
119-
// TODO: dont ignore
120-
}
116+
utteranceRewriter = new UtteranceRewriter(new String(data, StandardCharsets.UTF_8));
121117
} else {
122118
utteranceRewriter = loadFromUri(uri);
123119
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ServerListActivity extends AbstractContentActivity {
3232
Server.Columns.URL
3333
};
3434

35-
private static int[] TO = new int[]{
35+
private static final int[] TO = new int[]{
3636
R.id.itemServerId,
3737
R.id.itemServerUrl
3838
};

‎app/src/main/java/ee/ioc/phon/android/speak/demo/EncoderListDemo.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.widget.ListView
66
import androidx.appcompat.app.AppCompatActivity
77
import ee.ioc.phon.android.speak.R
88
import ee.ioc.phon.android.speechutils.utils.AudioUtils
9-
import java.util.*
109

1110
class EncoderListDemo : AppCompatActivity() {
1211

@@ -17,7 +16,7 @@ class EncoderListDemo : AppCompatActivity() {
1716
val mime = "audio/flac"
1817
info.add(mime + " encoders: " + AudioUtils.getEncoderNamesForType(mime).toString())
1918
info.addAll(AudioUtils.getAvailableEncoders(mime, 16000))
20-
val listView = findViewById(android.R.id.list) as ListView
19+
val listView = findViewById<ListView>(android.R.id.list)
2120
listView.adapter = ArrayAdapter(this, R.layout.list_item_detail, info.toTypedArray())
2221
}
2322
}

‎app/src/main/java/ee/ioc/phon/android/speak/demo/HandsfreeDemoActivity.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,22 @@ class HandsfreeDemoActivity : AbstractRecognizerDemoActivity() {
8181

8282

8383
private fun updateListView(list: List<String>) {
84-
(findViewById<View>(R.id.list_matches) as ListView).adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, list)
84+
(findViewById<View>(R.id.list_matches) as ListView).adapter =
85+
ArrayAdapter(this, android.R.layout.simple_list_item_1, list)
8586
}
8687

8788
companion object {
8889

8990
// TODO: smaller values (e.g. < 800) cause an error with the local server with a single slot
90-
private val SLEEP_TIME = 10
91-
private val MAX_COUNT = 5
91+
private const val SLEEP_TIME = 10
92+
private const val MAX_COUNT = 5
9293

9394
private fun createRecognizerIntent(): Intent {
9495
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
95-
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
96+
intent.putExtra(
97+
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
98+
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
99+
)
96100
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3)
97101
intent.putExtra(Extras.EXTRA_AUTO_START, true)
98102
intent.putExtra(Extras.EXTRA_RETURN_ERRORS, true)

‎app/src/main/java/ee/ioc/phon/android/speak/demo/ImeListDemo.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import android.widget.ListView
1111
import android.widget.TextView
1212
import androidx.appcompat.app.AppCompatActivity
1313
import ee.ioc.phon.android.speak.R
14-
import java.util.*
1514

1615
class ImeListDemo : AppCompatActivity() {
1716

@@ -22,7 +21,7 @@ class ImeListDemo : AppCompatActivity() {
2221
val mngr = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
2322
val info = getVoiceImeInputMethodInfo(packageManager, mngr)
2423

25-
val listView = findViewById(android.R.id.list) as ListView
24+
val listView = findViewById<ListView>(android.R.id.list)
2625
listView.adapter = ArrayAdapter(this, R.layout.list_item_detail, info.toTypedArray())
2726

2827
listView.onItemClickListener = OnItemClickListener { _, view, _, _ ->
@@ -33,10 +32,13 @@ class ImeListDemo : AppCompatActivity() {
3332
}
3433

3534
companion object {
36-
private val VOICE_IME_SUBTYPE_MODE = "voice"
35+
private const val VOICE_IME_SUBTYPE_MODE = "voice"
3736

3837
@Throws(SecurityException::class, IllegalArgumentException::class)
39-
private fun getVoiceImeInputMethodInfo(pm: PackageManager, inputMethodManager: InputMethodManager): List<String> {
38+
private fun getVoiceImeInputMethodInfo(
39+
pm: PackageManager,
40+
inputMethodManager: InputMethodManager
41+
): List<String> {
4042
val imeInfos = ArrayList<String>()
4143
for (inputMethodInfo in inputMethodManager.enabledInputMethodList) {
4244
for (i in 0 until inputMethodInfo.subtypeCount) {

‎app/src/main/java/ee/ioc/phon/android/speak/demo/SimpleDemo.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ class SimpleDemo : AbstractRecognizerDemoActivity() {
4040

4141
val intent = createRecognizerIntent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
4242

43-
if (getRecognizers(intent).size == 0) {
43+
if (getRecognizers(intent).isEmpty()) {
4444
toast(getString(R.string.errorRecognizerNotPresent))
4545
finish()
4646
} else {
47-
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
47+
intent.putExtra(
48+
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
49+
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
50+
)
4851
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3)
4952
launchRecognizerIntent(intent)
5053
}
@@ -55,7 +58,7 @@ class SimpleDemo : AbstractRecognizerDemoActivity() {
5558
*/
5659
override fun onSuccess(intent: Intent?) {
5760
val matches = intent?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
58-
(findViewById(android.R.id.list) as ListView).adapter =
59-
ArrayAdapter(this, android.R.layout.simple_list_item_1, matches as ArrayList<String>)
61+
(findViewById<ListView>(android.R.id.list)).adapter =
62+
ArrayAdapter(this, android.R.layout.simple_list_item_1, matches as ArrayList<String>)
6063
}
6164
}

‎app/src/main/java/ee/ioc/phon/android/speak/demo/VoiceSearchDemo.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class VoiceSearchDemo : AbstractRecognizerDemoActivity() {
3636
public override fun onCreate(savedInstanceState: Bundle?) {
3737
super.onCreate(savedInstanceState)
3838
setContentView(R.layout.voice_search_demo)
39-
val speakButton = findViewById(R.id.buttonMicrophone) as ImageButton
40-
speakButton.setOnClickListener({ launchRecognizerIntent(createVoiceAppSearchIntent()) })
39+
val speakButton = findViewById<ImageButton>(R.id.buttonMicrophone)
40+
speakButton.setOnClickListener { launchRecognizerIntent(createVoiceAppSearchIntent()) }
4141
}
4242

4343
override fun onSuccess(intent: Intent?) {
@@ -65,7 +65,10 @@ class VoiceSearchDemo : AbstractRecognizerDemoActivity() {
6565
val queryExtras = Bundle()
6666

6767
val voiceIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
68-
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
68+
voiceIntent.putExtra(
69+
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
70+
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
71+
)
6972
//voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, (String) null);
7073
voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1)
7174
// Add the values that configure forwarding the results

‎app/src/main/java/ee/ioc/phon/android/speak/provider/AppsContentProvider.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public class AppsContentProvider extends ContentProvider {
5858
private static final int SERVERS = 5;
5959
private static final int SERVER_ID = 6;
6060

61-
private static HashMap<String, String> appsProjectionMap;
62-
private static HashMap<String, String> grammarsProjectionMap;
63-
private static HashMap<String, String> serversProjectionMap;
61+
private static final HashMap<String, String> appsProjectionMap;
62+
private static final HashMap<String, String> grammarsProjectionMap;
63+
private static final HashMap<String, String> serversProjectionMap;
6464

6565
private DatabaseHelper dbHelper;
6666

‎app/src/main/java/ee/ioc/phon/android/speak/service/WebSocketRecognitionService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ee.ioc.phon.android.speak.service;
22

3+
import static android.Manifest.permission.RECORD_AUDIO;
4+
35
import android.content.Intent;
46
import android.os.Bundle;
57
import android.os.Handler;
@@ -32,8 +34,6 @@
3234
import ee.ioc.phon.android.speechutils.service.AbstractRecognitionService;
3335
import ee.ioc.phon.android.speechutils.utils.PreferenceUtils;
3436

35-
import static android.Manifest.permission.RECORD_AUDIO;
36-
3737
/**
3838
* Implements RecognitionService, connects to the server via WebSocket.
3939
*/

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

+6-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.net.URLEncoder;
99
import java.util.ArrayList;
1010
import java.util.List;
11+
import java.util.Objects;
1112

1213
import ee.ioc.phon.android.speak.ChunkedWebRecSessionBuilder;
1314
import ee.ioc.phon.android.speak.Log;
@@ -35,7 +36,7 @@ public static List<Pair<String, String>> getQueryParams(Intent intent, ChunkedWe
3536
List<Pair<String, String>> list = new ArrayList<>();
3637
flattenBundle("editorInfo_", list, intent.getBundleExtra(Extras.EXTRA_EDITOR_INFO));
3738
listAdd(list, "lang", builder.getLang());
38-
listAdd(list, "lm", toString(builder.getGrammarUrl()));
39+
listAdd(list, "lm", Objects.toString(builder.getGrammarUrl(), ""));
3940
listAdd(list, "output-lang", builder.getGrammarTargetLang());
4041
listAdd(list, "user-agent", builder.getUserAgentComment());
4142
listAdd(list, "calling-package", builder.getCaller());
@@ -44,11 +45,10 @@ public static List<Pair<String, String>> getQueryParams(Intent intent, ChunkedWe
4445
return list;
4546
}
4647

47-
private static boolean listAdd(List<Pair<String, String>> list, String key, String value) {
48-
if (value == null || value.length() == 0) {
49-
return false;
48+
private static void listAdd(List<Pair<String, String>> list, String key, String value) {
49+
if (value != null && value.length() > 0) {
50+
list.add(new Pair<>(key, value));
5051
}
51-
return list.add(new Pair<>(key, value));
5252
}
5353

5454
private static void flattenBundle(String prefix, List<Pair<String, String>> list, Bundle bundle) {
@@ -59,21 +59,13 @@ private static void flattenBundle(String prefix, List<Pair<String, String>> list
5959
if (value instanceof Bundle) {
6060
flattenBundle(prefix + key + "_", list, (Bundle) value);
6161
} else {
62-
listAdd(list, prefix + key, toString(value));
62+
listAdd(list, prefix + key, Objects.toString(value, ""));
6363
}
6464
}
6565
}
6666
}
6767
}
6868

69-
// TODO: replace by a built-in
70-
private static String toString(Object obj) {
71-
if (obj == null) {
72-
return null;
73-
}
74-
return obj.toString();
75-
}
76-
7769
/**
7870
* Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code>
7971
* list of parameters in an HTTP PUT or HTTP POST.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class ComboSelectorView @JvmOverloads constructor(
6363
val mBComboSelector = findViewById<Button>(R.id.tvComboSelector)
6464
val mRvComboButtons: RecyclerView = findViewById(R.id.rvComboButtons)
6565
val size = mSlc.size()
66-
if (size >= mMinButtons && mMinButtons > 0) {
66+
if (mMinButtons in (1..size)) {
6767
// We show buttons if the user has requested at least one button (by default at least 3),
6868
// and there are at least that many to show.
6969
mBComboSelector.visibility = GONE
@@ -94,7 +94,7 @@ class ComboSelectorView @JvmOverloads constructor(
9494
val combo = Combo(context, mSlc.combo)
9595
mBComboSelector.text = combo.longLabel
9696
}
97-
mBComboSelector.setOnLongClickListener { view: View? ->
97+
mBComboSelector.setOnLongClickListener {
9898
comboSelector(context, key)
9999
true
100100
}
@@ -108,7 +108,7 @@ class ComboSelectorView @JvmOverloads constructor(
108108
}
109109

110110
fun click() {
111-
mListener.onComboChange(mSlc.language, mSlc.service);
111+
mListener.onComboChange(mSlc.language, mSlc.service)
112112
}
113113

114114
val speechRecognizer: SpeechRecognizer

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void run() {
4646
mHandler.postDelayed(this, DELAY);
4747
}
4848
};
49-
private Runnable mTask2 = new Runnable() {
49+
private final Runnable mTask2 = new Runnable() {
5050
public void run() {
5151
onMoveAux(1, 1);
5252
mHandler.postDelayed(this, DELAY);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public boolean onTouch(View v, MotionEvent event) {
3333
case MotionEvent.ACTION_UP:
3434
case MotionEvent.ACTION_OUTSIDE:
3535
case MotionEvent.ACTION_CANCEL:
36-
if (mHandler != null) mHandler.removeCallbacks(mTask);
36+
mHandler.removeCallbacks(mTask);
3737
v.setPressed(false);
3838
break;
3939
default:

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

-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@
284284
<string name="summaryReturnErrors">Tagasta audio/võrgu/jne vigade teated kutsuvale rakendusele</string>
285285
<string name="titleImeShowPartialResults">Vahetulemused</string>
286286
<string name="summaryImeShowPartialResults">Näita tekstikastis kõnetuvastuse vahetulemusi</string>
287-
<string name="summaryImeHelpText">Näita klaviatuuril abiteksti (teeb klaviatuuri sellevõrra suuremaks)</string>
288-
<string name="titleImeHelpText">Abitekst</string>
289287
<string name="dialogTitleCombo">Keeled &amp; teenused</string>
290288
<string name="titleCombo">Kõnetuvastuskeeled &amp; teenused</string>
291289
<string name="summaryImeCombo">Uuendan…</string>

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

-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@
8686
<string name="summaryHelpText">Show usage instructions by the microphone button. Makes the search panel larger.</string>
8787
<string name="titleReturnErrors">Return errors</string>
8888
<string name="summaryReturnErrors">Return network/audio/etc. errors to the caller (useful if the caller does error handling)</string>
89-
<string name="titleImeHelpText">Help text</string>
90-
<string name="summaryImeHelpText">Show usage instructions by the microphone button. Makes the keyboard larger.</string>
9189
<string name="summaryImeCombo">Updating…</string>
9290
<string name="titleEnableIme">Enable Speak &amp; swipe keyboard</string>
9391
<string name="summaryEnableIme">The keyboard allows you to dictate into any text field in any app, and navigate and edit the text with swipe operations. Tap here to enable it in the Android virtual keyboard settings.</string>

0 commit comments

Comments
 (0)
Failed to load comments.