Skip to content

Commit

Permalink
Merge branch 'master' into support
Browse files Browse the repository at this point in the history
  • Loading branch information
mbacuiz committed Dec 4, 2019
2 parents f331d92 + 1ca3153 commit 6d689cf
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 26 deletions.
59 changes: 59 additions & 0 deletions anylayer/src/main/java/per/goweii/anylayer/BackgroundView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package per.goweii.anylayer;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;

/**
* Create by cuizhen on {2019/12/3}
* <p>
* ▄████▄ █ ██ ██▓▒███████▒ ██░ ██ ▓█████ ███▄ █
* ▒██▀ ▀█ ██ ▓██▒▓██▒▒ ▒ ▒ ▄▀░▓██░ ██▒▓█ ▀ ██ ▀█ █
* ▒▓█ ▄ ▓██ ▒██░▒██▒░ ▒ ▄▀▒░ ▒██▀▀██░▒███ ▓██ ▀█ ██▒
* ▒▓▓▄ ▄██▒▓▓█ ░██░░██░ ▄▀▒ ░░▓█ ░██ ▒▓█ ▄▓██▒ ▐▌██▒
* ▒ ▓███▀ ░▒▒█████▓ ░██░▒███████▒░▓█▒░██▓░▒████▒██░ ▓██░
* ░ ░▒ ▒ ░░▒▓▒ ▒ ▒ ░▓ ░▒▒ ▓░▒░▒ ▒ ░░▒░▒░░ ▒░ ░ ▒░ ▒ ▒
* ░ ▒ ░░▒░ ░ ░ ▒ ░░░▒ ▒ ░ ▒ ▒ ░▒░ ░ ░ ░ ░ ░░ ░ ▒░
* ░ ░░░ ░ ░ ▒ ░░ ░ ░ ░ ░ ░ ░░ ░ ░ ░ ░ ░
* ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
* ░ ░
*/
public class BackgroundView extends ImageView {

private OnTouchedListener mOnTouchedListener = null;

public BackgroundView(Context context) {
this(context, null);
}

public BackgroundView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public BackgroundView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
if (mOnTouchedListener != null) {
mOnTouchedListener.onTouched();
}
break;
default:
break;
}
return false;
}

public void setOnTouchedListener(OnTouchedListener onTouchedListener) {
this.mOnTouchedListener = onTouchedListener;
}

public interface OnTouchedListener {
void onTouched();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package per.goweii.anylayer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
Expand Down Expand Up @@ -36,8 +37,9 @@ public ContainerLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
if (mOnTouchedListener != null) {
Expand All @@ -47,7 +49,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
default:
break;
}
return super.dispatchTouchEvent(ev);
return super.onTouchEvent(ev);
}

