mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Show indicator for transformer suggestions, lazily load model
This commit is contained in:
parent
7c4531e32d
commit
21bd35237d
13
java/res/drawable/transformer_suggestion.xml
Normal file
13
java/res/drawable/transformer_suggestion.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:viewportWidth="13"
|
||||
android:viewportHeight="2.5"
|
||||
android:width="13dp"
|
||||
android:height="2.5dp">
|
||||
<path
|
||||
android:pathData="M13 1.75A6.5 0.75 0 0 1 0 1.75A6.5 0.75 0 0 1 13 1.75Z"
|
||||
android:fillColor="#FFFFFF" />
|
||||
<path
|
||||
android:pathData="M13 0.75A6.5 0.75 0 0 1 0 0.75A6.5 0.75 0 0 1 13 0.75Z"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillAlpha="0.5" />
|
||||
</vector>
|
@ -280,6 +280,8 @@ public class SuggestedWords {
|
||||
public final int mAutoCommitFirstWordConfidence;
|
||||
private String mDebugString = "";
|
||||
|
||||
public boolean mOriginatesFromTransformerLM = false;
|
||||
|
||||
/**
|
||||
* Create a new suggested word info.
|
||||
* @param word The string to suggest.
|
||||
|
@ -42,6 +42,8 @@ import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.graphics.drawscope.scale
|
||||
import androidx.compose.ui.graphics.drawscope.translate
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@ -168,20 +170,31 @@ fun RowScope.SuggestionItem(words: SuggestedWords, idx: Int, isPrimary: Boolean,
|
||||
null
|
||||
}
|
||||
|
||||
//val topSuggestionIcon = painterResource(id = R.drawable.top_suggestion)
|
||||
val textButtonModifier = when (isPrimary) {
|
||||
val wordInfo = try {
|
||||
words.getInfo(idx)
|
||||
} catch(e: IndexOutOfBoundsException) {
|
||||
null
|
||||
}
|
||||
|
||||
val iconColor = MaterialTheme.colorScheme.onBackground
|
||||
val topSuggestionIcon = painterResource(id = R.drawable.transformer_suggestion)
|
||||
val textButtonModifier = when (wordInfo?.mOriginatesFromTransformerLM) {
|
||||
true -> Modifier.drawBehind {
|
||||
/*with(topSuggestionIcon) {
|
||||
with(topSuggestionIcon) {
|
||||
val iconSize = topSuggestionIcon.intrinsicSize
|
||||
translate(
|
||||
left = (size.width - iconSize.width) / 2.0f,
|
||||
top = size.height - iconSize.height * 2.0f
|
||||
) {
|
||||
draw(topSuggestionIcon.intrinsicSize) // Needs to be tinted
|
||||
draw(
|
||||
topSuggestionIcon.intrinsicSize,
|
||||
alpha = if(isPrimary){ 1.0f } else { 0.66f } / 1.25f,
|
||||
//colorFilter = ColorFilter.tint(color = iconColor, blendMode = BlendMode.Multiply)
|
||||
)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
false -> Modifier
|
||||
}
|
||||
else -> Modifier
|
||||
}
|
||||
|
||||
val textModifier = when (isPrimary) {
|
||||
|
@ -75,10 +75,20 @@ public class LanguageModel extends Dictionary {
|
||||
return outputFile.getAbsolutePath() + ":" + outputFileTokenizer.getAbsolutePath();
|
||||
}
|
||||
|
||||
Context context = null;
|
||||
Thread initThread = null;
|
||||
public LanguageModel(Context context, String dictType, Locale locale) {
|
||||
super(dictType, locale);
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private void loadModel() {
|
||||
if (initThread != null && initThread.isAlive()){
|
||||
Log.d("LanguageModel", "Cannot load model again, as initThread is still active");
|
||||
return;
|
||||
}
|
||||
|
||||
initThread = new Thread() {
|
||||
@Override public void run() {
|
||||
if(mNativeState != 0) return;
|
||||
@ -113,6 +123,7 @@ public class LanguageModel extends Dictionary {
|
||||
Log.d("LanguageModel", "getSuggestions called");
|
||||
|
||||
if (mNativeState == 0) {
|
||||
loadModel();
|
||||
Log.d("LanguageModel", "Exiting becuase mNativeState == 0");
|
||||
return null;
|
||||
}
|
||||
@ -226,6 +237,7 @@ public class LanguageModel extends Dictionary {
|
||||
suggestions.add(new SuggestedWords.SuggestedWordInfo( word, context, (int)(outProbabilities[i] * 100.0f), kind, this, 0, 0 ));
|
||||
}
|
||||
|
||||
/*
|
||||
if(kind == SuggestedWords.SuggestedWordInfo.KIND_PREDICTION) {
|
||||
// TODO: Forcing the thing to appear
|
||||
for (int i = suggestions.size(); i < 3; i++) {
|
||||
@ -235,6 +247,11 @@ public class LanguageModel extends Dictionary {
|
||||
suggestions.add(new SuggestedWords.SuggestedWordInfo(word, context, 1, kind, this, 0, 0));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
for(SuggestedWords.SuggestedWordInfo suggestion : suggestions) {
|
||||
suggestion.mOriginatesFromTransformerLM = true;
|
||||
}
|
||||
|
||||
Log.d("LanguageModel", "returning " + String.valueOf(suggestions.size()) + " suggestions");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user