diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 613afb9..53c211e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,38 +1,18 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/res/layout/emoji_pane.xml b/res/layout/emoji_pane.xml index 69cb507..2d249f3 100644 --- a/res/layout/emoji_pane.xml +++ b/res/layout/emoji_pane.xml @@ -1,38 +1,11 @@ - - - - - - - - - + + + + + + + + + diff --git a/res/layout/keyboard.xml b/res/layout/keyboard.xml index 98c390c..43b3e47 100644 --- a/res/layout/keyboard.xml +++ b/res/layout/keyboard.xml @@ -1,5 +1,2 @@ - + diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml index dcc4e54..9c908a4 100644 --- a/res/values-land/dimens.xml +++ b/res/values-land/dimens.xml @@ -1,10 +1,10 @@ - 12dp - 3dp - 3dp - 36dp - 18dp - 11dp - 48dp + 12dp + 3dp + 3dp + 36dp + 18dp + 11dp + 48dp diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 7e8a9bf..77be329 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -5,9 +5,7 @@ azerty qwerty - 1 - @string/pref_accents_e_all_installed @string/pref_accents_e_selected diff --git a/res/values/colors.xml b/res/values/colors.xml index b3b128a..63d981b 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -1,14 +1,14 @@ - #1B1B1B - #303030 - #1B1B1B - #FFFFFF - #229933 - #226b99 - #A0A0A0 - #202020 - #FFFFFF - @color/emoji_button_bg - @color/key_label + #1B1B1B + #303030 + #1B1B1B + #FFFFFF + #229933 + #226b99 + #A0A0A0 + #202020 + #FFFFFF + @color/emoji_button_bg + @color/key_label diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 355c3a1..a8286cb 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -1,15 +1,15 @@ - 3dp - 3dp - 7dp - 2dp - 2dp - 2dp - 51dp - 5dp - 18dp - 12dp - 56dp - 250dp + 3dp + 3dp + 7dp + 2dp + 2dp + 2dp + 51dp + 5dp + 18dp + 12dp + 56dp + 250dp diff --git a/res/values/strings.xml b/res/values/strings.xml index 688667f..ce753cf 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,13 +1,9 @@ - - Unexpected Keyboard - - Unexpected Keyboard Settings - + Unexpected Keyboard + Unexpected Keyboard Settings %s - - Layout + Layout Change keyboard layout %s @@ -15,37 +11,33 @@ Azerty Qwerty - Accents %s Show accents for all the installed languages Show accents for the selected language Show every accents Hide accents - - Typing - Precision - Distance of corner values (%spx) - Long press timeout - %sms - Long press interval - %sms - - Vibration - Vibration - Enable/Disable vibrations on key down - Duration - %sms + Typing + Precision + Distance of corner values (%spx) + Long press timeout + %sms + Long press interval + %sms + Vibration + Vibration + Enable/Disable vibrations on key down + Duration + %sms Precise cursor movements Modulate the speed of movements by swiping more or less - - Style - Margin bottom - %sdp - Key height - %sdp - Horizontal margin - %sdp + Style + Margin bottom + %sdp + Key height + %sdp + Horizontal margin + %sdp Label size Size of characters displayed on the keyboard (%.2fx) diff --git a/res/values/styles.xml b/res/values/styles.xml index 050b926..7dcbb33 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -1,20 +1,20 @@ - - + + diff --git a/res/xml/azerty.xml b/res/xml/azerty.xml index f9ca3ea..ae079f0 100644 --- a/res/xml/azerty.xml +++ b/res/xml/azerty.xml @@ -1,44 +1,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/method.xml b/res/xml/method.xml index 0698beb..30097e2 100644 --- a/res/xml/method.xml +++ b/res/xml/method.xml @@ -1,40 +1,8 @@ - - - - - - + + + + + + diff --git a/res/xml/numeric.xml b/res/xml/numeric.xml index 0d235bd..3e37501 100644 --- a/res/xml/numeric.xml +++ b/res/xml/numeric.xml @@ -1,35 +1,35 @@ - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - - + + + + + - - - - - - + + + + + + diff --git a/res/xml/qwerty.xml b/res/xml/qwerty.xml index bde9f02..297e0e7 100644 --- a/res/xml/qwerty.xml +++ b/res/xml/qwerty.xml @@ -1,44 +1,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/settings.xml b/res/xml/settings.xml index a581896..568b6c1 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -1,102 +1,24 @@ - - - /> - - - - - - - - - - - - - - - - - - + + + /> + + + + + + + + + + + + + + + + + + diff --git a/srcs/juloo.common/IntSlideBarPreference.java b/srcs/juloo.common/IntSlideBarPreference.java index a9df4e6..ad5f206 100644 --- a/srcs/juloo.common/IntSlideBarPreference.java +++ b/srcs/juloo.common/IntSlideBarPreference.java @@ -11,106 +11,106 @@ import android.widget.TextView; import android.widget.SeekBar; /* -** IntSlideBarPreference -** - -** Open a dialog showing a seekbar -** - -** xml attrs: -** android:defaultValue Default value (int) -** min min value (int) -** max max value (int) -** - -** Summary field allow to show the current value using %s flag -*/ + ** IntSlideBarPreference + ** - + ** Open a dialog showing a seekbar + ** - + ** xml attrs: + ** android:defaultValue Default value (int) + ** min min value (int) + ** max max value (int) + ** - + ** Summary field allow to show the current value using %s flag + */ public class IntSlideBarPreference extends DialogPreference - implements SeekBar.OnSeekBarChangeListener + implements SeekBar.OnSeekBarChangeListener { - private LinearLayout _layout; - private TextView _textView; - private SeekBar _seekBar; + private LinearLayout _layout; + private TextView _textView; + private SeekBar _seekBar; - private int _min; + private int _min; - private String _initialSummary; + private String _initialSummary; - public IntSlideBarPreference(Context context, AttributeSet attrs) - { - super(context, attrs); - _initialSummary = getSummary().toString(); - _textView = new TextView(context); - _textView.setPadding(48, 40, 48, 40); - _seekBar = new SeekBar(context); - _seekBar.setOnSeekBarChangeListener(this); - _min = attrs.getAttributeIntValue(null, "min", 0); - int max = attrs.getAttributeIntValue(null, "max", 0); - _seekBar.setMax(max - _min); - _layout = new LinearLayout(getContext()); - _layout.setOrientation(LinearLayout.VERTICAL); - _layout.addView(_textView); - _layout.addView(_seekBar); - } + public IntSlideBarPreference(Context context, AttributeSet attrs) + { + super(context, attrs); + _initialSummary = getSummary().toString(); + _textView = new TextView(context); + _textView.setPadding(48, 40, 48, 40); + _seekBar = new SeekBar(context); + _seekBar.setOnSeekBarChangeListener(this); + _min = attrs.getAttributeIntValue(null, "min", 0); + int max = attrs.getAttributeIntValue(null, "max", 0); + _seekBar.setMax(max - _min); + _layout = new LinearLayout(getContext()); + _layout.setOrientation(LinearLayout.VERTICAL); + _layout.addView(_textView); + _layout.addView(_seekBar); + } - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) - { - updateText(); - } + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) + { + updateText(); + } - @Override - public void onStartTrackingTouch(SeekBar seekBar) - { - } + @Override + public void onStartTrackingTouch(SeekBar seekBar) + { + } - @Override - public void onStopTrackingTouch(SeekBar seekBar) - { - } + @Override + public void onStopTrackingTouch(SeekBar seekBar) + { + } - @Override - protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) - { - int value; + @Override + protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) + { + int value; - if (restorePersistedValue) - { - value = getPersistedInt(_min); - } - else - { - value = (Integer)defaultValue; - persistInt(value); - } - _seekBar.setProgress(value - _min); - updateText(); - } + if (restorePersistedValue) + { + value = getPersistedInt(_min); + } + else + { + value = (Integer)defaultValue; + persistInt(value); + } + _seekBar.setProgress(value - _min); + updateText(); + } - @Override - protected Object onGetDefaultValue(TypedArray a, int index) - { - return (a.getInt(index, _min)); - } + @Override + protected Object onGetDefaultValue(TypedArray a, int index) + { + return (a.getInt(index, _min)); + } - @Override - protected void onDialogClosed(boolean positiveResult) - { - if (positiveResult) - persistInt(_seekBar.getProgress() + _min); - } + @Override + protected void onDialogClosed(boolean positiveResult) + { + if (positiveResult) + persistInt(_seekBar.getProgress() + _min); + } - protected View onCreateDialogView() - { - ViewGroup parent = (ViewGroup)_layout.getParent(); + protected View onCreateDialogView() + { + ViewGroup parent = (ViewGroup)_layout.getParent(); - if (parent != null) - parent.removeView(_layout); - return (_layout); - } + if (parent != null) + parent.removeView(_layout); + return (_layout); + } - private void updateText() - { - String f = String.format(_initialSummary, _seekBar.getProgress() + _min); + private void updateText() + { + String f = String.format(_initialSummary, _seekBar.getProgress() + _min); - _textView.setText(f); - setSummary(f); - } + _textView.setText(f); + setSummary(f); + } } diff --git a/srcs/juloo.common/SlideBarPreference.java b/srcs/juloo.common/SlideBarPreference.java index 650f28b..99759de 100644 --- a/srcs/juloo.common/SlideBarPreference.java +++ b/srcs/juloo.common/SlideBarPreference.java @@ -11,117 +11,117 @@ import android.widget.TextView; import android.widget.SeekBar; /* -** SideBarPreference -** - -** Open a dialog showing a seekbar -** - -** xml attrs: -** android:defaultValue Default value (float) -** min min value (float) -** max max value (float) -** - -** Summary field allow to show the current value using %f or %s flag -*/ + ** SideBarPreference + ** - + ** Open a dialog showing a seekbar + ** - + ** xml attrs: + ** android:defaultValue Default value (float) + ** min min value (float) + ** max max value (float) + ** - + ** Summary field allow to show the current value using %f or %s flag + */ public class SlideBarPreference extends DialogPreference - implements SeekBar.OnSeekBarChangeListener + implements SeekBar.OnSeekBarChangeListener { - private static final int STEPS = 100; + private static final int STEPS = 100; - private LinearLayout _layout; - private TextView _textView; - private SeekBar _seekBar; + private LinearLayout _layout; + private TextView _textView; + private SeekBar _seekBar; - private float _min; - private float _max; - private float _value; + private float _min; + private float _max; + private float _value; - private String _initialSummary; + private String _initialSummary; - public SlideBarPreference(Context context, AttributeSet attrs) - { - super(context, attrs); - _initialSummary = getSummary().toString(); - _textView = new TextView(context); - _textView.setPadding(48, 40, 48, 40); - _seekBar = new SeekBar(context); - _seekBar.setOnSeekBarChangeListener(this); - _seekBar.setMax(STEPS); - _min = float_of_string(attrs.getAttributeValue(null, "min")); - _value = _min; - _max = Math.max(1f, float_of_string(attrs.getAttributeValue(null, "max"))); - _layout = new LinearLayout(getContext()); - _layout.setOrientation(LinearLayout.VERTICAL); - _layout.addView(_textView); - _layout.addView(_seekBar); - } + public SlideBarPreference(Context context, AttributeSet attrs) + { + super(context, attrs); + _initialSummary = getSummary().toString(); + _textView = new TextView(context); + _textView.setPadding(48, 40, 48, 40); + _seekBar = new SeekBar(context); + _seekBar.setOnSeekBarChangeListener(this); + _seekBar.setMax(STEPS); + _min = float_of_string(attrs.getAttributeValue(null, "min")); + _value = _min; + _max = Math.max(1f, float_of_string(attrs.getAttributeValue(null, "max"))); + _layout = new LinearLayout(getContext()); + _layout.setOrientation(LinearLayout.VERTICAL); + _layout.addView(_textView); + _layout.addView(_seekBar); + } - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) - { - _value = Math.round(progress * (_max - _min)) / (float)STEPS + _min; - updateText(); - } + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) + { + _value = Math.round(progress * (_max - _min)) / (float)STEPS + _min; + updateText(); + } - @Override - public void onStartTrackingTouch(SeekBar seekBar) - { - } + @Override + public void onStartTrackingTouch(SeekBar seekBar) + { + } - @Override - public void onStopTrackingTouch(SeekBar seekBar) - { - } + @Override + public void onStopTrackingTouch(SeekBar seekBar) + { + } - @Override - protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) - { - if (restorePersistedValue) - { - _value = getPersistedFloat(_min); - } - else - { - _value = (Float)defaultValue; - persistFloat(_value); - } - _seekBar.setProgress((int)((_value - _min) * STEPS / (_max - _min))); - updateText(); - } + @Override + protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) + { + if (restorePersistedValue) + { + _value = getPersistedFloat(_min); + } + else + { + _value = (Float)defaultValue; + persistFloat(_value); + } + _seekBar.setProgress((int)((_value - _min) * STEPS / (_max - _min))); + updateText(); + } - @Override - protected Object onGetDefaultValue(TypedArray a, int index) - { - return (a.getFloat(index, _min)); - } + @Override + protected Object onGetDefaultValue(TypedArray a, int index) + { + return (a.getFloat(index, _min)); + } - @Override - protected void onDialogClosed(boolean positiveResult) - { - if (positiveResult) - persistFloat(_value); - } + @Override + protected void onDialogClosed(boolean positiveResult) + { + if (positiveResult) + persistFloat(_value); + } - protected View onCreateDialogView() - { - ViewGroup parent = (ViewGroup)_layout.getParent(); + protected View onCreateDialogView() + { + ViewGroup parent = (ViewGroup)_layout.getParent(); - if (parent != null) - parent.removeView(_layout); - return (_layout); - } + if (parent != null) + parent.removeView(_layout); + return (_layout); + } - private void updateText() - { - String f = String.format(_initialSummary, _value); + private void updateText() + { + String f = String.format(_initialSummary, _value); - _textView.setText(f); - setSummary(f); - } + _textView.setText(f); + setSummary(f); + } - private static float float_of_string(String str) - { - if (str == null) - return (0f); - return (Float.parseFloat(str)); - } + private static float float_of_string(String str) + { + if (str == null) + return (0f); + return (Float.parseFloat(str)); + } } diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 8c6a46a..7f1b395 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -7,25 +7,25 @@ import android.util.TypedValue; class Config { - private Keyboard2 _context; + private Keyboard2 _context; // From resources - public final float marginTop; - public final float keyPadding; - public final float keyVerticalInterval; - public final float keyHorizontalInterval; - public final float keyRound; + public final float marginTop; + public final float keyPadding; + 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; - public long longPressTimeout; - public long longPressInterval; - public float marginBottom; - public float keyHeight; - public float horizontalMargin; + public float subValueDist; + public boolean vibrateEnabled; + public long vibrateDuration; + public long longPressTimeout; + public long longPressInterval; + public float marginBottom; + public float keyHeight; + public float horizontalMargin; public boolean preciseRepeat; public float characterSize; // Ratio public int accents; // Values are R.values.pref_accents_v_* @@ -34,67 +34,67 @@ class Config public boolean shouldOfferSwitchingToNextInputMethod; public int accent_flags_to_remove; - public Config(Keyboard2 context) - { - Resources res = context.getResources(); + public Config(Keyboard2 context) + { + Resources res = context.getResources(); - _context = context; - // static values - marginTop = res.getDimension(R.dimen.margin_top); - keyPadding = res.getDimension(R.dimen.key_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 + _context = context; + // static values + marginTop = res.getDimension(R.dimen.margin_top); + keyPadding = res.getDimension(R.dimen.key_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; - longPressTimeout = 600; - longPressInterval = 65; - marginBottom = res.getDimension(R.dimen.margin_bottom); - keyHeight = res.getDimension(R.dimen.key_height); - horizontalMargin = res.getDimension(R.dimen.horizontal_margin); + subValueDist = 10f; + vibrateEnabled = true; + vibrateDuration = 20; + longPressTimeout = 600; + longPressInterval = 65; + marginBottom = res.getDimension(R.dimen.margin_bottom); + keyHeight = res.getDimension(R.dimen.key_height); + horizontalMargin = res.getDimension(R.dimen.horizontal_margin); preciseRepeat = true; characterSize = 1.f; accents = 1; - // from prefs - refresh(); + // from prefs + refresh(); // initialized later shouldOfferSwitchingToNextInputMethod = false; accent_flags_to_remove = 0; - } + } - /* - ** Reload prefs - */ - public void refresh() - { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context); + /* + ** Reload prefs + */ + public void refresh() + { + 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); - longPressTimeout = prefs.getInt("longpress_timeout", (int)longPressTimeout); - longPressInterval = prefs.getInt("longpress_interval", (int)longPressInterval); - marginBottom = getDipPref(prefs, "margin_bottom", marginBottom); - keyHeight = getDipPref(prefs, "key_height", keyHeight); - horizontalMargin = getDipPref(prefs, "horizontal_margin", horizontalMargin); + subValueDist = prefs.getFloat("sub_value_dist", subValueDist); + vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled); + vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration); + longPressTimeout = prefs.getInt("longpress_timeout", (int)longPressTimeout); + longPressInterval = prefs.getInt("longpress_interval", (int)longPressInterval); + marginBottom = getDipPref(prefs, "margin_bottom", marginBottom); + keyHeight = getDipPref(prefs, "key_height", keyHeight); + horizontalMargin = getDipPref(prefs, "horizontal_margin", horizontalMargin); 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) - { - int value = prefs.getInt(pref_name, -1); + private float getDipPref(SharedPreferences prefs, String pref_name, float def) + { + int value = prefs.getInt(pref_name, -1); - if (value < 0) - return (def); - return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, - _context.getResources().getDisplayMetrics())); - } + if (value < 0) + return (def); + return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, + _context.getResources().getDisplayMetrics())); + } public static int layoutId_of_string(String name) { diff --git a/srcs/juloo.keyboard2/Emoji.java b/srcs/juloo.keyboard2/Emoji.java index 8f563cb..e8ee8a1 100644 --- a/srcs/juloo.keyboard2/Emoji.java +++ b/srcs/juloo.keyboard2/Emoji.java @@ -10,35 +10,35 @@ import java.util.HashMap; public class Emoji extends KeyValue { - private final String _desc; + private final String _desc; private static HashMap emojis_by_name = new HashMap(); - protected Emoji(String name, String bytecode, String desc) - { - super(name, bytecode, CHAR_NONE, EVENT_NONE, 0); - _desc = desc; + 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() - { - return (_desc); - } + public String getDescription() + { + return (_desc); + } public static int num_groups = 0; private static Emoji[][] emojis_by_group = new Emoji[][]{}; - public static Emoji getEmojiByName(String name) - { + public static Emoji getEmojiByName(String name) + { return emojis_by_name.get(name); - } + } - public static Emoji[] getEmojisByGroup(int group_id) - { - return (emojis_by_group[group_id]); - } + public static Emoji[] getEmojisByGroup(int group_id) + { + return (emojis_by_group[group_id]); + } /* Read the list of emojis from a raw file. Will initialize only once. */ public static void init(Resources res) diff --git a/srcs/juloo.keyboard2/EmojiGridView.java b/srcs/juloo.keyboard2/EmojiGridView.java index 58a0911..4f7ca05 100644 --- a/srcs/juloo.keyboard2/EmojiGridView.java +++ b/srcs/juloo.keyboard2/EmojiGridView.java @@ -19,158 +19,158 @@ import java.util.Set; import java.util.HashSet; public class EmojiGridView extends GridView - implements GridView.OnItemClickListener + implements GridView.OnItemClickListener { - public static final int GROUP_LAST_USE = -1; + public static final int GROUP_LAST_USE = -1; - public static final int COLUMN_WIDTH = 192; - public static final float EMOJI_SIZE = 32.f; + public static final int COLUMN_WIDTH = 192; + public static final float EMOJI_SIZE = 32.f; - private static final String LAST_USE_PREF = "emoji_last_use"; + private static final String LAST_USE_PREF = "emoji_last_use"; - private Emoji[] _emojiArray; - private HashMap _lastUsed; + private Emoji[] _emojiArray; + private HashMap _lastUsed; - /* - ** TODO: adapt column width and emoji size - ** TODO: use ArraySet instead of Emoji[] - */ - public EmojiGridView(Context context, AttributeSet attrs) - { - super(context, attrs); + /* + ** TODO: adapt column width and emoji size + ** TODO: use ArraySet instead of Emoji[] + */ + public EmojiGridView(Context context, AttributeSet attrs) + { + super(context, attrs); Emoji.init(context.getResources()); - setOnItemClickListener(this); - setColumnWidth(COLUMN_WIDTH); - loadLastUsed(); - setEmojiGroup((_lastUsed.size() == 0) ? 0 : GROUP_LAST_USE); - } + setOnItemClickListener(this); + setColumnWidth(COLUMN_WIDTH); + loadLastUsed(); + setEmojiGroup((_lastUsed.size() == 0) ? 0 : GROUP_LAST_USE); + } - public void setEmojiGroup(int group) - { - _emojiArray = (group == GROUP_LAST_USE) ? getLastEmojis() : Emoji.getEmojisByGroup(group); - setAdapter(new EmojiViewAdpater((Keyboard2)getContext(), _emojiArray)); - } + public void setEmojiGroup(int group) + { + _emojiArray = (group == GROUP_LAST_USE) ? getLastEmojis() : Emoji.getEmojisByGroup(group); + setAdapter(new EmojiViewAdpater((Keyboard2)getContext(), _emojiArray)); + } - public void onItemClick(AdapterView parent, View v, int pos, long id) - { - Keyboard2 main = (Keyboard2)getContext(); - Integer used = _lastUsed.get(_emojiArray[pos]); + public void onItemClick(AdapterView parent, View v, int pos, long id) + { + Keyboard2 main = (Keyboard2)getContext(); + Integer used = _lastUsed.get(_emojiArray[pos]); - _lastUsed.put(_emojiArray[pos], (used == null) ? 1 : used.intValue() + 1); - main.handleKeyUp(_emojiArray[pos], 0); - saveLastUsed(); // TODO: opti - } + _lastUsed.put(_emojiArray[pos], (used == null) ? 1 : used.intValue() + 1); + main.handleKeyUp(_emojiArray[pos], 0); + saveLastUsed(); // TODO: opti + } - @Override - public void onMeasure(int wSpec, int hSpec) - { - super.onMeasure(wSpec, hSpec); - setNumColumns(getMeasuredWidth() / COLUMN_WIDTH); - } + @Override + public void onMeasure(int wSpec, int hSpec) + { + super.onMeasure(wSpec, hSpec); + setNumColumns(getMeasuredWidth() / COLUMN_WIDTH); + } - private Emoji[] getLastEmojis() - { - final HashMap map = _lastUsed; - Emoji[] array = new Emoji[map.size()]; + private Emoji[] getLastEmojis() + { + final HashMap map = _lastUsed; + Emoji[] array = new Emoji[map.size()]; - map.keySet().toArray(array); - Arrays.sort(array, 0, array.length, new Comparator() - { - public int compare(Emoji a, Emoji b) - { - return (map.get(b).intValue() - map.get(a).intValue()); - } - }); - return (array); - } + map.keySet().toArray(array); + Arrays.sort(array, 0, array.length, new Comparator() + { + public int compare(Emoji a, Emoji b) + { + return (map.get(b).intValue() - map.get(a).intValue()); + } + }); + return (array); + } - private void saveLastUsed() - { - SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(getContext()).edit(); - HashSet set = new HashSet(); + private void saveLastUsed() + { + SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(getContext()).edit(); + HashSet set = new HashSet(); - for (Emoji emoji : _lastUsed.keySet()) - set.add(String.valueOf(_lastUsed.get(emoji)) + "-" + emoji.name); - edit.putStringSet(LAST_USE_PREF, set); - edit.apply(); - } + for (Emoji emoji : _lastUsed.keySet()) + set.add(String.valueOf(_lastUsed.get(emoji)) + "-" + emoji.name); + edit.putStringSet(LAST_USE_PREF, set); + edit.apply(); + } - private void loadLastUsed() - { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - Set lastUseSet = prefs.getStringSet(LAST_USE_PREF, null); + private void loadLastUsed() + { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + Set lastUseSet = prefs.getStringSet(LAST_USE_PREF, null); - _lastUsed = new HashMap(); - if (lastUseSet != null) - for (String emojiData : lastUseSet) - { - String[] data = emojiData.split("-", 2); - Emoji emoji; + _lastUsed = new HashMap(); + if (lastUseSet != null) + for (String emojiData : lastUseSet) + { + String[] data = emojiData.split("-", 2); + Emoji emoji; - if (data.length != 2) - continue ; - emoji = Emoji.getEmojiByName(data[1]); - if (emoji == null) - continue ; - _lastUsed.put(emoji, Integer.valueOf(data[0])); - } - } + if (data.length != 2) + continue ; + emoji = Emoji.getEmojiByName(data[1]); + if (emoji == null) + continue ; + _lastUsed.put(emoji, Integer.valueOf(data[0])); + } + } - private static class EmojiView extends TextView - { - public EmojiView(Keyboard2 context) - { - super(context); - setTextSize(EMOJI_SIZE); - setGravity(Gravity.CENTER); - setBackgroundColor(0x0); - setTextColor(getResources().getColor(R.color.emoji_color)); - setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT, GridView.LayoutParams.WRAP_CONTENT)); - } + private static class EmojiView extends TextView + { + public EmojiView(Keyboard2 context) + { + super(context); + setTextSize(EMOJI_SIZE); + setGravity(Gravity.CENTER); + setBackgroundColor(0x0); + setTextColor(getResources().getColor(R.color.emoji_color)); + setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT, GridView.LayoutParams.WRAP_CONTENT)); + } - public void setEmoji(Emoji emoji) - { - setText(emoji.symbol); - } - } + public void setEmoji(Emoji emoji) + { + setText(emoji.symbol); + } + } - private static class EmojiViewAdpater extends BaseAdapter - { - private Keyboard2 _main; + private static class EmojiViewAdpater extends BaseAdapter + { + private Keyboard2 _main; - private Emoji[] _emojiArray; + private Emoji[] _emojiArray; - public EmojiViewAdpater(Keyboard2 main, Emoji[] emojiArray) - { - _main = main; - _emojiArray = emojiArray; - } + public EmojiViewAdpater(Keyboard2 main, Emoji[] emojiArray) + { + _main = main; + _emojiArray = emojiArray; + } - public int getCount() - { - if (_emojiArray == null) - return (0); - return (_emojiArray.length); - } + public int getCount() + { + if (_emojiArray == null) + return (0); + return (_emojiArray.length); + } - public Object getItem(int pos) - { - return (_emojiArray[pos]); - } + public Object getItem(int pos) + { + return (_emojiArray[pos]); + } - public long getItemId(int pos) - { - return (pos); - } + public long getItemId(int pos) + { + return (pos); + } - public View getView(int pos, View convertView, ViewGroup parent) - { - EmojiView view = (EmojiView)convertView; + public View getView(int pos, View convertView, ViewGroup parent) + { + EmojiView view = (EmojiView)convertView; - if (view == null) - view = new EmojiView(_main); - view.setEmoji(_emojiArray[pos]); - return (view); - } - } + if (view == null) + view = new EmojiView(_main); + view.setEmoji(_emojiArray[pos]); + return (view); + } + } } diff --git a/srcs/juloo.keyboard2/EmojiKeyButton.java b/srcs/juloo.keyboard2/EmojiKeyButton.java index de9f206..3f86b1b 100644 --- a/srcs/juloo.keyboard2/EmojiKeyButton.java +++ b/srcs/juloo.keyboard2/EmojiKeyButton.java @@ -6,24 +6,24 @@ import android.view.View; import android.widget.Button; public class EmojiKeyButton extends Button - implements View.OnClickListener + implements View.OnClickListener { - KeyValue _key; + KeyValue _key; - public EmojiKeyButton(Context context, AttributeSet attrs) - { - super(context, attrs); - setOnClickListener(this); - _key = KeyValue.getKeyByName(attrs.getAttributeValue(null, "key")); - setText(_key.symbol); - if ((_key.flags & KeyValue.FLAG_KEY_FONT) != 0) - setTypeface(((Keyboard2)context).getSpecialKeyFont()); - } + public EmojiKeyButton(Context context, AttributeSet attrs) + { + super(context, attrs); + setOnClickListener(this); + _key = KeyValue.getKeyByName(attrs.getAttributeValue(null, "key")); + setText(_key.symbol); + if ((_key.flags & KeyValue.FLAG_KEY_FONT) != 0) + setTypeface(((Keyboard2)context).getSpecialKeyFont()); + } - public void onClick(View v) - { - Keyboard2 main = (Keyboard2)getContext(); + public void onClick(View v) + { + Keyboard2 main = (Keyboard2)getContext(); - main.handleKeyUp(_key, 0); - } + main.handleKeyUp(_key, 0); + } } diff --git a/srcs/juloo.keyboard2/EmojiTypeButton.java b/srcs/juloo.keyboard2/EmojiTypeButton.java index a36af8e..cd12325 100644 --- a/srcs/juloo.keyboard2/EmojiTypeButton.java +++ b/srcs/juloo.keyboard2/EmojiTypeButton.java @@ -10,28 +10,28 @@ import android.widget.Button; /* Emoji "types" are groups. This class is misnamed. */ public class EmojiTypeButton extends Button - implements View.OnTouchListener + implements View.OnTouchListener { - private int _emojiType; + private int _emojiType; static private final int DEFAULT_GROUP = 0; - public EmojiTypeButton(Context context, int group_id, String symbol) - { - super(new ContextThemeWrapper(context, R.style.emojiTypeButton), null, 0); + public EmojiTypeButton(Context context, int group_id, String symbol) + { + super(new ContextThemeWrapper(context, R.style.emojiTypeButton), null, 0); _emojiType = group_id; - setText(symbol); - setOnTouchListener(this); - } + setText(symbol); + setOnTouchListener(this); + } - public boolean onTouch(View view, MotionEvent event) - { - EmojiGridView emojiGrid; + public boolean onTouch(View view, MotionEvent event) + { + EmojiGridView emojiGrid; - if (event.getAction() != MotionEvent.ACTION_DOWN) - return (false); - emojiGrid = (EmojiGridView)((ViewGroup)(getParent().getParent())).findViewById(R.id.emoji_grid); - emojiGrid.setEmojiGroup(_emojiType); - return (true); - } + if (event.getAction() != MotionEvent.ACTION_DOWN) + return (false); + emojiGrid = (EmojiGridView)((ViewGroup)(getParent().getParent())).findViewById(R.id.emoji_grid); + emojiGrid.setEmojiGroup(_emojiType); + return (true); + } } diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index 6677248..80cb744 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -6,14 +6,14 @@ import java.util.HashMap; class KeyValue { - public static final int EVENT_NONE = -1; - public static final int EVENT_CONFIG = -2; - public static final int EVENT_SWITCH_TEXT = -3; - public static final int EVENT_SWITCH_NUMERIC = -4; - public static final int EVENT_SWITCH_EMOJI = -5; - public static final int EVENT_SWITCH_BACK_EMOJI = -6; - public static final int EVENT_CHANGE_METHOD = -7; - public static final char CHAR_NONE = '\0'; + public static final int EVENT_NONE = -1; + public static final int EVENT_CONFIG = -2; + public static final int EVENT_SWITCH_TEXT = -3; + public static final int EVENT_SWITCH_NUMERIC = -4; + public static final int EVENT_SWITCH_EMOJI = -5; + public static final int EVENT_SWITCH_BACK_EMOJI = -6; + public static final int EVENT_CHANGE_METHOD = -7; + public static final char CHAR_NONE = '\0'; // Behavior flags public static final int FLAG_KEEP_ON = 1; @@ -75,7 +75,7 @@ class KeyValue flags = f; } - public static KeyValue getKeyByName(String name) + public static KeyValue getKeyByName(String name) { if (name == null) return null; @@ -222,7 +222,7 @@ class KeyValue addEventKey("f9", "F9", KeyEvent.KEYCODE_F9); addEventKey("f10", "F10", KeyEvent.KEYCODE_F10); - addKey("tab", "↹", '\t', KeyEvent.KEYCODE_TAB, 0); - addKey("space", " ", ' ', KeyEvent.KEYCODE_SPACE, 0); + addKey("tab", "↹", '\t', KeyEvent.KEYCODE_TAB, 0); + addKey("space", " ", ' ', KeyEvent.KEYCODE_SPACE, 0); } } diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 58e71a3..b1bafbd 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -25,14 +25,14 @@ import java.util.Locale; import java.util.Map; public class Keyboard2 extends InputMethodService - implements SharedPreferences.OnSharedPreferenceChangeListener + implements SharedPreferences.OnSharedPreferenceChangeListener { - private Keyboard2View _keyboardView; + private Keyboard2View _keyboardView; private int _currentTextLayout; - private ViewGroup _emojiPane = null; - private Typeface _specialKeyFont = null; + private ViewGroup _emojiPane = null; + private Typeface _specialKeyFont = null; - private Config _config; + private Config _config; private Map _layoutCache = new HashMap(); @@ -47,27 +47,27 @@ public class Keyboard2 extends InputMethodService return l; } - @Override - public void onCreate() - { - super.onCreate(); - _specialKeyFont = Typeface.createFromAsset(getAssets(), "fonts/keys.ttf"); - PreferenceManager.setDefaultValues(this, R.xml.settings, false); - PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); - _config = new Config(this); - _keyboardView = (Keyboard2View)getLayoutInflater().inflate(R.layout.keyboard, null); - _keyboardView.reset(); - } + @Override + public void onCreate() + { + super.onCreate(); + _specialKeyFont = Typeface.createFromAsset(getAssets(), "fonts/keys.ttf"); + PreferenceManager.setDefaultValues(this, R.xml.settings, false); + PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); + _config = new Config(this); + _keyboardView = (Keyboard2View)getLayoutInflater().inflate(R.layout.keyboard, null); + _keyboardView.reset(); + } - public Config getConfig() - { - return (_config); - } + public Config getConfig() + { + return (_config); + } - public Typeface getSpecialKeyFont() - { - return (_specialKeyFont); - } + public Typeface getSpecialKeyFont() + { + return (_specialKeyFont); + } private List getEnabledSubtypes(InputMethodManager imm) { @@ -148,26 +148,26 @@ public class Keyboard2 extends InputMethodService } } - @Override - public View onCreateInputView() - { - ViewGroup parent = (ViewGroup)_keyboardView.getParent(); + @Override + public View onCreateInputView() + { + ViewGroup parent = (ViewGroup)_keyboardView.getParent(); - if (parent != null) - parent.removeView(_keyboardView); - return (_keyboardView); - } + if (parent != null) + parent.removeView(_keyboardView); + return (_keyboardView); + } - @Override - public void onStartInputView(EditorInfo info, boolean restarting) - { + @Override + public void onStartInputView(EditorInfo info, boolean restarting) + { refreshSubtypeImm(); - if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0) + 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) @@ -183,92 +183,92 @@ public class Keyboard2 extends InputMethodService _keyboardView.reset(); } - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) - { - _config.refresh(); + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) + { + _config.refresh(); refreshSubtypeImm(); - _keyboardView.refreshConfig(_config, getLayout(_currentTextLayout)); - } + _keyboardView.refreshConfig(_config, getLayout(_currentTextLayout)); + } - @Override - public void onConfigurationChanged(Configuration newConfig) - { - _keyboardView.reset(); - } + @Override + public void onConfigurationChanged(Configuration newConfig) + { + _keyboardView.reset(); + } - public void handleKeyUp(KeyValue key, int flags) - { - if (getCurrentInputConnection() == null) - return ; + public void handleKeyUp(KeyValue key, int flags) + { + if (getCurrentInputConnection() == null) + return ; key = KeyModifier.handleFlags(key, flags); - if (key.eventCode == KeyValue.EVENT_CONFIG) - { - Intent intent = new Intent(this, SettingsActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); - } - else if (key.eventCode == KeyValue.EVENT_SWITCH_TEXT) - _keyboardView.setKeyboard(getLayout(_currentTextLayout)); - else if (key.eventCode == KeyValue.EVENT_SWITCH_NUMERIC) - _keyboardView.setKeyboard(getLayout(R.xml.numeric)); - else if (key.eventCode == KeyValue.EVENT_SWITCH_EMOJI) - { - if (_emojiPane == null) - _emojiPane = (ViewGroup)getLayoutInflater().inflate(R.layout.emoji_pane, null); - setInputView(_emojiPane); - } - else if (key.eventCode == KeyValue.EVENT_SWITCH_BACK_EMOJI) - setInputView(_keyboardView); - else if (key.eventCode == KeyValue.EVENT_CHANGE_METHOD) - { - InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); - imm.switchToNextInputMethod(getConnectionToken(), false); - } - else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0) - handleMetaKeyUp(key, flags); - // else if (eventCode == KeyEvent.KEYCODE_DEL) - // handleDelKey(1, 0); - // else if (eventCode == KeyEvent.KEYCODE_FORWARD_DEL) - // handleDelKey(0, 1); - else if (key.char_ == KeyValue.CHAR_NONE) - { - if (key.eventCode != KeyValue.EVENT_NONE) - handleMetaKeyUp(key, flags); - else - getCurrentInputConnection().commitText(key.symbol, 1); - } - else - sendKeyChar(key.char_); - } + if (key.eventCode == KeyValue.EVENT_CONFIG) + { + Intent intent = new Intent(this, SettingsActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + else if (key.eventCode == KeyValue.EVENT_SWITCH_TEXT) + _keyboardView.setKeyboard(getLayout(_currentTextLayout)); + else if (key.eventCode == KeyValue.EVENT_SWITCH_NUMERIC) + _keyboardView.setKeyboard(getLayout(R.xml.numeric)); + else if (key.eventCode == KeyValue.EVENT_SWITCH_EMOJI) + { + if (_emojiPane == null) + _emojiPane = (ViewGroup)getLayoutInflater().inflate(R.layout.emoji_pane, null); + setInputView(_emojiPane); + } + else if (key.eventCode == KeyValue.EVENT_SWITCH_BACK_EMOJI) + setInputView(_keyboardView); + else if (key.eventCode == KeyValue.EVENT_CHANGE_METHOD) + { + InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); + imm.switchToNextInputMethod(getConnectionToken(), false); + } + else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0) + handleMetaKeyUp(key, flags); + // else if (eventCode == KeyEvent.KEYCODE_DEL) + // handleDelKey(1, 0); + // else if (eventCode == KeyEvent.KEYCODE_FORWARD_DEL) + // handleDelKey(0, 1); + else if (key.char_ == KeyValue.CHAR_NONE) + { + if (key.eventCode != KeyValue.EVENT_NONE) + handleMetaKeyUp(key, flags); + else + getCurrentInputConnection().commitText(key.symbol, 1); + } + else + sendKeyChar(key.char_); + } - // private void handleDelKey(int before, int after) - // { - // CharSequence selection = getCurrentInputConnection().getSelectedText(0); + // private void handleDelKey(int before, int after) + // { + // CharSequence selection = getCurrentInputConnection().getSelectedText(0); - // if (selection != null && selection.length() > 0) - // getCurrentInputConnection().commitText("", 1); - // else - // getCurrentInputConnection().deleteSurroundingText(before, after); - // } + // if (selection != null && selection.length() > 0) + // getCurrentInputConnection().commitText("", 1); + // else + // getCurrentInputConnection().deleteSurroundingText(before, after); + // } - private void handleMetaKeyUp(KeyValue key, int flags) - { - int metaState = 0; - KeyEvent event; + private void handleMetaKeyUp(KeyValue key, int flags) + { + int metaState = 0; + KeyEvent event; - if (key.eventCode == KeyValue.EVENT_NONE) - return ; - if ((flags & KeyValue.FLAG_CTRL) != 0) - metaState |= KeyEvent.META_CTRL_LEFT_ON | KeyEvent.META_CTRL_ON; - if ((flags & KeyValue.FLAG_ALT) != 0) - metaState |= KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_ON; - if ((flags & KeyValue.FLAG_SHIFT) != 0) - metaState |= KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON; - event = new KeyEvent(1, 1, KeyEvent.ACTION_DOWN, key.eventCode, 0, metaState); - getCurrentInputConnection().sendKeyEvent(event); - getCurrentInputConnection().sendKeyEvent(KeyEvent.changeAction(event, KeyEvent.ACTION_UP)); - } + if (key.eventCode == KeyValue.EVENT_NONE) + return ; + if ((flags & KeyValue.FLAG_CTRL) != 0) + metaState |= KeyEvent.META_CTRL_LEFT_ON | KeyEvent.META_CTRL_ON; + if ((flags & KeyValue.FLAG_ALT) != 0) + metaState |= KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_ON; + if ((flags & KeyValue.FLAG_SHIFT) != 0) + metaState |= KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON; + event = new KeyEvent(1, 1, KeyEvent.ACTION_DOWN, key.eventCode, 0, metaState); + getCurrentInputConnection().sendKeyEvent(event); + getCurrentInputConnection().sendKeyEvent(KeyEvent.changeAction(event, KeyEvent.ACTION_UP)); + } private IBinder getConnectionToken() { diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 5cbdfd0..c4f8462 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -17,32 +17,32 @@ import android.widget.PopupWindow; import java.util.ArrayList; public class Keyboard2View extends View - implements View.OnTouchListener, Handler.Callback + implements View.OnTouchListener, Handler.Callback { - private static final long VIBRATE_MIN_INTERVAL = 100; + private static final long VIBRATE_MIN_INTERVAL = 100; - private KeyboardData _keyboard; + private KeyboardData _keyboard; - private ArrayList _downKeys = new ArrayList(); + private ArrayList _downKeys = new ArrayList(); - private int _flags = 0; + private int _flags = 0; - private Vibrator _vibratorService; - private long _lastVibration = 0; + private Vibrator _vibratorService; + private long _lastVibration = 0; - private Handler _handler; - private static int _currentWhat = 0; + private Handler _handler; + private static int _currentWhat = 0; - private Config _config; + private Config _config; - private float _keyWidth; + private float _keyWidth; - private Paint _keyBgPaint = new Paint(); - private Paint _keyDownBgPaint = new Paint(); - private Paint _keyLabelPaint; - private Paint _keySubLabelPaint; - private Paint _specialKeyLabelPaint; - private Paint _specialKeySubLabelPaint; + 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; @@ -50,49 +50,49 @@ public class Keyboard2View extends View private float _labelTextSize; private float _sublabelTextSize; - private static RectF _tmpRect = new RectF(); + private static RectF _tmpRect = new RectF(); - public Keyboard2View(Context context, AttributeSet attrs) - { - super(context, attrs); - _vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); - _handler = new Handler(this); + public Keyboard2View(Context context, AttributeSet attrs) + { + super(context, attrs); + _vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); + _handler = new Handler(this); refreshConfig(((Keyboard2)context).getConfig(), null); - setOnTouchListener(this); - } + setOnTouchListener(this); + } /* Internally calls [reset()]. */ public void refreshConfig(Config config, KeyboardData kw) { Resources res = getResources(); - _config = config; + _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); + _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) - { + private Paint initLabelPaint(Paint.Align align, Typeface font) + { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(align); if (font != null) paint.setTypeface(font); - return (paint); - } + 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)); @@ -102,155 +102,155 @@ public class Keyboard2View extends View reset(); } - public void reset() - { - _flags = 0; - _downKeys.clear(); - requestLayout(); - invalidate(); - } + public void reset() + { + _flags = 0; + _downKeys.clear(); + requestLayout(); + invalidate(); + } - @Override - public boolean onTouch(View v, MotionEvent event) - { - float x; - float y; - float keyW; - int p; + @Override + public boolean onTouch(View v, MotionEvent event) + { + float x; + float y; + float keyW; + int p; - switch (event.getActionMasked()) - { - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_POINTER_UP: - onTouchUp(event.getPointerId(event.getActionIndex())); - break ; - case MotionEvent.ACTION_DOWN: - case MotionEvent.ACTION_POINTER_DOWN: - p = event.getActionIndex(); - onTouchDown(event.getX(p), event.getY(p), event.getPointerId(p)); - break ; - case MotionEvent.ACTION_MOVE: - for (p = 0; p < event.getPointerCount(); p++) - onTouchMove(event.getX(p), event.getY(p), event.getPointerId(p)); - break ; - default: - return (false); - } - return (true); - } + switch (event.getActionMasked()) + { + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_POINTER_UP: + onTouchUp(event.getPointerId(event.getActionIndex())); + break ; + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: + p = event.getActionIndex(); + onTouchDown(event.getX(p), event.getY(p), event.getPointerId(p)); + break ; + case MotionEvent.ACTION_MOVE: + for (p = 0; p < event.getPointerCount(); p++) + onTouchMove(event.getX(p), event.getY(p), event.getPointerId(p)); + break ; + default: + return (false); + } + return (true); + } - private KeyDown getKeyDown(int pointerId) - { - for (KeyDown k : _downKeys) - { - if (k.pointerId == pointerId) - return (k); - } - return (null); - } + private KeyDown getKeyDown(int pointerId) + { + for (KeyDown k : _downKeys) + { + if (k.pointerId == pointerId) + return (k); + } + return (null); + } - private KeyDown getKeyDown(KeyboardData.Key key) - { - for (KeyDown k : _downKeys) - { - if (k.key == key) - return (k); - } - return (null); - } + private KeyDown getKeyDown(KeyboardData.Key key) + { + for (KeyDown k : _downKeys) + { + if (k.key == key) + return (k); + } + return (null); + } - private KeyDown getKeyDown(KeyValue kv) - { - for (KeyDown k : _downKeys) - { - if (k.value == kv) - return (k); - } - 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); - KeyValue newValue; + private void onTouchMove(float moveX, float moveY, int pointerId) + { + KeyDown key = getKeyDown(pointerId); + KeyValue newValue; - if (key != null) - { - moveX -= key.downX; - moveY -= key.downY; + if (key != null) + { + moveX -= key.downX; + moveY -= key.downY; float absDist = Math.abs(moveX) + Math.abs(moveY); key.ptrDist = absDist; - if (absDist < _config.subValueDist) - newValue = key.key.key0; - else if (moveX < 0) - newValue = (moveY < 0) ? key.key.key1 : key.key.key3; - else if (moveY < 0) - newValue = key.key.key2; - else - newValue = key.key.key4; - if (newValue != null && newValue != key.value) - { - if (key.timeoutWhat != -1) - { - _handler.removeMessages(key.timeoutWhat); - if ((newValue.flags & KeyValue.FLAG_NOREPEAT) == 0) - _handler.sendEmptyMessageDelayed(key.timeoutWhat, _config.longPressTimeout); - } - key.value = newValue; - key.flags = newValue.flags; - updateFlags(); - invalidate(); - handleKeyDown(newValue); - } - } - } + if (absDist < _config.subValueDist) + newValue = key.key.key0; + else if (moveX < 0) + newValue = (moveY < 0) ? key.key.key1 : key.key.key3; + else if (moveY < 0) + newValue = key.key.key2; + else + newValue = key.key.key4; + if (newValue != null && newValue != key.value) + { + if (key.timeoutWhat != -1) + { + _handler.removeMessages(key.timeoutWhat); + if ((newValue.flags & KeyValue.FLAG_NOREPEAT) == 0) + _handler.sendEmptyMessageDelayed(key.timeoutWhat, _config.longPressTimeout); + } + key.value = newValue; + key.flags = newValue.flags; + updateFlags(); + invalidate(); + handleKeyDown(newValue); + } + } + } - private void onTouchDown(float touchX, float touchY, int pointerId) - { - float y = _config.marginTop - _config.keyHeight; - for (KeyboardData.Row row : _keyboard.rows) - { - y += _config.keyHeight; - if (touchY < y || touchY >= (y + _config.keyHeight)) - continue ; + private void onTouchDown(float touchX, float touchY, int pointerId) + { + float y = _config.marginTop - _config.keyHeight; + 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.keys) - { + for (KeyboardData.Key key : row.keys) + { x += key.shift * _keyWidth; - float keyW = _keyWidth * key.width; - if (touchX >= x && touchX < (x + keyW)) - { + float keyW = _keyWidth * key.width; + if (touchX >= x && touchX < (x + keyW)) + { 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(); - return ; - } - x += keyW; - } - } - } + handleKeyDown(key.key0); + updateFlags(); + invalidate(); + return ; + } + x += keyW; + } + } + } // 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); + for (KeyDown k : _downKeys) + { + if (k.value == kv && k.pointerId == -1) + return (k); + } + return (null); } - private void onTouchUp(int pointerId) - { - KeyDown k = getKeyDown(pointerId); + private void onTouchUp(int pointerId) + { + KeyDown k = getKeyDown(pointerId); - if (k != null) - { + if (k != null) + { // Stop key repeat if (k.timeoutWhat != -1) { @@ -295,55 +295,55 @@ public class Keyboard2View extends View } updateFlags(); invalidate(); - } - } + } + } - private void handleKeyUp(KeyDown key) - { - if (key.value != null && (key.flags & (KeyValue.FLAG_LOCKED | KeyValue.FLAG_NOCHAR)) == 0) - ((Keyboard2)getContext()).handleKeyUp(key.value, _flags); - } + private void handleKeyUp(KeyDown key) + { + if (key.value != null && (key.flags & (KeyValue.FLAG_LOCKED | KeyValue.FLAG_NOCHAR)) == 0) + ((Keyboard2)getContext()).handleKeyUp(key.value, _flags); + } - private void handleKeyDown(KeyValue key) - { - if (key == null) - return ; - vibrate(); - } + private void handleKeyDown(KeyValue key) + { + if (key == null) + return ; + vibrate(); + } - private void updateFlags() - { - _flags = 0; - for (KeyDown k : _downKeys) - _flags |= k.flags; - } + private void updateFlags() + { + _flags = 0; + for (KeyDown k : _downKeys) + _flags |= k.flags; + } - private void vibrate() - { - if (!_config.vibrateEnabled) - return ; - long now = System.currentTimeMillis(); - if ((now - _lastVibration) > VIBRATE_MIN_INTERVAL) - { - _lastVibration = now; - try - { - _vibratorService.vibrate(_config.vibrateDuration); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - } + private void vibrate() + { + if (!_config.vibrateEnabled) + return ; + long now = System.currentTimeMillis(); + if ((now - _lastVibration) > VIBRATE_MIN_INTERVAL) + { + _lastVibration = now; + try + { + _vibratorService.vibrate(_config.vibrateDuration); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } - @Override - public boolean handleMessage(Message msg) - { - for (KeyDown key : _downKeys) - { - if (key.timeoutWhat == msg.what) - { + @Override + public boolean handleMessage(Message msg) + { + for (KeyDown key : _downKeys) + { + if (key.timeoutWhat == msg.what) + { long nextInterval = _config.longPressInterval; if (_config.preciseRepeat && (key.flags & KeyValue.FLAG_PRECISE_REPEAT) != 0) { @@ -351,17 +351,17 @@ public class Keyboard2View extends View float accel = Math.min(4.f, Math.max(0.3f, key.ptrDist / (_config.subValueDist * 15.f))); nextInterval = (long)((float)nextInterval / accel); } - _handler.sendEmptyMessageDelayed(msg.what, nextInterval); - ((Keyboard2)getContext()).handleKeyUp(key.value, _flags); - return (true); - } - } - return (false); - } + _handler.sendEmptyMessageDelayed(msg.what, nextInterval); + ((Keyboard2)getContext()).handleKeyUp(key.value, _flags); + return (true); + } + } + return (false); + } - @Override - public void onMeasure(int wSpec, int hSpec) - { + @Override + public void onMeasure(int wSpec, int hSpec) + { DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); int width = dm.widthPixels; int height = @@ -370,49 +370,49 @@ public class Keyboard2View extends View + _config.marginTop + _config.marginBottom); setMeasuredDimension(width, height); _keyWidth = (width - (_config.horizontalMargin * 2)) / _keyboard.keysWidth; - } + } - @Override - protected void onDraw(Canvas canvas) - { - float y = _config.marginTop; - for (KeyboardData.Row row : _keyboard.rows) - { + @Override + protected void onDraw(Canvas canvas) + { + float y = _config.marginTop; + for (KeyboardData.Row row : _keyboard.rows) + { y += row.shift * _config.keyHeight; float x = _config.horizontalMargin; float keyH = row.height * _config.keyHeight; - for (KeyboardData.Key k : row.keys) - { + for (KeyboardData.Key k : row.keys) + { x += k.shift * _keyWidth + _config.keyHorizontalInterval; - float keyW = _keyWidth * k.width - _config.keyHorizontalInterval; - KeyDown keyDown = getKeyDown(k); - _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, (keyH + _labelTextSize) / 2f + y, keyDown); - float subPadding = _config.keyPadding; - if (k.key1 != null) - drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding, false, true, keyDown); - if (k.key3 != null) - 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, true, true, keyDown); - if (k.key4 != null) - drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + keyH - subPadding, true, false, keyDown); - x += keyW; - } - y += keyH + _config.keyVerticalInterval; - } - } + float keyW = _keyWidth * k.width - _config.keyHorizontalInterval; + KeyDown keyDown = getKeyDown(k); + _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, (keyH + _labelTextSize) / 2f + y, keyDown); + float subPadding = _config.keyPadding; + if (k.key1 != null) + drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding, false, true, keyDown); + if (k.key3 != null) + 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, true, true, keyDown); + if (k.key4 != null) + drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + keyH - subPadding, true, false, keyDown); + x += keyW; + } + y += keyH + _config.keyVerticalInterval; + } + } - @Override - public void onDetachedFromWindow() - { - super.onDetachedFromWindow(); - } + @Override + public void onDetachedFromWindow() + { + super.onDetachedFromWindow(); + } private int labelColor(KeyValue k, KeyDown hasKeyDown, int defaultColor) { @@ -430,17 +430,17 @@ public class Keyboard2View extends View return defaultColor; } - private void drawLabel(Canvas canvas, KeyValue k, float x, float y, KeyDown keyDown) - { + private void drawLabel(Canvas canvas, KeyValue k, float x, float y, KeyDown keyDown) + { k = KeyModifier.handleFlags(k, _flags); 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, boolean up, KeyDown keyDown) - { + private void drawSubLabel(Canvas canvas, KeyValue k, float x, float y, boolean right, boolean up, KeyDown keyDown) + { k = KeyModifier.handleFlags(k, _flags); Paint p = ((k.flags & KeyValue.FLAG_KEY_FONT) != 0) ? _specialKeySubLabelPaint : _keySubLabelPaint; p.setColor(labelColor(k, keyDown, _subLabelColor)); @@ -448,36 +448,36 @@ public class Keyboard2View extends View 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 KeyValue value; - public KeyboardData.Key key; - public float downX; - public float downY; + public int pointerId; + public KeyValue value; + public KeyboardData.Key key; + public float downX; + public float downY; /* Manhattan distance of the pointer to the center of the key */ public float ptrDist; - public int flags; - public int timeoutWhat; + public int flags; + public int timeoutWhat; - public KeyDown(int pointerId, KeyboardData.Key key, float x, float y, int what) - { - this.pointerId = pointerId; - value = key.key0; - this.key = key; - downX = x; - downY = y; + public KeyDown(int pointerId, KeyboardData.Key key, float x, float y, int what) + { + this.pointerId = pointerId; + value = key.key0; + this.key = key; + downX = x; + downY = y; ptrDist = 0.f; - flags = (value == null) ? 0 : value.flags; - timeoutWhat = what; - } - } + flags = (value == null) ? 0 : value.flags; + timeoutWhat = what; + } + } } diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index ea226ee..db3b884 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -6,7 +6,7 @@ import java.util.List; class KeyboardData { - public final List rows; + public final List rows; /* Total width of the keyboard. Unit is abstract. */ public final float keysWidth; /* Total height of the keyboard. Unit is abstract. */ @@ -26,54 +26,54 @@ class KeyboardData keysHeight = kh; } - public static KeyboardData parse(XmlResourceParser parser) - { - ArrayList rows = new ArrayList(); + public static KeyboardData parse(XmlResourceParser parser) + { + ArrayList rows = new ArrayList(); - try - { - int status; + try + { + int status; - while (parser.next() != XmlResourceParser.START_TAG) - continue ; - if (!parser.getName().equals("keyboard")) - throw new Exception("Unknow tag: " + parser.getName()); - while ((status = parser.next()) != XmlResourceParser.END_DOCUMENT) - { - if (status == XmlResourceParser.START_TAG) - { - String tag = parser.getName(); - if (tag.equals("row")) - rows.add(Row.parse(parser)); - else - throw new Exception("Unknow keyboard tag: " + tag); - } - } - } - catch (Exception e) - { - e.printStackTrace(); - } + while (parser.next() != XmlResourceParser.START_TAG) + continue ; + if (!parser.getName().equals("keyboard")) + throw new Exception("Unknow tag: " + parser.getName()); + while ((status = parser.next()) != XmlResourceParser.END_DOCUMENT) + { + if (status == XmlResourceParser.START_TAG) + { + String tag = parser.getName(); + if (tag.equals("row")) + rows.add(Row.parse(parser)); + else + throw new Exception("Unknow keyboard tag: " + tag); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } return new KeyboardData(rows); - } + } public KeyboardData removeKeys(MapKeys f) { - ArrayList rows_ = new ArrayList(); + ArrayList rows_ = new ArrayList(); for (Row r : rows) rows_.add(r.removeKeys(f)); return new KeyboardData(rows_); } - public static class Row - { + public static class Row + { public final List 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 keys_, float h, float s) { @@ -85,25 +85,25 @@ class KeyboardData keysWidth = kw; } - public static Row parse(XmlResourceParser parser) throws Exception - { + public static Row parse(XmlResourceParser parser) throws Exception + { ArrayList keys = new ArrayList(); - 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) - { - if (status == XmlResourceParser.START_TAG) - { - String tag = parser.getName(); - if (tag.equals("key")) + while ((status = parser.next()) != XmlResourceParser.END_TAG) + { + if (status == XmlResourceParser.START_TAG) + { + String tag = parser.getName(); + if (tag.equals("key")) keys.add(Key.parse(parser)); - else - throw new Exception("Unknow row tag: " + tag); - } - } + else + throw new Exception("Unknow row tag: " + tag); + } + } return new Row(keys, h, shift); - } + } public Row removeKeys(MapKeys f) { @@ -112,7 +112,7 @@ class KeyboardData keys_.add(k.removeKeys(f)); return new Row(keys_, height, shift); } - } + } public static class Key { diff --git a/srcs/juloo.keyboard2/SettingsActivity.java b/srcs/juloo.keyboard2/SettingsActivity.java index e9e49c3..9ec82c5 100644 --- a/srcs/juloo.keyboard2/SettingsActivity.java +++ b/srcs/juloo.keyboard2/SettingsActivity.java @@ -5,10 +5,10 @@ import android.preference.PreferenceActivity; public class SettingsActivity extends PreferenceActivity { - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.settings); - } + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.settings); + } }