Merge pull request #8671 from keymanapp/refactor/android/current-banner

refactor(android/engine): Move currentBanner to KMKeyboard
This commit is contained in:
Darcy Wong 2023-04-26 17:48:41 +07:00 committed by GitHub
commit ef77f70dc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 21 deletions

View file

@ -76,6 +76,21 @@ final class KMKeyboard extends WebView {
protected ArrayList<String> javascriptAfterLoad = new ArrayList<String>();
private static String currentKeyboard = null;
/**
* Banner state value: "blank" - no banner available.
*/
protected static final String KM_BANNER_STATE_BLANK = "blank";
/**
* Banner state value: "suggestion" - dictionary suggestions are shown.
*/
protected static final String KM_BANNER_STATE_SUGGESTION = "suggestion";
/**
* Current banner state.
*/
protected static String currentBanner = KM_BANNER_STATE_BLANK;
private static String txtFont = "";
private static String oskFont = null;
private static String keyboardRoot = "";
@ -401,6 +416,12 @@ final class KMKeyboard extends WebView {
return currentKeyboard;
}
public static void setCurrentBanner(String banner) {
currentBanner = banner;
}
public static String currentBanner() { return currentBanner; }
/**
* Return the full path to the display text font. Usually used for creating a Typeface font
* @return String

View file

@ -245,8 +245,8 @@ public final class KMKeyboardWebViewClient extends WebViewClient {
if (KMManager.currentLexicalModel != null) {
modelPredictionPref = prefs.getBoolean(KMManager.getLanguagePredictionPreferenceKey(KMManager.currentLexicalModel.get(KMManager.KMKey_LanguageID)), true);
}
KMManager.currentBanner = (isModelActive && modelPredictionPref) ?
KMManager.KM_BANNER_STATE_SUGGESTION : KMManager.KM_BANNER_STATE_BLANK;
kmKeyboard.setCurrentBanner((isModelActive && modelPredictionPref) ?
KMKeyboard.KM_BANNER_STATE_SUGGESTION : KMKeyboard.KM_BANNER_STATE_BLANK);
RelativeLayout.LayoutParams params = KMManager.getKeyboardLayoutParams();
kmKeyboard.setLayoutParams(params);
} else if (url.indexOf("suggestPopup") >= 0) {

View file

@ -190,22 +190,6 @@ public final class KMManager {
public final static String predictionPrefSuffix = ".mayPredict";
public final static String correctionPrefSuffix = ".mayCorrect";
/**
* Banner state value: "blank" - no banner available.
*/
protected static final String KM_BANNER_STATE_BLANK = "blank";
/**
* Banner state value: "suggestion" - dictionary suggestions are shown.
*/
protected static final String KM_BANNER_STATE_SUGGESTION = "suggestion";
//TODO: should be part of kmkeyboard
/**
* Current banner state.
*/
protected static String currentBanner = KM_BANNER_STATE_BLANK;
// Special override for when the keyboard may have haptic feedback when typing.
// haptic feedback disabled for hardware keystrokes
private static boolean mayHaveHapticFeedback = false;
@ -1852,7 +1836,9 @@ public final class KMManager {
public static int getBannerHeight(Context context) {
int bannerHeight = 0;
if (currentBanner.equals(KM_BANNER_STATE_SUGGESTION)) {
if (InAppKeyboard != null && InAppKeyboard.currentBanner().equals(KMKeyboard.KM_BANNER_STATE_SUGGESTION)) {
bannerHeight = (int) context.getResources().getDimension(R.dimen.banner_height);
} else if (SystemKeyboard != null && SystemKeyboard.currentBanner().equals(KMKeyboard.KM_BANNER_STATE_SUGGESTION)) {
bannerHeight = (int) context.getResources().getDimension(R.dimen.banner_height);
}
return bannerHeight;
@ -2168,9 +2154,14 @@ public final class KMManager {
private static void toggleSuggestionBanner(String languageID, boolean inappKeyboardChanged, boolean systemKeyboardChanged) {
//reset banner state if new language has no lexical model
if (currentBanner.equals(KMManager.KM_BANNER_STATE_SUGGESTION)
if (InAppKeyboard != null && InAppKeyboard.currentBanner().equals(KMKeyboard.KM_BANNER_STATE_SUGGESTION)
&& getAssociatedLexicalModel(languageID)==null) {
currentBanner = KMManager.KM_BANNER_STATE_BLANK;
InAppKeyboard.setCurrentBanner(KMKeyboard.KM_BANNER_STATE_BLANK);
}
if (SystemKeyboard != null && SystemKeyboard.currentBanner().equals(KMKeyboard.KM_BANNER_STATE_SUGGESTION)
&& getAssociatedLexicalModel(languageID)==null) {
SystemKeyboard.setCurrentBanner(KMKeyboard.KM_BANNER_STATE_BLANK);
}
if(inappKeyboardChanged) {