Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue where the promo WebView does not respond to click events #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 22 additions & 49 deletions affirm/src/main/java/com/affirm/android/PromotionWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.CookieManager;
Expand Down Expand Up @@ -49,60 +50,32 @@ public PromotionWebView(Context context, AttributeSet attrs) {
AffirmUtils.debuggableWebView(getContext());
setWebViewClient(new PromoWebViewClient(this));
setWebChromeClient(new AffirmWebChromeClient(this));


setOnTouchListener(new View.OnTouchListener() {

private static final int FINGER_RELEASED = 0;
private static final int FINGER_TOUCHED = 1;
private static final int FINGER_DRAGGING = 2;
private static final int FINGER_UNDEFINED = 3;

private int fingerState = FINGER_RELEASED;

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {

switch (motionEvent.getAction()) {

case MotionEvent.ACTION_DOWN:
if (fingerState == FINGER_RELEASED) {
fingerState = FINGER_TOUCHED;
} else {
fingerState = FINGER_UNDEFINED;
}
break;

case MotionEvent.ACTION_UP:
if (fingerState != FINGER_DRAGGING) {
fingerState = FINGER_RELEASED;
if (webViewClickListener != null) {
webViewClickListener.onClick((View) view.getParent());
}
} else {
fingerState = FINGER_RELEASED;
}
break;

case MotionEvent.ACTION_MOVE:
if (fingerState == FINGER_TOUCHED || fingerState == FINGER_DRAGGING) {
fingerState = FINGER_DRAGGING;
} else {
fingerState = FINGER_UNDEFINED;
}
break;

default:
fingerState = FINGER_UNDEFINED;

}

return false;
GestureDetector gestureDetector = new GestureDetector(context,
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
performClick();
return true;
}
});
setOnTouchListener((view, event) -> {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
});
setBackgroundColor(getResources().getColor(android.R.color.transparent));
}

@Override
public boolean performClick() {
super.performClick();
if (webViewClickListener != null) {
webViewClickListener.onClick((View) getParent());
}
return true;
}

public void loadWebData(String promoHtml, String remoteCssUrl, String typeface) {
final String html = initialHtml(promoHtml, remoteCssUrl, typeface);
loadDataWithBaseURL(null, html, TEXT_HTML, UTF_8, null);
Expand Down
Loading