mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-08-18 14:52:25 +02:00
Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b772ebf237 | ||
|
092b8e1c15 | ||
|
dd5fce6cae | ||
|
1a18ea56ca | ||
|
68945ff227 | ||
|
5e01198500 | ||
|
7a3312fd01 | ||
|
ebfb8f3b39 | ||
|
6a19c7a56d | ||
|
b5edcbeb20 | ||
|
41dfa844f1 | ||
|
8fb89c5c71 | ||
|
3fbc35135e | ||
|
1e6e3ab22a | ||
|
a036ebc47b | ||
|
abfa1cc8de | ||
|
5ad4450545 | ||
|
c6a54ed017 | ||
|
f287ff2e09 | ||
|
743b10165c | ||
|
ec5cda0ce6 | ||
|
b976f4a791 | ||
|
ec1cd9473a | ||
|
3f0c18612f | ||
|
d00576ac2d | ||
|
c86a119448 | ||
|
f7c062d0cb | ||
|
9bb2642e2c | ||
|
2dbb3dc28f | ||
|
5688e181fa | ||
|
87b237494a | ||
|
93c0ff5ff6 |
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="juloo.keyboard2"
|
||||
android:versionCode="8"
|
||||
android:versionName="1.7"
|
||||
android:versionCode="11"
|
||||
android:versionName="1.9.1"
|
||||
android:hardwareAccelerated="false">
|
||||
|
||||
<uses-sdk android:minSdkVersion="3"
|
||||
<uses-sdk android:minSdkVersion="4"
|
||||
android:targetSdkVersion="29" />
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
|
2
Makefile
2
Makefile
@@ -75,7 +75,7 @@ _build/$(PACKAGE_NAME).debug.unsigned-apk: AAPT_PACKAGE_FLAGS+=--rename-manifest
|
||||
# OPTS can be used to pass -storepass or -keypass options to jarsigner
|
||||
_build/%.signed-apk: _build/%.unsigned-apk %-keystore.conf
|
||||
eval `cat $(word 2,$^)` && \
|
||||
jarsigner -keystore "$$KEYSTORE" $$OPTS -signedjar "$@" "$<" "$$KEYNAME"
|
||||
jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore "$$KEYSTORE" $$OPTS -signedjar "$@" "$<" "$$KEYNAME"
|
||||
|
||||
# Package
|
||||
|
||||
|
@@ -1,7 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="pref_layout_values">
|
||||
<item>azerty</item>
|
||||
<item>qwerty</item>
|
||||
</string-array>
|
||||
<string-array name="pref_layout_values">
|
||||
<item>system</item>
|
||||
<item>azerty</item>
|
||||
<item>qwerty</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_accents_default">1</string>
|
||||
|
||||
<string-array name="pref_accents_entries">
|
||||
<item>@string/pref_accents_e_all_installed</item>
|
||||
<item>@string/pref_accents_e_selected</item>
|
||||
<item>@string/pref_accents_e_all</item>
|
||||
<item>@string/pref_accents_e_none</item>
|
||||
</string-array>
|
||||
<string-array name="pref_accents_values">
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@@ -5,6 +5,7 @@
|
||||
<item name="key_down_bg" type="color">#1B1B1B</item>
|
||||
<item name="key_label" type="color">#FFFFFF</item>
|
||||
<item name="key_label_locked" type="color">#229933</item>
|
||||
<item name="key_label_activated" type="color">#226b99</item>
|
||||
<item name="key_sub_label" type="color">#A0A0A0</item>
|
||||
<item name="emoji_button_bg" type="color">#202020</item>
|
||||
<item name="emoji_color" type="color">#FFFFFF</item>
|
||||
|
@@ -1,14 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="horizontal_margin">3dp</dimen>
|
||||
<dimen name="margin_top">2dp</dimen>
|
||||
<dimen name="margin_bottom">5dp</dimen>
|
||||
<dimen name="margin_top">3dp</dimen>
|
||||
<dimen name="margin_bottom">7dp</dimen>
|
||||
<dimen name="key_padding">2dp</dimen>
|
||||
<dimen name="key_bg_padding">1.3dp</dimen>
|
||||
<dimen name="key_height">50dp</dimen>
|
||||
<dimen name="key_round">4dp</dimen>
|
||||
<dimen name="label_text_size">16dp</dimen>
|
||||
<dimen name="sublabel_text_size">10dp</dimen>
|
||||
<dimen name="key_vertical_interval">2dp</dimen>
|
||||
<dimen name="key_horizontal_interval">2dp</dimen>
|
||||
<dimen name="key_height">51dp</dimen>
|
||||
<dimen name="key_round">5dp</dimen>
|
||||
<dimen name="label_text_size">18dp</dimen>
|
||||
<dimen name="sublabel_text_size">12dp</dimen>
|
||||
<dimen name="emoji_type_button_height">56dp</dimen>
|
||||
<dimen name="emoji_grid_height">250dp</dimen>
|
||||
</resources>
|
||||
|
@@ -5,10 +5,23 @@
|
||||
|
||||
<string name="settings_activity_label">Unexpected Keyboard Settings</string>
|
||||
|
||||
<string name="subtype_label_azerty">%s AZERTY</string>
|
||||
<string name="subtype_label_qwerty">%s QWERTY</string>
|
||||
<string name="subtype_label">%s</string>
|
||||
|
||||
<string name="pref_category_layout">Layout</string>
|
||||
<string name="pref_layout_title">Change keyboard layout</string>
|
||||
<string name="pref_layout_summary">%s</string>
|
||||
<string-array name="pref_layout_entries">
|
||||
<item>System settings</item>
|
||||
<item>Azerty</item>
|
||||
<item>Qwerty</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_accents_title">Accents</string>
|
||||
<string name="pref_accents_summary">%s</string>
|
||||
<string name="pref_accents_e_all_installed">Show accents for all the installed languages</string>
|
||||
<string name="pref_accents_e_selected">Show accents for the selected language</string>
|
||||
<string name="pref_accents_e_all">Show every accents</string>
|
||||
<string name="pref_accents_e_none">Hide accents</string>
|
||||
|
||||
<string name="pref_category_typing">Typing</string>
|
||||
<string name="pref_preci_title">Precision</string>
|
||||
@@ -33,6 +46,6 @@
|
||||
<string name="pref_key_height_summary">%sdp</string>
|
||||
<string name="pref_horizontal_margin_title">Horizontal margin</string>
|
||||
<string name="pref_horizontal_margin_summary">%sdp</string>
|
||||
<string name="pref_disable_accent_keys_title">Toggle accent keys</string>
|
||||
<string name="pref_disable_accent_keys_summary">Whether to remove the accent keys from the keyboard.</string>
|
||||
<string name="pref_character_size_title">Label size</string>
|
||||
<string name="pref_character_size_summary">Size of characters displayed on the keyboard (%.2fx)</string>
|
||||
</resources>
|
||||
|
@@ -2,43 +2,43 @@
|
||||
<keyboard>
|
||||
<row>
|
||||
<key key0="a" key1="esc" key2="1" key3="&" />
|
||||
<key key0="z" key2="2" key3="accent2" key4="~" />
|
||||
<key key0="z" key2="2" key4="~" />
|
||||
<key key0="e" key2="3" key3=""" key4="\#" />
|
||||
<key key0="r" key2="4" key3="'" key4="{" />
|
||||
<key key0="t" key2="5" key3="(" key4="[" />
|
||||
<key key0="r" key2="4" key3="'" />
|
||||
<key key0="t" key2="5" key3="(" key4=")" />
|
||||
<key key0="y" key2="6" key3="-" key4="|" />
|
||||
<key key0="u" key2="7" key3="accent1" key4="`" />
|
||||
<key key0="u" key2="7" key4="`" />
|
||||
<key key0="i" key2="8" key3="_" key4="\\" />
|
||||
<key key0="o" key2="9" key3="accent5" key4="^" />
|
||||
<key key0="p" key1="insert" key2="0" key3="config" key4="\@" />
|
||||
<key key0="o" key2="9" />
|
||||
<key key0="p" key2="0" key4="\@" />
|
||||
</row>
|
||||
<row>
|
||||
<key key0="q" key1="tab" />
|
||||
<key key0="s" />
|
||||
<key key0="d" />
|
||||
<key key0="f" />
|
||||
<key key0="g" key3=")" key4="]" />
|
||||
<key key0="h" key2="+" key3="=" key4="}" />
|
||||
<key key0="j" key2="accent6" key3="^" />
|
||||
<key key0="k" key2="£" key3="$" key4="accent3" />
|
||||
<key key0="l" key1="accent4" key2="%" />
|
||||
<key key0="d" key1="accent_grave" key3="accent_aigu" />
|
||||
<key key0="f" key3="{" key4="}" />
|
||||
<key key0="g" key3="[" key4="]" />
|
||||
<key key0="h" key3="=" key4="+" />
|
||||
<key key0="j" key1="accent_trema" key2="accent_circonflexe" key3="^" />
|
||||
<key key0="k" key2="€" key3="$" key4="£" />
|
||||
<key key0="l" key2="%" />
|
||||
<key key0="m" key4="*" />
|
||||
</row>
|
||||
<row>
|
||||
<key width="2.0" key0="shift" />
|
||||
<key key0="w" key1=">" key3="<" />
|
||||
<key key0="w" key3="<" key4=">" />
|
||||
<key key0="x" />
|
||||
<key key0="c" key2="\?" key4="," />
|
||||
<key key0="v" key2="." key4=";" />
|
||||
<key key0="b" key2="/" key4=":" />
|
||||
<key key0="n" key2="§" key4="!" />
|
||||
<key key0="c" key1="accent_cedille" key3="," key4="\?" />
|
||||
<key key0="v" key3=";" key4="." />
|
||||
<key key0="b" key3=":" key4="/" />
|
||||
<key key0="n" key1="accent_tilde" key2="§" key4="!" />
|
||||
<key width="2.0" key0="backspace" key2="delete" />
|
||||
</row>
|
||||
<row>
|
||||
<key width="1.8" key0="ctrl" key1="change_method" key3="switch_numeric" />
|
||||
<key width="1.2" key0="alt" key1="fn" />
|
||||
<row height="0.95">
|
||||
<key width="1.8" key0="ctrl" key3="switch_numeric" />
|
||||
<key width="1.2" key0="alt" key1="fn" key2="change_method" key3="switch_emoji" key4="config" />
|
||||
<key width="4.0" key0="space" />
|
||||
<key width="1.2" key0="switch_emoji" key1="up" key2="right" key3="left" key4="down" />
|
||||
<key width="1.2" key1="up" key2="right" key3="left" key4="down" />
|
||||
<key width="1.8" key0="enter" />
|
||||
</row>
|
||||
</keyboard>
|
||||
|
@@ -2,16 +2,32 @@
|
||||
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:settingsActivity="juloo.keyboard2.SettingsActivity"
|
||||
android:supportsSwitchingToNextInputMethod="true">
|
||||
<subtype android:label="@string/subtype_label_qwerty"
|
||||
<subtype android:label="@string/subtype_label"
|
||||
android:languageTag="en"
|
||||
android:imeSubtypeLocale="en_US"
|
||||
android:imeSubtypeMode="keyboard"
|
||||
android:isAsciiCapable="true"
|
||||
android:imeSubtypeExtraValue="default_layout=qwerty"
|
||||
/>
|
||||
<subtype android:label="@string/subtype_label_azerty"
|
||||
<subtype android:label="@string/subtype_label"
|
||||
android:languageTag="fr"
|
||||
android:imeSubtypeLocale="fr_FR"
|
||||
android:imeSubtypeMode="keyboard"
|
||||
android:isAsciiCapable="true"
|
||||
android:imeSubtypeExtraValue="default_layout=azerty,accents=grave|aigu|circonflexe|cedille|trema"
|
||||
/>
|
||||
<subtype android:label="@string/subtype_label"
|
||||
android:languageTag="es"
|
||||
android:imeSubtypeLocale="es_ES"
|
||||
android:imeSubtypeMode="keyboard"
|
||||
android:isAsciiCapable="true"
|
||||
android:imeSubtypeExtraValue="default_layout=qwerty,accents=aigu|tilde|trema"
|
||||
/>
|
||||
<subtype android:label="@string/subtype_label"
|
||||
android:languageTag="it"
|
||||
android:imeSubtypeLocale="it_IT"
|
||||
android:imeSubtypeMode="keyboard"
|
||||
android:isAsciiCapable="true"
|
||||
android:imeSubtypeExtraValue="default_layout=qwerty,accents=grave|aigu"
|
||||
/>
|
||||
</input-method>
|
||||
|
@@ -3,11 +3,11 @@
|
||||
<row>
|
||||
<key width="0.75" key0="esc" key2="~" key4="!" />
|
||||
<key width="0.75" key0="(" key2="[" key4="{" />
|
||||
<key key0="7" key2="<" key3="home" />
|
||||
<key key0="8" />
|
||||
<key key0="9" key2="page_up" key3=">" />
|
||||
<key width="0.75" key0="*" />
|
||||
<key width="0.75" key0="/" key1="%" key3=":" />
|
||||
<key key0="7" key3="<" key4=">" />
|
||||
<key key0="8" key2="∞" />
|
||||
<key key0="9" key2="π" />
|
||||
<key width="0.75" key0="*" key1="√" key2="×" />
|
||||
<key width="0.75" key0="/" key1="%" key3="÷" />
|
||||
</row>
|
||||
<row>
|
||||
<key width="0.75" key0="tab" key1=";" key2="|" key4="\\" />
|
||||
@@ -15,21 +15,21 @@
|
||||
<key key0="4" />
|
||||
<key key0="5" key1="up" key2="right" key3="left" key4="down" />
|
||||
<key key0="6" />
|
||||
<key width="0.75" key0="+" key2="$" />
|
||||
<key width="0.75" key0="+" key1="Σ" key2="$" />
|
||||
<key width="0.75" key0="-" key2="^" />
|
||||
</row>
|
||||
<row>
|
||||
<key shift="0.35" width="1.15" key0="shift" key4="alt" />
|
||||
<key key0="1" key3="end" />
|
||||
<key shift="0.35" width="1.15" key0="shift" key2="fn" key4="alt" />
|
||||
<key key0="1" key1="superscript" key3="subscript" />
|
||||
<key key0="2" />
|
||||
<key key0="3" key4="page_down" />
|
||||
<key key0="3" />
|
||||
<key width="1.15" key0="backspace" key2="delete" />
|
||||
</row>
|
||||
<row>
|
||||
<row height="0.95">
|
||||
<key width="1.5" key0="ctrl" key3="switch_text" />
|
||||
<key width="1.5" key0="0" />
|
||||
<key width="0.75" key0="." key2="," />
|
||||
<key width="0.75" key0="space" key1=""" key2="'" key4="_" />
|
||||
<key width="1.5" key0="enter" key3="=" />
|
||||
<key width="1.5" key0="enter" key2="±" key3="=" />
|
||||
</row>
|
||||
</keyboard>
|
||||
|
@@ -10,16 +10,16 @@
|
||||
<key key0="u" key2="7" key3="&" />
|
||||
<key key0="i" key2="8" key3="*" />
|
||||
<key key0="o" key2="9" key3="(" key4=")" />
|
||||
<key key0="p" key1="insert" key2="0" key3="config" />
|
||||
<key key0="p" key2="0" />
|
||||
</row>
|
||||
<row>
|
||||
<key shift="0.5" key0="a" key1="tab" key2="`" />
|
||||
<key key0="s" key1="accent1" key2="accent2" key4="accent6" />
|
||||
<key key0="d" key1="accent3" key2="accent4" key3="accent5" />
|
||||
<key key0="s" />
|
||||
<key key0="d" key1="accent_grave" key3="accent_aigu" />
|
||||
<key key0="f" />
|
||||
<key key0="g" key2="-" key3="_" />
|
||||
<key key0="h" key2="=" key3="+" />
|
||||
<key key0="j" key4="}" key3="{" />
|
||||
<key key0="j" key1="accent_trema" key2="accent_circonflexe" key4="}" key3="{" />
|
||||
<key key0="k" key4="]" key3="[" />
|
||||
<key key0="l" key2="|" key3="\\" />
|
||||
</row>
|
||||
@@ -27,18 +27,18 @@
|
||||
<key width="1.5" key0="shift" />
|
||||
<key key0="z" />
|
||||
<key key0="x" />
|
||||
<key key0="c" key1="<" key3="." />
|
||||
<key key0="c" key1="accent_cedille" key2="<" key3="." />
|
||||
<key key0="v" key2=">" key3="," />
|
||||
<key key0="b" key2="\?" key3="/" />
|
||||
<key key0="n" key2=":" key3=";" />
|
||||
<key key0="n" key1="accent_tilde" key2=":" key3=";" />
|
||||
<key key0="m" key2=""" key3="'" />
|
||||
<key width="1.5" key0="backspace" key2="delete" />
|
||||
</row>
|
||||
<row>
|
||||
<key width="1.8" key0="ctrl" key1="change_method" key3="switch_numeric" />
|
||||
<key width="1.2" key0="alt" key1="fn" />
|
||||
<row height="0.95">
|
||||
<key width="1.8" key0="ctrl" key3="switch_numeric" />
|
||||
<key width="1.2" key0="alt" key1="fn" key2="change_method" key3="switch_emoji" key4="config" />
|
||||
<key width="4.0" key0="space" />
|
||||
<key width="1.2" key0="switch_emoji" key1="up" key2="right" key3="left" key4="down" />
|
||||
<key width="1.2" key1="up" key2="right" key3="left" key4="down" />
|
||||
<key width="1.8" key0="enter" />
|
||||
</row>
|
||||
</keyboard>
|
||||
|
@@ -1,12 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory android:title="@string/pref_category_layout">
|
||||
<CheckBoxPreference
|
||||
android:key="disable_accent_keys"
|
||||
android:title="@string/pref_disable_accent_keys_title"
|
||||
android:summary="@string/pref_disable_accent_keys_summary"
|
||||
android:defaultValue="false"
|
||||
<ListPreference
|
||||
android:key="layout"
|
||||
android:title="@string/pref_layout_title"
|
||||
android:summary="@string/pref_layout_summary"
|
||||
android:defaultValue="system"
|
||||
android:entries="@array/pref_layout_entries"
|
||||
android:entryValues="@array/pref_layout_values" />
|
||||
/>
|
||||
<ListPreference
|
||||
android:key="accents"
|
||||
android:title="@string/pref_accents_title"
|
||||
android:summary="@string/pref_accents_summary"
|
||||
android:defaultValue="@string/pref_accents_default"
|
||||
android:entries="@array/pref_accents_entries"
|
||||
android:entryValues="@array/pref_accents_values" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_category_typing">
|
||||
<juloo.common.SlideBarPreference
|
||||
@@ -81,5 +90,13 @@
|
||||
min="0"
|
||||
max="20"
|
||||
/>
|
||||
<juloo.common.SlideBarPreference
|
||||
android:key="character_size"
|
||||
android:title="@string/pref_character_size_title"
|
||||
android:summary="@string/pref_character_size_summary"
|
||||
android:defaultValue="1.0"
|
||||
min="0.8"
|
||||
max="1.2"
|
||||
/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
@@ -25,7 +25,7 @@ import android.widget.SeekBar;
|
||||
public class SlideBarPreference extends DialogPreference
|
||||
implements SeekBar.OnSeekBarChangeListener
|
||||
{
|
||||
private static final int SEEKBAR_MAX = 100000;
|
||||
private static final int STEPS = 100;
|
||||
|
||||
private LinearLayout _layout;
|
||||
private TextView _textView;
|
||||
@@ -45,7 +45,7 @@ public class SlideBarPreference extends DialogPreference
|
||||
_textView.setPadding(48, 40, 48, 40);
|
||||
_seekBar = new SeekBar(context);
|
||||
_seekBar.setOnSeekBarChangeListener(this);
|
||||
_seekBar.setMax(SEEKBAR_MAX);
|
||||
_seekBar.setMax(STEPS);
|
||||
_min = float_of_string(attrs.getAttributeValue(null, "min"));
|
||||
_value = _min;
|
||||
_max = Math.max(1f, float_of_string(attrs.getAttributeValue(null, "max")));
|
||||
@@ -58,7 +58,7 @@ public class SlideBarPreference extends DialogPreference
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||
{
|
||||
_value = (progress * _max) / SEEKBAR_MAX + _min;
|
||||
_value = Math.round(progress * (_max - _min)) / (float)STEPS + _min;
|
||||
updateText();
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SlideBarPreference extends DialogPreference
|
||||
_value = (Float)defaultValue;
|
||||
persistFloat(_value);
|
||||
}
|
||||
_seekBar.setProgress((int)((_value - _min) * SEEKBAR_MAX / _max));
|
||||
_seekBar.setProgress((int)((_value - _min) * STEPS / (_max - _min)));
|
||||
updateText();
|
||||
}
|
||||
|
||||
|
@@ -9,11 +9,15 @@ class Config
|
||||
{
|
||||
private Keyboard2 _context;
|
||||
|
||||
// From resources
|
||||
public final float marginTop;
|
||||
public final float keyPadding;
|
||||
public final float keyBgPadding;
|
||||
public final float keyVerticalInterval;
|
||||
public final float keyHorizontalInterval;
|
||||
public final float keyRound;
|
||||
|
||||
// From preferences
|
||||
public int layout; // Or '-1' for the system defaults
|
||||
public float subValueDist;
|
||||
public boolean vibrateEnabled;
|
||||
public long vibrateDuration;
|
||||
@@ -22,10 +26,13 @@ class Config
|
||||
public float marginBottom;
|
||||
public float keyHeight;
|
||||
public float horizontalMargin;
|
||||
public boolean disableAccentKeys;
|
||||
public boolean preciseRepeat;
|
||||
public float characterSize; // Ratio
|
||||
public int accents; // Values are R.values.pref_accents_v_*
|
||||
|
||||
// Dynamically set
|
||||
public boolean shouldOfferSwitchingToNextInputMethod;
|
||||
public int accent_flags_to_remove;
|
||||
|
||||
public Config(Keyboard2 context)
|
||||
{
|
||||
@@ -35,9 +42,11 @@ class Config
|
||||
// static values
|
||||
marginTop = res.getDimension(R.dimen.margin_top);
|
||||
keyPadding = res.getDimension(R.dimen.key_padding);
|
||||
keyBgPadding = res.getDimension(R.dimen.key_bg_padding);
|
||||
keyVerticalInterval = res.getDimension(R.dimen.key_vertical_interval);
|
||||
keyHorizontalInterval = res.getDimension(R.dimen.key_horizontal_interval);
|
||||
keyRound = res.getDimension(R.dimen.key_round);
|
||||
// default values
|
||||
layout = -1;
|
||||
subValueDist = 10f;
|
||||
vibrateEnabled = true;
|
||||
vibrateDuration = 20;
|
||||
@@ -46,12 +55,14 @@ class Config
|
||||
marginBottom = res.getDimension(R.dimen.margin_bottom);
|
||||
keyHeight = res.getDimension(R.dimen.key_height);
|
||||
horizontalMargin = res.getDimension(R.dimen.horizontal_margin);
|
||||
disableAccentKeys = false;
|
||||
preciseRepeat = true;
|
||||
characterSize = 1.f;
|
||||
accents = 1;
|
||||
// from prefs
|
||||
refresh();
|
||||
// initialized later
|
||||
shouldOfferSwitchingToNextInputMethod = false;
|
||||
accent_flags_to_remove = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -61,6 +72,7 @@ class Config
|
||||
{
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context);
|
||||
|
||||
layout = layoutId_of_string(prefs.getString("layout", "system"));
|
||||
subValueDist = prefs.getFloat("sub_value_dist", subValueDist);
|
||||
vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled);
|
||||
vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration);
|
||||
@@ -69,8 +81,9 @@ class Config
|
||||
marginBottom = getDipPref(prefs, "margin_bottom", marginBottom);
|
||||
keyHeight = getDipPref(prefs, "key_height", keyHeight);
|
||||
horizontalMargin = getDipPref(prefs, "horizontal_margin", horizontalMargin);
|
||||
disableAccentKeys = prefs.getBoolean("disable_accent_keys", disableAccentKeys);
|
||||
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
|
||||
characterSize = prefs.getFloat("character_size", characterSize);
|
||||
accents = Integer.valueOf(prefs.getString("accents", "1"));
|
||||
}
|
||||
|
||||
private float getDipPref(SharedPreferences prefs, String pref_name, float def)
|
||||
@@ -82,4 +95,30 @@ class Config
|
||||
return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
|
||||
_context.getResources().getDisplayMetrics()));
|
||||
}
|
||||
|
||||
public static int layoutId_of_string(String name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "azerty": return R.xml.azerty;
|
||||
case "qwerty": return R.xml.qwerty;
|
||||
case "system": return -1;
|
||||
default: throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
/* Used for the accents option. */
|
||||
public static int accentFlag_of_name(String name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "grave": return KeyValue.FLAG_ACCENT1;
|
||||
case "aigu": return KeyValue.FLAG_ACCENT2;
|
||||
case "circonflexe": return KeyValue.FLAG_ACCENT3;
|
||||
case "tilde": return KeyValue.FLAG_ACCENT4;
|
||||
case "cedille": return KeyValue.FLAG_ACCENT5;
|
||||
case "trema": return KeyValue.FLAG_ACCENT6;
|
||||
default: throw new RuntimeException(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,10 +12,13 @@ public class Emoji extends KeyValue
|
||||
{
|
||||
private final String _desc;
|
||||
|
||||
private static HashMap<String, Emoji> emojis_by_name = new HashMap<String, Emoji>();
|
||||
|
||||
protected Emoji(String name, String bytecode, String desc)
|
||||
{
|
||||
super(name, bytecode, CHAR_NONE, EVENT_NONE, 0);
|
||||
_desc = desc;
|
||||
emojis_by_name.put(name, this);
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
@@ -29,7 +32,7 @@ public class Emoji extends KeyValue
|
||||
|
||||
public static Emoji getEmojiByName(String name)
|
||||
{
|
||||
return ((Emoji)KeyValue.getKeyByName(name));
|
||||
return emojis_by_name.get(name);
|
||||
}
|
||||
|
||||
public static Emoji[] getEmojisByGroup(int group_id)
|
||||
|
@@ -20,31 +20,46 @@ class KeyModifier
|
||||
KeyValue r = ks.get(flags);
|
||||
if (r != null) // Found in cache
|
||||
return r;
|
||||
if ((r = handleChar(k, flags)) != null) ;
|
||||
else if ((r = handleFn(k, flags)) != null) ;
|
||||
else r = k;
|
||||
r = k;
|
||||
r = handleFn(r, flags);
|
||||
r = handleShift(r, flags);
|
||||
r = handleAccents(r, flags);
|
||||
ks.put(flags, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Returns [null] if had no effect. */
|
||||
private static KeyValue handleChar(KeyValue k, int flags)
|
||||
private static KeyValue handleAccents(KeyValue k, int flags)
|
||||
{
|
||||
char c = k.char_;
|
||||
if (c == KeyValue.CHAR_NONE)
|
||||
return null;
|
||||
if ((flags & KeyValue.FLAG_SHIFT) != 0) // Shift
|
||||
c = Character.toUpperCase(c);
|
||||
if ((flags & KeyValue.FLAGS_ACCENTS) != 0) // Accents, after shift is applied
|
||||
c = handleAccentChar(c, flags);
|
||||
if (k.char_ == KeyValue.CHAR_NONE || (flags & KeyValue.FLAGS_ACCENTS) == 0)
|
||||
return k;
|
||||
char c = handleAccentChar(k.char_, flags);
|
||||
if (c == 0 || c == k.char_)
|
||||
return null;
|
||||
return k.withCharAndSymbol(String.valueOf(c), c);
|
||||
return k;
|
||||
return k.withCharAndSymbol(c);
|
||||
}
|
||||
|
||||
private static KeyValue handleShift(KeyValue k, int flags)
|
||||
{
|
||||
if ((flags & KeyValue.FLAG_SHIFT) == 0)
|
||||
return k;
|
||||
char c = k.char_;
|
||||
if (k.char_ != KeyValue.CHAR_NONE)
|
||||
c = Character.toUpperCase(c);
|
||||
if (c == k.char_) // More rules if toUpperCase() did nothing
|
||||
switch (k.symbol)
|
||||
{
|
||||
case "→": c = '⇒'; break;
|
||||
case "←": c = '⇐'; break;
|
||||
case "<": c = '«'; break;
|
||||
case ">": c = '»'; break;
|
||||
case "“": c = '”'; break;
|
||||
default: return k;
|
||||
}
|
||||
return k.withCharAndSymbol(c);
|
||||
}
|
||||
|
||||
private static char handleAccentChar(char c, int flags)
|
||||
{
|
||||
char accent;
|
||||
switch ((flags & KeyValue.FLAGS_ACCENTS))
|
||||
{
|
||||
case KeyValue.FLAG_ACCENT1:
|
||||
@@ -58,6 +73,36 @@ class KeyModifier
|
||||
default: return (char)KeyCharacterMap.getDeadChar('\u00B4', c);
|
||||
}
|
||||
case KeyValue.FLAG_ACCENT3:
|
||||
switch (c)
|
||||
{
|
||||
case '*': return '°';
|
||||
default: return (char)KeyCharacterMap.getDeadChar('\u02C6', c);
|
||||
}
|
||||
case KeyValue.FLAG_ACCENT4:
|
||||
switch (c)
|
||||
{
|
||||
case '?': return '¿';
|
||||
case '!': return '¡';
|
||||
default: return (char)KeyCharacterMap.getDeadChar('\u02DC', c);
|
||||
}
|
||||
case KeyValue.FLAG_ACCENT5:
|
||||
switch (c)
|
||||
{
|
||||
case 'u': return 'µ';
|
||||
case '"': return '„';
|
||||
case '\'': return '’';
|
||||
case '-': return '¬';
|
||||
case 'a': return 'æ';
|
||||
case 'o': return 'œ';
|
||||
default: return (char)KeyCharacterMap.getDeadChar('\u00B8', c);
|
||||
}
|
||||
case KeyValue.FLAG_ACCENT6:
|
||||
switch (c)
|
||||
{
|
||||
case '-': return '÷';
|
||||
default: return (char)KeyCharacterMap.getDeadChar('\u00A8', c);
|
||||
}
|
||||
case KeyValue.FLAG_ACCENT_SUPERSCRIPT:
|
||||
switch (c)
|
||||
{
|
||||
case '1': return '¹';
|
||||
@@ -70,12 +115,16 @@ class KeyModifier
|
||||
case '8': return '⁸';
|
||||
case '9': return '⁹';
|
||||
case '0': return '⁰';
|
||||
case '*': return '°';
|
||||
default: return (char)KeyCharacterMap.getDeadChar('\u02C6', c);
|
||||
case 'i': return 'ⁱ';
|
||||
case '+': return '⁺';
|
||||
case '-': return '⁻';
|
||||
case '=': return '⁼';
|
||||
case '(': return '⁽';
|
||||
case ')': return '⁾';
|
||||
case 'n': return 'ⁿ';
|
||||
default: return c;
|
||||
}
|
||||
case KeyValue.FLAG_ACCENT4:
|
||||
return (char)KeyCharacterMap.getDeadChar('\u02DC', c);
|
||||
case KeyValue.FLAG_ACCENT5:
|
||||
case KeyValue.FLAG_ACCENT_SUBSCRIPT:
|
||||
switch (c)
|
||||
{
|
||||
case '1': return '₁';
|
||||
@@ -88,16 +137,16 @@ class KeyModifier
|
||||
case '8': return '₈';
|
||||
case '9': return '₉';
|
||||
case '0': return '₀';
|
||||
case 'u': return 'µ';
|
||||
case '"': return '„';
|
||||
case '-': return '¬';
|
||||
default: return (char)KeyCharacterMap.getDeadChar('\u00B8', c);
|
||||
}
|
||||
case KeyValue.FLAG_ACCENT6:
|
||||
switch (c)
|
||||
{
|
||||
case '-': return '÷';
|
||||
default: return (char)KeyCharacterMap.getDeadChar('\u00A8', c);
|
||||
case '+': return '₊';
|
||||
case '-': return '₋';
|
||||
case '=': return '₌';
|
||||
case '(': return '₍';
|
||||
case ')': return '₎';
|
||||
case 'e': return 'ₑ';
|
||||
case 'a': return 'ₐ';
|
||||
case 'x': return 'ₓ';
|
||||
case 'o': return 'ₒ';
|
||||
default: return c;
|
||||
}
|
||||
default: return c; // Can't happen
|
||||
}
|
||||
@@ -106,7 +155,7 @@ class KeyModifier
|
||||
private static KeyValue handleFn(KeyValue k, int flags)
|
||||
{
|
||||
if ((flags & KeyValue.FLAG_FN) == 0)
|
||||
return null;
|
||||
return k;
|
||||
String name;
|
||||
switch (k.name)
|
||||
{
|
||||
@@ -124,7 +173,13 @@ class KeyModifier
|
||||
case "down": name = "page_down"; break;
|
||||
case "left": name = "home"; break;
|
||||
case "right": name = "end"; break;
|
||||
default: return null;
|
||||
case ">": name = "→"; break;
|
||||
case "<": name = "←"; break;
|
||||
case "\"": name = "“"; break;
|
||||
case "-": name = "–"; break;
|
||||
case "_": name = "—"; break;
|
||||
case "esc": name = "insert"; break;
|
||||
default: return k;
|
||||
}
|
||||
return KeyValue.getKeyByName(name);
|
||||
}
|
||||
|
@@ -39,9 +39,12 @@ class KeyValue
|
||||
public static final int FLAG_ACCENT4 = (1 << 19); // Tilde
|
||||
public static final int FLAG_ACCENT5 = (1 << 20); // Cédille
|
||||
public static final int FLAG_ACCENT6 = (1 << 21); // Tréma
|
||||
public static final int FLAG_ACCENT_SUPERSCRIPT = (1 << 22);
|
||||
public static final int FLAG_ACCENT_SUBSCRIPT = (1 << 23);
|
||||
|
||||
public static final int FLAGS_ACCENTS = FLAG_ACCENT1 | FLAG_ACCENT2 |
|
||||
FLAG_ACCENT3 | FLAG_ACCENT4 | FLAG_ACCENT5 | FLAG_ACCENT6;
|
||||
FLAG_ACCENT3 | FLAG_ACCENT4 | FLAG_ACCENT5 | FLAG_ACCENT6 |
|
||||
FLAG_ACCENT_SUPERSCRIPT | FLAG_ACCENT_SUBSCRIPT;
|
||||
|
||||
public final String name;
|
||||
public final String symbol;
|
||||
@@ -49,6 +52,12 @@ class KeyValue
|
||||
public final int eventCode;
|
||||
public final int flags;
|
||||
|
||||
/* Update the char and the symbol. */
|
||||
public KeyValue withCharAndSymbol(char c)
|
||||
{
|
||||
return withCharAndSymbol(String.valueOf(c), c);
|
||||
}
|
||||
|
||||
public KeyValue withCharAndSymbol(String s, char c)
|
||||
{
|
||||
return new KeyValue(name, s, c, eventCode, flags);
|
||||
@@ -67,7 +76,12 @@ class KeyValue
|
||||
|
||||
public static KeyValue getKeyByName(String name)
|
||||
{
|
||||
return (KeyValue.keys.get(name));
|
||||
if (name == null)
|
||||
return null;
|
||||
KeyValue kv = KeyValue.keys.get(name);
|
||||
if (kv != null)
|
||||
return kv;
|
||||
return new KeyValue(name, name, CHAR_NONE, EVENT_NONE, 0);
|
||||
}
|
||||
|
||||
private static void addKey(String name, String symbol, char c, int event, int flags)
|
||||
@@ -104,21 +118,21 @@ class KeyValue
|
||||
|
||||
static
|
||||
{
|
||||
String chars = "<>&\"'(-_)=°+"
|
||||
+ "~#{[|`\\^@]}"
|
||||
+ "^$*,;:!£%µ?./§";
|
||||
String chars = "<>&\"_°~{|^}$*:!£%µ?.§€";
|
||||
for (int i = 0; i < chars.length(); i++)
|
||||
addCharKey(chars.charAt(i), EVENT_NONE);
|
||||
|
||||
addModifierKey("shift", "⇧", FLAG_LOCK | FLAG_SHIFT);
|
||||
addModifierKey("ctrl", "Ctrl", FLAG_CTRL);
|
||||
addModifierKey("alt", "Alt", FLAG_ALT);
|
||||
addModifierKey("accent1", "\u02CB", FLAG_ACCENT1);
|
||||
addModifierKey("accent2", "\u00B4", FLAG_ACCENT2);
|
||||
addModifierKey("accent3", "\u02C6", FLAG_ACCENT3);
|
||||
addModifierKey("accent4", "\u02DC", FLAG_ACCENT4);
|
||||
addModifierKey("accent5", "\u00B8", FLAG_ACCENT5);
|
||||
addModifierKey("accent6", "\u00A8", FLAG_ACCENT6);
|
||||
addModifierKey("accent_grave", "◌̀", FLAG_ACCENT1);
|
||||
addModifierKey("accent_aigu", "◌́", FLAG_ACCENT2);
|
||||
addModifierKey("accent_circonflexe", "◌̂", FLAG_ACCENT3);
|
||||
addModifierKey("accent_tilde", "◌̃", FLAG_ACCENT4);
|
||||
addModifierKey("accent_cedille", "◌̧", FLAG_ACCENT5);
|
||||
addModifierKey("accent_trema", "◌̈", FLAG_ACCENT6);
|
||||
addModifierKey("superscript", "◌͆", FLAG_ACCENT_SUPERSCRIPT);
|
||||
addModifierKey("subscript", "◌̺", FLAG_ACCENT_SUBSCRIPT);
|
||||
addModifierKey("fn", "Fn", FLAG_FN);
|
||||
|
||||
addCharKey('a', KeyEvent.KEYCODE_A);
|
||||
@@ -157,6 +171,23 @@ class KeyValue
|
||||
addCharKey('7', KeyEvent.KEYCODE_7);
|
||||
addCharKey('8', KeyEvent.KEYCODE_8);
|
||||
addCharKey('9', KeyEvent.KEYCODE_9);
|
||||
addCharKey('`', KeyEvent.KEYCODE_GRAVE);
|
||||
addCharKey('-', KeyEvent.KEYCODE_MINUS);
|
||||
addCharKey('=', KeyEvent.KEYCODE_EQUALS);
|
||||
addCharKey('[', KeyEvent.KEYCODE_LEFT_BRACKET);
|
||||
addCharKey(']', KeyEvent.KEYCODE_RIGHT_BRACKET);
|
||||
addCharKey('\\', KeyEvent.KEYCODE_BACKSLASH);
|
||||
addCharKey(';', KeyEvent.KEYCODE_SEMICOLON);
|
||||
addCharKey('\'', KeyEvent.KEYCODE_APOSTROPHE);
|
||||
addCharKey('/', KeyEvent.KEYCODE_SLASH);
|
||||
addCharKey('@', KeyEvent.KEYCODE_AT);
|
||||
addCharKey('+', KeyEvent.KEYCODE_PLUS);
|
||||
addCharKey(',', KeyEvent.KEYCODE_COMMA);
|
||||
addCharKey('.', KeyEvent.KEYCODE_PERIOD);
|
||||
addCharKey('*', KeyEvent.KEYCODE_STAR);
|
||||
addCharKey('#', KeyEvent.KEYCODE_POUND);
|
||||
addCharKey('(', KeyEvent.KEYCODE_NUMPAD_LEFT_PAREN);
|
||||
addCharKey(')', KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN);
|
||||
|
||||
addSpecialKey("config", "Conf", EVENT_CONFIG);
|
||||
addSpecialKey("switch_text", "ABC", EVENT_SWITCH_TEXT);
|
||||
|
@@ -6,11 +6,13 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Typeface;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.text.InputType;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
import android.view.KeyEvent;
|
||||
@@ -18,6 +20,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.util.Log;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -33,19 +36,6 @@ public class Keyboard2 extends InputMethodService
|
||||
|
||||
private Map<Integer, KeyboardData> _layoutCache = new HashMap<Integer, KeyboardData>();
|
||||
|
||||
private static final int DEFAULT_LAYOUT = R.xml.qwerty;
|
||||
private static final Map<String, Integer> LAYOUTS = new HashMap<String, Integer>();
|
||||
|
||||
private static void add_layout(String lang, int resId)
|
||||
{
|
||||
LAYOUTS.put(new Locale(lang).getLanguage(), resId);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
add_layout("fr", R.xml.azerty);
|
||||
}
|
||||
|
||||
private KeyboardData getLayout(int resId)
|
||||
{
|
||||
KeyboardData l = _layoutCache.get(resId);
|
||||
@@ -79,14 +69,85 @@ public class Keyboard2 extends InputMethodService
|
||||
return (_specialKeyFont);
|
||||
}
|
||||
|
||||
private void refreshSubtype(InputMethodSubtype subtype)
|
||||
private List<InputMethodSubtype> getEnabledSubtypes(InputMethodManager imm)
|
||||
{
|
||||
Integer l = LAYOUTS.get(subtype.getLanguageTag());
|
||||
if (l == null)
|
||||
l = DEFAULT_LAYOUT;
|
||||
String pkg = getPackageName();
|
||||
for (InputMethodInfo imi : imm.getEnabledInputMethodList())
|
||||
if (imi.getPackageName().equals(pkg))
|
||||
return imm.getEnabledInputMethodSubtypeList(imi, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void refreshSubtypeLayout(InputMethodSubtype subtype)
|
||||
{
|
||||
int l = _config.layout;;
|
||||
if (l == -1)
|
||||
{
|
||||
String s = subtype.getExtraValueOf("default_layout");
|
||||
if (s != null)
|
||||
l = Config.layoutId_of_string(s);
|
||||
}
|
||||
_currentTextLayout = l;
|
||||
}
|
||||
|
||||
private int accents_of_subtype(InputMethodSubtype subtype)
|
||||
{
|
||||
String accents_option = subtype.getExtraValueOf("accents");
|
||||
int flags = 0;
|
||||
if (accents_option != null)
|
||||
for (String acc : accents_option.split("\\|"))
|
||||
flags |= Config.accentFlag_of_name(acc);
|
||||
return flags;
|
||||
}
|
||||
|
||||
private void refreshAccentsOption(InputMethodManager imm, InputMethodSubtype subtype)
|
||||
{
|
||||
final int DONT_REMOVE = KeyValue.FLAG_ACCENT_SUPERSCRIPT | KeyValue.FLAG_ACCENT_SUBSCRIPT;
|
||||
int to_keep = DONT_REMOVE;
|
||||
switch (_config.accents)
|
||||
{
|
||||
case 1:
|
||||
to_keep |= accents_of_subtype(subtype);
|
||||
for (InputMethodSubtype s : getEnabledSubtypes(imm))
|
||||
to_keep |= accents_of_subtype(s);
|
||||
break;
|
||||
case 2: to_keep |= accents_of_subtype(subtype); break;
|
||||
case 3: to_keep = KeyValue.FLAGS_ACCENTS; break;
|
||||
case 4: break;
|
||||
default: throw new IllegalArgumentException();
|
||||
}
|
||||
_config.accent_flags_to_remove = ~to_keep & KeyValue.FLAGS_ACCENTS;
|
||||
}
|
||||
|
||||
private void refreshSubtypeLegacyFallback()
|
||||
{
|
||||
// Fallback for the accents option: Only respect the "None" case
|
||||
switch (_config.accents)
|
||||
{
|
||||
case 1: case 2: case 3: _config.accent_flags_to_remove = 0; break;
|
||||
case 4: _config.accent_flags_to_remove = KeyValue.FLAGS_ACCENTS; break;
|
||||
}
|
||||
// Fallback for the layout option: Use qwerty in the "system settings" case
|
||||
_currentTextLayout = (_config.layout == -1) ? R.xml.qwerty : _config.layout;
|
||||
}
|
||||
|
||||
private void refreshSubtypeImm()
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken());
|
||||
if (VERSION.SDK_INT < 12)
|
||||
{
|
||||
// Subtypes won't work well under API level 12 (getExtraValueOf)
|
||||
refreshSubtypeLegacyFallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
InputMethodSubtype subtype = imm.getCurrentInputMethodSubtype();
|
||||
refreshSubtypeLayout(subtype);
|
||||
refreshAccentsOption(imm, subtype);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateInputView()
|
||||
{
|
||||
@@ -100,27 +161,34 @@ public class Keyboard2 extends InputMethodService
|
||||
@Override
|
||||
public void onStartInputView(EditorInfo info, boolean restarting)
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken());
|
||||
refreshSubtype(imm.getCurrentInputMethodSubtype());
|
||||
refreshSubtypeImm();
|
||||
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
|
||||
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
|
||||
else
|
||||
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
|
||||
_keyboardView.reset(); // Layout might need to change due to rotation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype)
|
||||
{
|
||||
refreshSubtype(subtype);
|
||||
refreshSubtypeImm();
|
||||
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishInputView(boolean finishingInput)
|
||||
{
|
||||
super.onFinishInputView(finishingInput);
|
||||
_keyboardView.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||
{
|
||||
_config.refresh();
|
||||
_keyboardView.reset();
|
||||
refreshSubtypeImm();
|
||||
_keyboardView.refreshConfig(_config, getLayout(_currentTextLayout));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
@@ -36,16 +37,18 @@ public class Keyboard2View extends View
|
||||
|
||||
private float _keyWidth;
|
||||
|
||||
private static Paint _keyBgPaint = new Paint();
|
||||
private static Paint _keyDownBgPaint = new Paint();
|
||||
private static Paint _keyLabelPaint;
|
||||
private static Paint _keyLabelLockedPaint;
|
||||
private static Paint _keySubLabelPaint;
|
||||
private static Paint _keySubLabelRightPaint;
|
||||
private static Paint _specialKeyLabelPaint;
|
||||
private static Paint _specialKeyLabelLockedPaint;
|
||||
private static Paint _specialKeySubLabelPaint;
|
||||
private static Paint _specialKeySubLabelRightPaint;
|
||||
private Paint _keyBgPaint = new Paint();
|
||||
private Paint _keyDownBgPaint = new Paint();
|
||||
private Paint _keyLabelPaint;
|
||||
private Paint _keySubLabelPaint;
|
||||
private Paint _specialKeyLabelPaint;
|
||||
private Paint _specialKeySubLabelPaint;
|
||||
private int _lockedColor;
|
||||
private int _activatedColor;
|
||||
private int _labelColor;
|
||||
private int _subLabelColor;
|
||||
private float _labelTextSize;
|
||||
private float _sublabelTextSize;
|
||||
|
||||
private static RectF _tmpRect = new RectF();
|
||||
|
||||
@@ -54,44 +57,50 @@ public class Keyboard2View extends View
|
||||
super(context, attrs);
|
||||
_vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
_handler = new Handler(this);
|
||||
_config = ((Keyboard2)context).getConfig();
|
||||
_keyBgPaint.setColor(getResources().getColor(R.color.key_bg));
|
||||
_keyDownBgPaint.setColor(getResources().getColor(R.color.key_down_bg));
|
||||
_keyLabelPaint = initLabelPaint(_keyLabelPaint, Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, null);
|
||||
_keyLabelLockedPaint = initLabelPaint(_keyLabelLockedPaint, Paint.Align.CENTER, R.color.key_label_locked, R.dimen.label_text_size, null);
|
||||
_keySubLabelPaint = initLabelPaint(_keySubLabelPaint, Paint.Align.LEFT, R.color.key_sub_label, R.dimen.sublabel_text_size, null);
|
||||
_keySubLabelRightPaint = initLabelPaint(_keySubLabelRightPaint, Paint.Align.RIGHT, R.color.key_sub_label, R.dimen.sublabel_text_size, null);
|
||||
Typeface specialKeysFont = ((Keyboard2)getContext()).getSpecialKeyFont();
|
||||
_specialKeyLabelPaint = initLabelPaint(_specialKeyLabelPaint, Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, specialKeysFont);
|
||||
_specialKeyLabelLockedPaint = initLabelPaint(_specialKeyLabelLockedPaint, Paint.Align.CENTER, R.color.key_label_locked, R.dimen.label_text_size, specialKeysFont);
|
||||
_specialKeySubLabelPaint = initLabelPaint(_specialKeySubLabelPaint, Paint.Align.LEFT, R.color.key_sub_label, R.dimen.sublabel_text_size, specialKeysFont);
|
||||
_specialKeySubLabelRightPaint = initLabelPaint(_specialKeySubLabelRightPaint, Paint.Align.RIGHT, R.color.key_sub_label, R.dimen.sublabel_text_size, specialKeysFont);
|
||||
refreshConfig(((Keyboard2)context).getConfig(), null);
|
||||
setOnTouchListener(this);
|
||||
}
|
||||
|
||||
private Paint initLabelPaint(Paint paint, Paint.Align align, int color, int size, Typeface font)
|
||||
/* Internally calls [reset()]. */
|
||||
public void refreshConfig(Config config, KeyboardData kw)
|
||||
{
|
||||
Resources res = getResources();
|
||||
_config = config;
|
||||
_lockedColor = res.getColor(R.color.key_label_locked);
|
||||
_activatedColor = res.getColor(R.color.key_label_activated);
|
||||
_labelColor = res.getColor(R.color.key_label);
|
||||
_subLabelColor = res.getColor(R.color.key_sub_label);
|
||||
_labelTextSize = res.getDimension(R.dimen.label_text_size) * config.characterSize;
|
||||
_sublabelTextSize = res.getDimension(R.dimen.sublabel_text_size) * config.characterSize;
|
||||
_keyBgPaint.setColor(res.getColor(R.color.key_bg));
|
||||
_keyDownBgPaint.setColor(res.getColor(R.color.key_down_bg));
|
||||
_keyLabelPaint = initLabelPaint(Paint.Align.CENTER, null);
|
||||
_keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, null);
|
||||
Typeface specialKeysFont = ((Keyboard2)getContext()).getSpecialKeyFont();
|
||||
_specialKeyLabelPaint = initLabelPaint(Paint.Align.CENTER, specialKeysFont);
|
||||
_specialKeySubLabelPaint = initLabelPaint(Paint.Align.LEFT, specialKeysFont);
|
||||
if (kw != null)
|
||||
setKeyboard(kw); // handle layout options then calls reset().
|
||||
}
|
||||
|
||||
private Paint initLabelPaint(Paint.Align align, Typeface font)
|
||||
{
|
||||
if (paint == null)
|
||||
{
|
||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setTextAlign(align);
|
||||
paint.setColor(getResources().getColor(color));
|
||||
paint.setTextSize(getResources().getDimension(size));
|
||||
if (font != null)
|
||||
paint.setTypeface(font);
|
||||
}
|
||||
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setTextAlign(align);
|
||||
if (font != null)
|
||||
paint.setTypeface(font);
|
||||
return (paint);
|
||||
}
|
||||
|
||||
public void setKeyboard(KeyboardData kw)
|
||||
{
|
||||
public void setKeyboard(KeyboardData kw)
|
||||
{
|
||||
if (!_config.shouldOfferSwitchingToNextInputMethod)
|
||||
kw = kw.removeKeys(new KeyboardData.RemoveKeysByEvent(KeyValue.EVENT_CHANGE_METHOD));
|
||||
if (_config.disableAccentKeys)
|
||||
kw = kw.removeKeys(new KeyboardData.RemoveKeysByFlags(KeyValue.FLAGS_ACCENTS));
|
||||
if (_config.accent_flags_to_remove != 0)
|
||||
kw = kw.removeKeys(new KeyboardData.RemoveKeysByFlags(_config.accent_flags_to_remove));
|
||||
_keyboard = kw;
|
||||
reset();
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
@@ -150,6 +159,16 @@ public class Keyboard2View extends View
|
||||
return (null);
|
||||
}
|
||||
|
||||
private KeyDown getKeyDown(KeyValue kv)
|
||||
{
|
||||
for (KeyDown k : _downKeys)
|
||||
{
|
||||
if (k.value == kv)
|
||||
return (k);
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
private void onTouchMove(float moveX, float moveY, int pointerId)
|
||||
{
|
||||
KeyDown key = getKeyDown(pointerId);
|
||||
@@ -189,36 +208,22 @@ public class Keyboard2View extends View
|
||||
private void onTouchDown(float touchX, float touchY, int pointerId)
|
||||
{
|
||||
float y = _config.marginTop - _config.keyHeight;
|
||||
for (KeyboardData.Row row : _keyboard.getRows())
|
||||
for (KeyboardData.Row row : _keyboard.rows)
|
||||
{
|
||||
y += _config.keyHeight;
|
||||
if (touchY < y || touchY >= (y + _config.keyHeight))
|
||||
continue ;
|
||||
float x = _config.horizontalMargin;
|
||||
for (KeyboardData.Key key : row.getKeys())
|
||||
for (KeyboardData.Key key : row.keys)
|
||||
{
|
||||
x += key.shift * _keyWidth;
|
||||
float keyW = _keyWidth * key.width;
|
||||
if (touchX >= x && touchX < (x + keyW))
|
||||
{
|
||||
KeyDown down = getKeyDown(key);
|
||||
if (down != null)
|
||||
{
|
||||
if ((down.flags & KeyValue.FLAG_LOCK) != 0)
|
||||
{
|
||||
down.flags ^= KeyValue.FLAG_LOCK;
|
||||
down.flags |= KeyValue.FLAG_LOCKED;
|
||||
}
|
||||
else if (down.pointerId == -1)
|
||||
down.pointerId = pointerId;
|
||||
}
|
||||
else
|
||||
{
|
||||
int what = _currentWhat++;
|
||||
if (key.key0 != null && (key.key0.flags & KeyValue.FLAG_NOREPEAT) == 0)
|
||||
_handler.sendEmptyMessageDelayed(what, _config.longPressTimeout);
|
||||
_downKeys.add(new KeyDown(pointerId, key, touchX, touchY, what));
|
||||
}
|
||||
int what = _currentWhat++;
|
||||
if (key.key0 != null && (key.key0.flags & KeyValue.FLAG_NOREPEAT) == 0)
|
||||
_handler.sendEmptyMessageDelayed(what, _config.longPressTimeout);
|
||||
_downKeys.add(new KeyDown(pointerId, key, touchX, touchY, what));
|
||||
handleKeyDown(key.key0);
|
||||
updateFlags();
|
||||
invalidate();
|
||||
@@ -229,36 +234,67 @@ public class Keyboard2View extends View
|
||||
}
|
||||
}
|
||||
|
||||
// Whether a key is already activated (key down but pointer up)
|
||||
private KeyDown getActivatedKey(KeyValue kv)
|
||||
{
|
||||
for (KeyDown k : _downKeys)
|
||||
{
|
||||
if (k.value == kv && k.pointerId == -1)
|
||||
return (k);
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
private void onTouchUp(int pointerId)
|
||||
{
|
||||
KeyDown k = getKeyDown(pointerId);
|
||||
|
||||
if (k != null)
|
||||
{
|
||||
if (k.timeoutWhat != -1)
|
||||
{
|
||||
_handler.removeMessages(k.timeoutWhat);
|
||||
k.timeoutWhat = -1;
|
||||
}
|
||||
if ((k.flags & KeyValue.FLAG_KEEP_ON) != 0)
|
||||
{
|
||||
k.flags ^= KeyValue.FLAG_KEEP_ON;
|
||||
k.pointerId = -1;
|
||||
return ;
|
||||
}
|
||||
for (int i = 0; i < _downKeys.size(); i++)
|
||||
{
|
||||
KeyDown downKey = _downKeys.get(i);
|
||||
if (downKey.pointerId == -1 && (downKey.flags & KeyValue.FLAG_LOCKED) == 0)
|
||||
_downKeys.remove(i--);
|
||||
else if ((downKey.flags & KeyValue.FLAG_KEEP_ON) != 0)
|
||||
downKey.flags ^= KeyValue.FLAG_KEEP_ON;
|
||||
}
|
||||
_downKeys.remove(k);
|
||||
handleKeyUp(k);
|
||||
updateFlags();
|
||||
invalidate();
|
||||
return ;
|
||||
// Stop key repeat
|
||||
if (k.timeoutWhat != -1)
|
||||
{
|
||||
_handler.removeMessages(k.timeoutWhat);
|
||||
k.timeoutWhat = -1;
|
||||
}
|
||||
KeyDown k_on = getActivatedKey(k.value);
|
||||
if (k_on != null)
|
||||
{
|
||||
_downKeys.remove(k); // Remove dupplicate
|
||||
// Same key with FLAG_LOCK is already on, do lock
|
||||
if ((k_on.flags & KeyValue.FLAG_LOCK) != 0)
|
||||
{
|
||||
k_on.flags ^= KeyValue.FLAG_LOCK; // Next time, disable it
|
||||
k_on.flags |= KeyValue.FLAG_LOCKED;
|
||||
}
|
||||
// Otherwise, toggle it
|
||||
else
|
||||
{
|
||||
_downKeys.remove(k_on);
|
||||
}
|
||||
}
|
||||
// Key stay activated
|
||||
else if ((k.flags & KeyValue.FLAG_KEEP_ON) != 0)
|
||||
{
|
||||
k.pointerId = -1; // Set pointer up
|
||||
}
|
||||
else // Regular key up
|
||||
{
|
||||
for (int i = 0; i < _downKeys.size(); i++)
|
||||
{
|
||||
KeyDown downKey = _downKeys.get(i);
|
||||
// Disable other activated keys that aren't locked
|
||||
if (downKey.pointerId == -1 && (downKey.flags & KeyValue.FLAG_LOCKED) == 0)
|
||||
_downKeys.remove(i--);
|
||||
// Other keys currently down won't stay activated
|
||||
else if ((downKey.flags & KeyValue.FLAG_KEEP_ON) != 0)
|
||||
downKey.flags ^= KeyValue.FLAG_KEEP_ON;
|
||||
}
|
||||
_downKeys.remove(k);
|
||||
handleKeyUp(k);
|
||||
}
|
||||
updateFlags();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,51 +362,48 @@ public class Keyboard2View extends View
|
||||
@Override
|
||||
public void onMeasure(int wSpec, int hSpec)
|
||||
{
|
||||
DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
|
||||
int height;
|
||||
|
||||
if (_keyboard.getRows() == null)
|
||||
height = 0;
|
||||
else
|
||||
height = (int)(_config.keyHeight * ((float)_keyboard.getRows().size())
|
||||
+ _config.marginTop + _config.marginBottom);
|
||||
setMeasuredDimension(dm.widthPixels, height);
|
||||
_keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.getKeysWidth();
|
||||
DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
|
||||
int height;
|
||||
height = (int)(_config.keyHeight * _keyboard.keysHeight
|
||||
+ _keyboard.rows.size() * _config.keyVerticalInterval
|
||||
+ _config.marginTop + _config.marginBottom);
|
||||
setMeasuredDimension(dm.widthPixels, height);
|
||||
_keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.keysWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas)
|
||||
{
|
||||
float y = _config.marginTop;
|
||||
for (KeyboardData.Row row : _keyboard.getRows())
|
||||
for (KeyboardData.Row row : _keyboard.rows)
|
||||
{
|
||||
y += row.shift * _config.keyHeight;
|
||||
float x = _config.horizontalMargin;
|
||||
for (KeyboardData.Key k : row.getKeys())
|
||||
float keyH = row.height * _config.keyHeight;
|
||||
for (KeyboardData.Key k : row.keys)
|
||||
{
|
||||
x += k.shift * _keyWidth;
|
||||
float keyW = _keyWidth * k.width;
|
||||
x += k.shift * _keyWidth + _config.keyHorizontalInterval;
|
||||
float keyW = _keyWidth * k.width - _config.keyHorizontalInterval;
|
||||
KeyDown keyDown = getKeyDown(k);
|
||||
_tmpRect.set(x + _config.keyBgPadding, y + _config.keyBgPadding,
|
||||
x + keyW - _config.keyBgPadding, y + _config.keyHeight - _config.keyBgPadding);
|
||||
_tmpRect.set(x, y, x + keyW, y + keyH);
|
||||
if (keyDown != null)
|
||||
canvas.drawRect(_tmpRect, _keyDownBgPaint);
|
||||
else
|
||||
canvas.drawRoundRect(_tmpRect, _config.keyRound, _config.keyRound, _keyBgPaint);
|
||||
if (k.key0 != null)
|
||||
drawLabel(canvas, k.key0, keyW / 2f + x, (_config.keyHeight + _keyLabelPaint.getTextSize()) / 2f + y,
|
||||
(keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0));
|
||||
float subPadding = _config.keyBgPadding + _config.keyPadding;
|
||||
drawLabel(canvas, k.key0, keyW / 2f + x, (keyH + _labelTextSize) / 2f + y, keyDown);
|
||||
float subPadding = _config.keyPadding;
|
||||
if (k.key1 != null)
|
||||
drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding - _keySubLabelPaint.ascent(), false);
|
||||
drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding, false, true, keyDown);
|
||||
if (k.key3 != null)
|
||||
drawSubLabel(canvas, k.key3, x + subPadding, y + _config.keyHeight - subPadding - _keySubLabelPaint.descent(), false);
|
||||
drawSubLabel(canvas, k.key3, x + subPadding, y + keyH - subPadding, false, false, keyDown);
|
||||
if (k.key2 != null)
|
||||
drawSubLabel(canvas, k.key2, x + keyW - subPadding, y + subPadding - _keySubLabelRightPaint.ascent(), true);
|
||||
drawSubLabel(canvas, k.key2, x + keyW - subPadding, y + subPadding, true, true, keyDown);
|
||||
if (k.key4 != null)
|
||||
drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + _config.keyHeight - subPadding - _keySubLabelRightPaint.descent(), true);
|
||||
drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + keyH - subPadding, true, false, keyDown);
|
||||
x += keyW;
|
||||
}
|
||||
y += _config.keyHeight;
|
||||
y += keyH + _config.keyVerticalInterval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,26 +413,50 @@ public class Keyboard2View extends View
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
private void drawLabel(Canvas canvas, KeyValue k, float x, float y, boolean locked)
|
||||
private int labelColor(KeyValue k, KeyDown hasKeyDown, int defaultColor)
|
||||
{
|
||||
if (hasKeyDown != null)
|
||||
{
|
||||
KeyDown kd = getKeyDown(k);
|
||||
if (kd != null)
|
||||
{
|
||||
if ((kd.flags & KeyValue.FLAG_LOCKED) != 0)
|
||||
return _lockedColor;
|
||||
if (kd.pointerId == -1)
|
||||
return _activatedColor;
|
||||
}
|
||||
}
|
||||
return defaultColor;
|
||||
}
|
||||
|
||||
private void drawLabel(Canvas canvas, KeyValue k, float x, float y, KeyDown keyDown)
|
||||
{
|
||||
k = KeyModifier.handleFlags(k, _flags);
|
||||
if ((k.flags & KeyValue.FLAG_KEY_FONT) != 0)
|
||||
canvas.drawText(k.symbol, x, y, locked ? _specialKeyLabelLockedPaint : _specialKeyLabelPaint);
|
||||
else
|
||||
canvas.drawText(k.symbol, x, y, locked ? _keyLabelLockedPaint : _keyLabelPaint);
|
||||
Paint p = ((k.flags & KeyValue.FLAG_KEY_FONT) != 0) ? _specialKeyLabelPaint : _keyLabelPaint;
|
||||
p.setColor(labelColor(k, keyDown, _labelColor));
|
||||
p.setTextSize(_labelTextSize * scaleTextSize(k));
|
||||
canvas.drawText(k.symbol, x, y, p);
|
||||
}
|
||||
|
||||
private void drawSubLabel(Canvas canvas, KeyValue k, float x, float y, boolean right)
|
||||
private void drawSubLabel(Canvas canvas, KeyValue k, float x, float y, boolean right, boolean up, KeyDown keyDown)
|
||||
{
|
||||
k = KeyModifier.handleFlags(k, _flags);
|
||||
if ((k.flags & KeyValue.FLAG_KEY_FONT) != 0)
|
||||
canvas.drawText(k.symbol, x, y, right ? _specialKeySubLabelRightPaint : _specialKeySubLabelPaint);
|
||||
else
|
||||
canvas.drawText(k.symbol, x, y, right ? _keySubLabelRightPaint : _keySubLabelPaint);
|
||||
Paint p = ((k.flags & KeyValue.FLAG_KEY_FONT) != 0) ? _specialKeySubLabelPaint : _keySubLabelPaint;
|
||||
p.setColor(labelColor(k, keyDown, _subLabelColor));
|
||||
p.setTextAlign(right ? Paint.Align.RIGHT : Paint.Align.LEFT);
|
||||
p.setTextSize(_sublabelTextSize * scaleTextSize(k));
|
||||
y -= up ? p.ascent() : p.descent();
|
||||
canvas.drawText(k.symbol, x, y, p);
|
||||
}
|
||||
|
||||
private float scaleTextSize(KeyValue k)
|
||||
{
|
||||
return (k.symbol.length() < 2) ? 1.f : 0.8f;
|
||||
}
|
||||
|
||||
private static class KeyDown
|
||||
{
|
||||
/* -1 if pointer is up. */
|
||||
public int pointerId;
|
||||
public KeyValue value;
|
||||
public KeyboardData.Key key;
|
||||
|
@@ -6,15 +6,24 @@ import java.util.List;
|
||||
|
||||
class KeyboardData
|
||||
{
|
||||
private final List<Row> _rows;
|
||||
private final float _keysWidth;
|
||||
public final List<Row> rows;
|
||||
/* Total width of the keyboard. Unit is abstract. */
|
||||
public final float keysWidth;
|
||||
/* Total height of the keyboard. Unit is abstract. */
|
||||
public final float keysHeight;
|
||||
|
||||
public KeyboardData(List<Row> rows)
|
||||
public KeyboardData(List<Row> rows_)
|
||||
{
|
||||
float kpr = 0.f;
|
||||
for (Row r : rows) kpr = Math.max(kpr, r.keysWidth());
|
||||
_rows = rows;
|
||||
_keysWidth = kpr;
|
||||
float kw = 0.f;
|
||||
float kh = 0.f;
|
||||
for (Row r : rows_)
|
||||
{
|
||||
kw = Math.max(kw, r.keysWidth);
|
||||
kh += r.height + r.shift;
|
||||
}
|
||||
rows = rows_;
|
||||
keysWidth = kw;
|
||||
keysHeight = kh;
|
||||
}
|
||||
|
||||
public static KeyboardData parse(XmlResourceParser parser)
|
||||
@@ -40,7 +49,6 @@ class KeyboardData
|
||||
throw new Exception("Unknow keyboard tag: " + tag);
|
||||
}
|
||||
}
|
||||
return new KeyboardData(rows);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -49,36 +57,40 @@ class KeyboardData
|
||||
return new KeyboardData(rows);
|
||||
}
|
||||
|
||||
public List<Row> getRows() { return _rows; }
|
||||
|
||||
public float getKeysWidth() { return _keysWidth; }
|
||||
|
||||
public KeyboardData removeKeys(MapKeys f)
|
||||
{
|
||||
ArrayList<Row> rows = new ArrayList<Row>();
|
||||
for (Row r : _rows)
|
||||
rows.add(r.removeKeys(f));
|
||||
return new KeyboardData(rows);
|
||||
ArrayList<Row> rows_ = new ArrayList<Row>();
|
||||
for (Row r : rows)
|
||||
rows_.add(r.removeKeys(f));
|
||||
return new KeyboardData(rows_);
|
||||
}
|
||||
|
||||
public static class Row
|
||||
{
|
||||
private final List<Key> _keys;
|
||||
public final List<Key> keys;
|
||||
/* Height of the row. Unit is abstract. */
|
||||
public final float height;
|
||||
/* Extra empty space on the top. */
|
||||
public final float shift;
|
||||
/* Total width of very keys. Unit is abstract. */
|
||||
private final float _keysWidth;
|
||||
private final float keysWidth;
|
||||
|
||||
public Row(List<Key> keys)
|
||||
public Row(List<Key> keys_, float h, float s)
|
||||
{
|
||||
float kw = 0.f;
|
||||
for (Key k : keys) kw += k.width + k.shift;
|
||||
_keys = keys;
|
||||
_keysWidth = kw;
|
||||
for (Key k : keys_) kw += k.width + k.shift;
|
||||
keys = keys_;
|
||||
height = h;
|
||||
shift = s;
|
||||
keysWidth = kw;
|
||||
}
|
||||
|
||||
public static Row parse(XmlResourceParser parser) throws Exception
|
||||
{
|
||||
ArrayList<Key> keys = new ArrayList<Key>();
|
||||
int status;
|
||||
float h = parser.getAttributeFloatValue(null, "height", 1f);
|
||||
float shift = parser.getAttributeFloatValue(null, "shift", 0f);
|
||||
while ((status = parser.next()) != XmlResourceParser.END_TAG)
|
||||
{
|
||||
if (status == XmlResourceParser.START_TAG)
|
||||
@@ -90,19 +102,15 @@ class KeyboardData
|
||||
throw new Exception("Unknow row tag: " + tag);
|
||||
}
|
||||
}
|
||||
return new Row(keys);
|
||||
return new Row(keys, h, shift);
|
||||
}
|
||||
|
||||
public List<Key> getKeys() { return _keys; }
|
||||
|
||||
public float keysWidth() { return _keysWidth; }
|
||||
|
||||
public Row removeKeys(MapKeys f)
|
||||
{
|
||||
ArrayList<Key> keys = new ArrayList<Key>();
|
||||
for (Key k : _keys)
|
||||
keys.add(k.removeKeys(f));
|
||||
return new Row(keys);
|
||||
ArrayList<Key> keys_ = new ArrayList<Key>();
|
||||
for (Key k : keys)
|
||||
keys_.add(k.removeKeys(f));
|
||||
return new Row(keys_, height, shift);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user