abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/KeyPreviewPopup.java
blob: 5cccefb4f19919ad3c3101b2dc6f50486a96a887 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;

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(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)
	{
		if (preview == null)
		{
			System.out.println("popup preview dismiss");
			dismiss();
		}
		else
		{
			System.out.println("popup preview: " + preview);
			_content.setText(preview);
			if (!isShowing())
				show();
		}
	}

	private void		show()
	{
		_content.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
		showAtLocation(_anchor, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0,
			-(_content.getMeasuredHeight() + _bottomMargin));
	}
}