Compare commits

...

18 Commits
1.7 ... 1.8

Author SHA1 Message Date
Jules Aguillon
a036ebc47b Release 1.8 (9) 2021-05-02 00:05:12 +02:00
Jules Aguillon
abfa1cc8de Add '¿' and '¡' 2021-05-01 23:57:40 +02:00
Jules Aguillon
5ad4450545 Better placement of accents on QWERTY
Also change internal names for accents.
2021-05-01 23:26:44 +02:00
Jules Aguillon
c6a54ed017 Fix rendering of the first label
Caused by a shared Paint not correctly resetted.
2021-05-01 23:26:34 +02:00
Jules Aguillon
f287ff2e09 Reset keyboard when finishing
This may cause key repeat continuing for a bit after the keyboard
closes.
2021-05-01 22:47:22 +02:00
Jules Aguillon
743b10165c Highlight activated keys 2021-04-29 01:33:57 +02:00
Jules Aguillon
ec5cda0ce6 Slightly reduce the size of the bottom row 2021-04-29 01:11:18 +02:00
Jules Aguillon
b976f4a791 Move system keys to the alt key 2021-04-29 01:11:07 +02:00
Jules Aguillon
ec1cd9473a Improve the azerty layout
- More intuitive placement of (), [], {} and <>.
- Move accent keys into the top-left corner, on a key they may be used with.
- Some minor changes.
2021-04-29 01:06:51 +02:00
Jules Aguillon
3f0c18612f Fix modifiers
Fixes:
- Toggling off a modifier was not possible in the corners (eg. accents).
- Modifiers on the same key can't be activated at the same time.
- Characters on the same key as a modifier weren't working properly.
2021-04-29 01:06:51 +02:00
Jules Aguillon
d00576ac2d Add the "layout" option again
Some versions of android don't allow to configure several languages.
2021-04-29 01:06:51 +02:00
Jules Aguillon
c86a119448 Tweak dimensions
Increase a bit labels size and reduce empty space between keys.
2021-04-25 00:12:16 +02:00
Jules Aguillon
f7c062d0cb Scale down larger symbols 2021-04-24 23:38:29 +02:00
Jules Aguillon
9bb2642e2c Add the label size option 2021-04-24 23:22:25 +02:00
Jules Aguillon
2dbb3dc28f Allow different sizes
Improve Paint code.
2021-04-24 23:18:16 +02:00
Jules Aguillon
5688e181fa SlideBarPreference: Reduce the number of step
To have cleaner values.
2021-04-24 23:12:06 +02:00
Jules Aguillon
87b237494a Add some missing keycodes
Allows to sent ctrl and alt combinations. Notably the ] character.
2021-04-21 23:25:14 +02:00
Jules Aguillon
93c0ff5ff6 build: Explicitly set signing algorithms
Newer versions of jarsigner default to SHA256, which is unsupported for
some versions of Android we support.
2021-04-20 23:01:36 +02:00
18 changed files with 370 additions and 235 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="juloo.keyboard2" package="juloo.keyboard2"
android:versionCode="8" android:versionCode="9"
android:versionName="1.7" android:versionName="1.8"
android:hardwareAccelerated="false"> android:hardwareAccelerated="false">
<uses-sdk android:minSdkVersion="3" <uses-sdk android:minSdkVersion="3"

View File

@@ -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 # OPTS can be used to pass -storepass or -keypass options to jarsigner
_build/%.signed-apk: _build/%.unsigned-apk %-keystore.conf _build/%.signed-apk: _build/%.unsigned-apk %-keystore.conf
eval `cat $(word 2,$^)` && \ eval `cat $(word 2,$^)` && \
jarsigner -keystore "$$KEYSTORE" $$OPTS -signedjar "$@" "$<" "$$KEYNAME" jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore "$$KEYSTORE" $$OPTS -signedjar "$@" "$<" "$$KEYNAME"
# Package # Package

View File

@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string-array name="pref_layout_values"> <string-array name="pref_layout_values">
<item>azerty</item> <item>system</item>
<item>qwerty</item> <item>azerty</item>
</string-array> <item>qwerty</item>
</string-array>
</resources> </resources>

View File

@@ -5,6 +5,7 @@
<item name="key_down_bg" type="color">#1B1B1B</item> <item name="key_down_bg" type="color">#1B1B1B</item>
<item name="key_label" type="color">#FFFFFF</item> <item name="key_label" type="color">#FFFFFF</item>
<item name="key_label_locked" type="color">#229933</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="key_sub_label" type="color">#A0A0A0</item>
<item name="emoji_button_bg" type="color">#202020</item> <item name="emoji_button_bg" type="color">#202020</item>
<item name="emoji_color" type="color">#FFFFFF</item> <item name="emoji_color" type="color">#FFFFFF</item>

View File

