Skip to content

Commit

Permalink
1.[ADD]support intercept touch event
Browse files Browse the repository at this point in the history
  • Loading branch information
soulqw committed Sep 10, 2021
1 parent 6369033 commit 7ecbfa0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
13 changes: 13 additions & 0 deletions curtain/src/main/java/com/qw/curtain/lib/Curtain.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ public Curtain setNoCurtainAnimation(boolean isNotNeed) {
return this;
}

/**
* set the curtain will intercept the touchEvent when it above your view
*
* @param isIntercept the touch event will be intercept when it is ture, the default config
* is the true
*/
public Curtain setInterceptTouchEvent(boolean isIntercept) {
this.buildParams.isInterceptTouchEvent = isIntercept;
return this;
}

@MainThread
public void show() {
SparseArray<HollowInfo> hollows = buildParams.hollows;
Expand Down Expand Up @@ -240,6 +251,8 @@ public static class Param {

boolean cancelBackPressed = true;

boolean isInterceptTouchEvent = true;

int curtainColor = 0xAA000000;

int animationStyle = Constance.STATE_NOT_SET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;

Expand Down Expand Up @@ -127,9 +126,10 @@ public void dismissGuide() {
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
if (dialog == null) {
dialog = new AlertDialog.Builder(requireActivity(), R.style.TransparentDialog)
.setView(contentView)
.create();
dialog = param.isInterceptTouchEvent ?
new Dialog(requireActivity(), R.style.TransparentDialog) :
new NoInterceptAlertDialog(requireActivity(), R.style.TransparentDialog);
dialog.setContentView(contentView);
setAnimation(dialog);
}
return dialog;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.qw.curtain.lib;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.MotionEvent;

import androidx.annotation.NonNull;

public class NoInterceptAlertDialog extends Dialog {

protected NoInterceptAlertDialog(@NonNull Context context, int themeResId) {
super(context, themeResId);
}

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
return super.onTouchEvent(event) || tryHandleByActivity(event);
}

private boolean tryHandleByActivity(MotionEvent ev) {
Activity activity = getOwnerActivity();
if (activity != null) {
return activity.dispatchTouchEvent(ev);
}
return false;
}

}

0 comments on commit 7ecbfa0

Please sign in to comment.