kongzue 4 éve
szülő
commit
f2cfc883d8

+ 34 - 4
DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java

@@ -22,6 +22,8 @@ import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
 import com.kongzue.dialogx.interfaces.DialogXStyle;
 import com.kongzue.dialogx.interfaces.OnBackPressedListener;
 import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
+import com.kongzue.dialogx.interfaces.OnInputDialogButtonClickListener;
 import com.kongzue.dialogx.interfaces.OnMenuItemClickListener;
 import com.kongzue.dialogx.util.BottomDialogTouchEventInterceptor;
 import com.kongzue.dialogx.util.views.BlurView;
@@ -42,6 +44,7 @@ public class BottomDialog extends BaseDialog {
     protected CharSequence message;
     protected CharSequence cancelText = "取消";
     protected boolean allowInterceptTouch = true;
+    protected OnDialogButtonClickListener cancelButtonClickListener;
     
     /**
      * 此值用于,当禁用滑动时(style.overrideBottomDialogRes.touchSlide = false时)的最大显示高度。
@@ -220,7 +223,13 @@ public class BottomDialog extends BaseDialog {
                 btnCancel.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
-                        dismiss();
+                        if (cancelButtonClickListener != null) {
+                            if (!cancelButtonClickListener.onClick(me, v)) {
+                                dismiss();
+                            }
+                        } else {
+                            dismiss();
+                        }
                     }
                 });
             }
@@ -326,7 +335,7 @@ public class BottomDialog extends BaseDialog {
                 }
             }
             
-            if (isAllowInterceptTouch()) {
+            if (isAllowInterceptTouch() && cancelable) {
                 if (imgTab != null) imgTab.setVisibility(View.VISIBLE);
             } else {
                 if (imgTab != null) imgTab.setVisibility(View.GONE);
@@ -458,12 +467,24 @@ public class BottomDialog extends BaseDialog {
         return this;
     }
     
-    public CharSequence getCancelText() {
+    public CharSequence getCancelButton() {
         return cancelText;
     }
     
-    public BottomDialog setCancelText(CharSequence cancelText) {
+    public BottomDialog setCancelButton(CharSequence cancelText) {
+        this.cancelText = cancelText;
+        refreshUI();
+        return this;
+    }
+    
+    public BottomDialog setCancelButton(OnDialogButtonClickListener cancelButtonClickListener) {
+        this.cancelButtonClickListener = cancelButtonClickListener;
+        return this;
+    }
+    
+    public BottomDialog setCancelButton(CharSequence cancelText, OnDialogButtonClickListener cancelButtonClickListener) {
         this.cancelText = cancelText;
+        this.cancelButtonClickListener = cancelButtonClickListener;
         refreshUI();
         return this;
     }
@@ -503,4 +524,13 @@ public class BottomDialog extends BaseDialog {
         this.dialogImpl = dialogImpl;
         return this;
     }
+    
+    public OnDialogButtonClickListener getCancelButtonClickListener() {
+        return cancelButtonClickListener;
+    }
+    
+    public BottomDialog setCancelButtonClickListener(OnDialogButtonClickListener cancelButtonClickListener) {
+        this.cancelButtonClickListener = cancelButtonClickListener;
+        return this;
+    }
 }

+ 24 - 2
DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomMenu.java

@@ -12,6 +12,7 @@ import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
 import com.kongzue.dialogx.interfaces.DialogXStyle;
 import com.kongzue.dialogx.interfaces.OnBackPressedListener;
 import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
 import com.kongzue.dialogx.interfaces.OnIconChangeCallBack;
 import com.kongzue.dialogx.interfaces.OnMenuItemClickListener;
 import com.kongzue.dialogx.util.NormalMenuArrayAdapter;
@@ -248,16 +249,28 @@ public class BottomMenu extends BottomDialog {
         return this;
     }
     
-    public CharSequence getCancelText() {
+    public CharSequence getCancelButton() {
         return cancelText;
     }
     
-    public BottomMenu setCancelText(CharSequence cancelText) {
+    public BottomMenu setCancelButton(CharSequence cancelText) {
         this.cancelText = cancelText;
         refreshUI();
         return this;
     }
     
+    public BottomMenu setCancelButton(OnDialogButtonClickListener cancelButtonClickListener) {
+        this.cancelButtonClickListener = cancelButtonClickListener;
+        return this;
+    }
+    
+    public BottomMenu setCancelButton(CharSequence cancelText,OnDialogButtonClickListener cancelButtonClickListener) {
+        this.cancelText = cancelText;
+        this.cancelButtonClickListener = cancelButtonClickListener;
+        refreshUI();
+        return this;
+    }
+    
     public BottomMenu setCustomView(OnBindView<BottomDialog> onBindView) {
         this.onBindView = onBindView;
         refreshUI();
@@ -316,4 +329,13 @@ public class BottomMenu extends BottomDialog {
         this.menuListAdapter = menuListAdapter;
         return this;
     }
+    
+    public OnDialogButtonClickListener getCancelButtonClickListener() {
+        return cancelButtonClickListener;
+    }
+    
+    public BottomMenu setCancelButtonClickListener(OnDialogButtonClickListener cancelButtonClickListener) {
+        this.cancelButtonClickListener = cancelButtonClickListener;
+        return this;
+    }
 }

+ 1 - 1
DialogX/src/main/java/com/kongzue/dialogx/util/views/BlurView.java

@@ -435,7 +435,7 @@ public class BlurView extends View {
         }.start();
     }
     
-    private static boolean DEBUGMODE = true;
+    private static boolean DEBUGMODE = false;
     
     static boolean isDebug() {
         return DEBUGMODE && DialogX.DEBUGMODE;

+ 11 - 4
app/src/main/java/com/kongzue/dialogxdemo/MainActivity.java

@@ -252,7 +252,6 @@ public class MainActivity extends BaseActivity {
                 WaitDialog.show("假装连接...").setOnBackPressedListener(new OnBackPressedListener() {
                     @Override
                     public boolean onBackPressed() {
-                        toast("点击返回");
                         MessageDialog.show("正在进行", "是否取消?", "是", "否").setOkButton(new OnDialogButtonClickListener() {
                             @Override
                             public boolean onClick(BaseDialog baseDialog, View v) {
@@ -294,7 +293,8 @@ public class MainActivity extends BaseActivity {
         btnBottomDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                new BottomDialog("标题", "这里是对话框内容。\n你可以向下滑动来关闭这个对话框。\n底部对话框也支持自定义布局扩展使用方式。",
+                String s = rdoMaterial.isChecked() ? "你可以向下滑动来关闭这个对话框" : "你可以点击空白区域或返回键来关闭这个对话框";
+                new BottomDialog("标题", "这里是对话框内容。\n" + s + "。\n底部对话框也支持自定义布局扩展使用方式。",
                         new OnBindView<BottomDialog>(R.layout.layout_custom_view) {
                             @Override
                             public void onBind(BottomDialog dialog, View v) {
@@ -353,8 +353,15 @@ public class MainActivity extends BaseActivity {
                             });
                 }
                 if (rdoIos.isChecked()) {
-                    BottomMenu.show(new String[]{"新标签页中打开","稍后阅读","复制链接网址"})
-                            .setMessage("http://www.kongzue.com/DialogX");
+                    BottomMenu.show(new String[]{"新标签页中打开", "稍后阅读", "复制链接网址"})
+                            .setMessage("http://www.kongzue.com/DialogX")
+                            .setOnMenuItemClickListener(new OnMenuItemClickListener<BottomMenu>() {
+                                @Override
+                                public boolean onClick(BottomMenu dialog, CharSequence text, int index) {
+                                    toast(text);
+                                    return false;
+                                }
+                            });
                 }
             }
         });