@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<dimen name="horizontal_margin">3dp</dimen> <dimen name="horizontal_margin">3dp</dimen>
<dimen name="margin_top">2dp</dimen> <dimen name="margin_top">3dp</dimen>
<dimen name="margin_bottom">5dp</dimen> <dimen name="margin_bottom">7dp</dimen>
<dimen name="key_padding">2dp</dimen> <dimen name="key_padding">2dp</dimen>
<dimen name="key_bg_padding">1.3dp</dimen> <dimen name="key_vertical_interval">2dp</dimen>
<dimen name="key_height">50dp</dimen> <dimen name="key_horizontal_interval">2dp</dimen>
<dimen name="key_round">4dp</dimen> <dimen name="key_height">51dp</dimen>
<dimen name="label_text_size">16dp</dimen> <dimen name="key_round">5dp</dimen>
<dimen name="sublabel_text_size">10dp</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_type_button_height">56dp</dimen>
<dimen name="emoji_grid_height">250dp</dimen> <dimen name="emoji_grid_height">250dp</dimen>
</resources> </resources>

View File

@@ -5,10 +5,19 @@
<string name="settings_activity_label">Unexpected Keyboard Settings</string> <string name="settings_activity_label">Unexpected Keyboard Settings</string>
<string name="subtype_label_azerty">%s AZERTY</string> <string name="subtype_label_azerty">%s</string>
<string name="subtype_label_qwerty">%s QWERTY</string> <string name="subtype_label_qwerty">%s</string>
<string name="pref_category_layout">Layout</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_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_category_typing">Typing</string> <string name="pref_category_typing">Typing</string>
<string name="pref_preci_title">Precision</string> <string name="pref_preci_title">Precision</string>
@@ -33,6 +42,6 @@
<string name="pref_key_height_summary">%sdp</string> <string name="pref_key_height_summary">%sdp</string>
<string name="pref_horizontal_margin_title">Horizontal margin</string> <string name="pref_horizontal_margin_title">Horizontal margin</string>
<string name="pref_horizontal_margin_summary">%sdp</string> <string name="pref_horizontal_margin_summary">%sdp</string>
<string name="pref_disable_accent_keys_title">Toggle accent keys</string> <string name="pref_character_size_title">Label size</string>
<string name="pref_disable_accent_keys_summary">Whether to remove the accent keys from the keyboard.</string> <string name="pref_character_size_summary">Size of characters displayed on the keyboard (%.2fx)</string>
</resources> </resources>

View File

@@ -2,43 +2,43 @@
<keyboard> <keyboard>
<row> <row>
<key key0="a" key1="esc" key2="1" key3="&amp;" /> <key key0="a" key1="esc" key2="1" key3="&amp;" />
<key key0="z" key2="2" key3="accent2" key4="~" /> <key key0="z" key2="2" key4="~" />
<key key0="e" key2="3" key3="&quot;" key4="\#" /> <key key0="e" key1="accent_aigu" key2="3" key3="&quot;" key4="\#" />
<key key0="r" key2="4" key3="'" key4="{" /> <key key0="r" key2="4" key3="'" />
<key key0="t" key2="5" key3="(" key4="[" /> <key key0="t" key2="5" key3="(" key4=")" />
<key key0="y" key2="6" key3="-" key4="|" /> <key key0="y" key2="6" key3="-" key4="|" />
<key key0="u" key2="7" key3="accent1" key4="`" /> <key key0="u" key1="accent_grave" key2="7" key4="`" />
<key key0="i" key2="8" key3="_" key4="\\" /> <key key0="i" key1="accent_trema" key2="8" key3="_" key4="\\" />
<key key0="o" key2="9" key3="accent5" key4="^" /> <key key0="o" key1="accent_circonflexe" key2="9" />
<key key0="p" key1="insert" key2="0" key3="config" key4="\@" /> <key key0="p" key1="insert" key2="0" key4="\@" />
</row> </row>
<row> <row>
<key key0="q" key1="tab" /> <key key0="q" key1="tab" />
<key key0="s" /> <key key0="s" />
<key key0="d" /> <key key0="d" />
<key key0="f" /> <key key0="f" key3="{" key4="}" />
<key key0="g" key3=")" key4="]" /> <key key0="g" key3="[" key4="]" />
<key key0="h" key2="+" key3="=" key4="}" /> <key key0="h" key3="=" key4="+" />
<key key0="j" key2="accent6" key3="^" /> <key key0="j" key3="^" />
<key key0="k" key2="£" key3="$" key4="accent3" /> <key key0="k" key2="" key3="$" key4="£" />
<key key0="l" key1="accent4" key2="%" /> <key key0="l" key2="%" />
<key key0="m" key4="*" /> <key key0="m" key4="*" />
</row> </row>
<row> <row>
<key width="2.0" key0="shift" /> <key width="2.0" key0="shift" />
<key key0="w" key1="&gt;" key3="&lt;" /> <key key0="w" key3="&lt;" key4="&gt;" />
<key key0="x" /> <key key0="x" />
<key key0="c" key2="\?" key4="," /> <key key0="c" key1="accent_cedille" key3="," key4="\?" />
<key key0="v" key2="." key4=";" /> <key key0="v" key3=";" key4="." />
<key key0="b" key2="/" key4=":" /> <key key0="b" key3=":" key4="/" />
<key key0="n" key2="§" key4="!" /> <key key0="n" key1="accent_tilde" key2="§" key4="!" />
<key width="2.0" key0="backspace" key2="delete" /> <key width="2.0" key0="backspace" key2="delete" />
</row> </row>
<row> <row height="0.95">
<key width="1.8" key0="ctrl" key1="change_method" key3="switch_numeric" /> <key width="1.8" key0="ctrl" key3="switch_numeric" />
<key width="1.2" key0="alt" key1="fn" /> <key width="1.2" key0="alt" key1="fn" key2="change_method" key3="switch_emoji" key4="config" />
<key width="4.0" key0="space" /> <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" /> <key width="1.8" key0="enter" />
</row> </row>
</keyboard> </keyboard>

