mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-26 20:51:33 +02:00
Show preview popup
This commit is contained in:
parent
804e9a7adc
commit
16763a5f1b
11
res/drawable/preview_popup.xml
Normal file
11
res/drawable/preview_popup.xml
Normal file
@ -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>
|
@ -2,6 +2,7 @@ package juloo.keyboard2;
|
|||||||
|
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.MeasureSpec;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -10,29 +11,48 @@ class KeyPreviewPopup extends PopupWindow
|
|||||||
{
|
{
|
||||||
private TextView _content;
|
private TextView _content;
|
||||||
private View _anchor;
|
private View _anchor;
|
||||||
|
private int _bottomMargin;
|
||||||
|
|
||||||
public KeyPreviewPopup(View anchor)
|
public KeyPreviewPopup(View anchor)
|
||||||
{
|
{
|
||||||
super(anchor.getContext());
|
super(anchor.getContext());
|
||||||
_content = new TextView(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;
|
_anchor = anchor;
|
||||||
|
_bottomMargin = (int)anchor.getResources().getDimension(R.dimen.preview_margin);
|
||||||
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
|
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
|
||||||
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
|
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
|
||||||
|
setBackgroundDrawable(anchor.getResources().getDrawable(R.drawable.preview_popup));
|
||||||
setContentView(_content);
|
setContentView(_content);
|
||||||
|
setClippingEnabled(false);
|
||||||
setTouchable(false);
|
setTouchable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreview(String preview)
|
public void setPreview(String preview)
|
||||||
{
|
{
|
||||||
System.out.println("popup preview: " + preview);
|
|
||||||
if (preview == null)
|
if (preview == null)
|
||||||
|
{
|
||||||
|
System.out.println("popup preview dismiss");
|
||||||
dismiss();
|
dismiss();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
System.out.println("popup preview: " + preview);
|
||||||
_content.setText(preview);
|
_content.setText(preview);
|
||||||
if (!isShowing())
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user