Skip to content

Commit

Permalink
0.0.40.beta4
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzue committed Jun 23, 2021
1 parent b0fe84a commit 1e5f5a2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,10 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
if (!onMenuItemSelectListener.onClick(me, menuList.get(position), position)) {
dismiss();
} else {
boolean select = false;
if (selectionIndex == position) {
selectionIndex = -1;
} else {
selectionIndex = position;
select = true;
}
selectionIndex = position;
menuListAdapter.notifyDataSetInvalidated();
menuListAdapter.notifyDataSetChanged();
onMenuItemSelectListener.onOneItemSelect(me, menuList.get(position), position, select);
onMenuItemSelectListener.onOneItemSelect(me, menuList.get(position), position, true);
}
} else {
if (onMenuItemClickListener != null) {
Expand Down
5 changes: 5 additions & 0 deletions DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ protected PopTip() {
super();
}

@Override
public boolean isCancelable() {
return false;
}

public static PopTip build() {
return new PopTip();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public BaseDialog() {
autoShowInputKeyboard = DialogX.autoShowInputKeyboard;
}

public abstract boolean isCancelable();

public View createView(int layoutId) {
if (getContext() == null) {
error("DialogX 未初始化。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
Expand Down Expand Up @@ -361,6 +363,11 @@ protected static void runOnMain(Runnable runnable) {
new Handler(Looper.getMainLooper()).post(runnable);
}

public View getDialogView() {
if (dialogView == null) return null;
return dialogView.get();
}

public Activity getActivity() {
return ownActivity == null ? null : ownActivity.get();
}
Expand All @@ -381,4 +388,8 @@ public static void recycleDialog(Activity activity) {
}
}
}

public static List<BaseDialog> getRunningDialogList() {
return new CopyOnWriteArrayList<>(runningDialogList);
}
}
37 changes: 35 additions & 2 deletions DialogX/src/main/java/com/kongzue/dialogx/util/WindowUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import android.os.Build;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Toast;

import com.kongzue.dialogx.R;
import com.kongzue.dialogx.dialogs.PopTip;
import com.kongzue.dialogx.interfaces.BaseDialog;

import static android.view.WindowManager.LayoutParams.*;
Expand All @@ -26,6 +28,25 @@
public class WindowUtil {

public static void show(Activity activity, View dialogView, boolean touchEnable) {
try {
if (activity.getWindow().getDecorView().isAttachedToWindow()) {
showNow(activity, dialogView, touchEnable);
} else {
activity.getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
showNow(activity, dialogView, touchEnable);
}
});
}
} catch (Exception e) {
if (activity != null && !activity.isDestroyed()) {
showNow(activity, dialogView, touchEnable);
}
}
}

private static void showNow(Activity activity, View dialogView, boolean touchEnable) {
WindowManager manager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();

Expand All @@ -38,12 +59,24 @@ public static void show(Activity activity, View dialogView, boolean touchEnable)
FLAG_LAYOUT_IN_SCREEN
;
if (!touchEnable) {
layoutParams.flags = layoutParams.flags | FLAG_NOT_FOCUSABLE;
dialogView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
for (BaseDialog baseDialog : BaseDialog.getRunningDialogList()) {
if (!(baseDialog instanceof PopTip) && !baseDialog.isCancelable() && baseDialog.getActivity() == activity) {
if (baseDialog.getDialogView() == null) {
return false;
}
return baseDialog.getDialogView().dispatchTouchEvent(event);
}
}
return activity.dispatchTouchEvent(event);
}
});
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
layoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}

manager.addView(dialogView, layoutParams);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ static boolean isDebug() {
return DEBUGMODE && DialogX.DEBUGMODE;
}

public static void log(Object o) {
private static void log(Object o) {
if (isDebug()) Log.i(">>>", o.toString());
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/kongzue/dialogxdemo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class App extends BaseApp<App> {
@Override
public void init() {
DialogX.init(this);
DialogX.implIMPLMode= DialogX.IMPL_MODE.VIEW;
DialogX.implIMPLMode= DialogX.IMPL_MODE.WINDOW;
DialogX.useHaptic = false;
DialogX.globalStyle = new MaterialStyle() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public void onClick(View v) {
@Override
public boolean onClick(PopTip popTip, View v) {
//点击“撤回”按钮回调
toastS("邮件已撤回");
toast("邮件已撤回");
return false;
}
}).showLong();
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

BUILD_VERSION=0.0.40.beta3
BUILD_VERSION=0.0.40.beta4
BUILD_VERSION_INT=39

0 comments on commit 1e5f5a2

Please sign in to comment.