From 6cac9e25129f7a2ed16f4c8895ac6da2d1ee4a9b Mon Sep 17 00:00:00 2001 From: Helium314 Date: Fri, 1 Sep 2023 20:08:26 +0200 Subject: [PATCH] use instanceof instead of comparing classes --- .../inputmethod/keyboard/KeyboardView.java | 15 +++++++-------- .../inputmethod/keyboard/MainKeyboardView.java | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java index 512339ac1..c0bcbeabf 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/KeyboardView.java @@ -151,7 +151,7 @@ public class KeyboardView extends View { R.styleable.KeyboardView_spacebarBackground); mSpacebarBackground = (spacebarBackground != null) ? spacebarBackground.mutate() : keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground).mutate(); - if (mColors.getClass() == HoloColors.class) // todo: this logic should be in Colors, not here + if (mColors instanceof HoloColors) // todo: this logic should be in Colors, not here mActionKeyBackground = mFunctionalKeyBackground; else mActionKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground).mutate(); @@ -180,11 +180,10 @@ public class KeyboardView extends View { mPaint.setAntiAlias(true); - final Class c = this.getClass(); - if (c == MoreKeysKeyboardView.class) { - mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_ADJUSTED_BACKGROUND); - } else if (c == EmojiPageKeyboardView.class || c == MoreSuggestionsView.class) { + if (this instanceof EmojiPageKeyboardView || this instanceof MoreSuggestionsView) { mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_BACKGROUND); + } else if (this instanceof MoreKeysKeyboardView) { + mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_ADJUSTED_BACKGROUND); } else { mColors.setBackgroundColor(mKeyBackground, Colors.TYPE_KEY); } @@ -197,7 +196,7 @@ public class KeyboardView extends View { // todo: this should only be applied to specific keyboards, check original version for which one // and actually this again is something that maybe should be done in Colors final Drawable keyboardBackground = mColors.getKeyboardBackground(); - if (this.getClass() != MoreSuggestionsView.class && keyboardBackground != null) + if (this instanceof MoreSuggestionsView && keyboardBackground != null) setBackground(keyboardBackground); else getBackground().setColorFilter(mColors.backgroundFilter); @@ -621,7 +620,7 @@ public class KeyboardView extends View { } private void setKeyIconColor(Key key, Drawable icon, Keyboard keyboard) { - if (key.isAccentColored() && mColors.getClass() != HoloColors.class) { // todo: again sth that should not be here + if (key.isAccentColored() && !(mColors instanceof HoloColors)) { // todo: again sth that should not be here icon.setColorFilter(mColors.actionKeyIconColorFilter); } else if (key.isShift() && keyboard != null) { // todo (idea): replace shift icon with white one and use the normal multiply filters @@ -636,7 +635,7 @@ public class KeyboardView extends View { icon.setColorFilter(mColors.keyTextFilter); // key text if not shifted } else if (key.getBackgroundType() != Key.BACKGROUND_TYPE_NORMAL) { icon.setColorFilter(mColors.keyTextFilter); - } else if (this.getClass() == MoreKeysKeyboardView.class) { + } else if (this instanceof MoreKeysKeyboardView) { // set color filter for long press comma key, should not trigger anywhere else icon.setColorFilter(mColors.keyTextFilter); } diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/MainKeyboardView.java b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/MainKeyboardView.java index dd4c0fa8b..55970b0d4 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/MainKeyboardView.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/keyboard/MainKeyboardView.java @@ -219,7 +219,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction( R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f); final Colors colors = Settings.getInstance().getCurrent().mColors; - if (colors.getClass() == HoloColors.class) // todo: this logic should be in Colors + if (colors instanceof HoloColors) // todo: this logic should be in Colors mLanguageOnSpacebarTextColor = colors.keyText; else mLanguageOnSpacebarTextColor = colors.keyHintText; //mainKeyboardViewAttr.getColor(R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);