forked from razerdp/BasePopup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnyPosPopupFrag.java
89 lines (75 loc) · 2.69 KB
/
AnyPosPopupFrag.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package razerdp.demo.fragment.basedemo;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import razerdp.basepopup.BasePopupWindow;
import razerdp.basepopup.R;
import razerdp.demo.fragment.other.SimpleBaseFrag;
import razerdp.demo.popup.DemoPopup;
import razerdp.demo.utils.MultiSpanUtil;
import razerdp.util.SimpleAnimationUtils;
/**
* Created by 大灯泡 on 2018/12/11.
*/
public class AnyPosPopupFrag extends SimpleBaseFrag {
private ViewHolder vh;
private static final String DESC = "· BasePopup在任意位置弹出。";
private DemoPopup mDemoPopup;
float x, y;
@SuppressLint("ClickableViewAccessibility")
@Override
public void onInitView(View rootView) {
vh = new ViewHolder(rootView);
MultiSpanUtil.create(DESC)
.append("任意位置").setTextColor(Color.RED)
.into(vh.tvDesc);
mDemoPopup = new DemoPopup(getContext());
mDemoPopup.setPopupGravity(Gravity.CENTER)
.setShowAnimation(SimpleAnimationUtils.getDefaultScaleAnimation(true))
.setDismissAnimation(SimpleAnimationUtils.getDefaultScaleAnimation(false));
vh.layoutTouchContainer.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
x = event.getRawX();
y = event.getRawY();
}
return false;
}
});
vh.layoutTouchContainer.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
mDemoPopup.showPopupWindow((int) x, (int) y);
return true;
}
});
}
@Override
public BasePopupWindow getPopup() {
return null;
}
@Override
public Button getButton() {
return null;
}
@Override
public View getFragment() {
return mInflater.inflate(R.layout.frag_demo_any_pos, container, false);
}
public static class ViewHolder {
public View rootView;
public TextView tvDesc;
public LinearLayout layoutTouchContainer;
public ViewHolder(View rootView) {
this.rootView = rootView;
this.tvDesc = (TextView) rootView.findViewById(R.id.tv_desc);
this.layoutTouchContainer = (LinearLayout) rootView.findViewById(R.id.layout_touch_container);
}
}
}