some more warnings addressed

This commit is contained in:
Helium314 2023-09-09 18:47:21 +02:00
parent 9426a2d616
commit 3ba28b7a22
18 changed files with 74 additions and 174 deletions

View file

@ -5,7 +5,7 @@ import java.util.*
object EditorInfoCompatUtils { object EditorInfoCompatUtils {
// Note that EditorInfo.IME_FLAG_FORCE_ASCII has been introduced // Note that EditorInfo.IME_FLAG_FORCE_ASCII has been introduced
// in API level 16 (Build.VERSION_CODES.JELLY_BEAN). // in API level 16 (Build.VERSION_CODES.JELLY_BEAN).
private val FIELD_IME_FLAG_FORCE_ASCII = CompatUtils.getField( private val FIELD_IME_FLAG_FORCE_ASCII = CompatUtils.getField(
EditorInfo::class.java, "IME_FLAG_FORCE_ASCII") EditorInfo::class.java, "IME_FLAG_FORCE_ASCII")
private val OBJ_IME_FLAG_FORCE_ASCII: Int? = CompatUtils.getFieldValue( private val OBJ_IME_FLAG_FORCE_ASCII: Int? = CompatUtils.getFieldValue(
@ -13,12 +13,12 @@ object EditorInfoCompatUtils {
private val FIELD_HINT_LOCALES = CompatUtils.getField( private val FIELD_HINT_LOCALES = CompatUtils.getField(
EditorInfo::class.java, "hintLocales") EditorInfo::class.java, "hintLocales")
@kotlin.jvm.JvmStatic @JvmStatic
fun hasFlagForceAscii(imeOptions: Int): Boolean { fun hasFlagForceAscii(imeOptions: Int): Boolean {
return if (OBJ_IME_FLAG_FORCE_ASCII == null) false else imeOptions and OBJ_IME_FLAG_FORCE_ASCII != 0 return if (OBJ_IME_FLAG_FORCE_ASCII == null) false else imeOptions and OBJ_IME_FLAG_FORCE_ASCII != 0
} }
@kotlin.jvm.JvmStatic @JvmStatic
fun imeActionName(imeOptions: Int): String { fun imeActionName(imeOptions: Int): String {
val actionId = imeOptions and EditorInfo.IME_MASK_ACTION val actionId = imeOptions and EditorInfo.IME_MASK_ACTION
return when (actionId) { return when (actionId) {
@ -49,10 +49,10 @@ object EditorInfoCompatUtils {
if (hasFlagForceAscii(imeOptions)) { if (hasFlagForceAscii(imeOptions)) {
flags.append("flagForceAscii|") flags.append("flagForceAscii|")
} }
return if (action != null) flags.toString() + action else flags.toString() return flags.toString() + action
} }
@kotlin.jvm.JvmStatic @JvmStatic
fun getPrimaryHintLocale(editorInfo: EditorInfo?): Locale? { fun getPrimaryHintLocale(editorInfo: EditorInfo?): Locale? {
if (editorInfo == null) { if (editorInfo == null) {
return null return null
@ -61,6 +61,6 @@ object EditorInfoCompatUtils {
?: return null ?: return null
return if (LocaleListCompatUtils.isEmpty(localeList)) { return if (LocaleListCompatUtils.isEmpty(localeList)) {
null null
} else LocaleListCompatUtils.get(localeList, 0) } else LocaleListCompatUtils[localeList, 0]
} }
} }

View file

@ -7,7 +7,7 @@ import org.dslul.openboard.inputmethod.compat.CompatUtils.ToBooleanMethodWrapper
object InputConnectionCompatUtils { object InputConnectionCompatUtils {
private var sInputConnectionType: ClassWrapper? = null private var sInputConnectionType: ClassWrapper? = null
private var sRequestCursorUpdatesMethod: ToBooleanMethodWrapper? = null private var sRequestCursorUpdatesMethod: ToBooleanMethodWrapper? = null
val isRequestCursorUpdatesAvailable: Boolean private val isRequestCursorUpdatesAvailable: Boolean
get() = sRequestCursorUpdatesMethod != null get() = sRequestCursorUpdatesMethod != null
/** /**
@ -31,7 +31,7 @@ object InputConnectionCompatUtils {
* as soon as possible to notify the current cursor/anchor position to the input method. * as soon as possible to notify the current cursor/anchor position to the input method.
* @return `false` if the request is not handled. Otherwise returns `true`. * @return `false` if the request is not handled. Otherwise returns `true`.
*/ */
@kotlin.jvm.JvmStatic @JvmStatic
fun requestCursorUpdates(inputConnection: InputConnection, fun requestCursorUpdates(inputConnection: InputConnection,
enableMonitor: Boolean, requestImmediateCallback: Boolean): Boolean { enableMonitor: Boolean, requestImmediateCallback: Boolean): Boolean {
val cursorUpdateMode = ((if (enableMonitor) CURSOR_UPDATE_MONITOR else 0) val cursorUpdateMode = ((if (enableMonitor) CURSOR_UPDATE_MONITOR else 0)

View file

@ -4,42 +4,19 @@ import android.content.Context
import android.text.Spannable import android.text.Spannable
import android.text.SpannableString import android.text.SpannableString
import android.text.Spanned import android.text.Spanned
import android.text.TextUtils
import android.text.style.SuggestionSpan import android.text.style.SuggestionSpan
import org.dslul.openboard.inputmethod.annotations.UsedForTesting import org.dslul.openboard.inputmethod.annotations.UsedForTesting
import org.dslul.openboard.inputmethod.latin.SuggestedWords
import org.dslul.openboard.inputmethod.latin.SuggestedWords.SuggestedWordInfo
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils
import org.dslul.openboard.inputmethod.latin.define.DebugFlags
import java.util.* import java.util.*
object SuggestionSpanUtils { object SuggestionSpanUtils {
// Note that SuggestionSpan.FLAG_AUTO_CORRECTION has been introduced @JvmStatic
// in API level 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1).
private val FIELD_FLAG_AUTO_CORRECTION = CompatUtils.getField(
SuggestionSpan::class.java, "FLAG_AUTO_CORRECTION")
private val OBJ_FLAG_AUTO_CORRECTION: Int? = CompatUtils.getFieldValue(
null /* receiver */, null /* defaultValue */, FIELD_FLAG_AUTO_CORRECTION) as Int
@kotlin.jvm.JvmStatic
@UsedForTesting @UsedForTesting
fun getTextWithAutoCorrectionIndicatorUnderline( fun getTextWithAutoCorrectionIndicatorUnderline(context: Context?, text: String, locale: Locale?): CharSequence {
context: Context?, text: String,locale: Locale?): CharSequence { if (text.isEmpty())
if (TextUtils.isEmpty(text) || OBJ_FLAG_AUTO_CORRECTION == null) {
return text return text
}
val spannable: Spannable = SpannableString(text) val spannable: Spannable = SpannableString(text)
val suggestionSpan = SuggestionSpan(context, locale, arrayOf(), OBJ_FLAG_AUTO_CORRECTION, null) val suggestionSpan = SuggestionSpan(context, locale, arrayOf(), SuggestionSpan.FLAG_AUTO_CORRECTION, null)
spannable.setSpan(suggestionSpan, 0, text.length, spannable.setSpan(suggestionSpan, 0, text.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE or Spanned.SPAN_COMPOSING)
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE or Spanned.SPAN_COMPOSING)
return spannable return spannable
} }
init {
if (DebugFlags.DEBUG_ENABLED) {
if (OBJ_FLAG_AUTO_CORRECTION == null) {
throw RuntimeException("Field is accidentially null.")
}
}
}
} }

View file

@ -1,28 +1,24 @@
package org.dslul.openboard.inputmethod.compat package org.dslul.openboard.inputmethod.compat
import android.os.Build
import android.view.textservice.TextInfo import android.view.textservice.TextInfo
import org.dslul.openboard.inputmethod.annotations.UsedForTesting import org.dslul.openboard.inputmethod.annotations.UsedForTesting
object TextInfoCompatUtils { object TextInfoCompatUtils {
// Note that TextInfo.getCharSequence() is supposed to be available in API level 21 and later. // Note that TextInfo.getCharSequence() is supposed to be available in API level 21 and later.
private val TEXT_INFO_GET_CHAR_SEQUENCE = CompatUtils.getMethod(TextInfo::class.java, "getCharSequence") private val TEXT_INFO_GET_CHAR_SEQUENCE = CompatUtils.getMethod(TextInfo::class.java, "getCharSequence")
private val TEXT_INFO_CONSTRUCTOR_FOR_CHAR_SEQUENCE = CompatUtils.getConstructor(TextInfo::class.java, CharSequence::class.java, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType,
Int::class.javaPrimitiveType, Int::class.javaPrimitiveType)
@get:UsedForTesting @get:UsedForTesting
val isCharSequenceSupported: Boolean val isCharSequenceSupported: Boolean
get() = TEXT_INFO_GET_CHAR_SEQUENCE != null && get() = TEXT_INFO_GET_CHAR_SEQUENCE != null
TEXT_INFO_CONSTRUCTOR_FOR_CHAR_SEQUENCE != null
@kotlin.jvm.JvmStatic @JvmStatic
@UsedForTesting @UsedForTesting
fun newInstance(charSequence: CharSequence, start: Int, end: Int, cookie: Int, fun newInstance(charSequence: CharSequence, start: Int, end: Int, cookie: Int,
sequenceNumber: Int): TextInfo? { sequenceNumber: Int): TextInfo {
return if (TEXT_INFO_CONSTRUCTOR_FOR_CHAR_SEQUENCE != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
CompatUtils.newInstance(TEXT_INFO_CONSTRUCTOR_FOR_CHAR_SEQUENCE, return TextInfo(charSequence, start, end, cookie, sequenceNumber)
charSequence, start, end, cookie, sequenceNumber) as TextInfo return TextInfo(charSequence.subSequence(start, end).toString(), cookie, sequenceNumber)
} else TextInfo(charSequence.subSequence(start, end).toString(), cookie,
sequenceNumber)
} }
/** /**
@ -34,11 +30,12 @@ object TextInfoCompatUtils {
* the result of [TextInfo.getText] as fall back. If `textInfo` is `null`, * the result of [TextInfo.getText] as fall back. If `textInfo` is `null`,
* returns `null`. * returns `null`.
*/ */
@kotlin.jvm.JvmStatic @JvmStatic
@UsedForTesting @UsedForTesting
fun getCharSequenceOrString(textInfo: TextInfo?): CharSequence? { fun getCharSequenceOrString(textInfo: TextInfo?): CharSequence? {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
return textInfo?.charSequence
val defaultValue: CharSequence? = textInfo?.text val defaultValue: CharSequence? = textInfo?.text
return CompatUtils.invoke(textInfo, defaultValue!!, return CompatUtils.invoke(textInfo, defaultValue!!, TEXT_INFO_GET_CHAR_SEQUENCE) as CharSequence
TEXT_INFO_GET_CHAR_SEQUENCE) as CharSequence
} }
} }

View file

@ -1,51 +0,0 @@
package org.dslul.openboard.inputmethod.compat
import android.content.Context
import android.os.Build
import android.os.Build.VERSION_CODES
import android.os.UserManager
import androidx.annotation.IntDef
import androidx.annotation.RequiresApi
import java.lang.reflect.Method
/**
* A temporary solution until `UserManagerCompat.isUserUnlocked()` in the support-v4 library
* becomes publicly available.
*/
object UserManagerCompatUtils {
private var METHOD_isUserUnlocked: Method? = null
const val LOCK_STATE_UNKNOWN = 0
const val LOCK_STATE_UNLOCKED = 1
const val LOCK_STATE_LOCKED = 2
/**
* Check if the calling user is running in an "unlocked" state. A user is unlocked only after
* they've entered their credentials (such as a lock pattern or PIN), and credential-encrypted
* private app data storage is available.
* @param context context from which [UserManager] should be obtained.
* @return One of [LockState].
*/
@RequiresApi(VERSION_CODES.M)
@kotlin.jvm.JvmStatic
@LockState
fun getUserLockState(context: Context): Int {
if (METHOD_isUserUnlocked == null) {
return LOCK_STATE_UNKNOWN
}
val userManager = context.getSystemService(UserManager::class.java)
?: return LOCK_STATE_UNKNOWN
val result = CompatUtils.invoke(userManager, null, METHOD_isUserUnlocked) as Boolean
return if (result) LOCK_STATE_UNLOCKED else LOCK_STATE_LOCKED
}
@kotlin.annotation.Retention(AnnotationRetention.SOURCE)
@IntDef(LOCK_STATE_UNKNOWN, LOCK_STATE_UNLOCKED, LOCK_STATE_LOCKED)
annotation class LockState
init { // We do not try to search the method in Android M and prior.
METHOD_isUserUnlocked = if (Build.VERSION.SDK_INT <= VERSION_CODES.M) {
null
} else {
CompatUtils.getMethod(UserManager::class.java, "isUserUnlocked")
}
}
}

View file

@ -10,8 +10,8 @@ object ViewOutlineProviderCompatUtils {
override fun setInsets(insets: InputMethodService.Insets) {} override fun setInsets(insets: InputMethodService.Insets) {}
} }
@kotlin.jvm.JvmStatic @JvmStatic
fun setInsetsOutlineProvider(view: View): InsetsUpdater? { fun setInsetsOutlineProvider(view: View): InsetsUpdater {
return if (Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) { return if (Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
EMPTY_INSETS_UPDATER EMPTY_INSETS_UPDATER
} else ViewOutlineProviderCompatUtilsLXX.setInsetsOutlineProvider(view) } else ViewOutlineProviderCompatUtilsLXX.setInsetsOutlineProvider(view)

View file

@ -2,10 +2,13 @@ package org.dslul.openboard.inputmethod.compat
import android.graphics.Outline import android.graphics.Outline
import android.inputmethodservice.InputMethodService import android.inputmethodservice.InputMethodService
import android.os.Build
import android.view.View import android.view.View
import android.view.ViewOutlineProvider import android.view.ViewOutlineProvider
import androidx.annotation.RequiresApi
import org.dslul.openboard.inputmethod.compat.ViewOutlineProviderCompatUtils.InsetsUpdater import org.dslul.openboard.inputmethod.compat.ViewOutlineProviderCompatUtils.InsetsUpdater
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
internal object ViewOutlineProviderCompatUtilsLXX { internal object ViewOutlineProviderCompatUtilsLXX {
fun setInsetsOutlineProvider(view: View): InsetsUpdater { fun setInsetsOutlineProvider(view: View): InsetsUpdater {
val provider = InsetsOutlineProvider(view) val provider = InsetsOutlineProvider(view)
@ -29,8 +32,7 @@ internal object ViewOutlineProviderCompatUtilsLXX {
return return
} }
// TODO: Revisit this when floating/resize keyboard is supported. // TODO: Revisit this when floating/resize keyboard is supported.
outline.setRect( outline.setRect(view.left, mLastVisibleTopInsets, view.right, view.bottom)
view.left, mLastVisibleTopInsets, view.right, view.bottom)
} }
companion object { companion object {

View file

@ -22,7 +22,6 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import org.dslul.openboard.inputmethod.keyboard.internal.KeyDrawParams; import org.dslul.openboard.inputmethod.keyboard.internal.KeyDrawParams;
import org.dslul.openboard.inputmethod.keyboard.internal.KeySpecParser; import org.dslul.openboard.inputmethod.keyboard.internal.KeySpecParser;
import org.dslul.openboard.inputmethod.keyboard.internal.KeyStyle; import org.dslul.openboard.inputmethod.keyboard.internal.KeyStyle;

View file

@ -28,7 +28,6 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import org.dslul.openboard.inputmethod.compat.EditorInfoCompatUtils; import org.dslul.openboard.inputmethod.compat.EditorInfoCompatUtils;
import org.dslul.openboard.inputmethod.compat.UserManagerCompatUtils;
import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardBuilder; import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardBuilder;
import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams; import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams;
import org.dslul.openboard.inputmethod.keyboard.internal.UniqueKeysCache; import org.dslul.openboard.inputmethod.keyboard.internal.UniqueKeysCache;
@ -51,6 +50,7 @@ import static org.dslul.openboard.inputmethod.latin.common.Constants.ImeOption.N
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.os.UserManagerCompat;
/** /**
* This class represents a set of keyboard layouts. Each of them represents a different keyboard * This class represents a set of keyboard layouts. Each of them represents a different keyboard
@ -88,7 +88,6 @@ public final class KeyboardLayoutSet {
private final static HashMap<InputMethodSubtype, Integer> sScriptIdsForSubtypes = private final static HashMap<InputMethodSubtype, Integer> sScriptIdsForSubtypes =
new HashMap<>(); new HashMap<>();
@SuppressWarnings("serial")
public static final class KeyboardLayoutSetException extends RuntimeException { public static final class KeyboardLayoutSetException extends RuntimeException {
public final KeyboardId mKeyboardId; public final KeyboardId mKeyboardId;
@ -166,8 +165,6 @@ public final class KeyboardLayoutSet {
mParams = params; mParams = params;
} }
public static final String LOCALE_GEORGIAN = "ka";
@NonNull @NonNull
public Keyboard getKeyboard(final int baseKeyboardLayoutSetElementId) { public Keyboard getKeyboard(final int baseKeyboardLayoutSetElementId) {
final int keyboardLayoutSetElementId; final int keyboardLayoutSetElementId;
@ -287,10 +284,7 @@ public final class KeyboardLayoutSet {
// When the device is still unlocked, features like showing the IME setting app need to // When the device is still unlocked, features like showing the IME setting app need to
// be locked down. // be locked down.
// TODO: Switch to {@code UserManagerCompat.isUserUnlocked()} in the support-v4 library if (!UserManagerCompat.isUserUnlocked(context)) {
// when it becomes publicly available.
@UserManagerCompatUtils.LockState final int lockState = UserManagerCompatUtils.getUserLockState(context);
if (lockState == UserManagerCompatUtils.LOCK_STATE_LOCKED) {
params.mNoSettingsKey = true; params.mNoSettingsKey = true;
} }
} }
@ -363,8 +357,7 @@ public final class KeyboardLayoutSet {
final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX
+ SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype); + SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
final int xmlId = getXmlId(resources, layoutSetName); final int xmlId = getXmlId(resources, layoutSetName);
final XmlResourceParser parser = resources.getXml(xmlId); try (XmlResourceParser parser = resources.getXml(xmlId)) {
try {
while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
// Bovinate through the XML stupidly searching for TAG_FEATURE, and read // Bovinate through the XML stupidly searching for TAG_FEATURE, and read
// the script Id from it. // the script Id from it.
@ -376,8 +369,6 @@ public final class KeyboardLayoutSet {
} }
} catch (final IOException | XmlPullParserException e) { } catch (final IOException | XmlPullParserException e) {
throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e); throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e);
} finally {
parser.close();
} }
// If the tag is not found, then the default script is Latin. // If the tag is not found, then the default script is Latin.
return ScriptUtils.SCRIPT_LATIN; return ScriptUtils.SCRIPT_LATIN;
@ -419,8 +410,7 @@ public final class KeyboardLayoutSet {
private void parseKeyboardLayoutSet(final Resources res, final int resId) private void parseKeyboardLayoutSet(final Resources res, final int resId)
throws XmlPullParserException, IOException { throws XmlPullParserException, IOException {
final XmlResourceParser parser = res.getXml(resId); try (XmlResourceParser parser = res.getXml(resId)) {
try {
while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
final int event = parser.next(); final int event = parser.next();
if (event == XmlPullParser.START_TAG) { if (event == XmlPullParser.START_TAG) {
@ -432,8 +422,6 @@ public final class KeyboardLayoutSet {
} }
} }
} }
} finally {
parser.close();
} }
} }

View file

@ -129,20 +129,19 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
final Resources res = mThemeContext.getResources(); final Resources res = mThemeContext.getResources();
final int keyboardWidth = ResourceUtils.getKeyboardWidth(res, settingsValues); final int keyboardWidth = ResourceUtils.getKeyboardWidth(res, settingsValues);
final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues); final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues);
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
builder.setSubtype(mRichImm.getCurrentSubtype());
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
builder.setNumberRowEnabled(settingsValues.mShowsNumberRow);
builder.setLanguageSwitchKeyEnabled(settingsValues.isLanguageSwitchKeyEnabled());
builder.setEmojiKeyEnabled(settingsValues.mShowsEmojiKey);
builder.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
&& settingsValues.mIsSplitKeyboardEnabled);
final boolean oneHandedModeEnabled = settingsValues.mOneHandedModeEnabled; final boolean oneHandedModeEnabled = settingsValues.mOneHandedModeEnabled;
builder.setOneHandedModeEnabled(oneHandedModeEnabled); mKeyboardLayoutSet = builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
mKeyboardLayoutSet = builder.build(); .setSubtype(mRichImm.getCurrentSubtype())
.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey)
.setNumberRowEnabled(settingsValues.mShowsNumberRow)
.setLanguageSwitchKeyEnabled(settingsValues.isLanguageSwitchKeyEnabled())
.setEmojiKeyEnabled(settingsValues.mShowsEmojiKey)
.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
&& settingsValues.mIsSplitKeyboardEnabled)
.setOneHandedModeEnabled(oneHandedModeEnabled)
.build();
try { try {
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState, mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState, oneHandedModeEnabled);
oneHandedModeEnabled);
mKeyboardTextsSet.setLocale(mRichImm.getCurrentSubtypeLocale(), mThemeContext); mKeyboardTextsSet.setLocale(mRichImm.getCurrentSubtypeLocale(), mThemeContext);
} catch (KeyboardLayoutSetException e) { } catch (KeyboardLayoutSetException e) {
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause()); Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());

View file

@ -393,7 +393,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
* @param keyboard the keyboard to display in this view * @param keyboard the keyboard to display in this view
*/ */
@Override @Override
public void setKeyboard(final Keyboard keyboard) { public void setKeyboard(@NonNull final Keyboard keyboard) {
// Remove any pending messages, except dismissing preview and key repeat. // Remove any pending messages, except dismissing preview and key repeat.
mTimerHandler.cancelLongPressTimers(); mTimerHandler.cancelLongPressTimers();
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
@ -804,8 +804,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
} }
@Override @Override
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint, protected void onDrawKeyTopVisuals(@NonNull final Key key, @NonNull final Canvas canvas,
final KeyDrawParams params) { @NonNull final Paint paint, @NonNull final KeyDrawParams params) {
if (key.altCodeWhileTyping() && key.isEnabled()) { if (key.altCodeWhileTyping() && key.isEnabled()) {
params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha; params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha;
} }

View file

@ -26,6 +26,8 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull;
import org.dslul.openboard.inputmethod.accessibility.AccessibilityUtils; import org.dslul.openboard.inputmethod.accessibility.AccessibilityUtils;
import org.dslul.openboard.inputmethod.accessibility.MoreKeysKeyboardAccessibilityDelegate; import org.dslul.openboard.inputmethod.accessibility.MoreKeysKeyboardAccessibilityDelegate;
import org.dslul.openboard.inputmethod.keyboard.emoji.OnKeyEventListener; import org.dslul.openboard.inputmethod.keyboard.emoji.OnKeyEventListener;
@ -86,8 +88,8 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
} }
@Override @Override
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint, protected void onDrawKeyTopVisuals(@NonNull final Key key, @NonNull final Canvas canvas,
final KeyDrawParams params) { @NonNull final Paint paint, @NonNull final KeyDrawParams params) {
if (!key.isSpacer() || !(key instanceof MoreKeysKeyboard.MoreKeyDivider) if (!key.isSpacer() || !(key instanceof MoreKeysKeyboard.MoreKeyDivider)
|| mDivider == null) { || mDivider == null) {
super.onDrawKeyTopVisuals(key, canvas, paint, params); super.onDrawKeyTopVisuals(key, canvas, paint, params);
@ -103,7 +105,7 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
} }
@Override @Override
public void setKeyboard(final Keyboard keyboard) { public void setKeyboard(@NonNull final Keyboard keyboard) {
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
mKeyDetector.setKeyboard( mKeyDetector.setKeyboard(
keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection()); keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());

View file

@ -166,7 +166,7 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void setKeyboard(final Keyboard keyboard) { public void setKeyboard(@NonNull final Keyboard keyboard) {
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
mKeyDetector.setKeyboard(keyboard, 0 /* correctionX */, 0 /* correctionY */); mKeyDetector.setKeyboard(keyboard, 0 /* correctionX */, 0 /* correctionY */);
mMoreKeysKeyboardCache.clear(); mMoreKeysKeyboardCache.clear();
@ -321,22 +321,12 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
private void registerPress(final Key key) { private void registerPress(final Key key) {
// Do not trigger key-down effect right now in case this is actually a fling action. // Do not trigger key-down effect right now in case this is actually a fling action.
mPendingKeyDown = new Runnable() { mPendingKeyDown = () -> callListenerOnPressKey(key);
@Override
public void run() {
callListenerOnPressKey(key);
}
};
mHandler.postDelayed(mPendingKeyDown, KEY_PRESS_DELAY_TIME); mHandler.postDelayed(mPendingKeyDown, KEY_PRESS_DELAY_TIME);
} }
private void registerLongPress(final Key key) { private void registerLongPress(final Key key) {
mPendingLongPress = new Runnable() { mPendingLongPress = () -> onLongPressed(key);
@Override
public void run() {
onLongPressed(key);
}
};
mHandler.postDelayed(mPendingLongPress, getLongPressTimeout()); mHandler.postDelayed(mPendingLongPress, getLongPressTimeout());
} }

View file

@ -167,8 +167,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
public KeyboardBuilder<KP> load(final int xmlId, final KeyboardId id) { public KeyboardBuilder<KP> load(final int xmlId, final KeyboardId id) {
mParams.mId = id; mParams.mId = id;
final XmlResourceParser parser = mResources.getXml(xmlId); try (XmlResourceParser parser = mResources.getXml(xmlId)) {
try {
parseKeyboard(parser); parseKeyboard(parser);
} catch (XmlPullParserException e) { } catch (XmlPullParserException e) {
Log.w(BUILDER_TAG, "keyboard XML parse error", e); Log.w(BUILDER_TAG, "keyboard XML parse error", e);
@ -176,8 +175,6 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
} catch (IOException e) { } catch (IOException e) {
Log.w(BUILDER_TAG, "keyboard XML parse error", e); Log.w(BUILDER_TAG, "keyboard XML parse error", e);
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);
} finally {
parser.close();
} }
return this; return this;
} }
@ -481,9 +478,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final int width = (int)keyWidth; final int width = (int)keyWidth;
final int height = row.getRowHeight(); final int height = row.getRowHeight();
final String hintLabel = moreKeySpecs != null ? "\u25E5" : null; final String hintLabel = moreKeySpecs != null ? "\u25E5" : null;
final KeyboardParams params = mParams;
final Key key = new Key(label, code, outputText, hintLabel, moreKeySpecs, final Key key = new Key(label, code, outputText, hintLabel, moreKeySpecs,
labelFlags, backgroundType, x, y, width, height, params); labelFlags, backgroundType, x, y, width, height, mParams);
endKey(key); endKey(key);
row.advanceXPos(keyWidth); row.advanceXPos(keyWidth);
} }
@ -555,7 +551,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final TypedArray keyboardAttr = mResources.obtainAttributes( final TypedArray keyboardAttr = mResources.obtainAttributes(
attr, R.styleable.Keyboard_Include); attr, R.styleable.Keyboard_Include);
final TypedArray keyAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key); final TypedArray keyAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
int keyboardLayout = 0; final int keyboardLayout;
try { try {
XmlParseUtils.checkAttributeExists( XmlParseUtils.checkAttributeExists(
keyboardAttr, R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout", keyboardAttr, R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout",
@ -578,15 +574,13 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
startEndTag("<%s keyboardLayout=%s />",TAG_INCLUDE, startEndTag("<%s keyboardLayout=%s />",TAG_INCLUDE,
mResources.getResourceEntryName(keyboardLayout)); mResources.getResourceEntryName(keyboardLayout));
} }
final XmlResourceParser parserForInclude = mResources.getXml(keyboardLayout); try (XmlResourceParser parserForInclude = mResources.getXml(keyboardLayout)) {
try {
parseMerge(parserForInclude, row, skip); parseMerge(parserForInclude, row, skip);
} finally { } finally {
if (row != null) { if (row != null) {
// Restore Row attributes. // Restore Row attributes.
row.popRowAttributes(); row.popRowAttributes();
} }
parserForInclude.close();
} }
} }

View file

@ -140,6 +140,7 @@ public final class KeyboardTextsSet {
final RunInLocale<String> getTextJob = new RunInLocale<String>() { final RunInLocale<String> getTextJob = new RunInLocale<String>() {
@Override @Override
protected String job(final Resources res) { protected String job(final Resources res) {
// this is for identifiers in strings-action-keys.xml (100% only?)
final int resId = res.getIdentifier(name, "string", resourcePackageName); final int resId = res.getIdentifier(name, "string", resourcePackageName);
return res.getString(resId); return res.getString(resId);
} }

View file

@ -222,7 +222,7 @@ public final class MoreKeySpec {
if (remain != null) { if (remain != null) {
list.add(remain); list.add(remain);
} }
return list.toArray(new String[list.size()]); return list.toArray(new String[0]);
} }
@NonNull @NonNull
@ -247,7 +247,7 @@ public final class MoreKeySpec {
if (out == null) { if (out == null) {
return array; return array;
} }
return out.toArray(new String[out.size()]); return out.toArray(new String[0]);
} }
public static String[] insertAdditionalMoreKeys(@Nullable final String[] moreKeySpecs, public static String[] insertAdditionalMoreKeys(@Nullable final String[] moreKeySpecs,
@ -300,7 +300,7 @@ public final class MoreKeySpec {
if (out == null && moreKeysCount > 0) { if (out == null && moreKeysCount > 0) {
return moreKeys; return moreKeys;
} else if (out != null && out.size() > 0) { } else if (out != null && out.size() > 0) {
return out.toArray(new String[out.size()]); return out.toArray(new String[0]);
} else { } else {
return null; return null;
} }

View file

@ -242,11 +242,11 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
final EditorInfo editorInfo = new EditorInfo(); final EditorInfo editorInfo = new EditorInfo();
editorInfo.inputType = InputType.TYPE_CLASS_TEXT; editorInfo.inputType = InputType.TYPE_CLASS_TEXT;
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(this, editorInfo); final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(this, editorInfo);
builder.setKeyboardGeometry( return builder
SPELLCHECKER_DUMMY_KEYBOARD_WIDTH, SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT); .setKeyboardGeometry(SPELLCHECKER_DUMMY_KEYBOARD_WIDTH, SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT)
builder.setSubtype(RichInputMethodSubtype.getRichInputMethodSubtype(subtype)); .setSubtype(RichInputMethodSubtype.getRichInputMethodSubtype(subtype))
builder.setIsSpellChecker(true /* isSpellChecker */); .setIsSpellChecker(true /* isSpellChecker */)
builder.disableTouchPositionCorrectionData(); .disableTouchPositionCorrectionData()
return builder.build(); .build();
} }
} }

View file

@ -20,6 +20,8 @@ import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import org.dslul.openboard.inputmethod.keyboard.Key; import org.dslul.openboard.inputmethod.keyboard.Key;
import org.dslul.openboard.inputmethod.keyboard.Keyboard; import org.dslul.openboard.inputmethod.keyboard.Keyboard;
import org.dslul.openboard.inputmethod.keyboard.KeyboardActionListener; import org.dslul.openboard.inputmethod.keyboard.KeyboardActionListener;
@ -53,7 +55,7 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView {
// TODO: Remove redundant override method. // TODO: Remove redundant override method.
@Override @Override
public void setKeyboard(final Keyboard keyboard) { public void setKeyboard(@NonNull final Keyboard keyboard) {
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
mIsInModalMode = false; mIsInModalMode = false;
// With accessibility mode off, {@link #mAccessibilityDelegate} is set to null at the // With accessibility mode off, {@link #mAccessibilityDelegate} is set to null at the
@ -69,7 +71,7 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView {
@Override @Override
protected int getDefaultCoordX() { protected int getDefaultCoordX() {
final MoreSuggestions pane = (MoreSuggestions)getKeyboard(); final MoreSuggestions pane = (MoreSuggestions) getKeyboard();
return pane.mOccupiedWidth / 2; return pane.mOccupiedWidth / 2;
} }