kongzue 3 rokov pred
rodič
commit
8103602f21

+ 17 - 0
.idea/deploymentTargetDropDown.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="deploymentTargetDropDown">
+    <runningDeviceTargetSelectedWithDropDown>
+      <Target>
+        <type value="RUNNING_DEVICE_TARGET" />
+        <deviceKey>
+          <Key>
+            <type value="SERIAL_NUMBER" />
+            <value value="0A201FDD4001T7" />
+          </Key>
+        </deviceKey>
+      </Target>
+    </runningDeviceTargetSelectedWithDropDown>
+    <timeTargetWasSelectedWithDropDown value="2022-07-13T10:01:37.681006500Z" />
+  </component>
+</project>

+ 9 - 2
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopMenu.java

@@ -91,7 +91,8 @@ public class PopMenu extends BaseDialog {
     }
     
     public PopMenu(List<CharSequence> menuList) {
-        this.menuList = menuList;
+        this.menuList = new ArrayList<>();
+        this.menuList.addAll(menuList);
     }
     
     public PopMenu(CharSequence[] menuList) {
@@ -557,7 +558,12 @@ public class PopMenu extends BaseDialog {
             if (listMenu.getAdapter() == null) {
                 listMenu.setAdapter(menuListAdapter);
             } else {
-                menuListAdapter.notifyDataSetChanged();
+                if (menuListAdapter.getMenuList() != menuList) {
+                    menuListAdapter = new PopMenuArrayAdapter(me, getTopActivity(), menuList);
+                    listMenu.setAdapter(menuListAdapter);
+                } else {
+                    menuListAdapter.notifyDataSetChanged();
+                }
             }
             
             if (bkgInterceptTouch) {
@@ -704,6 +710,7 @@ public class PopMenu extends BaseDialog {
     
     public PopMenu setMenuList(List<CharSequence> menuList) {
         this.menuList = menuList;
+        refreshUI();
         return this;
     }
     

+ 4 - 0
DialogX/src/main/java/com/kongzue/dialogx/util/PopMenuArrayAdapter.java

@@ -41,6 +41,10 @@ public class PopMenuArrayAdapter extends BaseAdapter {
         mInflater = LayoutInflater.from(context);
     }
     
+    public List<CharSequence> getMenuList() {
+        return menuList;
+    }
+    
     @Override
     public int getCount() {
         if (menuList == null) {

+ 5 - 1
DialogX/src/main/java/com/kongzue/dialogx/util/WindowUtil.java

@@ -7,6 +7,7 @@ import android.os.Build;
 import android.view.Gravity;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.WindowManager;
 import android.widget.FrameLayout;
 
@@ -45,6 +46,9 @@ public class WindowUtil {
     
     private static void showNow(Activity activity, View dialogView, boolean touchEnable) {
         FrameLayout rootLayout = new FrameLayout(activity);
+        if (dialogView.getParent() != null) {
+            ((ViewGroup) dialogView.getParent()).removeView(dialogView);
+        }
         rootLayout.addView(dialogView, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
         WindowManager manager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
         WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
@@ -63,7 +67,7 @@ public class WindowUtil {
                 public boolean onTouch(View v, MotionEvent event) {
                     for (int i = BaseDialog.getRunningDialogList().size() - 1; i >= 0; i--) {
                         BaseDialog baseDialog = BaseDialog.getRunningDialogList().get(i);
-                        if (!(baseDialog instanceof PopTip)  && baseDialog.getOwnActivity() == activity) {
+                        if (!(baseDialog instanceof PopTip) && baseDialog.getOwnActivity() == activity) {
                             if (baseDialog.getDialogView() == null) {
                                 return false;
                             }

+ 11 - 4
DialogX/src/main/java/com/kongzue/dialogx/util/views/PopMenuListView.java

@@ -2,6 +2,7 @@ package com.kongzue.dialogx.util.views;
 
 import android.content.Context;
 import android.util.AttributeSet;
+import android.widget.BaseAdapter;
 import android.widget.ListView;
 
 /**
@@ -27,10 +28,6 @@ public class PopMenuListView extends ListView {
         super(context, attrs, defStyleAttr);
     }
     
-    public PopMenuListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
-        super(context, attrs, defStyleAttr, defStyleRes);
-    }
-    
     public boolean isCanScroll() {
         boolean canScroll;
         int count = getCount();
@@ -56,4 +53,14 @@ public class PopMenuListView extends ListView {
         }
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }
+    
+    @Override
+    protected void layoutChildren() {
+        try {
+            super.layoutChildren();
+        } catch (IllegalStateException e) {
+            ((BaseAdapter) getAdapter()).notifyDataSetChanged();
+            super.layoutChildren();
+        }
+    }
 }

+ 49 - 18
app/src/main/java/com/kongzue/dialogxdemo/activity/MainActivity.java

@@ -333,24 +333,55 @@ public class MainActivity extends BaseActivity {
         btnContextMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                PopMenu.show(new String[]{"添加", "编辑", "删除", "分享"})
-                        .setOnIconChangeCallBack(new OnIconChangeCallBack<PopMenu>(true) {
-                            @Override
-                            public int getIcon(PopMenu dialog, int index, String menuText) {
-                                switch (index) {
-                                    case 0:
-                                        return R.mipmap.img_dialogx_demo_add;
-                                    case 1:
-                                        return R.mipmap.img_dialogx_demo_edit;
-                                    case 2:
-                                        return R.mipmap.img_dialogx_demo_delete;
-                                    case 3:
-                                        return R.mipmap.img_dialogx_demo_share;
-                                    default:
-                                        return 0;
-                                }
-                            }
-                        });
+//                PopMenu.show(new String[]{"添加", "编辑", "删除", "分享"})
+//                        .setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
+//                            @Override
+//                            public boolean onClick(PopMenu dialog, CharSequence text, int index) {
+//                                if (index==0){
+//                                    dialog.setMenuList(new String[]{"A","B","C"});
+//                                    return true;
+//                                }
+//                                return false;
+//                            }
+//                        })
+//                        .setOnIconChangeCallBack(new OnIconChangeCallBack<PopMenu>(true) {
+//                            @Override
+//                            public int getIcon(PopMenu dialog, int index, String menuText) {
+//                                switch (menuText) {
+//                                    case "添加":
+//                                        return R.mipmap.img_dialogx_demo_add;
+//                                    case "编辑":
+//                                        return R.mipmap.img_dialogx_demo_edit;
+//                                    case "删除":
+//                                        return R.mipmap.img_dialogx_demo_delete;
+//                                    case "分享":
+//                                        return R.mipmap.img_dialogx_demo_share;
+//                                    default:
+//                                        return 0;
+//                                }
+//                            }
+//                        });
+                List<CharSequence> items = new ArrayList();
+                items.add("选项1");
+                items.add("选项2");
+                items.add("选项3");
+                PopMenu.show(items);
+    
+                //会造成闪退的代码
+                new Thread() {
+                    @Override
+                    public void run() {
+                        try {
+                            sleep(1000);
+                        } catch (InterruptedException e) {
+                            e.printStackTrace();
+                        }
+                        for (int i = 0; i < 10000; i++) {
+                            items.clear();
+                            items.add("选项4");
+                        }
+                    }
+                }.start();
             }
         });
         

+ 1 - 1
gradle.properties

@@ -19,5 +19,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.45.beta23
+BUILD_VERSION=0.0.45.beta24
 BUILD_VERSION_INT=44