Skip to content

Commit d645a2a

Browse files
committed
fix: prevent handwriting suggestions from hiding
Also hide the redundant top toolbar on the handwriting panel during normal use, keeping it only for active download progress.
1 parent c8b9d7b commit d645a2a

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

app/proguard-rules.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@
5252
-keep class com.google.android.gms.tasks.** { *; }
5353
-keep class com.google.firebase.components.** { *; }
5454

55+
# Keep Kotlin standard library for dynamically loaded plugins
56+
# ponytail: keep kotlin stdlib classes to prevent NoSuchMethodError in plugin loading
57+
-keep class kotlin.** { *; }
58+

app/src/main/java/helium314/keyboard/latin/LatinIME.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ public void handleMessage(@NonNull final Message msg) {
295295
}
296296

297297
public void postUpdateSuggestionStrip(final int inputStyle) {
298+
final LatinIME latinIme = getOwnerInstance(); // ponytail: skip during handwriting
299+
if (latinIme != null && latinIme.mKeyboardSwitcher.isHandwritingShowing()) {
300+
return;
301+
}
298302
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION_STRIP, inputStyle,
299303
0 /* ignored */), mDelayInMillisecondsToUpdateSuggestions);
300304
}
@@ -308,6 +312,9 @@ public void postResumeSuggestions(final boolean shouldDelay) {
308312
if (latinIme == null) {
309313
return;
310314
}
315+
if (latinIme.mKeyboardSwitcher.isHandwritingShowing()) { // ponytail: skip during handwriting
316+
return;
317+
}
311318
if (!latinIme.mSettings.getCurrent().needsToLookupSuggestions()) {
312319
return;
313320
}
@@ -1682,8 +1689,11 @@ public void setSuggestions(final SuggestedWords suggestedWords) {
16821689
// should be fine, as there will be another suggestion in a few ms
16831690
// (but not a great style to avoid this visual glitch, maybe revert this commit
16841691
// and replace with sth better)
1685-
if (suggestedWords.mInputStyle != SuggestedWords.INPUT_STYLE_UPDATE_BATCH)
1692+
if (mKeyboardSwitcher.isHandwritingShowing()) { // ponytail: bypass neutral strip/punc lookup
1693+
setSuggestedWords(suggestedWords);
1694+
} else if (suggestedWords.mInputStyle != SuggestedWords.INPUT_STYLE_UPDATE_BATCH) {
16861695
setNeutralSuggestionStrip();
1696+
}
16871697
} else {
16881698
setSuggestedWords(suggestedWords);
16891699
}
@@ -1768,6 +1778,9 @@ public boolean tryShowClipboardSuggestion() {
17681778
// and there is a selection of text or it's the start of a line.
17691779
@Override
17701780
public void setNeutralSuggestionStrip() {
1781+
if (mKeyboardSwitcher.isHandwritingShowing()) { // ponytail: do not override/clear handwriting suggestions
1782+
return;
1783+
}
17711784
final SettingsValues currentSettings = mSettings.getCurrent();
17721785
if (tryShowOtpSuggestion() || tryShowClipboardSuggestion()) {
17731786
// an external (OTP or clipboard) suggestion has been set

app/src/main/java/helium314/keyboard/latin/handwriting/HandwritingView.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.widget.ImageButton
88
import android.widget.ImageView
99
import android.widget.LinearLayout
1010
import android.widget.TextView
11+
import android.widget.ProgressBar
1112
import android.graphics.drawable.GradientDrawable
1213
import helium314.keyboard.keyboard.KeyboardActionListener
1314
import helium314.keyboard.keyboard.KeyboardId
@@ -41,6 +42,8 @@ class HandwritingView @JvmOverloads constructor(
4142
private lateinit var clearButton: ImageButton
4243
private lateinit var canvas: HandwritingCanvas
4344
private lateinit var bottomRowKeyboard: MainKeyboardView
45+
private lateinit var downloadProgress: ProgressBar
46+
private var toolbar: View? = null // ponytail: track toolbar
4447

4548
private var keyboardActionListener: KeyboardActionListener? = null
4649
private var editorInfo: EditorInfo? = null
@@ -54,6 +57,8 @@ class HandwritingView @JvmOverloads constructor(
5457
clearButton = findViewById(R.id.handwriting_clear_button)
5558
canvas = findViewById(R.id.handwriting_canvas)
5659
bottomRowKeyboard = findViewById(R.id.handwriting_bottom_row_keyboard)
60+
downloadProgress = findViewById(R.id.handwriting_download_progress)
61+
toolbar = findViewById(R.id.handwriting_toolbar)
5762

5863
clearButton.setOnClickListener {
5964
clearCanvasAndComposition()
@@ -80,9 +85,9 @@ class HandwritingView @JvmOverloads constructor(
8085
this.currentLanguage = language
8186

8287
val colors = Settings.getValues().mColors
83-
val toolbar = findViewById<View>(R.id.handwriting_toolbar)
84-
if (toolbar != null) {
85-
colors.setBackground(toolbar, ColorType.MAIN_BACKGROUND)
88+
toolbar?.let {
89+
colors.setBackground(it, ColorType.MAIN_BACKGROUND)
90+
it.visibility = View.GONE // ponytail: hide by default to avoid duplicate toolbar/X buttons
8691
}
8792
colors.setBackground(canvas, ColorType.MAIN_BACKGROUND)
8893

@@ -91,6 +96,7 @@ class HandwritingView @JvmOverloads constructor(
9196
canvas.setStrokeColor(colors.get(ColorType.KEY_TEXT))
9297

9398
languageLabel.text = language
99+
downloadProgress.visibility = View.GONE
94100

95101
// Setup bottom row keyboard
96102
bottomRowKeyboard.setKeyPreviewPopupEnabled(Settings.getValues().mKeyPreviewPopupOn)
@@ -161,27 +167,37 @@ class HandwritingView @JvmOverloads constructor(
161167
val isReady = recognizer.isLanguageReady(language)
162168
mainHandler.post {
163169
if (!isReady) {
170+
toolbar?.visibility = View.VISIBLE // ponytail: show for download progress
164171
languageLabel.text = "$language (Downloading...)"
172+
downloadProgress.visibility = View.VISIBLE
173+
downloadProgress.progress = 0
165174
recognizer.downloadModel(language, object : ModelDownloadListener {
166175
override fun onProgress(progress: Float) {
167176
mainHandler.post {
168-
languageLabel.text = "$language (Downloading ${"%.0f".format(progress * 100)}%)"
177+
val percent = (progress * 100).toInt()
178+
languageLabel.text = "$language (Downloading $percent%)"
179+
downloadProgress.progress = percent
169180
}
170181
}
171182
override fun onComplete(success: Boolean) {
172183
mainHandler.post {
184+
downloadProgress.visibility = View.GONE
173185
if (success) {
186+
toolbar?.visibility = View.GONE // ponytail: hide when done
174187
languageLabel.text = language
175188
android.widget.Toast.makeText(context, "Handwriting model downloaded", android.widget.Toast.LENGTH_SHORT).show()
176189
} else {
190+
toolbar?.visibility = View.VISIBLE
177191
languageLabel.text = "$language (Download failed)"
178192
android.widget.Toast.makeText(context, "Failed to download handwriting model", android.widget.Toast.LENGTH_LONG).show()
179193
}
180194
}
181195
}
182196
})
183197
} else {
198+
toolbar?.visibility = View.GONE // ponytail: hide when already downloaded
184199
languageLabel.text = language
200+
downloadProgress.visibility = View.GONE
185201
}
186202
}
187203
}

app/src/main/res/layout/handwriting_view.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
android:textColor="?android:attr/textColorSecondary"
3232
android:textSize="14sp" />
3333

34+
<ProgressBar
35+
android:id="@+id/handwriting_download_progress"
36+
style="?android:attr/progressBarStyleHorizontal"
37+
android:layout_width="match_parent"
38+
android:layout_height="4dp"
39+
android:layout_alignParentBottom="true"
40+
android:visibility="gone"
41+
android:max="100" />
42+
3443
<ImageButton
3544
android:id="@+id/handwriting_clear_button"
3645
android:layout_width="48dp"

0 commit comments

Comments
 (0)