diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/KeyboardManager.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/KeyboardManager.java index 44033b6..996b017 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/KeyboardManager.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/KeyboardManager.java @@ -47,7 +47,7 @@ public class KeyboardManager { } /** - * Get next keyboard from internal source (looped) + * NOTE: Get next keyboard from internal source (looped) * @return keyboard */ public Keyboard getNextKeyboard() { diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/kbdsize/KeyboardSizeWatcher.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/kbdsize/KeyboardSizeWatcher.java new file mode 100644 index 0000000..4e93f53 --- /dev/null +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/kbdsize/KeyboardSizeWatcher.java @@ -0,0 +1,4 @@ +package com.liskovsoft.leankeyboard.addons.kbdsize; + +public class KeyboardSizeWatcher { +} diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/data/CheckedSource.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/CheckedSource.java similarity index 77% rename from leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/data/CheckedSource.java rename to leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/CheckedSource.java index b178aa0..8292437 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/data/CheckedSource.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/CheckedSource.java @@ -1,4 +1,4 @@ -package com.liskovsoft.leankeyboard.keyboard.data; +package com.liskovsoft.leankeyboard.addons.reskbdfactory; import java.util.List; diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/KeyboardInfoAdapter.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/KeyboardInfoAdapter.java index e081a39..1740a2d 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/KeyboardInfoAdapter.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/KeyboardInfoAdapter.java @@ -2,7 +2,6 @@ package com.liskovsoft.leankeyboard.addons.reskbdfactory; import android.content.Context; import com.liskovsoft.leankeyboard.addons.KeyboardInfo; -import com.liskovsoft.leankeyboard.keyboard.data.CheckedSource; import java.util.ArrayList; import java.util.List; diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/ResKeyboardInfo.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/ResKeyboardInfo.java index ca5d964..517db94 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/ResKeyboardInfo.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/addons/reskbdfactory/ResKeyboardInfo.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import com.liskovsoft.leankeyboard.addons.KeyboardInfo; -import com.liskovsoft.leankeyboard.keyboard.data.CheckedSource; import com.liskovsoft.leankeykeyboard.R; import java.util.ArrayList; diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/LeanbackKeyboardView.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/LeanbackKeyboardView.java index 200134e..c431c39 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/LeanbackKeyboardView.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/LeanbackKeyboardView.java @@ -14,9 +14,10 @@ import android.graphics.Typeface; import android.inputmethodservice.Keyboard; import android.inputmethodservice.Keyboard.Key; import android.util.AttributeSet; -import android.util.DisplayMetrics; import android.util.Log; import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; import android.widget.FrameLayout; import android.widget.ImageView; import androidx.core.content.ContextCompat; @@ -27,12 +28,13 @@ import java.util.Iterator; import java.util.List; public class LeanbackKeyboardView extends FrameLayout { + private static final String TAG = "LbKbView"; /** - * space key index (important: wrong value will broke navigation) + * Space key index (important: wrong value will broke navigation) */ public static final int ASCII_PERIOD = 47; /** - * keys count among which space key spans (important: wrong value will broke navigation) + * Keys count among which space key spans (important: wrong value will broke navigation) */ public static final int ASCII_PERIOD_LEN = 5; public static final int ASCII_SPACE = 32; @@ -51,7 +53,6 @@ public class LeanbackKeyboardView extends FrameLayout { public static final int SHIFT_LOCKED = 2; public static final int SHIFT_OFF = 0; public static final int SHIFT_ON = 1; - private static final String TAG = "LbKbView"; private int mBaseMiniKbIndex = -1; private final int mClickAnimDur; private final float mClickedScale; @@ -64,19 +65,19 @@ public class LeanbackKeyboardView extends FrameLayout { private final int mInactiveMiniKbAlpha; private ImageView[] mKeyImageViews; private int mKeyTextColor; - private int mKeyTextSize; private Keyboard mKeyboard; private KeyHolder[] mKeys; private boolean mMiniKeyboardOnScreen; - private int mModeChangeTextSize; private Rect mPadding; - private Paint mPaint; private int mRowCount; private int mShiftState; private final int mUnfocusStartDelay; private final KeyConverter mConverter; + protected Paint mPaint; + protected int mKeyTextSize; + protected int mModeChangeTextSize; - private class KeyConverter { + private static class KeyConverter { private static final int LOWER_CASE = 0; private static final int UPPER_CASE = 1; @@ -134,7 +135,7 @@ public class LeanbackKeyboardView extends FrameLayout { mKeyTextSize = (int) res.getDimension(R.dimen.key_font_size); mPaint = new Paint(); mPaint.setAntiAlias(true); - mPaint.setTextSize((float) mKeyTextSize); + mPaint.setTextSize(mKeyTextSize); mPaint.setTextAlign(Align.CENTER); mPaint.setAlpha(255); mPadding = new Rect(0, 0, 0, 0); @@ -256,7 +257,8 @@ public class LeanbackKeyboardView extends FrameLayout { image.setImageBitmap(bitmap); image.setContentDescription(label); // Adds key views to root window - addView(image, new LayoutParams(-2, -2)); + addView(image, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + // Set position manually for each key image.setX((float) (key.x + kbdPaddingLeft)); image.setY((float) (key.y + kbdPaddingTop)); int opacity; diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/resize/KeyboardWrapper.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/resize/KeyboardWrapper.java new file mode 100644 index 0000000..60520e3 --- /dev/null +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/resize/KeyboardWrapper.java @@ -0,0 +1,85 @@ +package com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.resize; + +import android.content.Context; +import android.inputmethodservice.Keyboard; +import com.liskovsoft.leankeykeyboard.R; + +import java.util.List; + +public class KeyboardWrapper extends Keyboard { + private Keyboard mKeyboard; + private int mHeight = -1; + private float mHeightFactor = 1.0f; + private float mWidthFactor = 1.0f; + + public KeyboardWrapper(Context context, int xmlLayoutResId) { + super(context, xmlLayoutResId); + } + + public KeyboardWrapper(Context context, int xmlLayoutResId, int modeId, int width, int height) { + super(context, xmlLayoutResId, modeId, width, height); + } + + public KeyboardWrapper(Context context, int xmlLayoutResId, int modeId) { + super(context, xmlLayoutResId, modeId); + } + + public KeyboardWrapper(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding) { + super(context, layoutTemplateResId, characters, columns, horizontalPadding); + } + + public static KeyboardWrapper from(Keyboard keyboard, Context context) { + KeyboardWrapper wrapper = new KeyboardWrapper(context, R.xml.empty_kbd); + wrapper.mKeyboard = keyboard; + + return wrapper; + } + + @Override + public List getKeys() { + return mKeyboard.getKeys(); + } + + @Override + public List getModifierKeys() { + return mKeyboard.getModifierKeys(); + } + + @Override + public int getHeight() { + return (int)(mKeyboard.getHeight() * mHeightFactor); + } + + @Override + public int getMinWidth() { + return (int)(mKeyboard.getMinWidth() * mWidthFactor); + } + + @Override + public boolean setShifted(boolean shiftState) { + return mKeyboard.setShifted(shiftState); + } + + @Override + public boolean isShifted() { + return mKeyboard.isShifted(); + } + + @Override + public int getShiftKeyIndex() { + return mKeyboard.getShiftKeyIndex(); + } + + @Override + public int[] getNearestKeys(int x, int y) { + return mKeyboard.getNearestKeys(x, y); + } + + public void setHeightFactor(float factor) { + mHeightFactor = factor; + } + + public void setWidthFactor(float factor) { + mWidthFactor = factor; + } +} diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/resize/ResizeableLeanbackKeyboardView.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/resize/ResizeableLeanbackKeyboardView.java new file mode 100644 index 0000000..429c375 --- /dev/null +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/keyboard/android/leanback/ime/resize/ResizeableLeanbackKeyboardView.java @@ -0,0 +1,75 @@ +package com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.resize; + +import android.content.Context; +import android.inputmethodservice.Keyboard; +import android.inputmethodservice.Keyboard.Key; +import android.util.AttributeSet; +import com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.LeanbackKeyboardView; +import com.liskovsoft.leankeyboard.utils.LeanKeySettings; + +import java.util.List; + +public class ResizeableLeanbackKeyboardView extends LeanbackKeyboardView { + private final LeanKeySettings mPrefs; + private final int mKeyTextSizeOrigin; + private final int mModeChangeTextSizeOrigin; + private final float mSizeFactor = 1.2f; + private int mKeyOriginWidth; + + public ResizeableLeanbackKeyboardView(Context context, AttributeSet attrs) { + super(context, attrs); + mPrefs = LeanKeySettings.instance(getContext()); + mKeyTextSizeOrigin = mKeyTextSize; + mModeChangeTextSizeOrigin = mModeChangeTextSize; + } + + @Override + public void setKeyboard(Keyboard keyboard) { + if (mPrefs.getEnlargeKeyboard()) { + mKeyTextSize = (int) (mKeyTextSizeOrigin * mSizeFactor); + mModeChangeTextSize = (int) (mModeChangeTextSizeOrigin * mSizeFactor); + keyboard = updateKeyboard(keyboard); + } else { + mKeyTextSize = mKeyTextSizeOrigin; + mModeChangeTextSize = mModeChangeTextSizeOrigin; + } + + mPaint.setTextSize(mKeyTextSize); + + super.setKeyboard(keyboard); + } + + private Keyboard updateKeyboard(Keyboard keyboard) { + List keys = keyboard.getKeys(); + + if (notSizedYet(keys.get(0))) { + for (Key key : keys) { + key.width *= mSizeFactor; + key.height *= mSizeFactor; + key.gap *= mSizeFactor; + key.x *= mSizeFactor; + key.y *= mSizeFactor; + } + } + + KeyboardWrapper wrapper = KeyboardWrapper.from(keyboard, getContext()); + wrapper.setHeightFactor(mSizeFactor); + //wrapper.setWidthFactor(mKeyboardHeightFactor); + + return wrapper; + } + + private boolean notSizedYet(Key key) { + boolean result = false; + + if (mKeyOriginWidth == 0) { + mKeyOriginWidth = key.width; + } + + if (mKeyOriginWidth == key.width) { + result = true; + } + + return result; + } +} diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/settings/kblayout/KbLayoutFragment.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/settings/kblayout/KbLayoutFragment.java index 70f5dfc..995b287 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/settings/kblayout/KbLayoutFragment.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/settings/kblayout/KbLayoutFragment.java @@ -7,8 +7,8 @@ import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.leanback.widget.GuidanceStylist.Guidance; import com.liskovsoft.leankeyboard.addons.reskbdfactory.KeyboardInfoAdapter; -import com.liskovsoft.leankeyboard.keyboard.data.CheckedSource; -import com.liskovsoft.leankeyboard.keyboard.data.CheckedSource.CheckedItem; +import com.liskovsoft.leankeyboard.addons.reskbdfactory.CheckedSource; +import com.liskovsoft.leankeyboard.addons.reskbdfactory.CheckedSource.CheckedItem; import com.liskovsoft.leankeyboard.settings.base.BaseSettingsFragment; import com.liskovsoft.leankeykeyboard.R; diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/utils/LeanKeySettings.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/utils/LeanKeySettings.java index 5d90061..ee6c838 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/utils/LeanKeySettings.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/utils/LeanKeySettings.java @@ -56,7 +56,7 @@ public final class LeanKeySettings { } public boolean getForceShowKeyboard() { - return mPrefs.getBoolean(FORCE_SHOW_KEYBOARD, false); + return mPrefs.getBoolean(FORCE_SHOW_KEYBOARD, true); } public void setForceShowKeyboard(boolean force) { diff --git a/leankeykeyboard/src/main/res/layout/input_leanback.xml b/leankeykeyboard/src/main/res/layout/input_leanback.xml index f56e573..443b83a 100644 --- a/leankeykeyboard/src/main/res/layout/input_leanback.xml +++ b/leankeykeyboard/src/main/res/layout/input_leanback.xml @@ -4,7 +4,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:leanbackime="http://schemas.android.com/apk/res-auto"> - + diff --git a/leankeykeyboard/src/main/res/values/dimens.xml b/leankeykeyboard/src/main/res/values/dimens.xml index 812a424..7b601c7 100644 --- a/leankeykeyboard/src/main/res/values/dimens.xml +++ b/leankeykeyboard/src/main/res/values/dimens.xml @@ -1,5 +1,6 @@ + 28.0dip 28.0dip + 32.0dip + 18.0sp + 16.0dip + + 6.0dip + 28.0dip + + 64.0dip + 96.0dip + + 28.0dip + 56.0dip + 18.0sp + 16.0dip + 4.0dip + + 7.0sp 15dp 25dp diff --git a/leankeykeyboard/src/main/res/xml/empty_kbd.xml b/leankeykeyboard/src/main/res/xml/empty_kbd.xml new file mode 100644 index 0000000..03b9110 --- /dev/null +++ b/leankeykeyboard/src/main/res/xml/empty_kbd.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file