Fix compatibility with Android 6

Android 6 uses Java 1.7, the only incompatible feature in use was
lambdas.
This commit is contained in:
Jules Aguillon 2022-04-16 23:36:54 +02:00
parent 14cc318a0e
commit 9a8c4f291d
4 changed files with 42 additions and 32 deletions

View File

@ -3,7 +3,7 @@
PACKAGE_NAME = juloo.keyboard2 PACKAGE_NAME = juloo.keyboard2
ANDROID_PLATFORM_VERSION = android-30 ANDROID_PLATFORM_VERSION = android-30
JAVA_VERSION = 1.8 JAVA_VERSION = 1.7
SRC_DIR = srcs SRC_DIR = srcs
RES_DIR = res RES_DIR = res

View File

@ -149,34 +149,38 @@ final class Config
public KeyboardData modify_layout(KeyboardData kw) public KeyboardData modify_layout(KeyboardData kw)
{ {
// Update the name to avoid caching in KeyModifier // Update the name to avoid caching in KeyModifier
KeyValue action_key = (actionLabel == null) ? null : final KeyValue action_key = (actionLabel == null) ? null :
KeyValue.getKeyByName("action").withNameAndSymbol(actionLabel, actionLabel); KeyValue.getKeyByName("action").withNameAndSymbol(actionLabel, actionLabel);
return kw.replaceKeys(key -> { return kw.replaceKeys(new KeyboardData.MapKeys() {
if (key == null) public KeyValue apply(KeyValue key)
return null;
switch (key.eventCode)
{ {
case KeyValue.EVENT_CHANGE_METHOD: if (key == null)
return shouldOfferSwitchingToNextInputMethod ? key : null; return null;
case KeyEvent.KEYCODE_ENTER: switch (key.eventCode)
return (swapEnterActionKey && action_key != null) ? action_key : key; {
case KeyValue.EVENT_ACTION: case KeyValue.EVENT_CHANGE_METHOD:
return (swapEnterActionKey && action_key != null) ? return shouldOfferSwitchingToNextInputMethod ? key : null;
KeyValue.getKeyByName("enter") : action_key; case KeyEvent.KEYCODE_ENTER:
case KeyValue.EVENT_SWITCH_PROGRAMMING: return (swapEnterActionKey && action_key != null) ? action_key : key;
return shouldOfferSwitchingToProgramming ? key : null; case KeyValue.EVENT_ACTION:
default: return (swapEnterActionKey && action_key != null) ?
if (key.flags != 0) KeyValue.getKeyByName("enter") : action_key;
{ case KeyValue.EVENT_SWITCH_PROGRAMMING:
if ((key.flags & KeyValue.FLAG_LOCALIZED) != 0 && return shouldOfferSwitchingToProgramming ? key : null;
extra_keys != null && default:
!extra_keys.contains(key.name)) if (key.flags != 0)
return null; {
if ((key.flags & lockable_modifiers) != 0) if ((key.flags & KeyValue.FLAG_LOCALIZED) != 0 &&
return key.withFlags(key.flags | KeyValue.FLAG_LOCK); extra_keys != null &&
} !extra_keys.contains(key.name))
return key; return null;
}}); if ((key.flags & lockable_modifiers) != 0)
return key.withFlags(key.flags | KeyValue.FLAG_LOCK);
}
return key;
}
}
});
} }
private float getDipPref(DisplayMetrics dm, SharedPreferences prefs, String pref_name, float def) private float getDipPref(DisplayMetrics dm, SharedPreferences prefs, String pref_name, float def)

View File

@ -294,10 +294,13 @@ public class Keyboard2 extends InputMethodService
if (_config.programming_layout == -1) if (_config.programming_layout == -1)
return; return;
KeyboardData layout = KeyboardData layout =
getLayout(_config.programming_layout).replaceKeys(key -> { getLayout(_config.programming_layout).replaceKeys(new KeyboardData.MapKeys() {
if (key != null && key.eventCode == KeyValue.EVENT_SWITCH_PROGRAMMING) public KeyValue apply(KeyValue key)
return KeyValue.getKeyByName("switch_text"); {
return key; if (key != null && key.eventCode == KeyValue.EVENT_SWITCH_PROGRAMMING)
return KeyValue.getKeyByName("switch_text");
return key;
}
}); });
_keyboardView.setKeyboard(layout); _keyboardView.setKeyboard(layout);
} }

View File

@ -208,7 +208,10 @@ class KeyboardData
} }
} }
public static abstract interface MapKeys extends Function<KeyValue, KeyValue> { } // Not using Function<KeyValue, KeyValue> to keep compatibility with Android 6.
public static abstract interface MapKeys {
public KeyValue apply(KeyValue kv);
}
/** Parsing utils */ /** Parsing utils */