View File

@@ -7,11 +7,13 @@
android:imeSubtypeLocale="en_US" android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard" android:imeSubtypeMode="keyboard"
android:isAsciiCapable="true" android:isAsciiCapable="true"
android:imeSubtypeExtraValue="default_layout=qwerty"
/> />
<subtype android:label="@string/subtype_label_azerty" <subtype android:label="@string/subtype_label_azerty"
android:languageTag="fr" android:languageTag="fr"
android:imeSubtypeLocale="fr_FR" android:imeSubtypeLocale="fr_FR"
android:imeSubtypeMode="keyboard" android:imeSubtypeMode="keyboard"
android:isAsciiCapable="true" android:isAsciiCapable="true"
android:imeSubtypeExtraValue="default_layout=azerty"
/> />
</input-method> </input-method>

View File

@@ -25,7 +25,7 @@
<key key0="3" key4="page_down" /> <key key0="3" key4="page_down" />
<key width="1.15" key0="backspace" key2="delete" /> <key width="1.15" key0="backspace" key2="delete" />
</row> </row>
<row> <row height="0.95">
<key width="1.5" key0="ctrl" key3="switch_text" /> <key width="1.5" key0="ctrl" key3="switch_text" />
<key width="1.5" key0="0" /> <key width="1.5" key0="0" />
<key width="0.75" key0="." key2="," /> <key width="0.75" key0="." key2="," />

View File

@@ -3,19 +3,19 @@
<row> <row>
<key key0="q" key1="esc" key2="1" key3="~" key4="!" /> <key key0="q" key1="esc" key2="1" key3="~" key4="!" />
<key key0="w" key2="2" key3="\@" /> <key key0="w" key2="2" key3="\@" />
<key key0="e" key2="3" key3="\#" /> <key key0="e" key1="accent_aigu" key2="3" key3="\#" />
<key key0="r" key2="4" key3="$" /> <key key0="r" key2="4" key3="$" />
<key key0="t" key2="5" key3="%" /> <key key0="t" key2="5" key3="%" />
<key key0="y" key2="6" key3="^" /> <key key0="y" key2="6" key3="^" />
<key key0="u" key2="7" key3="&amp;" /> <key key0="u" key1="accent_grave" key2="7" key3="&amp;" />
<key key0="i" key2="8" key3="*" /> <key key0="i" key1="accent_trema" key2="8" key3="*" />
<key key0="o" key2="9" key3="(" key4=")" /> <key key0="o" key1="accent_circonflexe" key2="9" key3="(" key4=")" />
<key key0="p" key1="insert" key2="0" key3="config" /> <key key0="p" key1="insert" key2="0" />
</row> </row>
<row> <row>
<key shift="0.5" key0="a" key1="tab" key2="`" /> <key shift="0.5" key0="a" key1="tab" key2="`" />
<key key0="s" key1="accent1" key2="accent2" key4="accent6" /> <key key0="s" />
<key key0="d" key1="accent3" key2="accent4" key3="accent5" /> <key key0="d" />
<key key0="f" /> <key key0="f" />
<key key0="g" key2="-" key3="_" /> <key key0="g" key2="-" key3="_" />
<key key0="h" key2="=" key3="+" /> <key key0="h" key2="=" key3="+" />
@@ -27,18 +27,18 @@
<key width="1.5" key0="shift" /> <key width="1.5" key0="shift" />
<key key0="z" /> <key key0="z" />
<key key0="x" /> <key key0="x" />
<key key0="c" key1="&lt;" key3="." /> <key key0="c" key1="accent_cedille" key2="&lt;" key3="." />
<key key0="v" key2="&gt;" key3="," /> <key key0="v" key2="&gt;" key3="," />
<key key0="b" key2="\?" key3="/" /> <key key0="b" key2="\?" key3="/" />
<key key0="n" key2=":" key3=";" /> <key key0="n" key1="accent_tilde" key2=":" key3=";" />
<key key0="m" key2="&quot;" key3="'" /> <key key0="m" key2="&quot;" key3="'" />
<key width="1.5" key0="backspace" key2="delete" /> <key width="1.5" key0="backspace" key2="delete" />
</row> </row>
<row> <row height="0.95">
<key width="1.8" key0="ctrl" key1="change_method" key3="switch_numeric" /> <key width="1.8" key0="ctrl" key3="switch_numeric" />
<key width="1.2" key0="alt" key1="fn" /> <key width="1.2" key0="alt" key1="fn" key2="change_method" key3="switch_emoji" key4="config" />
<key width="4.0" key0="space" /> <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" /> <key width="1.8" key0="enter" />
</row> </row>
</keyboard> </keyboard>

