|
3 | 3 | import android.content.Context;
|
4 | 4 | import android.os.Build;
|
5 | 5 | import android.util.AttributeSet;
|
| 6 | +import android.view.GestureDetector; |
6 | 7 | import android.view.MotionEvent;
|
7 | 8 | import android.view.View;
|
8 | 9 | import android.webkit.CookieManager;
|
@@ -49,60 +50,32 @@ public PromotionWebView(Context context, AttributeSet attrs) {
|
49 | 50 | AffirmUtils.debuggableWebView(getContext());
|
50 | 51 | setWebViewClient(new PromoWebViewClient(this));
|
51 | 52 | setWebChromeClient(new AffirmWebChromeClient(this));
|
52 |
| - |
53 |
| - |
54 |
| - setOnTouchListener(new View.OnTouchListener() { |
55 |
| - |
56 |
| - private static final int FINGER_RELEASED = 0; |
57 |
| - private static final int FINGER_TOUCHED = 1; |
58 |
| - private static final int FINGER_DRAGGING = 2; |
59 |
| - private static final int FINGER_UNDEFINED = 3; |
60 |
| - |
61 |
| - private int fingerState = FINGER_RELEASED; |
62 |
| - |
63 |
| - @Override |
64 |
| - public boolean onTouch(View view, MotionEvent motionEvent) { |
65 |
| - |
66 |
| - switch (motionEvent.getAction()) { |
67 |
| - |
68 |
| - case MotionEvent.ACTION_DOWN: |
69 |
| - if (fingerState == FINGER_RELEASED) { |
70 |
| - fingerState = FINGER_TOUCHED; |
71 |
| - } else { |
72 |
| - fingerState = FINGER_UNDEFINED; |
73 |
| - } |
74 |
| - break; |
75 |
| - |
76 |
| - case MotionEvent.ACTION_UP: |
77 |
| - if (fingerState != FINGER_DRAGGING) { |
78 |
| - fingerState = FINGER_RELEASED; |
79 |
| - if (webViewClickListener != null) { |
80 |
| - webViewClickListener.onClick((View) view.getParent()); |
81 |
| - } |
82 |
| - } else { |
83 |
| - fingerState = FINGER_RELEASED; |
84 |
| - } |
85 |
| - break; |
86 |
| - |
87 |
| - case MotionEvent.ACTION_MOVE: |
88 |
| - if (fingerState == FINGER_TOUCHED || fingerState == FINGER_DRAGGING) { |
89 |
| - fingerState = FINGER_DRAGGING; |
90 |
| - } else { |
91 |
| - fingerState = FINGER_UNDEFINED; |
92 |
| - } |
93 |
| - break; |
94 |
| - |
95 |
| - default: |
96 |
| - fingerState = FINGER_UNDEFINED; |
97 |
| - |
98 |
| - } |
99 |
| - |
100 |
| - return false; |
| 53 | + GestureDetector gestureDetector = new GestureDetector(context, |
| 54 | + new GestureDetector.SimpleOnGestureListener() { |
| 55 | + @Override |
| 56 | + public boolean onSingleTapConfirmed(MotionEvent e) { |
| 57 | + performClick(); |
| 58 | + return true; |
| 59 | + } |
| 60 | + }); |
| 61 | + setOnTouchListener((view, event) -> { |
| 62 | + if (gestureDetector.onTouchEvent(event)) { |
| 63 | + return true; |
101 | 64 | }
|
| 65 | + return false; |
102 | 66 | });
|
103 | 67 | setBackgroundColor(getResources().getColor(android.R.color.transparent));
|
104 | 68 | }
|
105 | 69 |
|
| 70 | + @Override |
| 71 | + public boolean performClick() { |
| 72 | + super.performClick(); |
| 73 | + if (webViewClickListener != null) { |
| 74 | + webViewClickListener.onClick((View) getParent()); |
| 75 | + } |
| 76 | + return true; |
| 77 | + } |
| 78 | + |
106 | 79 | public void loadWebData(String promoHtml, String remoteCssUrl, String typeface) {
|
107 | 80 | final String html = initialHtml(promoHtml, remoteCssUrl, typeface);
|
108 | 81 | loadDataWithBaseURL(null, html, TEXT_HTML, UTF_8, null);
|
|
0 commit comments