aa8fff2c0d
Integrates LiteRT-LM (Google) with Gemma 4 E2B-it for on-device spell/grammar correction in HeliBoard. After sentence-ending punctuation, the model checks the sentence and shows a correction in the suggestion strip. Tapping it replaces the original text — fully offline, no cloud API. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
75 lines
3.8 KiB
Diff
75 lines
3.8 KiB
Diff
From: AIKeyboard AI Integration <ai@aikeyboard.local>
|
|
Date: Wed, 09 Apr 2025 00:00:00 +0000
|
|
Subject: [PATCH 3/3] Add italic colour styling for AI correction suggestions
|
|
|
|
Modifies two methods in SuggestionStripLayoutHelper:
|
|
|
|
1. getSuggestionTextColor(): Returns mColorAutoCorrect for AI suggestions
|
|
(KIND_APP_DEFINED / KIND_AI_CORRECTION = 6), giving them the same accent
|
|
colour as auto-corrections.
|
|
|
|
2. getStyledSuggestedWord(): Adds an italic StyleSpan for AI suggestions so
|
|
users can visually distinguish them from regular word predictions.
|
|
|
|
Both method signatures and bodies verified against HeliBoard main (Apr 2025).
|
|
---
|
|
.../suggestions/SuggestionStripLayoutHelper.java | 31 ++++++++++++++++++
|
|
1 file changed, 31 insertions(+)
|
|
|
|
diff --git a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripLayoutHelper.java b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripLayoutHelper.java
|
|
--- a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripLayoutHelper.java
|
|
+++ b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripLayoutHelper.java
|
|
@@ -1,3 +1,5 @@
|
|
+import android.graphics.Typeface;
|
|
+import android.text.style.StyleSpan;
|
|
/*
|
|
* Copyright (C) 2013 The Android Open Source Project
|
|
*
|
|
@@ -1,0 +1,0 @@ private int getSuggestionTextColor(final SuggestedWords suggestedWords,
|
|
private int getSuggestionTextColor(final SuggestedWords suggestedWords,
|
|
final int indexInSuggestedWords) {
|
|
- final boolean isTypedWord = suggestedWords.getInfo(indexInSuggestedWords).isKindOf(SuggestedWordInfo.KIND_TYPED);
|
|
+ final SuggestedWordInfo wordInfo = suggestedWords.getInfo(indexInSuggestedWords);
|
|
+ final boolean isTypedWord = wordInfo.isKindOf(SuggestedWordInfo.KIND_TYPED);
|
|
+
|
|
+ // AI correction: use auto-correct accent colour so it stands out
|
|
+ if (wordInfo.isKindOf(SuggestedWordInfo.KIND_APP_DEFINED)) {
|
|
+ return mColorAutoCorrect;
|
|
+ }
|
|
|
|
final int color;
|
|
if (indexInSuggestedWords == SuggestedWords.INDEX_OF_AUTO_CORRECTION && suggestedWords.mWillAutoCorrect) {
|
|
@@ -1,0 +1,0 @@ private CharSequence getStyledSuggestedWord(final SuggestedWords suggestedWords,
|
|
private CharSequence getStyledSuggestedWord(final SuggestedWords suggestedWords,
|
|
final int indexInSuggestedWords) {
|
|
if (indexInSuggestedWords >= suggestedWords.size()) {
|
|
return null;
|
|
}
|
|
final String word = suggestedWords.getLabel(indexInSuggestedWords);
|
|
final boolean isAutoCorrection = suggestedWords.mWillAutoCorrect
|
|
&& indexInSuggestedWords == SuggestedWords.INDEX_OF_AUTO_CORRECTION;
|
|
final boolean isTypedWordValid = suggestedWords.mTypedWordValid
|
|
&& indexInSuggestedWords == SuggestedWords.INDEX_OF_TYPED_WORD;
|
|
- if (!isAutoCorrection && !isTypedWordValid) {
|
|
+ final boolean isAiCorrection = suggestedWords.getInfo(indexInSuggestedWords)
|
|
+ .isKindOf(SuggestedWordInfo.KIND_APP_DEFINED);
|
|
+ if (!isAutoCorrection && !isTypedWordValid && !isAiCorrection) {
|
|
return word;
|
|
}
|
|
|
|
final Spannable spannedWord = new SpannableString(word);
|
|
final int options = mSuggestionStripOptions;
|
|
if ((isAutoCorrection && (options & AUTO_CORRECT_BOLD) != 0)
|
|
|| (isTypedWordValid && (options & VALID_TYPED_WORD_BOLD) != 0)) {
|
|
addStyleSpan(spannedWord, BOLD_SPAN);
|
|
}
|
|
if (isAutoCorrection && (options & AUTO_CORRECT_UNDERLINE) != 0) {
|
|
addStyleSpan(spannedWord, UNDERLINE_SPAN);
|
|
}
|
|
+ // AI correction: italic to signal model-generated suggestion
|
|
+ if (isAiCorrection) {
|
|
+ addStyleSpan(spannedWord, new StyleSpan(Typeface.ITALIC));
|
|
+ }
|
|
return spannedWord;
|
|
}
|