public void setOnTouchedListener(OnTouchedListener onTouchedListener) {
Expand Down
31 changes: 21 additions & 10 deletions anylayer/src/main/java/per/goweii/anylayer/DialogLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,19 @@ public void onClick(View v) {
getViewHolder().getChild().setOnClickListener(null);
getViewHolder().getChild().setClickable(false);
}
getViewHolder().getChild().setOnTouchedListener(new ContainerLayout.OnTouchedListener() {
@Override
public void onTouched() {
if (getConfig().mOutsideTouchedListener != null) {
getConfig().mOutsideTouchedListener.outsideTouched();
if (getConfig().mOutsideTouchedToDismiss || getConfig().mOutsideTouchedListener != null) {
getViewHolder().getChild().setOnTouchedListener(new ContainerLayout.OnTouchedListener() {
@Override
public void onTouched() {
if (getConfig().mOutsideTouchedToDismiss) {
dismiss();
}
if (getConfig().mOutsideTouchedListener != null) {
getConfig().mOutsideTouchedListener.outsideTouched();
}
}
}
});
});
}
fitContainerToActivityContent();
FrameLayout.LayoutParams contentWrapperParams = (FrameLayout.LayoutParams) getViewHolder().getContentWrapper().getLayoutParams();
contentWrapperParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
Expand Down Expand Up @@ -600,9 +605,14 @@ public DialogLayer outsideTouched(OutsideTouchedListener listener) {
return this;
}

public DialogLayer outsideTouchedToDismiss(boolean toDismiss) {
getConfig().mOutsideTouchedToDismiss = toDismiss;
return this;
}

public static class ViewHolder extends DecorLayer.ViewHolder {
private FrameLayout mActivityContent;
private ImageView mBackground;
private BackgroundView mBackground;
private DragLayout mContentWrapper;
private View mContent;

Expand Down Expand Up @@ -645,14 +655,15 @@ public DragLayout getContentWrapper() {
return mContentWrapper;
}

public ImageView getBackground() {
return mBackground;
public BackgroundView getBackground() {
return (BackgroundView) mBackground;
}
}

protected static class Config extends DecorLayer.Config {
protected boolean mOutsideInterceptTouchEvent = true;
protected OutsideTouchedListener mOutsideTouchedListener = null;
protected boolean mOutsideTouchedToDismiss = false;

protected AnimatorCreator mBackgroundAnimatorCreator = null;
protected AnimatorCreator mContentAnimatorCreator = null;
Expand Down
44 changes: 31 additions & 13 deletions anylayer/src/main/java/per/goweii/anylayer/PopupLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ public void onPreRemove() {

@Override
public void onDetach() {
if (mOnScrollChangedListener != null) {
getViewHolder().getParent().getViewTreeObserver().removeOnScrollChangedListener(mOnScrollChangedListener);
mOnScrollChangedListener = null;
}
getViewHolder().getParent().getViewTreeObserver().removeOnScrollChangedListener(mOnScrollChangedListener);
mOnScrollChangedListener = null;
super.onDetach();
}

Expand Down Expand Up @@ -163,15 +161,19 @@ public void run() {
updateLocation();
}
});
if (!getConfig().mOutsideInterceptTouchEvent) {
mOnScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
updateLocation();
mOnScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
if (getConfig().mViewTreeScrollChangedToDismiss) {
dismiss();
}
};
getViewHolder().getParent().getViewTreeObserver().addOnScrollChangedListener(mOnScrollChangedListener);
}
if (getConfig().mOnViewTreeScrollChangedListener != null) {
getConfig().mOnViewTreeScrollChangedListener.onScrollChanged();
}
updateLocation();
}
};
getViewHolder().getParent().getViewTreeObserver().addOnScrollChangedListener(mOnScrollChangedListener);
}

private void initContentWrapperLocation(int targetX, int targetY, int targetWidth, int targetHeight) {
Expand Down Expand Up @@ -483,7 +485,7 @@ public void updateLocation() {
int targetHeight = 0;
if (target != null) {
targetWidth = target.getWidth();
targetHeight = target.getWidth();
targetHeight = target.getHeight();
}
initContentWrapperLocation(targetX, targetY, targetWidth, targetHeight);
initBackgroundLocation();
Expand All @@ -494,6 +496,16 @@ public PopupLayer updateLocationInterceptor(UpdateLocationInterceptor intercepto
return this;
}

public PopupLayer onViewTreeScrollChangedListener(OnViewTreeScrollChangedListener listener) {
getConfig().mOnViewTreeScrollChangedListener = listener;
return this;
}

public PopupLayer scrollChangedToDismiss(boolean toDismiss) {
getConfig().mViewTreeScrollChangedToDismiss = toDismiss;
return this;
}

public PopupLayer targetView(View targetView) {
getViewHolder().setTarget(targetView);
updateLocation();
Expand Down Expand Up @@ -674,6 +686,8 @@ public View getTarget() {
}

protected static class Config extends DialogLayer.Config {
protected OnViewTreeScrollChangedListener mOnViewTreeScrollChangedListener = null;
protected boolean mViewTreeScrollChangedToDismiss = false;
protected UpdateLocationInterceptor mUpdateLocationInterceptor = null;
protected boolean mContentClip = true;
protected boolean mBackgroundAlign = true;
Expand All @@ -695,4 +709,8 @@ void interceptor(float[] popupXY, int popupWidth, int popupHeight,
int targetX, int targetY, int targetWidth, int targetHeight,
int parentX, int parentY, int parentWidth, int parentHeight);
}

public interface OnViewTreeScrollChangedListener {
void onScrollChanged();
}
}
2 changes: 1 addition & 1 deletion anylayer/src/main/res/layout/anylayer_dialog_layer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
<per.goweii.anylayer.BackgroundView
android:id="@+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down

0 comments on commit 6d689cf

Please sign in to comment.