mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-12-23 22:48:54 +01:00
Fix some bugs + Try to show a preview popup
This commit is contained in:
parent
8716801261
commit
804e9a7adc
@ -51,7 +51,6 @@
|
||||
<juloo.keyboard2.EmojiGridView
|
||||
android:id="@+id/emoji_grid"
|
||||
android:background="@color/bg"
|
||||
android:textColor="@color/emoji_key_text"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="@dimen/emoji_grid_height"
|
||||
/>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<item name="key_label_locked" type="color">#229933</item>
|
||||
<item name="key_sub_label" type="color">#BDBDBD</item>
|
||||
<item name="emoji_button_bg" type="color">#202020</item>
|
||||
<item name="emoji_emoji_bg" type="color">#00FFFFFF</item>
|
||||
<item name="emoji_color" type="color">#FFFFFF</item>
|
||||
<item name="emoji_key_bg" type="color">@color/emoji_button_bg</item>
|
||||
<item name="emoji_key_text" type="color">@color/key_label</item>
|
||||
</resources>
|
||||
|
@ -117,17 +117,14 @@ public class EmojiGridView extends GridView
|
||||
|
||||
private static class EmojiView extends TextView
|
||||
{
|
||||
private static ViewGroup.LayoutParams _layoutParams = null;
|
||||
|
||||
public EmojiView(Keyboard2 context)
|
||||
{
|
||||
super(context);
|
||||
setTextSize(EMOJI_SIZE);
|
||||
setGravity(Gravity.CENTER);
|
||||
setBackgroundColor(getResources().getColor(R.color.emoji_emoji_bg));
|
||||
if (_layoutParams == null)
|
||||
_layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
|
||||
setLayoutParams(_layoutParams);
|
||||
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)
|
||||
|
38
srcs/juloo.keyboard2/KeyPreviewPopup.java
Normal file
38
srcs/juloo.keyboard2/KeyPreviewPopup.java
Normal file
@ -0,0 +1,38 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
|
||||
class KeyPreviewPopup extends PopupWindow
|
||||
{
|
||||
private TextView _content;
|
||||
private View _anchor;
|
||||
|
||||
public KeyPreviewPopup(View anchor)
|
||||
{
|
||||
super(anchor.getContext());
|
||||
_content = new TextView(anchor.getContext());
|
||||
_content.setTextColor(0xFFFFFFFF);
|
||||
_anchor = anchor;
|
||||
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
|
||||
setContentView(_content);
|
||||
setTouchable(false);
|
||||
}
|
||||
|
||||
public void setPreview(String preview)
|
||||
{
|
||||
System.out.println("popup preview: " + preview);
|
||||
if (preview == null)
|
||||
dismiss();
|
||||
else
|
||||
{
|
||||
_content.setText(preview);
|
||||
if (!isShowing())
|
||||
showAtLocation(_anchor, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, -400);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,8 @@ class KeyValue
|
||||
public static final int FLAG_CTRL = (1 << 2);
|
||||
public static final int FLAG_SHIFT = (1 << 3);
|
||||
public static final int FLAG_ALT = (1 << 4);
|
||||
public static final int FLAG_NOCHAR = (1 << 5);
|
||||
public static final int FLAG_NOREPEAT = (1 << 5);
|
||||
public static final int FLAG_NOCHAR = (1 << 6);
|
||||
public static final int FLAG_LOCKED = (1 << 8);
|
||||
|
||||
public static final int FLAG_KEY_FONT = (1 << 12);
|
||||
@ -123,15 +124,15 @@ class KeyValue
|
||||
new KeyValue(key, key, key.charAt(0), EVENT_NONE, 0);
|
||||
}
|
||||
|
||||
new KeyValue("shift", "⇧", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_LOCK | FLAG_SHIFT);
|
||||
new KeyValue("ctrl", "Ctrl", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_CTRL);
|
||||
new KeyValue("alt", "Alt", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ALT);
|
||||
new KeyValue("accent1", "\u02CB", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT1);
|
||||
new KeyValue("accent2", "\u00B4", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT2);
|
||||
new KeyValue("accent3", "\u02C6", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT3);
|
||||
new KeyValue("accent4", "\u02DC", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT4);
|
||||
new KeyValue("accent5", "\u00B8", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT5);
|
||||
new KeyValue("accent6", "\u00A8", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT6);
|
||||
new KeyValue("shift", "⇧", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_LOCK | FLAG_SHIFT);
|
||||
new KeyValue("ctrl", "Ctrl", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_CTRL);
|
||||
new KeyValue("alt", "Alt", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_ALT);
|
||||
new KeyValue("accent1", "\u02CB", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_ACCENT1);
|
||||
new KeyValue("accent2", "\u00B4", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_ACCENT2);
|
||||
new KeyValue("accent3", "\u02C6", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_ACCENT3);
|
||||
new KeyValue("accent4", "\u02DC", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_ACCENT4);
|
||||
new KeyValue("accent5", "\u00B8", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_ACCENT5);
|
||||
new KeyValue("accent6", "\u00A8", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | FLAG_ACCENT6);
|
||||
|
||||
new KeyValue("a", null, 'a', KeyEvent.KEYCODE_A, 0);
|
||||
new KeyValue("b", null, 'b', KeyEvent.KEYCODE_B, 0);
|
||||
@ -170,11 +171,11 @@ class KeyValue
|
||||
new KeyValue("8", null, '8', KeyEvent.KEYCODE_8, 0);
|
||||
new KeyValue("9", null, '9', KeyEvent.KEYCODE_9, 0);
|
||||
|
||||
new KeyValue("config", "Conf", CHAR_NONE, EVENT_CONFIG, 0);
|
||||
new KeyValue("switch_text", "ABC", CHAR_NONE, EVENT_SWITCH_TEXT, 0);
|
||||
new KeyValue("switch_numeric", "123+", CHAR_NONE, EVENT_SWITCH_NUMERIC, 0);
|
||||
new KeyValue("switch_emoji", "\uD83D\uDE03", CHAR_NONE, EVENT_SWITCH_EMOJI, 0);
|
||||
new KeyValue("switch_back_emoji", "ABC", CHAR_NONE, EVENT_SWITCH_BACK_EMOJI, 0);
|
||||
new KeyValue("config", "Conf", CHAR_NONE, EVENT_CONFIG, FLAG_NOREPEAT);
|
||||
new KeyValue("switch_text", "ABC", CHAR_NONE, EVENT_SWITCH_TEXT, FLAG_NOREPEAT);
|
||||
new KeyValue("switch_numeric", "123+", CHAR_NONE, EVENT_SWITCH_NUMERIC, FLAG_NOREPEAT);
|
||||
new KeyValue("switch_emoji", "\uD83D\uDE03", CHAR_NONE, EVENT_SWITCH_EMOJI, FLAG_NOREPEAT);
|
||||
new KeyValue("switch_back_emoji", "ABC", CHAR_NONE, EVENT_SWITCH_BACK_EMOJI, FLAG_NOREPEAT);
|
||||
|
||||
new KeyValue("esc", "Esc", CHAR_NONE, KeyEvent.KEYCODE_ESCAPE, 0);
|
||||
new KeyValue("enter", "\uE800", CHAR_NONE, KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT);
|
||||
|
@ -15,6 +15,7 @@ import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.PopupWindow;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Keyboard2View extends View
|
||||
@ -36,6 +37,8 @@ public class Keyboard2View extends View
|
||||
private Handler _handler;
|
||||
private static int _currentWhat = 0;
|
||||
|
||||
private KeyPreviewPopup _previewPopup;
|
||||
|
||||
/*
|
||||
** TODO: move config values in a Config object
|
||||
*/
|
||||
@ -72,6 +75,7 @@ public class Keyboard2View extends View
|
||||
super(context, attrs);
|
||||
_vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
_handler = new Handler(this);
|
||||
_previewPopup = new KeyPreviewPopup(this);
|
||||
_horizontalMargin = getResources().getDimension(R.dimen.horizontal_margin);
|
||||
_marginTop = getResources().getDimension(R.dimen.margin_top);
|
||||
_marginBottom = getResources().getDimension(R.dimen.margin_bottom);
|
||||
@ -210,14 +214,14 @@ public class Keyboard2View extends View
|
||||
if (key.timeoutWhat != -1)
|
||||
{
|
||||
_handler.removeMessages(key.timeoutWhat);
|
||||
if ((newValue.getFlags() & KeyValue.FLAG_NOCHAR) == 0)
|
||||
if ((newValue.getFlags() & KeyValue.FLAG_NOREPEAT) == 0)
|
||||
_handler.sendEmptyMessageDelayed(key.timeoutWhat, _longPressTimeout);
|
||||
}
|
||||
key.value = newValue;
|
||||
key.flags = newValue.getFlags();
|
||||
updateFlags();
|
||||
invalidate();
|
||||
vibrate();
|
||||
handleKeyDown(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -254,11 +258,11 @@ public class Keyboard2View extends View
|
||||
else
|
||||
{
|
||||
int what = _currentWhat++;
|
||||
if (key.key0 != null && (key.key0.getFlags() & KeyValue.FLAG_NOCHAR) == 0)
|
||||
if (key.key0 != null && (key.key0.getFlags() & KeyValue.FLAG_NOREPEAT) == 0)
|
||||
_handler.sendEmptyMessageDelayed(what, _longPressTimeout);
|
||||
_downKeys.add(new KeyDown(pointerId, key, touchX, touchY, what));
|
||||
}
|
||||
vibrate();
|
||||
handleKeyDown(key.key0);
|
||||
updateFlags();
|
||||
invalidate();
|
||||
return ;
|
||||
@ -293,15 +297,28 @@ public class Keyboard2View extends View
|
||||
else if ((downKey.flags & KeyValue.FLAG_KEEP_ON) != 0)
|
||||
downKey.flags ^= KeyValue.FLAG_KEEP_ON;
|
||||
}
|
||||
if (k.value != null && (k.flags & (KeyValue.FLAG_LOCKED | KeyValue.FLAG_NOCHAR)) == 0)
|
||||
((Keyboard2)getContext()).handleKeyUp(k.value, _flags);
|
||||
_downKeys.remove(k);
|
||||
handleKeyUp(k);
|
||||
updateFlags();
|
||||
invalidate();
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleKeyUp(KeyDown key)
|
||||
{
|
||||
if (key.value != null && (key.flags & (KeyValue.FLAG_LOCKED | KeyValue.FLAG_NOCHAR)) == 0)
|
||||
((Keyboard2)getContext()).handleKeyUp(key.value, _flags);
|
||||
_previewPopup.setPreview(null); // TODO: preview next down key
|
||||
}
|
||||
|
||||
private void handleKeyDown(KeyValue key)
|
||||
{
|
||||
if (key != null)
|
||||
_previewPopup.setPreview(key.getSymbol(_flags));
|
||||
vibrate();
|
||||
}
|
||||
|
||||
private void updateFlags()
|
||||
{
|
||||
_flags = 0;
|
||||
@ -399,6 +416,13 @@ public class Keyboard2View extends View
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow()
|
||||
{
|
||||
super.onDetachedFromWindow();
|
||||
_previewPopup.setPreview(null);
|
||||
}
|
||||
|
||||
private void drawLabel(Canvas canvas, KeyValue k, float x, float y, boolean locked)
|
||||
{
|
||||
if ((k.getFlags() & KeyValue.FLAG_KEY_FONT) != 0)
|
||||
|
Loading…
Reference in New Issue
Block a user