enlarge kbd next upd

This commit is contained in:
Yuriy Liskov
2020-02-10 04:36:16 +02:00
parent 7b47303911
commit ae0141851d
13 changed files with 203 additions and 31 deletions

View File

@@ -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() {

View File

@@ -0,0 +1,4 @@
package com.liskovsoft.leankeyboard.addons.kbdsize;
public class KeyboardSizeWatcher {
}

View File

@@ -1,4 +1,4 @@
package com.liskovsoft.leankeyboard.keyboard.data;
package com.liskovsoft.leankeyboard.addons.reskbdfactory;
import java.util.List;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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<Key> getKeys() {
return mKeyboard.getKeys();
}
@Override
public List<Key> 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;
}
}

View File

@@ -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<Key> 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;
}
}

View File

@@ -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;

View File

@@ -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) {

View File

@@ -4,7 +4,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:leanbackime="http://schemas.android.com/apk/res-auto">
<LinearLayout android:id="@+id/keyboard" android:orientation="horizontal" android:clipChildren="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true">
<com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.LeanbackKeyboardView android:id="@+id/main_keyboard" android:clipChildren="false" android:layout_width="wrap_content" android:layout_height="wrap_content" leanbackime:rowCount="5" leanbackime:columnCount="11" />
<com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.resize.ResizeableLeanbackKeyboardView android:id="@+id/main_keyboard" android:clipChildren="false" android:layout_width="wrap_content" android:layout_height="wrap_content" leanbackime:rowCount="5" leanbackime:columnCount="11" />
</LinearLayout>
<FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignTop="@id/keyboard" android:layout_alignBottom="@id/keyboard" android:layout_centerHorizontal="true">
<com.liskovsoft.leankeyboard.keyboard.android.leanback.ime.voice.RecognizerView android:id="@+id/voice" android:layout_gravity="center" android:visibility="invisible" android:layout_width="@dimen/recognizer_size" android:layout_height="@dimen/recognizer_size" />

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Main values -->
<dimen name="key_height">28.0dip</dimen>
<dimen name="key_width">28.0dip</dimen>
<!--
@@ -10,23 +11,28 @@
<dimen name="space_key_width">188.0dip</dimen>
<dimen name="keyboard_horizontal_gap">12.0dip</dimen>
<dimen name="keyboard_vertical_gap">8.0dip</dimen>
<dimen name="recognizer_size">96.0dip</dimen>
<dimen name="selector_size">24.0dip</dimen>
<dimen name="keyboard_top_spacing">6.0dip</dimen>
<dimen name="keyboard_bottom_spacing">28.0dip</dimen>
<dimen name="action_button_size">64.0dip</dimen>
<dimen name="enter_key_height">32.0dip</dimen>
<dimen name="enter_key_font_size">18.0sp</dimen>
<dimen name="enter_key_padding_horizontal">16.0dip</dimen>
<dimen name="mode_change_key_font_size">7.0sp</dimen>
<dimen name="candidate_font_size">18.0sp</dimen>
<dimen name="candidate_padding_horizontal">16.0dip</dimen>
<dimen name="candidate_margin_horizontal">4.0dip</dimen>
<dimen name="candidate_height">28.0dip</dimen>
<dimen name="candidate_scroll_view_horz_spacing">56.0dip</dimen>
<dimen name="key_font_size">18.0sp</dimen>
<dimen name="function_key_mode_change_font_size">16.0sp</dimen>
<dimen name="resize_move_distance">12.0dip</dimen>
<!-- Enter key values -->
<dimen name="enter_key_height">32.0dip</dimen>
<dimen name="enter_key_font_size">18.0sp</dimen>
<dimen name="enter_key_padding_horizontal">16.0dip</dimen>
<!-- Keyboard other -->
<dimen name="keyboard_top_spacing">6.0dip</dimen>
<dimen name="keyboard_bottom_spacing">28.0dip</dimen>
<!-- Voice input -->
<dimen name="action_button_size">64.0dip</dimen>
<dimen name="recognizer_size">96.0dip</dimen>
<!-- Suggestions -->
<dimen name="candidate_height">28.0dip</dimen>
<dimen name="candidate_scroll_view_horz_spacing">56.0dip</dimen>
<dimen name="candidate_font_size">18.0sp</dimen>
<dimen name="candidate_padding_horizontal">16.0dip</dimen>
<dimen name="candidate_margin_horizontal">4.0dip</dimen>
<!-- Unused values -->
<dimen name="mode_change_key_font_size">7.0sp</dimen>
<dimen name="text_size_dp">15dp</dimen>
<dimen name="text_size_big_dp">25dp</dimen>
</resources>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<Keyboard/>