Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft-Keyboard numpad #188

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions res/layout/mainview.xml → res/layout/mainview_small.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainview_small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Expand Down
191 changes: 191 additions & 0 deletions res/layout/mainview_with_numpad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainview_with_numpad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/main_suggestions_list"
android:layout_width="fill_parent"
android:layout_height="@dimen/candidate_list_height"
android:fadingEdge="horizontal"
android:orientation="horizontal"
android:paddingTop="1px"
android:scrollbars="none" />


<TableLayout
android:id="@+id/main_soft_keys"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget" >
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_1"
android:text="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_2"
android:text="2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_3"
android:text="3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<Button
android:id="@+id/main_right"
style="@android:style/Widget.Holo.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:longClickable="true"
android:text="⌫"
android:textSize="@dimen/soft_key_icon_size"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget" >
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_4"
android:text="4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_5"
android:text="5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_6"
android:text="6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<Button
android:id="@+id/main_mid"
style="@android:style/Widget.Holo.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:longClickable="true"
android:text="@android:string/ok"
tools:ignore="ButtonOrder,KeyboardInaccessibleWidget" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget" >
<!-- android:textSize="@dimen/soft_key_icon_size"-->
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_7"
android:text="7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_8"
android:text="8"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_9"
android:text="9"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<Button
android:id="@+id/soft_language"
style="@android:style/Widget.Holo.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="🪐"
android:textSize="@dimen/soft_key_icon_size"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget" />
</TableRow>


<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget" >
<Button
android:id="@+id/soft_addWord"
android:text="++"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<io.github.sspanak.tt9.ui.NumpadButton
android:id="@+id/soft_0"
android:text="0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<Button
android:id="@+id/soft_mode"
android:text="⇄"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@android:style/Widget.Holo.Button.Borderless"
android:textSize="@dimen/soft_key_icon_size"/>
<Button
android:id="@+id/main_left"
style="@android:style/Widget.Holo.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:longClickable="true"
android:text="⚙"
android:textSize="@dimen/soft_key_icon_size"
tools:ignore="HardcodedText,KeyboardInaccessibleWidget" />
</TableRow>
</TableLayout>

</LinearLayout>
5 changes: 5 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<string name="pref_dark_theme">Dark Theme</string>
<string name="pref_double_zero_char">Character for Double 0-key Press</string>
<string name="pref_show_soft_function_keys">Show On-Screen Keys</string>
<string name="pref_show_soft_numpad">Full On-Screen Keyboard</string>
<string name="pref_show_soft_numpad_summary_on">Numpad is shown</string>
<string name="pref_show_soft_numpad_summary_off">Numpad is not shown. Only main buttons.</string>
<string name="pref_dpad_softkeys_navigation">Dpad navigation on soft keys</string>
<string name="pref_dpad_softkeys_navigation_summary">Use Dpad Keys to navigate over On-Screen Keys. DPad_Down is used to change in navigation mode. This setting only effects non-touch displays.</string>
<string name="pref_help">Help</string>
<string name="pref_upside_down_keys">Reverse Key Order</string>
<string name="pref_upside_down_keys_summary">Use this if you have 7–8–9 on the first row, instead of 1–2–3.</string>
Expand Down
17 changes: 17 additions & 0 deletions res/xml/prefs_screen_appearance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@
app:layout="@layout/pref_switch"
app:title="@string/pref_show_soft_function_keys" />

<SwitchPreferenceCompat
app:defaultValue="false"
app:key="pref_show_soft_numpad"
app:layout="@layout/pref_switch"
app:title="@string/pref_show_soft_numpad"
app:summaryOn="@string/pref_show_soft_numpad_summary_on"
app:summaryOff="@string/pref_show_soft_numpad_summary_off"
app:dependency="pref_show_soft_keys" />

<SwitchPreferenceCompat
app:defaultValue="false"
app:key="pref_dpad_softkeys_navigation"
app:layout="@layout/pref_switch"
app:title="@string/pref_dpad_softkeys_navigation"
app:summary="@string/pref_dpad_softkeys_navigation_summary"
app:dependency="pref_show_soft_keys"/>

</PreferenceScreen>
25 changes: 20 additions & 5 deletions src/io/github/sspanak/tt9/ime/KeyPadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,40 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
}

if (Key.isOK(keyCode)) {
return onOK();
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER && onDpad(keyCode)){
return true;
}else {
return onOK();
}
}

if (Key.isNumber(keyCode)) {
return onNumber(Key.codeToNumber(settings, keyCode), false, numKeyRepeatCounter);
}

switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP: return onUp();
case KeyEvent.KEYCODE_DPAD_DOWN: return onDown();
case KeyEvent.KEYCODE_DPAD_LEFT: return onLeft();
case KeyEvent.KEYCODE_DPAD_RIGHT: return onRight(keyRepeatCounter > 0);
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT: return onDpad(keyCode);
case KeyEvent.KEYCODE_STAR: return onStar();
case KeyEvent.KEYCODE_POUND: return onPound();
}

return false;
}

protected boolean onDpad(int keyCode){
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP: return onUp();
case KeyEvent.KEYCODE_DPAD_DOWN: return onDown();
case KeyEvent.KEYCODE_DPAD_LEFT: return onLeft();
case KeyEvent.KEYCODE_DPAD_RIGHT: return onRight(keyRepeatCounter > 0);
case KeyEvent.KEYCODE_DPAD_CENTER: return false;
default: throw new RuntimeException("KeypadHandler - unsupported dpad key code");
}
}


private boolean handleHotkey(int keyCode, boolean hold) {
if (keyCode == settings.getKeyAddWord() * (hold ? -1 : 1)) {
Expand Down
Loading