View File

@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_category_layout"> <PreferenceCategory android:title="@string/pref_category_layout">
<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" />
/>
<CheckBoxPreference <CheckBoxPreference
android:key="disable_accent_keys" android:key="disable_accent_keys"
android:title="@string/pref_disable_accent_keys_title" android:title="@string/pref_disable_accent_keys_title"
@@ -81,5 +89,13 @@
min="0" min="0"
max="20" 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> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -25,7 +25,7 @@ import android.widget.SeekBar;
public class SlideBarPreference extends DialogPreference public class SlideBarPreference extends DialogPreference
implements SeekBar.OnSeekBarChangeListener implements SeekBar.OnSeekBarChangeListener
{ {
private static final int SEEKBAR_MAX = 100000; private static final int STEPS = 100;
private LinearLayout _layout; private LinearLayout _layout;
private TextView _textView; private TextView _textView;
@@ -45,7 +45,7 @@ public class SlideBarPreference extends DialogPreference
_textView.setPadding(48, 40, 48, 40); _textView.setPadding(48, 40, 48, 40);
_seekBar = new SeekBar(context); _seekBar = new SeekBar(context);
_seekBar.setOnSeekBarChangeListener(this); _seekBar.setOnSeekBarChangeListener(this);
_seekBar.setMax(SEEKBAR_MAX); _seekBar.setMax(STEPS);
_min = float_of_string(attrs.getAttributeValue(null, "min")); _min = float_of_string(attrs.getAttributeValue(null, "min"));
_value = _min; _value = _min;
_max = Math.max(1f, float_of_string(attrs.getAttributeValue(null, "max"))); _max = Math.max(1f, float_of_string(attrs.getAttributeValue(null, "max")));
@@ -58,7 +58,7 @@ public class SlideBarPreference extends DialogPreference
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) 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(); updateText();
} }
@@ -84,7 +84,7 @@ public class SlideBarPreference extends DialogPreference
_value = (Float)defaultValue; _value = (Float)defaultValue;
persistFloat(_value); persistFloat(_value);
} }
_seekBar.setProgress((int)((_value - _min) * SEEKBAR_MAX / _max)); _seekBar.setProgress((int)((_value - _min) * STEPS / (_max - _min)));
updateText(); updateText();
} }

View File

@@ -11,9 +11,11 @@ class Config
public final float marginTop; public final float marginTop;
public final float keyPadding; public final float keyPadding;
public final float keyBgPadding; public final float keyVerticalInterval;
public final float keyHorizontalInterval;
public final float keyRound; public final float keyRound;
public int layout; // Or '-1' for the system defaults
public float subValueDist; public float subValueDist;
public boolean vibrateEnabled; public boolean vibrateEnabled;
public long vibrateDuration; public long vibrateDuration;
@@ -24,6 +26,7 @@ class Config
public float horizontalMargin; public float horizontalMargin;
public boolean disableAccentKeys; public boolean disableAccentKeys;
public boolean preciseRepeat; public boolean preciseRepeat;
public float characterSize; // Ratio
public boolean shouldOfferSwitchingToNextInputMethod; public boolean shouldOfferSwitchingToNextInputMethod;
@@ -35,9 +38,11 @@ class Config
// static values // static values
marginTop = res.getDimension(R.dimen.margin_top); marginTop = res.getDimension(R.dimen.margin_top);
keyPadding = res.getDimension(R.dimen.key_padding); 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); keyRound = res.getDimension(R.dimen.key_round);
// default values // default values
layout = -1;
subValueDist = 10f; subValueDist = 10f;
vibrateEnabled = true; vibrateEnabled = true;
vibrateDuration = 20; vibrateDuration = 20;
@@ -48,6 +53,7 @@ class Config
horizontalMargin = res.getDimension(R.dimen.horizontal_margin); horizontalMargin = res.getDimension(R.dimen.horizontal_margin);
disableAccentKeys = false; disableAccentKeys = false;
preciseRepeat = true; preciseRepeat = true;
characterSize = 1.f;
// from prefs // from prefs
refresh(); refresh();
// initialized later // initialized later
@@ -61,6 +67,7 @@ class Config
{ {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context);
layout = layoutId_of_string(prefs.getString("layout", "system"));
subValueDist = prefs.getFloat("sub_value_dist", subValueDist); subValueDist = prefs.getFloat("sub_value_dist", subValueDist);
vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled); vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled);
vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration); vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration);
@@ -71,6 +78,7 @@ class Config
horizontalMargin = getDipPref(prefs, "horizontal_margin", horizontalMargin); horizontalMargin = getDipPref(prefs, "horizontal_margin", horizontalMargin);
disableAccentKeys = prefs.getBoolean("disable_accent_keys", disableAccentKeys); disableAccentKeys = prefs.getBoolean("disable_accent_keys", disableAccentKeys);
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat); preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
characterSize = prefs.getFloat("character_size", characterSize);
} }
private float getDipPref(SharedPreferences prefs, String pref_name, float def) private float getDipPref(SharedPreferences prefs, String pref_name, float def)
@@ -82,4 +90,16 @@ class Config
return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
_context.getResources().getDisplayMetrics())); _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();
}
}
} }

