diff options
| author | jaguillo | 2015-10-28 16:15:19 +0100 |
|---|---|---|
| committer | jaguillo | 2015-10-28 16:15:19 +0100 |
| commit | 16763a5f1b292ddf7010c7a0a47dadc0c3dd5372 (patch) | |
| tree | c2068de90f48ac7e521a5aab326194f92c99cb15 | |
| parent | 804e9a7adcc58d81327873ba787c2230eeee350b (diff) | |
| download | unexpected-keyboard-16763a5f1b292ddf7010c7a0a47dadc0c3dd5372.tar.gz unexpected-keyboard-16763a5f1b292ddf7010c7a0a47dadc0c3dd5372.zip | |
Show preview popup
| -rw-r--r-- | res/drawable/preview_popup.xml | 11 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/KeyPreviewPopup.java | 26 |
2 files changed, 34 insertions, 3 deletions
diff --git a/res/drawable/preview_popup.xml b/res/drawable/preview_popup.xml new file mode 100644 index 0000000..ce9a7fa --- /dev/null +++ b/res/drawable/preview_popup.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle" +> + <corner android:radius="@dimen/preview_corners" /> + <solid android:color="@color/preview_bg" /> + <stroke + android:width="@dimen/preview_stroke" + android:color="@color/preview_stroke" + /> +</shape> diff --git a/srcs/juloo.keyboard2/KeyPreviewPopup.java b/srcs/juloo.keyboard2/KeyPreviewPopup.java index 3eb1505..5cccefb 100644 --- a/srcs/juloo.keyboard2/KeyPreviewPopup.java +++ b/srcs/juloo.keyboard2/KeyPreviewPopup.java @@ -2,6 +2,7 @@ package juloo.keyboard2; import android.view.Gravity; import android.view.View; +import android.view.View.MeasureSpec; import android.view.WindowManager; import android.widget.PopupWindow; import android.widget.TextView; @@ -10,29 +11,48 @@ class KeyPreviewPopup extends PopupWindow { private TextView _content; private View _anchor; + private int _bottomMargin; public KeyPreviewPopup(View anchor) { super(anchor.getContext()); _content = new TextView(anchor.getContext()); - _content.setTextColor(0xFFFFFFFF); + _content.setTextColor(anchor.getResources().getColor(R.color.preview_text)); + _content.setTextSize(anchor.getResources().getDimension(R.dimen.preview_text)); + int padding = (int)anchor.getResources().getDimension(R.dimen.preview_padding); + _content.setPaddingRelative(padding, padding, padding, padding); + _content.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY); + _content.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); _anchor = anchor; + _bottomMargin = (int)anchor.getResources().getDimension(R.dimen.preview_margin); setWidth(WindowManager.LayoutParams.WRAP_CONTENT); setHeight(WindowManager.LayoutParams.WRAP_CONTENT); + setBackgroundDrawable(anchor.getResources().getDrawable(R.drawable.preview_popup)); setContentView(_content); + setClippingEnabled(false); setTouchable(false); } public void setPreview(String preview) { - System.out.println("popup preview: " + preview); if (preview == null) + { + System.out.println("popup preview dismiss"); dismiss(); + } else { + System.out.println("popup preview: " + preview); _content.setText(preview); if (!isShowing()) - showAtLocation(_anchor, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, -400); + show(); } } + + private void show() + { + _content.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); + showAtLocation(_anchor, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, + -(_content.getMeasuredHeight() + _bottomMargin)); + } } |
