abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/KeyPreviewPopup.java
diff options
context:
space:
mode:
authorjaguillo2015-10-28 16:15:19 +0100
committerjaguillo2015-10-28 16:15:19 +0100
commit16763a5f1b292ddf7010c7a0a47dadc0c3dd5372 (patch)
treec2068de90f48ac7e521a5aab326194f92c99cb15 /srcs/juloo.keyboard2/KeyPreviewPopup.java
parent804e9a7adcc58d81327873ba787c2230eeee350b (diff)
downloadunexpected-keyboard-16763a5f1b292ddf7010c7a0a47dadc0c3dd5372.tar.gz
unexpected-keyboard-16763a5f1b292ddf7010c7a0a47dadc0c3dd5372.zip
Show preview popup
Diffstat (limited to 'srcs/juloo.keyboard2/KeyPreviewPopup.java')
-rw-r--r--srcs/juloo.keyboard2/KeyPreviewPopup.java26
1 files changed, 23 insertions, 3 deletions
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));
+ }
}