diff --git a/.gitignore b/.gitignore
index 3849997..58fc7c6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,38 @@
-.gradle
-.idea
-/local.properties
-/build
-/app/build
-/models/build
+# Gradle files
+.gradle/
+build/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Log/OS Files
+*.log
+
+# Android Studio generated files and folders
+captures/
+.externalNativeBuild/
+.cxx/
+*.apk
+output.json
+
+# IntelliJ
+*.iml
+.idea/
+misc.xml
+deploymentTargetDropDown.xml
+render.experimental.xml
+
+# Keystore files
+*.jks
+*.keystore
+
+# Google Services (e.g. APIs or Firebase)
+google-services.json
+
+# Android Profiling
+*.hprof
+
.DS_Store
*.md5
*.lst
-*.iml
+/app/release/
\ No newline at end of file
diff --git a/app/src/main/java/com/elishaazaria/sayboard/AppCtx.java b/app/src/main/java/com/elishaazaria/sayboard/AppCtx.java
index e4e4540..dccc569 100644
--- a/app/src/main/java/com/elishaazaria/sayboard/AppCtx.java
+++ b/app/src/main/java/com/elishaazaria/sayboard/AppCtx.java
@@ -2,7 +2,10 @@
import android.annotation.SuppressLint;
import android.content.Context;
+import android.content.res.Resources;
+import androidx.annotation.ArrayRes;
+import androidx.annotation.BoolRes;
import androidx.annotation.IntegerRes;
import androidx.annotation.StringRes;
@@ -22,7 +25,15 @@ public static String getStringRes(@StringRes int res) {
return appCtx.getString(res);
}
- public static int getIntegerRes(@IntegerRes int res){
+ public static int getIntegerRes(@IntegerRes int res) {
return appCtx.getResources().getInteger(res);
}
+
+ public static boolean getBoolRes(@BoolRes int res) {
+ return appCtx.getResources().getBoolean(res);
+ }
+
+ public static String[] getStringArrayRes(@ArrayRes int res){
+ return appCtx.getResources().getStringArray(res);
+ }
}
diff --git a/app/src/main/java/com/elishaazaria/sayboard/SettingsActivity.java b/app/src/main/java/com/elishaazaria/sayboard/SettingsActivity.java
index ccb0331..9120d71 100644
--- a/app/src/main/java/com/elishaazaria/sayboard/SettingsActivity.java
+++ b/app/src/main/java/com/elishaazaria/sayboard/SettingsActivity.java
@@ -44,7 +44,8 @@ public void permissionsGranted() {
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
// R.id.navigation_setup,
R.id.navigation_models,
- R.id.navigation_theme)
+ R.id.navigation_theme,
+ R.id.navigation_other_settings)
.build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(binding.navView, navController);
diff --git a/app/src/main/java/com/elishaazaria/sayboard/ime/IME.java b/app/src/main/java/com/elishaazaria/sayboard/ime/IME.java
index 83f887a..868039a 100644
--- a/app/src/main/java/com/elishaazaria/sayboard/ime/IME.java
+++ b/app/src/main/java/com/elishaazaria/sayboard/ime/IME.java
@@ -18,6 +18,7 @@
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
+import android.content.res.Configuration;
import android.inputmethodservice.InputMethodService;
import android.os.Build;
import android.os.Handler;
@@ -29,6 +30,7 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
+import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
@@ -51,6 +53,7 @@
import com.elishaazaria.sayboard.R;
import com.elishaazaria.sayboard.Tools;
+import com.elishaazaria.sayboard.preferences.OtherPreferences;
import java.io.IOException;
import java.util.List;
@@ -139,11 +142,14 @@ public void onStartInputView(EditorInfo info, boolean restarting) {
modelManager.reloadModels();
viewManager.refresh();
+
+ setKeepScreenOn(OtherPreferences.getKeepScreenAwake() == OtherPreferences.KEEP_SCREEN_AWAKE_WHEN_OPEN);
}
@Override
public void onFinishInputView(boolean finishingInput) {
// text input has ended
+ setKeepScreenOn(false);
}
@Override
@@ -156,8 +162,13 @@ public void micClick() {
if (modelManager.isRunning()) {
modelManager.stop();
viewManager.setUiState(ViewManager.STATE_DONE);
+
+ if (OtherPreferences.getKeepScreenAwake() == OtherPreferences.KEEP_SCREEN_AWAKE_WHEN_LISTENING)
+ setKeepScreenOn(false);
} else {
modelManager.start();
+ if (OtherPreferences.getKeepScreenAwake() == OtherPreferences.KEEP_SCREEN_AWAKE_WHEN_LISTENING)
+ setKeepScreenOn(true);
}
}
@@ -256,6 +267,12 @@ public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, i
Log.d("VoskIME", "selection update: " + selectionStart + ", " + selectionEnd);
}
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+// viewManager.orientationChanged(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE);
+ }
private int selectionStart = 0;
private int selectionEnd = 0;
@@ -330,7 +347,7 @@ private IBinder getToken() {
return window.getAttributes().token;
}
- private Window getMyWindow() {
+ public Window getMyWindow() {
final Dialog dialog = getWindow();
if (dialog == null) {
return null;
@@ -338,6 +355,16 @@ private Window getMyWindow() {
return dialog.getWindow();
}
+ private void setKeepScreenOn(boolean keepScreenOn) {
+ Window window = getMyWindow();
+ if (window == null) return;
+
+ if (keepScreenOn)
+ window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ else
+ window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
+
// @Override
// public void onRequestPermissionsResult(int requestCode,
diff --git a/app/src/main/java/com/elishaazaria/sayboard/ime/ViewManager.java b/app/src/main/java/com/elishaazaria/sayboard/ime/ViewManager.java
index ef3117c..6d02359 100644
--- a/app/src/main/java/com/elishaazaria/sayboard/ime/ViewManager.java
+++ b/app/src/main/java/com/elishaazaria/sayboard/ime/ViewManager.java
@@ -1,13 +1,14 @@
package com.elishaazaria.sayboard.ime;
import android.content.res.ColorStateList;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
+import android.content.res.Configuration;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
+import android.view.Window;
import android.widget.Button;
+import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;
@@ -16,6 +17,7 @@
import androidx.core.widget.TextViewCompat;
import com.elishaazaria.sayboard.R;
+import com.elishaazaria.sayboard.preferences.OtherPreferences;
import com.elishaazaria.sayboard.preferences.ThemePreferences;
public class ViewManager {
@@ -57,10 +59,10 @@ public void init() {
modelButton = overlayView.findViewById(R.id.model_button);
returnButton = overlayView.findViewById(R.id.return_button);
- overlayView.setMinHeight(convertDpToPixel(300));
-
resultView.setMovementMethod(new ScrollingMovementMethod());
+ reloadOrientation();
+
micButton.setOnClickListener(v -> {
if (listener != null) listener.micClick();
});
@@ -94,6 +96,8 @@ public void init() {
setModelName(modelName);
+ currentForeground = Integer.MAX_VALUE;
+ currentBackground = Integer.MAX_VALUE;
setUpTheme();
}
@@ -121,8 +125,39 @@ private void setUpTheme() {
resultView.setTextColor(foreground);
}
+ private void reloadOrientation() {
+ boolean landscape = ime.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
+
+ Window window = ime.getMyWindow();
+ if (window == null)
+ return;
+
+ int screenHeight = ime.getResources().getDisplayMetrics().heightPixels;
+
+ float percent;
+ if (landscape) {
+ percent = OtherPreferences.getScreenHeightLandscape();
+ } else {
+ percent = OtherPreferences.getScreenHeightPortrait();
+ }
+ int height = (int) (percent * screenHeight);
+
+
+ Log.d("ViewManager", "Screen height: " + screenHeight + ", height: " + height);
+
+// WindowManager.LayoutParams params = window.getAttributes();
+// params.height = height;
+// window.setAttributes(params);
+//
+ overlayView.setMinHeight(height);
+ overlayView.setMaxHeight(height);
+// overlayView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, height));
+ }
+
public void refresh() {
setUpTheme();
+
+ reloadOrientation();
}
public void setUiState(int state) {
diff --git a/app/src/main/java/com/elishaazaria/sayboard/preferences/OtherPreferences.java b/app/src/main/java/com/elishaazaria/sayboard/preferences/OtherPreferences.java
new file mode 100644
index 0000000..7164217
--- /dev/null
+++ b/app/src/main/java/com/elishaazaria/sayboard/preferences/OtherPreferences.java
@@ -0,0 +1,37 @@
+package com.elishaazaria.sayboard.preferences;
+
+import android.util.Log;
+
+import com.elishaazaria.sayboard.AppCtx;
+import com.elishaazaria.sayboard.R;
+
+public class OtherPreferences {
+ public static final int KEEP_SCREEN_AWAKE_NEVER = 0;
+ public static final int KEEP_SCREEN_AWAKE_WHEN_LISTENING = 1;
+ public static final int KEEP_SCREEN_AWAKE_WHEN_OPEN = 2;
+
+ public static int getKeepScreenAwake() {
+ String val = MyPreferences.getSharedPref()
+ .getString(AppCtx.getStringRes(R.string.pref_other_keep_screen_awake_l),
+ AppCtx.getStringRes(R.string.pref_keep_awake_default));
+
+ if (val.equals(AppCtx.getStringRes(R.string.value_keep_awake_never)))
+ return KEEP_SCREEN_AWAKE_NEVER;
+ if (val.equals(AppCtx.getStringRes(R.string.value_keep_awake_when_listening)))
+ return KEEP_SCREEN_AWAKE_WHEN_LISTENING;
+ if (val.equals(AppCtx.getStringRes(R.string.value_keep_awake_when_open)))
+ return KEEP_SCREEN_AWAKE_WHEN_OPEN;
+
+ return -1;
+ }
+
+ public static float getScreenHeightPortrait() {
+ return MyPreferences.getSharedPref().getInt(AppCtx.getStringRes(R.string.pref_other_keyboard_height_portrait_i),
+ AppCtx.getIntegerRes(R.integer.pref_keyboard_height_portrait_default)) / (float) AppCtx.getIntegerRes(R.integer.keyboard_height_max);
+ }
+
+ public static float getScreenHeightLandscape() {
+ return MyPreferences.getSharedPref().getInt(AppCtx.getStringRes(R.string.pref_other_keyboard_height_landscape_i),
+ AppCtx.getIntegerRes(R.integer.pref_keyboard_height_landscape_default)) / (float) AppCtx.getIntegerRes(R.integer.keyboard_height_max);
+ }
+}
diff --git a/app/src/main/java/com/elishaazaria/sayboard/settingsfragments/LogicSettingsFragment.java b/app/src/main/java/com/elishaazaria/sayboard/settingsfragments/LogicSettingsFragment.java
new file mode 100644
index 0000000..a7371e4
--- /dev/null
+++ b/app/src/main/java/com/elishaazaria/sayboard/settingsfragments/LogicSettingsFragment.java
@@ -0,0 +1,19 @@
+package com.elishaazaria.sayboard.settingsfragments;
+
+import android.os.Bundle;
+
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceManager;
+
+import com.elishaazaria.sayboard.AppCtx;
+import com.elishaazaria.sayboard.R;
+
+public class LogicSettingsFragment extends PreferenceFragmentCompat {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ PreferenceManager preferenceManager = getPreferenceManager();
+ preferenceManager.setSharedPreferencesName(AppCtx.getStringRes(R.string.main_shared_pref));
+ setPreferencesFromResource(R.xml.logic_preferences, rootKey);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/elishaazaria/sayboard/settingsfragments/OtherSettingsFragment.java b/app/src/main/java/com/elishaazaria/sayboard/settingsfragments/OtherSettingsFragment.java
new file mode 100644
index 0000000..533bb93
--- /dev/null
+++ b/app/src/main/java/com/elishaazaria/sayboard/settingsfragments/OtherSettingsFragment.java
@@ -0,0 +1,19 @@
+package com.elishaazaria.sayboard.settingsfragments;
+
+import android.os.Bundle;
+
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceManager;
+
+import com.elishaazaria.sayboard.AppCtx;
+import com.elishaazaria.sayboard.R;
+
+public class OtherSettingsFragment extends PreferenceFragmentCompat {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ PreferenceManager preferenceManager = getPreferenceManager();
+ preferenceManager.setSharedPreferencesName(AppCtx.getStringRes(R.string.main_shared_pref));
+ setPreferencesFromResource(R.xml.other_preferences, rootKey);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml
new file mode 100644
index 0000000..298a5a1
--- /dev/null
+++ b/app/src/main/res/drawable/ic_settings.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/layout/fragment_theme.xml b/app/src/main/res/layout/fragment_theme.xml
deleted file mode 100644
index 75f254f..0000000
--- a/app/src/main/res/layout/fragment_theme.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/menu/bottom_nav_menu.xml b/app/src/main/res/menu/bottom_nav_menu.xml
index 466e42e..28e7cba 100644
--- a/app/src/main/res/menu/bottom_nav_menu.xml
+++ b/app/src/main/res/menu/bottom_nav_menu.xml
@@ -15,4 +15,9 @@
android:icon="@drawable/ic_baseline_color_lens_24"
android:title="@string/title_theme" />
+
+
\ No newline at end of file
diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml
index 503677e..2f7e565 100644
--- a/app/src/main/res/navigation/mobile_navigation.xml
+++ b/app/src/main/res/navigation/mobile_navigation.xml
@@ -9,7 +9,7 @@
android:id="@+id/navigation_setup"
android:name="com.elishaazaria.sayboard.settingsfragments.SetupFragment"
android:label="@string/title_setup"
- tools:layout="@layout/fragment_setup" >
+ tools:layout="@layout/fragment_setup">
@@ -24,6 +24,10 @@
+ android:label="@string/title_theme" />
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 6cf9ed4..1c744cf 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -1,12 +1,19 @@
-
- - Reply
- - Reply to all
+
+ - Never
+ - When listening
+ - When open
-
- - reply
- - reply_all
+
+ never
+ when_listening
+ when_open
+
+
+ - @string/value_keep_awake_never
+ - @string/value_keep_awake_when_listening
+ - @string/value_keep_awake_when_open
\ No newline at end of file
diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml
index 37a9b36..58a4169 100644
--- a/app/src/main/res/values/integers.xml
+++ b/app/src/main/res/values/integers.xml
@@ -1,5 +1,5 @@
- 0xFF377A00
- 0xFFFFFFFF
+ 1
+ 100
\ No newline at end of file
diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml
index 3bfd3a8..47f4128 100644
--- a/app/src/main/res/values/keys.xml
+++ b/app/src/main/res/values/keys.xml
@@ -4,4 +4,7 @@
c_foreground
c_background
+ i_keyboard_height_portrait
+ i_keyboard_height_landscape
+ l_keep_screen_awake
\ No newline at end of file
diff --git a/app/src/main/res/values/pref_defaults.xml b/app/src/main/res/values/pref_defaults.xml
new file mode 100644
index 0000000..544b542
--- /dev/null
+++ b/app/src/main/res/values/pref_defaults.xml
@@ -0,0 +1,10 @@
+
+
+ 0xFF377A00
+ 0xFFFFFFFF
+
+ false
+ 30
+ 50
+ @string/value_keep_awake_when_listening
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 461bec7..99b149f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -6,7 +6,7 @@
Error\n
Preparing the recognizer\n
Ready\n
- Failed to init recognizer %s\n
+ Failed to initialize recognizer %s\n
Say something\n
@@ -38,15 +38,23 @@
Setup
Models
Theme
+ Settings
Theme
+ Keyboard Logic
+ Other Settings
Foreground color
Background color
Reset
+
+ Keep screen awake
+ Keyboard height in portrait mode (%)
+ Keyboard height in landscape mode (%)
+
Model download
Model download status notifications.
diff --git a/app/src/main/res/xml/logic_preferences.xml b/app/src/main/res/xml/logic_preferences.xml
new file mode 100644
index 0000000..364d317
--- /dev/null
+++ b/app/src/main/res/xml/logic_preferences.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/other_preferences.xml b/app/src/main/res/xml/other_preferences.xml
new file mode 100644
index 0000000..71c92bc
--- /dev/null
+++ b/app/src/main/res/xml/other_preferences.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file