View File

@@ -97,6 +97,8 @@ class KeyModifier
switch (c) switch (c)
{ {
case '-': return '÷'; case '-': return '÷';
case '?': return '¿';
case '!': return '¡';
default: return (char)KeyCharacterMap.getDeadChar('\u00A8', c); default: return (char)KeyCharacterMap.getDeadChar('\u00A8', c);
} }
default: return c; // Can't happen default: return c; // Can't happen

View File

@@ -104,21 +104,19 @@ class KeyValue
static static
{ {
String chars = "<>&\"'(-_)=°+" String chars = "<>&\"_°~{|^}$*:!£%µ?.§€";
+ "~#{[|`\\^@]}"
+ "^$*,;:!£%µ?./§";
for (int i = 0; i < chars.length(); i++) for (int i = 0; i < chars.length(); i++)
addCharKey(chars.charAt(i), EVENT_NONE); addCharKey(chars.charAt(i), EVENT_NONE);
addModifierKey("shift", "", FLAG_LOCK | FLAG_SHIFT); addModifierKey("shift", "", FLAG_LOCK | FLAG_SHIFT);
addModifierKey("ctrl", "Ctrl", FLAG_CTRL); addModifierKey("ctrl", "Ctrl", FLAG_CTRL);
addModifierKey("alt", "Alt", FLAG_ALT); addModifierKey("alt", "Alt", FLAG_ALT);
addModifierKey("accent1", "\u02CB", FLAG_ACCENT1); addModifierKey("accent_grave", "\u02CB", FLAG_ACCENT1);
addModifierKey("accent2", "\u00B4", FLAG_ACCENT2); addModifierKey("accent_aigu", "\u00B4", FLAG_ACCENT2);
addModifierKey("accent3", "\u02C6", FLAG_ACCENT3); addModifierKey("accent_circonflexe", "\u02C6", FLAG_ACCENT3);
addModifierKey("accent4", "\u02DC", FLAG_ACCENT4); addModifierKey("accent_tilde", "\u02DC", FLAG_ACCENT4);
addModifierKey("accent5", "\u00B8", FLAG_ACCENT5); addModifierKey("accent_cedille", "\u00B8", FLAG_ACCENT5);
addModifierKey("accent6", "\u00A8", FLAG_ACCENT6); addModifierKey("accent_trema", "\u00A8", FLAG_ACCENT6);
addModifierKey("fn", "Fn", FLAG_FN); addModifierKey("fn", "Fn", FLAG_FN);
addCharKey('a', KeyEvent.KEYCODE_A); addCharKey('a', KeyEvent.KEYCODE_A);
@@ -157,6 +155,23 @@ class KeyValue
addCharKey('7', KeyEvent.KEYCODE_7); addCharKey('7', KeyEvent.KEYCODE_7);
addCharKey('8', KeyEvent.KEYCODE_8); addCharKey('8', KeyEvent.KEYCODE_8);
addCharKey('9', KeyEvent.KEYCODE_9); 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("config", "Conf", EVENT_CONFIG);
addSpecialKey("switch_text", "ABC", EVENT_SWITCH_TEXT); addSpecialKey("switch_text", "ABC", EVENT_SWITCH_TEXT);

View File

@@ -33,19 +33,6 @@ public class Keyboard2 extends InputMethodService
private Map<Integer, KeyboardData> _layoutCache = new HashMap<Integer, KeyboardData>(); 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) private KeyboardData getLayout(int resId)
{ {
KeyboardData l = _layoutCache.get(resId); KeyboardData l = _layoutCache.get(resId);
@@ -81,10 +68,23 @@ public class Keyboard2 extends InputMethodService
private void refreshSubtype(InputMethodSubtype subtype) private void refreshSubtype(InputMethodSubtype subtype)
{ {
Integer l = LAYOUTS.get(subtype.getLanguageTag()); int l;
if (l == null) if (_config.layout == -1)
l = DEFAULT_LAYOUT; l = Config.layoutId_of_string(subtype.getExtraValueOf("default_layout"));
_currentTextLayout = l; else
l = _config.layout;
if (_currentTextLayout != l)
{
_currentTextLayout = l;
_keyboardView.setKeyboard(getLayout(l));
}
}
private void refreshSubtypeImm()
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken());
refreshSubtype(imm.getCurrentInputMethodSubtype());
} }
@Override @Override
@@ -100,27 +100,30 @@ public class Keyboard2 extends InputMethodService
@Override @Override
public void onStartInputView(EditorInfo info, boolean restarting) public void onStartInputView(EditorInfo info, boolean restarting)
{ {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); refreshSubtypeImm();
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken());
refreshSubtype(imm.getCurrentInputMethodSubtype());
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0) if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
_keyboardView.setKeyboard(getLayout(R.xml.numeric)); _keyboardView.setKeyboard(getLayout(R.xml.numeric));
else
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
} }
@Override @Override
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype)
{ {
refreshSubtype(subtype); refreshSubtype(subtype);
_keyboardView.setKeyboard(getLayout(_currentTextLayout)); }
@Override
public void onFinishInputView(boolean finishingInput)
{
super.onFinishInputView(finishingInput);
_keyboardView.reset();
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{ {
_config.refresh(); _config.refresh();
_keyboardView.reset(); refreshSubtypeImm();
_keyboardView.refreshConfig(_config, getLayout(_currentTextLayout));
} }
@Override @Override

View File

@@ -1,6 +1,7 @@
package juloo.keyboard2; package juloo.keyboard2;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.RectF; import android.graphics.RectF;
@@ -36,16 +37,18 @@ public class Keyboard2View extends View
private float _keyWidth; private float _keyWidth;
private static Paint _keyBgPaint = new Paint(); private Paint _keyBgPaint = new Paint();
private static Paint _keyDownBgPaint = new Paint(); private Paint _keyDownBgPaint = new Paint();
private static Paint _keyLabelPaint; private Paint _keyLabelPaint;
private static Paint _keyLabelLockedPaint; private Paint _keySubLabelPaint;
private static Paint _keySubLabelPaint; private Paint _specialKeyLabelPaint;
private static Paint _keySubLabelRightPaint; private Paint _specialKeySubLabelPaint;
private static Paint _specialKeyLabelPaint; private int _lockedColor;
private static Paint _specialKeyLabelLockedPaint; private int _activatedColor;
private static Paint _specialKeySubLabelPaint; private int _labelColor;
private static Paint _specialKeySubLabelRightPaint; private int _subLabelColor;
private float _labelTextSize;
private float _sublabelTextSize;
private static RectF _tmpRect = new RectF(); private static RectF _tmpRect = new RectF();
@@ -54,32 +57,38 @@ public class Keyboard2View extends View
super(context, attrs); super(context, attrs);
_vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); _vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
_handler = new Handler(this); _handler = new Handler(this);
_config = ((Keyboard2)context).getConfig(); refreshConfig(((Keyboard2)context).getConfig(), null);
_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);
setOnTouchListener(this); 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 paint = new Paint(Paint.ANTI_ALIAS_FLAG);
{ paint.setTextAlign(align);
paint = new Paint(Paint.ANTI_ALIAS_FLAG); if (font != null)
paint.setTextAlign(align); paint.setTypeface(font);
paint.setColor(getResources().getColor(color));
paint.setTextSize(getResources().getDimension(size));
if (font != null)
paint.setTypeface(font);
}
return (paint); return (paint);
} }
@@ -150,6 +159,16 @@ public class Keyboard2View extends View
return (null); 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) private void onTouchMove(float moveX, float moveY, int pointerId)
{ {
KeyDown key = getKeyDown(pointerId); KeyDown key = getKeyDown(pointerId);
@@ -189,36 +208,22 @@ public class Keyboard2View extends View
private void onTouchDown(float touchX, float touchY, int pointerId) private void onTouchDown(float touchX, float touchY, int pointerId)
{ {
float y = _config.marginTop - _config.keyHeight; float y = _config.marginTop - _config.keyHeight;
for (KeyboardData.Row row : _keyboard.getRows()) for (KeyboardData.Row row : _keyboard.rows)
{ {
y += _config.keyHeight; y += _config.keyHeight;
if (touchY < y || touchY >= (y + _config.keyHeight)) if (touchY < y || touchY >= (y + _config.keyHeight))
continue ; continue ;
float x = _config.horizontalMargin; float x = _config.horizontalMargin;
for (KeyboardData.Key key : row.getKeys()) for (KeyboardData.Key key : row.keys)
{ {
x += key.shift * _keyWidth; x += key.shift * _keyWidth;
float keyW = _keyWidth * key.width; float keyW = _keyWidth * key.width;
if (touchX >= x && touchX < (x + keyW)) if (touchX >= x && touchX < (x + keyW))
{ {
KeyDown down = getKeyDown(key); int what = _currentWhat++;
if (down != null) if (key.key0 != null && (key.key0.flags & KeyValue.FLAG_NOREPEAT) == 0)
{ _handler.sendEmptyMessageDelayed(what, _config.longPressTimeout);
if ((down.flags & KeyValue.FLAG_LOCK) != 0) _downKeys.add(new KeyDown(pointerId, key, touchX, touchY, what));
{
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));
}
handleKeyDown(key.key0); handleKeyDown(key.key0);
updateFlags(); updateFlags();
invalidate(); 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) private void onTouchUp(int pointerId)
{ {
KeyDown k = getKeyDown(pointerId); KeyDown k = getKeyDown(pointerId);
if (k != null) if (k != null)
{ {
if (k.timeoutWhat != -1) // Stop key repeat
{ if (k.timeoutWhat != -1)
_handler.removeMessages(k.timeoutWhat); {
k.timeoutWhat = -1; _handler.removeMessages(k.timeoutWhat);
} k.timeoutWhat = -1;
if ((k.flags & KeyValue.FLAG_KEEP_ON) != 0) }
{ KeyDown k_on = getActivatedKey(k.value);
k.flags ^= KeyValue.FLAG_KEEP_ON; if (k_on != null)
k.pointerId = -1; {
return ; _downKeys.remove(k); // Remove dupplicate
} // Same key with FLAG_LOCK is already on, do lock
for (int i = 0; i < _downKeys.size(); i++) if ((k_on.flags & KeyValue.FLAG_LOCK) != 0)
{ {
KeyDown downKey = _downKeys.get(i); k_on.flags ^= KeyValue.FLAG_LOCK; // Next time, disable it
if (downKey.pointerId == -1 && (downKey.flags & KeyValue.FLAG_LOCKED) == 0) k_on.flags |= KeyValue.FLAG_LOCKED;
_downKeys.remove(i--); }
else if ((downKey.flags & KeyValue.FLAG_KEEP_ON) != 0) // Otherwise, toggle it
downKey.flags ^= KeyValue.FLAG_KEEP_ON; else
} {
_downKeys.remove(k); _downKeys.remove(k_on);
handleKeyUp(k); }
updateFlags(); }
invalidate(); // Key stay activated
return ; 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 @Override
public void onMeasure(int wSpec, int hSpec) public void onMeasure(int wSpec, int hSpec)
{ {
DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
int height; int height;
height = (int)(_config.keyHeight * _keyboard.keysHeight
if (_keyboard.getRows() == null) + _keyboard.rows.size() * _config.keyVerticalInterval
height = 0; + _config.marginTop + _config.marginBottom);
else setMeasuredDimension(dm.widthPixels, height);
height = (int)(_config.keyHeight * ((float)_keyboard.getRows().size()) _keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.keysWidth;
+ _config.marginTop + _config.marginBottom);
setMeasuredDimension(dm.widthPixels, height);
_keyWidth = (getWidth() - (_config.horizontalMargin * 2)) / _keyboard.getKeysWidth();
} }
@Override @Override
protected void onDraw(Canvas canvas) protected void onDraw(Canvas canvas)
{ {
float y = _config.marginTop; 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; 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; x += k.shift * _keyWidth + _config.keyHorizontalInterval;
float keyW = _keyWidth * k.width; float keyW = _keyWidth * k.width - _config.keyHorizontalInterval;
KeyDown keyDown = getKeyDown(k); KeyDown keyDown = getKeyDown(k);
_tmpRect.set(x + _config.keyBgPadding, y + _config.keyBgPadding, _tmpRect.set(x, y, x + keyW, y + keyH);
x + keyW - _config.keyBgPadding, y + _config.keyHeight - _config.keyBgPadding);
if (keyDown != null) if (keyDown != null)
canvas.drawRect(_tmpRect, _keyDownBgPaint); canvas.drawRect(_tmpRect, _keyDownBgPaint);
else else
canvas.drawRoundRect(_tmpRect, _config.keyRound, _config.keyRound, _keyBgPaint); canvas.drawRoundRect(_tmpRect, _config.keyRound, _config.keyRound, _keyBgPaint);
if (k.key0 != null) if (k.key0 != null)
drawLabel(canvas, k.key0, keyW / 2f + x, (_config.keyHeight + _keyLabelPaint.getTextSize()) / 2f + y, drawLabel(canvas, k.key0, keyW / 2f + x, (keyH + _labelTextSize) / 2f + y, keyDown);
(keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0)); float subPadding = _config.keyPadding;
float subPadding = _config.keyBgPadding + _config.keyPadding;
if (k.key1 != null) 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) 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) 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) 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; x += keyW;
} }
y += _config.keyHeight; y += keyH + _config.keyVerticalInterval;
} }
} }
@@ -380,26 +413,50 @@ public class Keyboard2View extends View
super.onDetachedFromWindow(); 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); k = KeyModifier.handleFlags(k, _flags);
if ((k.flags & KeyValue.FLAG_KEY_FONT) != 0) Paint p = ((k.flags & KeyValue.FLAG_KEY_FONT) != 0) ? _specialKeyLabelPaint : _keyLabelPaint;
canvas.drawText(k.symbol, x, y, locked ? _specialKeyLabelLockedPaint : _specialKeyLabelPaint); p.setColor(labelColor(k, keyDown, _labelColor));
else p.setTextSize(_labelTextSize * scaleTextSize(k));
canvas.drawText(k.symbol, x, y, locked ? _keyLabelLockedPaint : _keyLabelPaint); 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); k = KeyModifier.handleFlags(k, _flags);
if ((k.flags & KeyValue.FLAG_KEY_FONT) != 0) Paint p = ((k.flags & KeyValue.FLAG_KEY_FONT) != 0) ? _specialKeySubLabelPaint : _keySubLabelPaint;
canvas.drawText(k.symbol, x, y, right ? _specialKeySubLabelRightPaint : _specialKeySubLabelPaint); p.setColor(labelColor(k, keyDown, _subLabelColor));
else p.setTextAlign(right ? Paint.Align.RIGHT : Paint.Align.LEFT);
canvas.drawText(k.symbol, x, y, right ? _keySubLabelRightPaint : _keySubLabelPaint); 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 private static class KeyDown
{ {
/* -1 if pointer is up. */
public int pointerId; public int pointerId;
public KeyValue value; public KeyValue value;
public KeyboardData.Key key; public KeyboardData.Key key;

View File

@@ -6,15 +6,24 @@ import java.util.List;
class KeyboardData class KeyboardData
{ {
private final List<Row> _rows; public final List<Row> rows;
private final float _keysWidth; /* 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; float kw = 0.f;
for (Row r : rows) kpr = Math.max(kpr, r.keysWidth()); float kh = 0.f;
_rows = rows; for (Row r : rows_)
_keysWidth = kpr; {
kw = Math.max(kw, r.keysWidth);
kh += r.height + r.shift;
}
rows = rows_;
keysWidth = kw;
keysHeight = kh;
} }
public static KeyboardData parse(XmlResourceParser parser) public static KeyboardData parse(XmlResourceParser parser)
@@ -40,7 +49,6 @@ class KeyboardData
throw new Exception("Unknow keyboard tag: " + tag); throw new Exception("Unknow keyboard tag: " + tag);
} }
} }
return new KeyboardData(rows);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -49,36 +57,40 @@ class KeyboardData
return new KeyboardData(rows); return new KeyboardData(rows);
} }
public List<Row> getRows() { return _rows; }
public float getKeysWidth() { return _keysWidth; }
public KeyboardData removeKeys(MapKeys f) public KeyboardData removeKeys(MapKeys f)
{ {
ArrayList<Row> rows = new ArrayList<Row>(); ArrayList<Row> rows_ = new ArrayList<Row>();
for (Row r : _rows) for (Row r : rows)
rows.add(r.removeKeys(f)); rows_.add(r.removeKeys(f));
return new KeyboardData(rows); return new KeyboardData(rows_);
} }
public static class Row 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. */ /* 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; float kw = 0.f;
for (Key k : keys) kw += k.width + k.shift; for (Key k : keys_) kw += k.width + k.shift;
_keys = keys; keys = keys_;
_keysWidth = kw; height = h;
shift = s;
keysWidth = kw;
} }
public static Row parse(XmlResourceParser parser) throws Exception public static Row parse(XmlResourceParser parser) throws Exception
{ {
ArrayList<Key> keys = new ArrayList<Key>(); ArrayList<Key> keys = new ArrayList<Key>();
int status; int status;
float h = parser.getAttributeFloatValue(null, "height", 1f);
float shift = parser.getAttributeFloatValue(null, "shift", 0f);
while ((status = parser.next()) != XmlResourceParser.END_TAG) while ((status = parser.next()) != XmlResourceParser.END_TAG)
{ {
if (status == XmlResourceParser.START_TAG) if (status == XmlResourceParser.START_TAG)
@@ -90,19 +102,15 @@ class KeyboardData
throw new Exception("Unknow row tag: " + tag); 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) public Row removeKeys(MapKeys f)
{ {
ArrayList<Key> keys = new ArrayList<Key>(); ArrayList<Key> keys_ = new ArrayList<Key>();
for (Key k : _keys) for (Key k : keys)
keys.add(k.removeKeys(f)); keys_.add(k.removeKeys(f));
return new Row(keys); return new Row(keys_, height, shift);
} }
} }