Restore support for Android < 12, set minimal version to 4

API level 12 is required for "subtype" code introduced in 1.7.
This adds a fallback for older version, "subtype" features are not
available but the keyboard is usable.

Changet he minimal version to 4 to be able to query the API level.

Using integer constant for versions because that's how it's presented in
the documentation. Build.VERSION_CODES is WTF.
This commit is contained in:
Jules Aguillon 2021-05-09 00:56:59 +02:00
parent 5e01198500
commit 68945ff227
2 changed files with 25 additions and 4 deletions

View File

@ -5,7 +5,7 @@
android:versionName="1.8" android:versionName="1.8"
android:hardwareAccelerated="false"> android:hardwareAccelerated="false">
<uses-sdk android:minSdkVersion="3" <uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="29" /> android:targetSdkVersion="29" />
<application android:label="@string/app_name" <application android:label="@string/app_name"

View File

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.os.Build.VERSION;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.text.InputType; import android.text.InputType;
@ -114,13 +115,33 @@ public class Keyboard2 extends InputMethodService
_config.accent_flags_to_remove = ~to_keep & KeyValue.FLAGS_ACCENTS; _config.accent_flags_to_remove = ~to_keep & KeyValue.FLAGS_ACCENTS;
} }
private void refreshSubtypeLegacyFallback()
{
// Fallback for the accents option: Only respect the "None" case
switch (_config.accents)
{
case 1: case 2: case 3: _config.accent_flags_to_remove = 0; break;
case 4: _config.accent_flags_to_remove = KeyValue.FLAGS_ACCENTS; break;
}
// Fallback for the layout option: Use qwerty in the "system settings" case
_currentTextLayout = (_config.layout == -1) ? R.xml.qwerty : _config.layout;
}
private void refreshSubtypeImm() private void refreshSubtypeImm()
{ {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken()); _config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken());
if (VERSION.SDK_INT < 12)
{
// Subtypes won't work well under API level 12 (getExtraValueOf)
refreshSubtypeLegacyFallback();
}
else
{
InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype(); InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype();
refreshSubtypeLayout(subtype); refreshSubtypeLayout(subtype);
refreshAccentsOption(imm, subtype); refreshAccentsOption(imm, subtype);
}
} }
@Override @Override