From 19d9bc629dc9c69d916198c15c21c1bddd28d5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 11:08:39 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8Ddialog?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=A8=A1=E5=BC=8F=E8=AE=BE=E7=BD=AE=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E9=94=AE=E4=B8=8D=E5=85=B3=E9=97=AD=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 4 +-- .../java/com/lxj/xpopupdemo/MainAbility.java | 8 ----- .../stackLayout/QuickStartDemo.java | 7 ++-- .../com/lxj/xpopup/core/BasePopupView.java | 33 ++++++------------- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/changelog.md b/changelog.md index 79a6cdc..47564aa 100644 --- a/changelog.md +++ b/changelog.md @@ -20,7 +20,7 @@ ## 1.0.3 初始移植版本 -##功能点 +## 功能点 已支持部分: 1.Center类型,就是在中间弹出的弹窗,比如确认和取消弹窗,Loading弹窗从页面底部弹出,比如从底部弹出的分享窗体,知乎的从底部弹出的评论列表添加绑定的控件在某一页时需要执行的动画 @@ -45,7 +45,7 @@ 11.设置是否自动打开输入法(暂时仅Dialog模式支持) -12.设置按下返回键、点击弹窗外面是否关闭弹窗(暂时仅Component模式支持) +12.设置按下返回键、点击弹窗外面是否关闭弹窗 13.设置是否半透明背景(暂时仅Component模式支持) diff --git a/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java b/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java index ffaca6a..2e6f68a 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java @@ -1,7 +1,6 @@ package com.lxj.xpopupdemo; import com.lxj.xpopup.XPopup; -import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.impl.LoadingPopupView; import com.lxj.xpopup.util.ElementUtil; import com.lxj.xpopup.util.XPermission; @@ -19,7 +18,6 @@ import ohos.agp.components.PageSlider; import ohos.agp.components.PageSliderProvider; import ohos.agp.components.RadioButton; import ohos.agp.components.RadioContainer; -import ohos.multimodalinput.event.KeyEvent; import java.util.ArrayList; @@ -133,10 +131,4 @@ public class MainAbility extends Ability { XPermission.onRequestPermissionsFromUserResult(this, requestCode, permissions, grantResults); } - // 如需用到Component模式实现的弹窗,则需要在Ability页面像下面这样重写此方法 - @Override - public boolean onKeyDown(int keyCode, KeyEvent keyEvent) { - return BasePopupView.onKeyEvent(keyCode); - } - } diff --git a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java index d049b5b..a5a7977 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java @@ -22,7 +22,6 @@ import com.lxj.xpopupdemo.custom.PagerDrawerPopup; import com.lxj.xpopupdemo.custom.QQMsgPopup; import com.lxj.xpopupdemo.custom.ZhihuCommentPopup; import ohos.agp.components.Component; -import ohos.agp.components.ComponentContainer; import ohos.app.Context; import ohos.hiviewdfx.HiLog; import ohos.hiviewdfx.HiLogLabel; @@ -102,7 +101,7 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked .hasStatusBar(false) // 暂未实现是否显示状态栏 .hasNavigationBar(false) // 暂未实现是否显示导航栏 .hasBlurBg(true) // 暂未实现高斯模糊背景 - .dismissOnBackPressed(true) // 点击返回键是否消失,暂时仅Component模式支持不消失 + .dismissOnBackPressed(false) // 点击返回键是否消失 .dismissOnTouchOutside(true) // 点击外部是否消失 .setPopupCallback(new DemoXPopupListener()) .isComponentMode(true, content) // Component实现模式 @@ -119,6 +118,7 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked break; case ResourceTable.Id_btnBindLayout: // 复用项目中已有布局,使用XPopup已有的交互能力 new XPopup.Builder(getContext()) + .setPopupCallback(new DemoXPopupListener()) .asConfirm("复用项目已有布局", "您可以复用项目已有布局,来使用XPopup强大的交互能力和逻辑封装,弹窗的布局完全由你自己控制。\n" + "注意:你自己的布局必须提供一些控件Id,否则XPopup找不到控件。", "关闭", "XPopup牛逼", @@ -135,6 +135,7 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked .hasStatusBarShadow(false) // 暂无实现 .autoOpenSoftInput(true) .isDarkTheme(true) + .setPopupCallback(new DemoXPopupListener()) .asInputConfirm("我是标题", null, null, "我是默认Hint文字", new OnInputConfirmListener() { @Override @@ -337,7 +338,7 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked @Override public boolean onBackPressed(BasePopupView popupView) { loge("tag", "拦截的返回按键,按返回键XPopup不会关闭了"); - ToastUtil.showToast(getContext(), "onBackPressed返回true,拦截了返回按键,按返回键XPopup不会关闭了(暂时仅Component模式支持)"); + ToastUtil.showToast(getContext(), "onBackPressed返回true,拦截了返回按键,按返回键XPopup不会关闭了"); return true; } diff --git a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java index 3098ce0..77e9201 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java @@ -52,7 +52,6 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan private int touchSlop = 24; // 触发移动事件的最小距离 public PopupStatus popupStatus = PopupStatus.Dismiss; protected boolean isCreated = false; - protected static BasePopupView basePopupView; private EventHandler handler = new EventHandler(EventRunner.getMainEventRunner()); public BasePopupView(Context context, PopupInfo popupInfo) { @@ -80,7 +79,6 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan addComponent(contentView); setTouchEventListener(this); setBindStateChangedListener(this); - basePopupView = this; } /** @@ -119,7 +117,6 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan if (popupInfo.xPopupCallback != null) { popupInfo.xPopupCallback.beforeShow(BasePopupView.this); } - focusAndProcessBackPress(); // 由于Attach弹窗有个位置设置过程,需要在位置设置完毕自己开启动画 if (!(BasePopupView.this instanceof AttachPopupView) && !(BasePopupView.this instanceof PositionPopupView)) { @@ -129,6 +126,8 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan doAfterShow(); } + // 必须在控件VISABLE之后再设置onKey监听才能生效 + focusAndProcessBackPress(); } }; @@ -267,6 +266,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan XPopupUtils.findAllEditText(list, (ComponentContainer) getPopupContentView()); for (int i = 0; i < list.size(); i++) { final TextField et = list.get(i); + // 给输入框设置返回按键监听无效,暂未找到原因 et.setKeyEventListener(new BackPressListener()); if (i == 0 && popupInfo.autoFocusEditText) { et.setFocusable(FOCUS_ENABLE); @@ -317,29 +317,19 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan class BackPressListener implements KeyEventListener { @Override public boolean onKeyEvent(Component component, KeyEvent event) { - if (event.getKeyCode() == KeyEvent.KEY_BACK && popupInfo != null) { - if (popupInfo.isDismissOnBackPressed && - (popupInfo.xPopupCallback == null || !popupInfo.xPopupCallback.onBackPressed(BasePopupView.this))) { - dismissOrHideSoftInput(); + if (event.isKeyDown()) { + if (event.getKeyCode() == KeyEvent.KEY_BACK && popupInfo != null) { + if (popupInfo.isDismissOnBackPressed && + (popupInfo.xPopupCallback == null || !popupInfo.xPopupCallback.onBackPressed(BasePopupView.this))) { + dismissOrHideSoftInput(); + } + return true; } - return true; } return false; } } - public static boolean onKeyEvent(int keyCode) { - if (basePopupView != null && basePopupView.popupInfo.isComponentMode) { - if (keyCode == KeyEvent.KEY_BACK && basePopupView.popupInfo != null) { - if (basePopupView.popupInfo.isDismissOnBackPressed && - (basePopupView.popupInfo.xPopupCallback == null || !basePopupView.popupInfo.xPopupCallback.onBackPressed(basePopupView))) { - basePopupView.dismissOrHideSoftInput(); - } - } - } - return basePopupView.popupStatus != PopupStatus.Dismiss; - } - /** * 根据PopupInfo的popupAnimation字段来生成对应的内置的动画执行器 * @@ -689,9 +679,6 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan blurAnimator.decorBitmap = null; } } - if (basePopupView != null) { - basePopupView = null; - } } @Override -- Gitee From a7e1cd26a07db883024591e66cb77fb5bb5a1949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 11:16:34 +0800 Subject: [PATCH 2/9] =?UTF-8?q?perf=EF=BC=9A=E5=A2=9E=E5=8A=A0NPE=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lxj/xpopupdemo/DemoAbility.java | 33 +++++++++++-------- .../resources/base/layout/ability_demo.xml | 1 + .../resources/base/layout/adapter_image.xml | 1 + .../com/lxj/xpopup/core/BasePopupView.java | 6 ++-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/entry/src/main/java/com/lxj/xpopupdemo/DemoAbility.java b/entry/src/main/java/com/lxj/xpopupdemo/DemoAbility.java index b883fe5..dc90f5b 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/DemoAbility.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/DemoAbility.java @@ -20,6 +20,8 @@ import ohos.agp.components.TextField; public class DemoAbility extends Ability { TextField editText; + Component content; + BasePopupView attachPopup; @Override public void onStart(Intent intent) { @@ -28,6 +30,7 @@ public class DemoAbility extends Ability { // 修改状态栏的颜色 StatusBarUtils.setStatusBarColor(this, ElementUtil.getColor(this, ResourceTable.Color_colorBar)); editText = (TextField) findComponentById(ResourceTable.Id_et); + content = findComponentById(ResourceTable.Id_content); findComponentById(ResourceTable.Id_text).setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { @@ -35,26 +38,28 @@ public class DemoAbility extends Ability { } }); showMultiPopup(); + attachPopup = new XPopup.Builder(DemoAbility.this) + .atView(editText) + .isRequestFocus(false) // 要设置这个,否则Activity内的输入框会无法获取焦点 + .hasShadowBg(false) + .positionByWindowCenter(true) + .isComponentMode(true, content) + .popupAnimation(PopupAnimation.ScaleAlphaFromCenter) + .asAttachList(new String[]{"联想到的内容 - 1", "联想到的内容 - 2", "联想到的内容 - 333"}, null, new OnSelectListener() { + @Override + public void onSelect(int position, String text) { + ToastUtil.showToast(DemoAbility.this, text); + } + }); editText.addTextObserver(new Text.TextObserver() { @Override public void onTextUpdated(String phoneNumber, int start, int before, int count) { - final BasePopupView popupView = new XPopup.Builder(DemoAbility.this) - .atView(editText) - .isRequestFocus(false) // 要设置这个,否则Activity内的输入框会无法获取焦点 - .hasShadowBg(false) - .popupAnimation(PopupAnimation.ScaleAlphaFromCenter) - .asAttachList(new String[]{"联想到的内容 - 1", "联想到的内容 - 2", "联想到的内容 - 333"}, null, new OnSelectListener() { - @Override - public void onSelect(int position, String text) { - ToastUtil.showToast(DemoAbility.this, text); - } - }); if (phoneNumber.isEmpty()) { - popupView.dismiss(); + attachPopup.dismiss(); return; } - if (popupView.isDismiss()) { - popupView.show(); + if (attachPopup.isDismiss()) { + attachPopup.show(); } } }); diff --git a/entry/src/main/resources/base/layout/ability_demo.xml b/entry/src/main/resources/base/layout/ability_demo.xml index ab5f84a..9e12361 100644 --- a/entry/src/main/resources/base/layout/ability_demo.xml +++ b/entry/src/main/resources/base/layout/ability_demo.xml @@ -1,6 +1,7 @@ diff --git a/entry/src/main/resources/base/layout/adapter_image.xml b/entry/src/main/resources/base/layout/adapter_image.xml index bdfd5e3..f35891f 100644 --- a/entry/src/main/resources/base/layout/adapter_image.xml +++ b/entry/src/main/resources/base/layout/adapter_image.xml @@ -9,6 +9,7 @@ ohos:id="$+id:image" ohos:height="120vp" ohos:width="match_parent" + ohos:background_element="#eee" ohos:layout_alignment="center" ohos:scale_mode="zoom_center"/> \ No newline at end of file diff --git a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java index 77e9201..cc27870 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java @@ -107,7 +107,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan handler.postTask(initTask, 10); } - private Runnable initTask = new Runnable() { + private final Runnable initTask = new Runnable() { @Override public void run() { if (getHostWindow() == null) { @@ -179,7 +179,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan } public BasePopupView show() { - if (popupStatus == PopupStatus.Showing) { + if (popupStatus == PopupStatus.Showing || popupStatus == PopupStatus.Dismiss) { return this; } popupStatus = PopupStatus.Showing; @@ -190,7 +190,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan return this; } - private Runnable attachTask = new Runnable() { + private final Runnable attachTask = new Runnable() { @Override public void run() { // 1. add PopupView to its dialog. -- Gitee From ec2cbe8c1a6858dd62866c5b28495dd1d305f58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 14:47:32 +0800 Subject: [PATCH 3/9] =?UTF-8?q?perf=EF=BC=9A=E5=85=BC=E5=AE=B9=E8=A7=A3?= =?UTF-8?q?=E5=86=B3Component=E6=A8=A1=E5=BC=8F=E5=BC=B9=E7=AA=97=E5=9C=A8?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8=E4=B8=8A=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=88=E6=8C=89=E8=BF=94=E5=9B=9E=E9=94=AE?= =?UTF-8?q?=E5=81=B6=E7=8E=B0=E9=A1=B5=E9=9D=A2=E5=85=B3=E9=97=AD=EF=BC=89?= =?UTF-8?q?=EF=BC=8CAttach=E5=BC=B9=E7=AA=97=E5=9C=A8Component=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E4=BD=BF=E7=94=A8=E5=85=A8=E9=80=8F=E6=98=8E?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=98=B4?= =?UTF-8?q?=E5=BD=B1=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lxj/xpopupdemo/MainAbility.java | 9 ++ .../xpopupdemo/custom/CustomAttachPopup.java | 1 + .../stackLayout/QuickStartDemo.java | 7 +- .../com/lxj/xpopup/core/AttachPopupView.java | 20 ++-- .../com/lxj/xpopup/core/BasePopupView.java | 31 +++++- .../com/lxj/xpopup/widget/ShadowLayout.java | 104 ++++++++++++++++++ 6 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 library/src/main/java/com/lxj/xpopup/widget/ShadowLayout.java diff --git a/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java b/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java index 2e6f68a..4355b85 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java @@ -1,6 +1,7 @@ package com.lxj.xpopupdemo; import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.impl.LoadingPopupView; import com.lxj.xpopup.util.ElementUtil; import com.lxj.xpopup.util.XPermission; @@ -18,6 +19,7 @@ import ohos.agp.components.PageSlider; import ohos.agp.components.PageSliderProvider; import ohos.agp.components.RadioButton; import ohos.agp.components.RadioContainer; +import ohos.multimodalinput.event.KeyEvent; import java.util.ArrayList; @@ -131,4 +133,11 @@ public class MainAbility extends Ability { XPermission.onRequestPermissionsFromUserResult(this, requestCode, permissions, grantResults); } + // 1.如需用到Component模式实现的弹窗;2.如果是在模拟器上运行。 + // 则需要在Ability页面像下面这样重写此方法 + @Override + public boolean onKeyDown(int keyCode, KeyEvent keyEvent) { + return BasePopupView.onKeyEvent(keyCode); + } + } diff --git a/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup.java b/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup.java index 0ae75b4..8f1a0e8 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup.java @@ -37,6 +37,7 @@ public class CustomAttachPopup extends HorizontalAttachPopupView { dismiss(); } }); + shadowLayout.setRadius(0); } // 设置状态栏的高度,用以修正自定义位置弹窗的高度 diff --git a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java index a5a7977..947c49f 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java @@ -98,12 +98,8 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked case ResourceTable.Id_btnShowConfirm: // 带确认和取消按钮的弹窗 if (popupView == null) { // 复用弹窗,暂时仅Component模式支持 popupView = new XPopup.Builder(getContext()) - .hasStatusBar(false) // 暂未实现是否显示状态栏 - .hasNavigationBar(false) // 暂未实现是否显示导航栏 - .hasBlurBg(true) // 暂未实现高斯模糊背景 .dismissOnBackPressed(false) // 点击返回键是否消失 .dismissOnTouchOutside(true) // 点击外部是否消失 - .setPopupCallback(new DemoXPopupListener()) .isComponentMode(true, content) // Component实现模式 .asConfirm("哈哈", "床前明月光,疑是地上霜;举头望明月,低头思故乡。", "取消", "确定", @@ -239,6 +235,7 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked .hasShadowBg(false) .isDestroyOnDismiss(true) // 对于只使用一次的弹窗,推荐设置这个 .atView(component) // 依附于所点击的View,内部会自动判断在上方或者下方显示 + .isComponentMode(true, content) // Component实现模式 .asAttachList(new String[]{"分享", "编辑", "不带icon不带icon", "分享分享分享"}, new int[]{ResourceTable.Media_icon, ResourceTable.Media_icon}, new OnSelectListener() { @@ -252,6 +249,7 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked new XPopup.Builder(getContext()) .hasShadowBg(false) // 去掉半透明背景 .atView(component) + .isComponentMode(true, content) // Component实现模式 .asCustom(new CustomAttachPopup(getContext())) .show(); break; @@ -260,6 +258,7 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked .isDestroyOnDismiss(true) // 对于只使用一次的弹窗,推荐设置这个 .atView(component) .hasShadowBg(false) // 去掉半透明背景 + .isComponentMode(true, content) // Component实现模式 .asCustom(new CustomAttachPopup2(getContext())).show(); break; case ResourceTable.Id_btnShowDrawerLeft: // 像DrawerLayout一样的Drawer弹窗 diff --git a/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java b/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java index 5b713b2..392a72d 100644 --- a/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java @@ -9,10 +9,10 @@ import com.lxj.xpopup.enums.PopupPosition; import com.lxj.xpopup.util.ElementUtil; import com.lxj.xpopup.util.XPopupUtils; import com.lxj.xpopup.widget.PartShadowContainer; +import com.lxj.xpopup.widget.ShadowLayout; import ohos.agp.components.Component; import ohos.agp.components.ComponentContainer; import ohos.agp.components.LayoutScatter; -import ohos.agp.components.element.Element; import ohos.agp.utils.Rect; import ohos.app.Context; @@ -34,7 +34,15 @@ public abstract class AttachPopupView extends BasePopupView { protected void addInnerContent() { Component contentView = LayoutScatter.getInstance(getContext()).parse(getImplLayoutId(), attachPopupContainer, false); - attachPopupContainer.addComponent(contentView); + if (popupInfo.isComponentMode && !popupInfo.hasShadowBg) { + shadowLayout = new ShadowLayout(getContext()); + shadowLayout.setLayoutConfig(new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_CONTENT, ComponentContainer.LayoutConfig.MATCH_CONTENT)); + shadowLayout.setPadding(15, 15, 15, 15); + shadowLayout.addComponent(contentView); + attachPopupContainer.addComponent(shadowLayout); + } else { + attachPopupContainer.addComponent(contentView); + } } @Override @@ -76,14 +84,8 @@ public abstract class AttachPopupView extends BasePopupView { if (getPopupImplView().getBackgroundElement() == null) { defaultOffsetX -= bgDrawableMargin; defaultOffsetY -= bgDrawableMargin; - attachPopupContainer.setBackground(XPopupUtils.createDrawable((popupInfo.isDarkTheme ? ElementUtil.getColor(getContext(), ResourceTable.Color__xpopup_bg_dark_color) + getPopupImplView().setBackground(XPopupUtils.createDrawable((popupInfo.isDarkTheme ? ElementUtil.getColor(getContext(), ResourceTable.Color__xpopup_bg_dark_color) : ElementUtil.getColor(getContext(), ResourceTable.Color__xpopup_light_color)), popupInfo.borderRadius)); - } else { - Element backgroundElement = getPopupImplView().getBackgroundElement(); - if (backgroundElement != null) { - attachPopupContainer.setBackground(backgroundElement); - getPopupImplView().setBackground(null); - } } } } diff --git a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java index cc27870..5d4eea5 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java @@ -16,6 +16,7 @@ import com.lxj.xpopup.util.EventUtil; import com.lxj.xpopup.util.KeyboardUtils; import com.lxj.xpopup.util.LogUtil; import com.lxj.xpopup.util.XPopupUtils; +import com.lxj.xpopup.widget.ShadowLayout; import ohos.aafwk.ability.Ability; import ohos.aafwk.ability.AbilityPackage; import ohos.aafwk.ability.Lifecycle; @@ -52,7 +53,9 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan private int touchSlop = 24; // 触发移动事件的最小距离 public PopupStatus popupStatus = PopupStatus.Dismiss; protected boolean isCreated = false; + protected ShadowLayout shadowLayout; private EventHandler handler = new EventHandler(EventRunner.getMainEventRunner()); + protected static BasePopupView basePopupView; public BasePopupView(Context context, PopupInfo popupInfo) { super(context); @@ -79,6 +82,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan addComponent(contentView); setTouchEventListener(this); setBindStateChangedListener(this); + basePopupView = this; } /** @@ -179,7 +183,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan } public BasePopupView show() { - if (popupStatus == PopupStatus.Showing || popupStatus == PopupStatus.Dismiss) { + if (popupStatus == PopupStatus.Showing || popupStatus == PopupStatus.Dismissing) { return this; } popupStatus = PopupStatus.Showing; @@ -220,6 +224,9 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan dialog = new FullScreenDialog(getContext()) .setContent(this); } + if (shadowLayout != null) { + shadowLayout.invalidate(); // 复用弹窗时,需要再次调用绘制才有阴影 + } dialog.show(); } if (popupInfo == null) { @@ -330,6 +337,18 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan } } + public static boolean onKeyEvent(int keyCode) { + if (basePopupView != null && basePopupView.popupInfo.isComponentMode) { + if (keyCode == KeyEvent.KEY_BACK && basePopupView.popupInfo != null) { + if (basePopupView.popupInfo.isDismissOnBackPressed && + (basePopupView.popupInfo.xPopupCallback == null || !basePopupView.popupInfo.xPopupCallback.onBackPressed(basePopupView))) { + basePopupView.dismissOrHideSoftInput(); + } + } + } + return basePopupView.popupStatus != PopupStatus.Dismiss; + } + /** * 根据PopupInfo的popupAnimation字段来生成对应的内置的动画执行器 * @@ -469,7 +488,12 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan } public Component getPopupImplView() { - return ((ComponentContainer) getPopupContentView()).getComponentAt(0); + Component imlView = ((ComponentContainer) getPopupContentView()).getComponentAt(0); + if (imlView instanceof ShadowLayout) { + return ((ShadowLayout) imlView).getComponentAt(0); + } else { + return imlView; + } } public int getAnimationDuration() { @@ -679,6 +703,9 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan blurAnimator.decorBitmap = null; } } + if (basePopupView != null) { + basePopupView = null; + } } @Override diff --git a/library/src/main/java/com/lxj/xpopup/widget/ShadowLayout.java b/library/src/main/java/com/lxj/xpopup/widget/ShadowLayout.java new file mode 100644 index 0000000..7a51dea --- /dev/null +++ b/library/src/main/java/com/lxj/xpopup/widget/ShadowLayout.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.lxj.xpopup.widget; + +import ohos.agp.components.AttrSet; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.render.Arc; +import ohos.agp.render.Canvas; +import ohos.agp.render.Paint; +import ohos.agp.utils.Color; +import ohos.agp.utils.RectFloat; +import ohos.app.Context; + +/** + * 具有阴影效果的布局 + */ +public class ShadowLayout extends ComponentContainer implements Component.DrawTask { + + private final String STROKE = "stroke"; // 阴影宽度 + private final String RADIUS = "radius"; // 圆角宽度 + + private int width; + private int height; + private Paint mPaint; + private int stroke = 15; + private int radius = 15; + private int alpha = 30; + private int red = 90; + private int green = 90; + private int blue = 90; + + public ShadowLayout(Context context) { + this(context, null); + } + + public ShadowLayout(Context context, AttrSet attrSet) { + this(context, attrSet, null); + } + + public ShadowLayout(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + mPaint = new Paint(); + mPaint.setAntiAlias(true); + mPaint.setStyle(Paint.Style.STROKE_STYLE); + + if (attrSet != null) { + attrSet.getAttr(STROKE).ifPresent(attr -> stroke = attr.getDimensionValue()); + attrSet.getAttr(RADIUS).ifPresent(attr -> radius = attr.getDimensionValue()); + } + addDrawTask(this); + } + + /** + * 设置阴影宽度 + * + * @param stroke 阴影宽度,单位px,默认值15px + */ + public void setStroke(int stroke) { + this.stroke = stroke; + } + + /** + * 设置阴影圆角宽度 + * + * @param radius 阴影圆角宽度。单位px,默认值15px + */ + public void setRadius(int radius) { + this.radius = radius; + } + + @Override + public void onDraw(Component component, Canvas canvas) { + int rectWidth = stroke + radius + stroke + radius; + width = getWidth(); + height = getHeight(); + for (int i = 0; i < stroke; i++) { + float fraction = ((float) i) / ((float) stroke); + mPaint.setColor(new Color(Color.argb((int) (fraction * alpha), (int) (fraction * red), (int) (fraction * green), (int) (fraction * blue)))); + canvas.drawLine(stroke + radius, i, width - stroke - radius, i, mPaint); // 左上-右上 + canvas.drawLine(stroke + radius, height - i, width - stroke - radius, height - i, mPaint); // 左下-右下 + canvas.drawLine(i, stroke + radius, i, height - stroke - radius, mPaint); // 左上-左下 + canvas.drawLine(width - i, stroke + radius, width - i, height - stroke - radius, mPaint); // 右上-右下 + + canvas.drawArc(new RectFloat(i, i, rectWidth - i, rectWidth - i), new Arc(180, 90, false), mPaint); + canvas.drawArc(new RectFloat(width - rectWidth + i, i, width - i, rectWidth - i), new Arc(270, 90, false), mPaint); + canvas.drawArc(new RectFloat(width - rectWidth + i, height - rectWidth + i, width - i, height - i), new Arc(0, 90, false), mPaint); + canvas.drawArc(new RectFloat(i, height - rectWidth + i, rectWidth - i, height - i), new Arc(90, 90, false), mPaint); + } + } + +} -- Gitee From 9e0bb981c647bbf1fa9de13a6cb37a65781eb9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 14:54:36 +0800 Subject: [PATCH 4/9] =?UTF-8?q?perf=EF=BC=9A=E4=BC=98=E5=8C=96ImageViewer?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E4=BF=9D=E5=AD=98=E5=9B=BE=E7=89=87=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AD=98=E6=B3=84=E9=9C=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lxj/xpopup/core/BasePopupView.java | 6 +++--- .../com/lxj/xpopup/core/ImageViewerPopupView.java | 2 ++ .../main/java/com/lxj/xpopup/util/XPermission.java | 13 ++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java index 5d4eea5..5ace423 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java @@ -756,15 +756,15 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan float dx = EventUtil.getRawX(event) - x; float dy = EventUtil.getRawY(event) - y; float distance = (float) Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); + if (!XPopupUtils.isInRect(EventUtil.getX(event), EventUtil.getY(event), rect2)) { + passClickThrough(event); + } if (distance < touchSlop && popupInfo.isDismissOnTouchOutside) { if (!(this instanceof ImageViewerPopupView)) { dismiss(); getGlobalVisibleRect(getPopupImplView(), rect2); } } - if (!XPopupUtils.isInRect(EventUtil.getX(event), EventUtil.getY(event), rect2)) { - passClickThrough(event); - } x = 0; y = 0; break; diff --git a/library/src/main/java/com/lxj/xpopup/core/ImageViewerPopupView.java b/library/src/main/java/com/lxj/xpopup/core/ImageViewerPopupView.java index 973b978..1a0bc23 100644 --- a/library/src/main/java/com/lxj/xpopup/core/ImageViewerPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/ImageViewerPopupView.java @@ -382,6 +382,7 @@ public class ImageViewerPopupView extends BasePopupView implements OnDragChangeL .callback(new XPermission.SimpleCallback() { @Override public void onGranted() { + XPermission.getInstance().releaseConext(); if (imageLoader == null) { ToastUtil.showToast(getContext(), "已获取保存权限,请重新进行保存!"); } else { @@ -391,6 +392,7 @@ public class ImageViewerPopupView extends BasePopupView implements OnDragChangeL @Override public void onDenied() { + XPermission.getInstance().releaseConext(); ToastUtil.showToast(getContext(), "没有保存权限,保存功能无法使用!"); } diff --git a/library/src/main/java/com/lxj/xpopup/util/XPermission.java b/library/src/main/java/com/lxj/xpopup/util/XPermission.java index 7ab2cc8..7a22a67 100644 --- a/library/src/main/java/com/lxj/xpopup/util/XPermission.java +++ b/library/src/main/java/com/lxj/xpopup/util/XPermission.java @@ -28,11 +28,18 @@ public final class XPermission { * @return the single {@link XPermission} instance */ public static XPermission create(Context ctx, final String... permissions) { - sInstance = new XPermission(ctx, permissions); + if (sInstance == null) { + return new XPermission(ctx, permissions); + } + sInstance.context = new WeakReference<>(ctx); sInstance.prepare(permissions); return sInstance; } + public static XPermission getInstance() { + return sInstance; + } + private XPermission(Context ctx, final String... permissions) { sInstance = this; context = new WeakReference<>(ctx); @@ -137,6 +144,10 @@ public final class XPermission { void onForbid(List mPermissionsDeniedForever); } + public void releaseConext() { + context = null; + } + public static void onDestroy() { if (context != null) { context.clear(); -- Gitee From bc90c1dbf1e79024f5a45f8b0b8789d7607229b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 15:14:02 +0800 Subject: [PATCH 5/9] =?UTF-8?q?feat=EF=BC=9AImageViewer=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE=E9=95=BF=E6=8C=89=E7=9B=91?= =?UTF-8?q?=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xpopupdemo/stackLayout/ImageViewerDemo.java | 15 +++++++++++---- .../src/main/java/com/lxj/xpopup/XPopup.java | 17 +++++++++++------ .../lxj/xpopup/core/ImageViewerPopupView.java | 15 +++++++++++++++ .../OnImageViewerLongPressListener.java | 7 +++++++ 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 library/src/main/java/com/lxj/xpopup/interfaces/OnImageViewerLongPressListener.java diff --git a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/ImageViewerDemo.java b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/ImageViewerDemo.java index d501768..8f7ce3d 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/ImageViewerDemo.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/ImageViewerDemo.java @@ -3,11 +3,14 @@ package com.lxj.xpopupdemo.stackLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.core.ImageViewerPopupView; +import com.lxj.xpopup.interfaces.OnImageViewerLongPressListener; import com.lxj.xpopup.interfaces.OnSrcViewUpdateListener; import com.lxj.xpopup.interfaces.XPopupImageLoader; import com.lxj.xpopup.provider.EasyProvider; import com.lxj.xpopup.util.LogUtil; +import com.lxj.xpopup.util.ToastUtil; import com.lxj.xpopupdemo.ResourceTable; import com.lxj.xpopupdemo.custom.CustomImagePopup; import com.lzy.okgo.OkGo; @@ -20,7 +23,6 @@ import ohos.agp.components.Image; import ohos.agp.components.ListContainer; import ohos.agp.components.PageSlider; import ohos.agp.components.PageSliderProvider; -import ohos.agp.utils.Color; import ohos.app.Context; import java.io.File; @@ -91,7 +93,12 @@ public class ImageViewerDemo extends BaseStackLayout { public void onClick(Component component) { new XPopup.Builder(getContext()) .asImageViewer(image1, url1, true, 0xf1f1f1ff, -1, 0, - false, color_black, new ImageLoader()) + false, color_black, new ImageLoader(), new OnImageViewerLongPressListener() { + @Override + public void onLongPressed(BasePopupView popupView, int position) { + ToastUtil.showToast(getContext(), "长按了第" + position + "个图片"); + } + }) .show(); } }); @@ -145,7 +152,7 @@ public class ImageViewerDemo extends BaseStackLayout { public void onSrcViewUpdate(ImageViewerPopupView popupView, int position) { } - }, new ImageLoader()) + }, new ImageLoader(), null) .show(); } }); @@ -182,7 +189,7 @@ public class ImageViewerDemo extends BaseStackLayout { // 保证能拿到child,如果不设置pageLimit,ViewPager默认最多维护3个page,会导致拿不到child } - }, new ImageLoader()) + }, new ImageLoader(), null) .show(); } }); diff --git a/library/src/main/java/com/lxj/xpopup/XPopup.java b/library/src/main/java/com/lxj/xpopup/XPopup.java index 5d0d2b6..890f8f7 100644 --- a/library/src/main/java/com/lxj/xpopup/XPopup.java +++ b/library/src/main/java/com/lxj/xpopup/XPopup.java @@ -19,6 +19,7 @@ import com.lxj.xpopup.impl.InputConfirmPopupView; import com.lxj.xpopup.impl.LoadingPopupView; import com.lxj.xpopup.interfaces.OnCancelListener; import com.lxj.xpopup.interfaces.OnConfirmListener; +import com.lxj.xpopup.interfaces.OnImageViewerLongPressListener; import com.lxj.xpopup.interfaces.OnInputConfirmListener; import com.lxj.xpopup.interfaces.OnSelectListener; import com.lxj.xpopup.interfaces.OnSrcViewUpdateListener; @@ -715,7 +716,7 @@ public class XPopup { * @return 大图浏览类型弹窗,单张图片使用场景 */ public ImageViewerPopupView asImageViewer(Image srcView, String url, boolean isInfinite, int placeholderColor, int placeholderStroke, - int placeholderRadius, boolean isShowSaveBtn, int bgColor, XPopupImageLoader imageLoader) { + int placeholderRadius, boolean isShowSaveBtn, int bgColor, XPopupImageLoader imageLoader, OnImageViewerLongPressListener longPressListener) { popupType(PopupType.ImageViewer); ImageViewerPopupView popupView = new ImageViewerPopupView(this.context, popupInfo) .setSingleSrcView(srcView, url) @@ -725,7 +726,8 @@ public class XPopup { .setPlaceholderRadius(placeholderRadius) .isShowSaveButton(isShowSaveBtn) .setBgColor(bgColor) - .setXPopupImageLoader(imageLoader); + .setXPopupImageLoader(imageLoader) + .setLongPressListener(longPressListener); popupView.popupInfo = this.popupInfo; return popupView; } @@ -742,7 +744,7 @@ public class XPopup { */ public ImageViewerPopupView asImageViewer(Image srcView, int currentPosition, List urls, OnSrcViewUpdateListener srcViewUpdateListener, XPopupImageLoader imageLoader) { return asImageViewer(srcView, currentPosition, urls, false, true, -1, -1, -1, true, - new RgbColor(32, 36, 46).asRgbaInt(), srcViewUpdateListener, imageLoader); + new RgbColor(32, 36, 46).asRgbaInt(), srcViewUpdateListener, imageLoader, null); } /** @@ -760,10 +762,12 @@ public class XPopup { * @param bgColor 背景颜色,rgba * @param srcViewUpdateListener 当滑动ViewPager切换图片后,需要更新srcView,此时会执行该回调,你需要调用updateSrcView方法。 * @param imageLoader 用于加载图片和下载图片文件,实现XPopupImageLoader接口 + * @param longPressListener 当图片长按的时候执行 * @return 大图浏览类型弹窗,多张图片使用场景 */ - public ImageViewerPopupView asImageViewer(Image srcView, int currentPosition, List urls, boolean isInfinite, boolean isShowPlaceHolder, int placeholderColor, int placeholderStroke, - int placeholderRadius, boolean isShowSaveBtn, int bgColor, OnSrcViewUpdateListener srcViewUpdateListener, XPopupImageLoader imageLoader) { + public ImageViewerPopupView asImageViewer(Image srcView, int currentPosition, List urls, boolean isInfinite, boolean isShowPlaceHolder, int placeholderColor, + int placeholderStroke, int placeholderRadius, boolean isShowSaveBtn, int bgColor, OnSrcViewUpdateListener srcViewUpdateListener, + XPopupImageLoader imageLoader, OnImageViewerLongPressListener longPressListener) { popupType(PopupType.ImageViewer); ImageViewerPopupView popupView = new ImageViewerPopupView(this.context, popupInfo) .setSrcView(srcView, currentPosition) @@ -776,7 +780,8 @@ public class XPopup { .isShowSaveButton(isShowSaveBtn) .setBgColor(bgColor) .setSrcViewUpdateListener(srcViewUpdateListener) - .setXPopupImageLoader(imageLoader); + .setXPopupImageLoader(imageLoader) + .setLongPressListener(longPressListener); popupView.popupInfo = this.popupInfo; return popupView; } diff --git a/library/src/main/java/com/lxj/xpopup/core/ImageViewerPopupView.java b/library/src/main/java/com/lxj/xpopup/core/ImageViewerPopupView.java index 1a0bc23..c166080 100644 --- a/library/src/main/java/com/lxj/xpopup/core/ImageViewerPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/ImageViewerPopupView.java @@ -5,6 +5,7 @@ import com.lxj.xpopup.XPopup; import com.lxj.xpopup.animator.PopupAnimator; import com.lxj.xpopup.animator.ScaleAlphaAnimator; import com.lxj.xpopup.interfaces.OnDragChangeListener; +import com.lxj.xpopup.interfaces.OnImageViewerLongPressListener; import com.lxj.xpopup.interfaces.OnSrcViewUpdateListener; import com.lxj.xpopup.interfaces.XPopupImageLoader; import com.lxj.xpopup.util.ElementUtil; @@ -58,6 +59,7 @@ public class ImageViewerPopupView extends BasePopupView implements OnDragChangeL private boolean isInfinite = false; // 是否需要无限滚动 private Component customView; private int bgColor = new RgbColor(32, 36, 46).asRgbaInt(); // 弹窗的背景颜色,可以自定义 + protected OnImageViewerLongPressListener longPressListener; public ImageViewerPopupView(Context context, PopupInfo popupInfo) { super(context, popupInfo); @@ -299,6 +301,11 @@ public class ImageViewerPopupView extends BasePopupView implements OnDragChangeL return this; } + public ImageViewerPopupView setLongPressListener(OnImageViewerLongPressListener longPressListener) { + this.longPressListener = longPressListener; + return this; + } + /** * 设置单个使用的源View。单个使用的情况下,无需设置url集合和SrcViewUpdateListener * @@ -427,6 +434,14 @@ public class ImageViewerPopupView extends BasePopupView implements OnDragChangeL dismiss(); } }); + if (longPressListener != null) { + photoView.setLongClickedListener(new LongClickedListener() { + @Override + public void onLongClicked(Component component) { + longPressListener.onLongPressed(ImageViewerPopupView.this, position); + } + }); + } return photoView; } diff --git a/library/src/main/java/com/lxj/xpopup/interfaces/OnImageViewerLongPressListener.java b/library/src/main/java/com/lxj/xpopup/interfaces/OnImageViewerLongPressListener.java new file mode 100644 index 0000000..d61666a --- /dev/null +++ b/library/src/main/java/com/lxj/xpopup/interfaces/OnImageViewerLongPressListener.java @@ -0,0 +1,7 @@ +package com.lxj.xpopup.interfaces; + +import com.lxj.xpopup.core.BasePopupView; + +public interface OnImageViewerLongPressListener { + void onLongPressed(BasePopupView popupView, int position); +} -- Gitee From 2cb21a2cc66f3b817524f46d6f1f43d7a5d41028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 15:19:01 +0800 Subject: [PATCH 6/9] =?UTF-8?q?perf=EF=BC=9A=E4=BF=AE=E5=A4=8D=E6=9E=81?= =?UTF-8?q?=E7=AB=AF=E6=83=85=E5=86=B5=E4=B8=8BpopupInfo=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E5=BC=95=E5=8F=91=E7=9A=84PNE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lxj/xpopup/core/BasePopupView.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java index 5ace423..8075f2c 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java @@ -136,7 +136,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan }; private void detachFromHost() { - if (popupInfo.isComponentMode) { + if (popupInfo != null && popupInfo.isComponentMode) { ComponentContainer decorView = (ComponentContainer) getComponentParent(); if (decorView != null) { decorView.removeComponent(this); @@ -149,7 +149,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan } public Window getHostWindow() { - if (popupInfo.isComponentMode) { + if (popupInfo != null && popupInfo.isComponentMode) { return ((Ability) getContext()).getWindow(); } else { return dialog == null ? null : dialog.getWindow(); @@ -209,7 +209,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan if (getContext() instanceof Ability) { ((Ability) getContext()).getLifecycle().addObserver(this); } - if (popupInfo.isComponentMode) { + if (popupInfo != null && popupInfo.isComponentMode) { // component实现 ComponentContainer decorView = (ComponentContainer) popupInfo.contentRoot.getComponentParent(); popupInfo.decorView = decorView; @@ -286,7 +286,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan } protected void showSoftInput(Component focusView) { - if (popupInfo.autoOpenSoftInput) { + if (popupInfo != null && popupInfo.autoOpenSoftInput) { if (showSoftInputTask == null) { showSoftInputTask = new ShowSoftInputTask(focusView); } else { @@ -450,6 +450,9 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan * 背景动画由父类实现,Content由子类实现 */ protected void doShowAnimation() { + if (popupInfo == null) { + return; + } getPopupContentView().setAlpha(1f); setVisibility(VISIBLE); if (popupInfo.hasShadowBg && !popupInfo.hasBlurBg && popupInfo.isComponentMode) { @@ -467,6 +470,9 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan * 背景动画由父类实现,Content由子类实现 */ protected void doDismissAnimation() { + if (popupInfo == null) { + return; + } if (popupInfo.hasShadowBg && !popupInfo.hasBlurBg && popupInfo.isComponentMode) { shadowBgAnimator.animateDismiss(); } else if (popupInfo.hasBlurBg && blurAnimator != null) { @@ -497,7 +503,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan } public int getAnimationDuration() { - return popupInfo.popupAnimation == NoAnimation ? 10 : XPopup.getAnimationDuration() + 10; + return popupInfo != null && popupInfo.popupAnimation == NoAnimation ? 10 : XPopup.getAnimationDuration() + 10; } /** @@ -676,8 +682,8 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan } public void onDestroy() { - detachFromHost(); onComponentUnboundFromWindow(null); + detachFromHost(); destroy(); } @@ -759,7 +765,7 @@ public abstract class BasePopupView extends StackLayout implements BindStateChan if (!XPopupUtils.isInRect(EventUtil.getX(event), EventUtil.getY(event), rect2)) { passClickThrough(event); } - if (distance < touchSlop && popupInfo.isDismissOnTouchOutside) { + if (distance < touchSlop && popupInfo != null && popupInfo.isDismissOnTouchOutside) { if (!(this instanceof ImageViewerPopupView)) { dismiss(); getGlobalVisibleRect(getPopupImplView(), rect2); -- Gitee From bb7ea351d2f97f3381c16f75d072fd73105bd047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 15:42:36 +0800 Subject: [PATCH 7/9] =?UTF-8?q?perf=EF=BC=9Asdk=E7=BC=96=E8=AF=91=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8D=87=E4=B8=BA6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 6 +++--- entry/build.gradle | 4 ++-- entry/src/main/config.json | 11 +++-------- library/build.gradle | 2 +- library/src/main/config.json | 2 +- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 0367685..36f102d 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.huawei.ohos.app' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } @@ -19,8 +19,8 @@ buildscript { jcenter() } dependencies { - classpath 'com.huawei.ohos:hap:2.4.2.7' - classpath 'com.huawei.ohos:decctest:1.0.0.6' + classpath 'com.huawei.ohos:hap:2.4.5.0' + classpath 'com.huawei.ohos:decctest:1.2.4.1' } } diff --git a/entry/build.gradle b/entry/build.gradle index 363e3db..5673d18 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.huawei.ohos.hap' apply plugin: 'com.huawei.ohos.decctest' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } @@ -10,7 +10,7 @@ ohos { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) implementation 'com.squareup.okhttp3:okhttp:3.8.1' - implementation 'io.openharmony.tpc.thirdlib:glide:1.0.4' + implementation 'io.openharmony.tpc.thirdlib:glide:1.0.9' implementation 'io.openharmony.tpc.thirdlib:okgo:1.0.2' implementation project(':library') } diff --git a/entry/src/main/config.json b/entry/src/main/config.json index 6315fb0..544910a 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -7,7 +7,7 @@ "name": "1.0" }, "apiVersion": { - "compatible": 5, + "compatible": 6, "target": 5 } }, @@ -23,9 +23,7 @@ ], "package": "com.lxj.xpopupdemo", "name": ".XPopup", - "reqCapabilities": [ - "video_support" - ], + "mainAbility": "com.lxj.xpopupdemo.MainAbility", "deviceType": [ "phone" ], @@ -56,9 +54,8 @@ ] }, "orientation": "unspecified", - "formEnabled": false, "name": "com.lxj.xpopupdemo.MainAbility", - "label": "XPopup", + "label": "$string:app_name", "type": "page", "launchType": "standard" }, @@ -73,9 +70,7 @@ ] }, "orientation": "unspecified", - "formEnabled": false, "name": "com.lxj.xpopupdemo.DemoAbility", - "label": "XPopup", "type": "page", "launchType": "standard" } diff --git a/library/build.gradle b/library/build.gradle index f3beffc..fb183ce 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.huawei.ohos.library' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } diff --git a/library/src/main/config.json b/library/src/main/config.json index e490895..b25492f 100644 --- a/library/src/main/config.json +++ b/library/src/main/config.json @@ -7,7 +7,7 @@ "name": "1.0" }, "apiVersion": { - "compatible": 5, + "compatible": 6, "target": 5 } }, -- Gitee From b6fe6e11db1c01c75e1d90f496e683330bdb6c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 16:28:16 +0800 Subject: [PATCH 8/9] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8DAttach?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E5=9C=A8=E4=B8=8D=E5=90=8C=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A0=8F=E7=9A=84=E8=AE=BE=E5=A4=87=E4=B8=8A?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=BD=8D=E7=BD=AE=E4=B8=8D=E5=90=8C=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=88=E4=BF=AE=E6=94=B9=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=BD=8D=E7=BD=AE=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xpopupdemo/custom/CustomAttachPopup.java | 6 -- .../xpopupdemo/custom/CustomAttachPopup2.java | 6 -- .../custom/CustomPartShadowPopupView.java | 4 -- .../src/main/java/com/lxj/xpopup/XPopup.java | 8 ++- .../com/lxj/xpopup/core/AttachPopupView.java | 43 ++++++-------- .../core/HorizontalAttachPopupView.java | 6 +- .../lxj/xpopup/impl/AttachListPopupView.java | 5 -- .../lxj/xpopup/impl/PartShadowPopupView.java | 13 +---- .../com/lxj/xpopup/util/ComponentUtil.java | 58 +++++++++++++++++++ .../java/com/lxj/xpopup/util/EventUtil.java | 4 +- .../java/com/lxj/xpopup/util/XPopupUtils.java | 3 - 11 files changed, 87 insertions(+), 69 deletions(-) create mode 100644 library/src/main/java/com/lxj/xpopup/util/ComponentUtil.java diff --git a/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup.java b/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup.java index 8f1a0e8..5ff6e72 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup.java @@ -40,10 +40,4 @@ public class CustomAttachPopup extends HorizontalAttachPopupView { shadowLayout.setRadius(0); } - // 设置状态栏的高度,用以修正自定义位置弹窗的高度 - @Override - protected int setStatusBarHeight() { - return 130; - } - } diff --git a/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup2.java b/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup2.java index 8603550..d6081ca 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup2.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomAttachPopup2.java @@ -34,10 +34,4 @@ public class CustomAttachPopup2 extends AttachPopupView { getPopupImplView().setBackground(XPopupUtils.createDrawable(0xFFFFFFFF, popupInfo.borderRadius, 0, popupInfo.borderRadius, 0)); } - // 设置状态栏的高度,用以修正自定义位置弹窗的高度 - @Override - protected int setStatusBarHeight() { - return 130; - } - } diff --git a/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomPartShadowPopupView.java b/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomPartShadowPopupView.java index 9463427..04a9106 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomPartShadowPopupView.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/custom/CustomPartShadowPopupView.java @@ -40,8 +40,4 @@ public class CustomPartShadowPopupView extends PartShadowPopupView { }); } - @Override - protected int setStatusBarHeight() { - return 130; - } } diff --git a/library/src/main/java/com/lxj/xpopup/XPopup.java b/library/src/main/java/com/lxj/xpopup/XPopup.java index 890f8f7..882faf2 100644 --- a/library/src/main/java/com/lxj/xpopup/XPopup.java +++ b/library/src/main/java/com/lxj/xpopup/XPopup.java @@ -25,6 +25,7 @@ import com.lxj.xpopup.interfaces.OnSelectListener; import com.lxj.xpopup.interfaces.OnSrcViewUpdateListener; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lxj.xpopup.interfaces.XPopupImageLoader; +import com.lxj.xpopup.util.ComponentUtil; import com.lxj.xpopup.util.EventUtil; import com.lxj.xpopup.util.LogUtil; import ohos.agp.colors.RgbColor; @@ -76,7 +77,6 @@ public class XPopup { } } - public static Quaternion longClickPoint = null; /** @@ -89,7 +89,8 @@ public class XPopup { @Override public boolean onTouchEvent(Component component, TouchEvent event) { if (event.getAction() == event.PRIMARY_POINT_DOWN) { - longClickPoint = new Quaternion(EventUtil.getRawX(event), EventUtil.getRawY(event), + longClickPoint = new Quaternion(ComponentUtil.getLocationInDecorView(component).left + EventUtil.getX(event), + ComponentUtil.getLocationInDecorView(component).top + EventUtil.getY(event), event.getPointerPosition(0).getZ(), 0); } if ("xpopup".equals(component.getTag()) && event.getAction() == TouchEvent.POINT_MOVE) { @@ -201,7 +202,8 @@ public class XPopup { @Override public boolean onTouchEvent(Component component, TouchEvent event) { if (event.getAction() == TouchEvent.PRIMARY_POINT_DOWN) { - popupInfo.touchPoint = new Quaternion(EventUtil.getRawX(event), EventUtil.getRawY(event), + popupInfo.touchPoint = new Quaternion(ComponentUtil.getLocationInDecorView(popupInfo.watchView).left + EventUtil.getX(event), + ComponentUtil.getLocationInDecorView(popupInfo.watchView).top + EventUtil.getY(event), event.getPointerPosition(0).getZ(), 0); } return false; diff --git a/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java b/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java index 392a72d..b117f10 100644 --- a/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/AttachPopupView.java @@ -6,6 +6,7 @@ import com.lxj.xpopup.animator.PopupAnimator; import com.lxj.xpopup.animator.ScrollScaleAnimator; import com.lxj.xpopup.enums.PopupAnimation; import com.lxj.xpopup.enums.PopupPosition; +import com.lxj.xpopup.util.ComponentUtil; import com.lxj.xpopup.util.ElementUtil; import com.lxj.xpopup.util.XPopupUtils; import com.lxj.xpopup.widget.PartShadowContainer; @@ -111,17 +112,16 @@ public abstract class AttachPopupView extends BasePopupView { } centerY = popupInfo.touchPoint.getY(); // 依附于指定点,尽量优先放在下方,当不够的时候在显示在上方 - isShowUp = false; - if ((popupInfo.touchPoint.getY() + getPopupContentView().getHeight()) > maxY - getStatusBarHeight()) { // 如果下方放不下,超出window高度 - if (popupInfo.touchPoint.getY() > XPopupUtils.getScreenHeight(getContext()) / 2) { // 如果触摸点在屏幕中心的下方 - isShowUp = true; - } + if ((popupInfo.touchPoint.getY() + getPopupContentView().getHeight()) > maxY) { // 如果下方放不下,超出window高度 + isShowUp = popupInfo.touchPoint.getY() > XPopupUtils.getScreenHeight(getContext()) / 2; + } else { + isShowUp = false; } isShowLeft = popupInfo.touchPoint.getX() < XPopupUtils.getWindowWidth(getContext()) / 2; // 限制最大宽高 ComponentContainer.LayoutConfig params = getPopupContentView().getLayoutConfig(); - int maxHeight = (int) (isShowUpToTarget() ? (popupInfo.touchPoint.getY() - XPopupUtils.getStatusBarHeight(this) - overflow) + int maxHeight = (int) (isShowUpToTarget() ? (popupInfo.touchPoint.getY() - overflow) : (XPopupUtils.getScreenHeight(getContext()) - popupInfo.touchPoint.getY() - overflow)); int maxWidth = (int) (isShowLeft ? (XPopupUtils.getWindowWidth(getContext()) - popupInfo.touchPoint.getX() - overflow) : (popupInfo.touchPoint.getX() - overflow)); if (getPopupContentView().getHeight() > maxHeight) { @@ -164,28 +164,28 @@ public abstract class AttachPopupView extends BasePopupView { } else { // 依附于指定View // 1. 获取atView在屏幕上的位置 - int[] locations = new int[2]; - int[] rectOld = popupInfo.getAtView().getLocationOnScreen(); - locations[0] = rectOld[0]; - locations[1] = rectOld[1]; - final Rect rect = new Rect(locations[0], locations[1], locations[0] + popupInfo.getAtView().getWidth(), - locations[1] + popupInfo.getAtView().getHeight()); + final Rect rect = ComponentUtil.getLocationInDecorView(popupInfo.getAtView()); final int centerX = (rect.left + rect.right) / 2; // 尽量优先放在下方,当不够的时候在显示在上方 centerY = (rect.top + rect.bottom) / 2; - isShowUp = false; - if ((rect.bottom + getPopupContentView().getHeight()) > maxY + getStatusBarHeight()) { // 如果下方放不下,超出window高度 - if (centerY > XPopupUtils.getScreenHeight(getContext()) / 2) { // 如果触摸点在屏幕中心的下方 + int contentHeight = getPopupContentView().getHeight(); + if (contentHeight > maxY - rect.bottom) { // 如果下方放不下,超出window高度 + int upAvailableSpace = rect.top - overflow; // 上方可用大小 + if (contentHeight > upAvailableSpace) { // 超出上方可用大小 + // 如果也超出了上方可用区域则哪里空间大显示在哪个方向 + isShowUp = upAvailableSpace > maxY - rect.bottom; + } else { isShowUp = true; } + } else { + isShowUp = false; } isShowLeft = centerX < XPopupUtils.getWindowWidth(getContext()) / 2; // 修正高度,弹窗的高有可能超出window区域 ComponentContainer.LayoutConfig params = getPopupContentView().getLayoutConfig(); - int maxHeight = isShowUpToTarget() ? (rect.top - XPopupUtils.getStatusBarHeight(this) - overflow) - : (XPopupUtils.getScreenHeight(getContext()) - rect.bottom - overflow); + int maxHeight = isShowUpToTarget() ? (rect.top - overflow) : (XPopupUtils.getScreenHeight(getContext()) - rect.bottom - overflow); int maxWidth = isShowLeft ? (XPopupUtils.getWindowWidth(getContext()) - rect.left - overflow) : (rect.right - overflow); if (getPopupContentView().getHeight() > maxHeight) { params.height = maxHeight; @@ -225,7 +225,6 @@ public abstract class AttachPopupView extends BasePopupView { translationY = rect.bottom + defaultOffsetY; } } - translationY -= getStatusBarHeight(); // 减去状态栏的高度 getPopupContentView().setTranslationX(translationX); getPopupContentView().setTranslationY(translationY); initAndStartAnimation(); @@ -237,14 +236,6 @@ public abstract class AttachPopupView extends BasePopupView { doAfterShow(); } - // 设置状态栏的高度,用以修正自定义位置弹窗的高度 - protected abstract int setStatusBarHeight(); - - public int getStatusBarHeight() { - return setStatusBarHeight(); - } - - // 是否显示在目标上方 protected boolean isShowUpToTarget() { if (popupInfo.positionByWindowCenter) { diff --git a/library/src/main/java/com/lxj/xpopup/core/HorizontalAttachPopupView.java b/library/src/main/java/com/lxj/xpopup/core/HorizontalAttachPopupView.java index 7f06002..be33987 100644 --- a/library/src/main/java/com/lxj/xpopup/core/HorizontalAttachPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/HorizontalAttachPopupView.java @@ -5,6 +5,7 @@ import com.lxj.xpopup.animator.PopupAnimator; import com.lxj.xpopup.animator.ScrollScaleAnimator; import com.lxj.xpopup.enums.PopupAnimation; import com.lxj.xpopup.enums.PopupPosition; +import com.lxj.xpopup.util.ComponentUtil; import com.lxj.xpopup.util.XPopupUtils; import ohos.agp.utils.Rect; import ohos.app.Context; @@ -54,9 +55,7 @@ public abstract class HorizontalAttachPopupView extends AttachPopupView { } else { // 依附于指定View // 1. 获取atView在屏幕上的位置 - int[] locations = popupInfo.getAtView().getLocationOnScreen(); - Rect rect = new Rect(locations[0], locations[1], locations[0] + popupInfo.getAtView().getWidth(), - locations[1] + popupInfo.getAtView().getHeight()); + Rect rect = ComponentUtil.getLocationInDecorView(popupInfo.getAtView()); int centerX = (rect.left + rect.right) / 2; @@ -69,7 +68,6 @@ public abstract class HorizontalAttachPopupView extends AttachPopupView { } translationY = rect.top + (rect.getHeight() - height) / 2 + defaultOffsetY; } - translationY -= getStatusBarHeight(); // 减去状态栏的高度 getPopupContentView().setTranslationX(translationX); getPopupContentView().setTranslationY(translationY); initAndStartAnimation(); diff --git a/library/src/main/java/com/lxj/xpopup/impl/AttachListPopupView.java b/library/src/main/java/com/lxj/xpopup/impl/AttachListPopupView.java index a0a09fa..684082c 100644 --- a/library/src/main/java/com/lxj/xpopup/impl/AttachListPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/impl/AttachListPopupView.java @@ -113,11 +113,6 @@ public class AttachListPopupView extends AttachPopupView { super.applyLightTheme(); } - @Override - protected int setStatusBarHeight() { - return 130; - } - String[] data; int[] iconIds; diff --git a/library/src/main/java/com/lxj/xpopup/impl/PartShadowPopupView.java b/library/src/main/java/com/lxj/xpopup/impl/PartShadowPopupView.java index 1a500dc..b73b771 100644 --- a/library/src/main/java/com/lxj/xpopup/impl/PartShadowPopupView.java +++ b/library/src/main/java/com/lxj/xpopup/impl/PartShadowPopupView.java @@ -52,7 +52,7 @@ public abstract class PartShadowPopupView extends BasePopupView implements Compo if (popupInfo.hasShadowBg) { shadowBgAnimator.targetView = getPopupContentView(); } - XPopupUtils.applyPopupSize((ComponentContainer) getPopupContentView(), getMaxWidth(), getMaxHeight(),getPopupWidth(), getPopupHeight(), new Runnable() { + XPopupUtils.applyPopupSize((ComponentContainer) getPopupContentView(), getMaxWidth(), getMaxHeight(), getPopupWidth(), getPopupHeight(), new Runnable() { @Override public void run() { doAttach(); @@ -60,7 +60,7 @@ public abstract class PartShadowPopupView extends BasePopupView implements Compo }); } - protected void initAndStartAnimation(){ + protected void initAndStartAnimation() { initAnimator(); doShowAnimation(); doAfterShow(); @@ -119,7 +119,7 @@ public abstract class PartShadowPopupView extends BasePopupView implements Compo // atView在上半部分,PartShadow应该显示在它下方,计算atView之下的高度 params.height = getHeight() - rect.bottom; isShowUp = false; - params.setMarginTop(rect.bottom - getStatusBarHeight()); + params.setMarginTop(rect.bottom); // 同时自定义的impl View应该Gravity居于顶部 Component implView = ((ComponentContainer) getPopupContentView()).getComponentAt(0); StackLayout.LayoutConfig implParams = (LayoutConfig) implView.getLayoutConfig(); @@ -149,11 +149,4 @@ public abstract class PartShadowPopupView extends BasePopupView implements Compo PopupAnimation.TranslateFromBottom : PopupAnimation.TranslateFromTop); } - // 设置状态栏的高度,用以修正自定义位置弹窗的高度 - protected abstract int setStatusBarHeight(); - - public int getStatusBarHeight() { - return setStatusBarHeight(); - } - } diff --git a/library/src/main/java/com/lxj/xpopup/util/ComponentUtil.java b/library/src/main/java/com/lxj/xpopup/util/ComponentUtil.java new file mode 100644 index 0000000..7864c12 --- /dev/null +++ b/library/src/main/java/com/lxj/xpopup/util/ComponentUtil.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.lxj.xpopup.util; + +import ohos.agp.components.Component; +import ohos.agp.components.ComponentParent; +import ohos.agp.utils.Rect; + +/** + * 控件相关工具类 + */ +public class ComponentUtil { + + /** + * 获取控件在根容器中的位置 + * + * @param component 控件 + * @return 位置信息 + */ + public static Rect getLocationInDecorView(Component component) { + Component decorView = getDecorView(component); + int[] componentLocationOnScreen = component.getLocationOnScreen(); + int[] decorViewLocationOnScreen = decorView.getLocationOnScreen(); + Rect rect = new Rect(); + rect.left = componentLocationOnScreen[0] - decorViewLocationOnScreen[0]; + rect.right = rect.left + component.getWidth(); + rect.top = componentLocationOnScreen[1] - decorViewLocationOnScreen[1]; + rect.bottom = rect.top + component.getHeight(); + return rect; + } + + /** + * 获取根容器 + * + * @param component 根容器中的任意一个控件 + * @return 根容器 + */ + public static Component getDecorView(Component component) { + ComponentParent componentParent = component.getComponentParent(); + if (componentParent == null) { + return component; + } else { + return getDecorView((Component) componentParent); + } + } +} diff --git a/library/src/main/java/com/lxj/xpopup/util/EventUtil.java b/library/src/main/java/com/lxj/xpopup/util/EventUtil.java index 73d38ea..c3dd8e6 100644 --- a/library/src/main/java/com/lxj/xpopup/util/EventUtil.java +++ b/library/src/main/java/com/lxj/xpopup/util/EventUtil.java @@ -22,7 +22,7 @@ import ohos.multimodalinput.event.TouchEvent; public class EventUtil { /** - * 获取相对于偏移位置的x坐标 + * 获取相对于被触摸的控件偏移位置的x坐标 * * @param touchEvent 触摸事件 * @return x坐标 @@ -32,7 +32,7 @@ public class EventUtil { } /** - * 获取相对于偏移位置的y坐标 + * 获取相对于被触摸的控件偏移位置的y坐标 * * @param touchEvent 触摸事件 * @return y坐标 diff --git a/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java b/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java index f9d0265..0c6d435 100644 --- a/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java +++ b/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java @@ -85,9 +85,6 @@ public class XPopupUtils { * @return 状态栏高度 */ public static int getStatusBarHeight(AttachPopupView attachPopupView) { - if (attachPopupView != null) { - return attachPopupView.getStatusBarHeight(); - } return 0; } -- Gitee From f594c80f46ca929763cd671aea5f2bdf4a0bdbbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com> Date: Wed, 21 Jul 2021 16:39:45 +0800 Subject: [PATCH 9/9] =?UTF-8?q?docs=EF=BC=9Amaven=E5=92=8Chapm=E5=8F=91?= =?UTF-8?q?=E5=B8=831.0.9=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.OPENSOURCE | 2 +- README.md | 2 +- changelog.md | 27 ++++++++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.OPENSOURCE b/README.OPENSOURCE index 12cf966..1a22434 100644 --- a/README.OPENSOURCE +++ b/README.OPENSOURCE @@ -3,7 +3,7 @@ "Name": " XPopup ", "License": "Apache License", "License File": " LICENSE ", - "Version Number": "2.3.0", + "Version Number": "2.3.2", "Upstream URL": "https://github.com/li-xiaojun/XPopup/archive/1906806f1e33ab4ae6758dff84643ad1b4cab280.zip", "Description": "Powerful, interactive, and silky general pop-up window" } diff --git a/README.md b/README.md index 37a6f3f..3b26e28 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ allprojects{ mavenCentral() } } -implementation 'io.openharmony.tpc.thirdlib:XPopup:1.0.8' +implementation 'io.openharmony.tpc.thirdlib:XPopup:1.0.9' ``` ## entry运行要求 diff --git a/changelog.md b/changelog.md index 47564aa..811e1eb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,13 @@ -## 1.0.8 +## 1.0.9 +1.修复dialog模式设置返回键不关闭弹窗功能失效的问题 + +2.修复Attach弹窗在不同设备下显示位置不同的问题 + +3.AttchList弹窗使用Component模式时增加阴影效果 + +4.ImageViewer弹窗增加长按监听 + +## 1.0.8 增加Component模式的实现 ## 1.0.7 @@ -43,12 +52,14 @@ 10.设置各种弹窗的自定义布局 -11.设置是否自动打开输入法(暂时仅Dialog模式支持) +11.设置按下返回键、点击弹窗外面是否关闭弹窗 -12.设置按下返回键、点击弹窗外面是否关闭弹窗 +12.设置是否自动打开输入法(暂时仅Dialog模式支持) 13.设置是否半透明背景(暂时仅Component模式支持) +14.设置是否点击事件透传(暂时仅Component模式支持,滑动事件暂时无法拦截) + 未支持部分: 1.ImageXPopup滑动功能 @@ -63,12 +74,10 @@ 6.Popup移动到软键盘上面 -7.设置是否点击事件透传 - -8.设置是否高斯模糊背景 +7.设置是否高斯模糊背景 -9.设置是否显示状态栏阴影 +8.设置是否显示状态栏阴影 -10.设置是否显示状态栏 +9.设置是否显示状态栏 -11.设置是否显示导航栏 \ No newline at end of file +10.设置是否显示导航栏 \ No newline at end of file -- Gitee