From 5804d7cd0bb853cc0ce21aa199dc196e0a26711e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Android=20=E8=BD=AE=E5=AD=90=E5=93=A5?= Date: Sun, 24 Sep 2023 21:57:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=20Toast=20=E8=B7=A8=E9=A1=B5=E9=9D=A2=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HelpDoc-en.md | 13 ++++++++++ HelpDoc-zh.md | 14 +++++++++++ README-en.md | 18 +++++++++++--- README.md | 24 +++++++++++++------ app/build.gradle | 12 +++++----- .../java/com/hjq/toast/demo/MainActivity.java | 9 +++++-- app/src/main/res/layout/activity_main.xml | 8 +++++++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ build.gradle | 2 +- library/build.gradle | 4 ++-- .../main/java/com/hjq/toast/ToastParams.java | 3 +++ .../java/com/hjq/toast/ToastStrategy.java | 14 +++++------ .../src/main/java/com/hjq/toast/Toaster.java | 10 +++++++- .../com/hjq/toast/config/IToastStrategy.java | 3 +-- .../com/hjq/toast/style/BlackToastStyle.java | 13 ++++++---- .../com/hjq/toast/style/WhiteToastStyle.java | 3 ++- 17 files changed, 116 insertions(+), 38 deletions(-) diff --git a/HelpDoc-en.md b/HelpDoc-en.md index 2a454fc..860f712 100644 --- a/HelpDoc-en.md +++ b/HelpDoc-en.md @@ -10,6 +10,8 @@ * [What should I do if the framework cannot meet the scene I am currently using](#what-should-i-do-if-the-framework-cannot-meet-the-scene-i-am-currently-using) +* [How to implement cross page display of toast in the framework](#how-to-implement-cross-page-display-of-toast-in-the-framework) + * [Why the framework prefers to use window manager to implement toast](#why-the-framework-prefers-to-use-window-manager-to-implement-toast) #### How to customize toast display animation @@ -146,6 +148,17 @@ public class ToastStrategy { * The Toaster framework is intended to solve some toast requirements. If Toaster cannot meet your needs, you can consider using the [EasyWindow](https://github.com/getActivity/EasyWindow) floating window framework to achieve it. +#### How to implement cross page display of toast in the framework + +* By default, Toasts in the Toaster framework are only displayed on the current Activity. If an Activity switch occurs, the Toast becomes invisible as the current Activity is destroyed, making it impossible to display on the new Activity. The framework added support for this feature in version [12.5](https://github.com/getActivity/Toaster/releases/tag/12.5). The following is an example of how to use it: + +```java +ToastParams params = new ToastParams(); +params.text = "I am a Toast that can be displayed across pages"; +// Indicates that this Toast needs to be displayed across pages +params.crossPageShow = true; +Toaster.show(params); + #### Why the framework prefers to use window manager to implement toast * There are too many pits in the system toast, the main problems are as follows: diff --git a/HelpDoc-zh.md b/HelpDoc-zh.md index eedcf6b..0e916d8 100644 --- a/HelpDoc-zh.md +++ b/HelpDoc-zh.md @@ -12,6 +12,8 @@ * [框架无法满足我当前使用的场景怎么办](#框架无法满足我当前使用的场景怎么办) +* [框架中的 Toast 如何实现跨页面显示](#框架中的-toast-如何实现跨页面显示) + * [为什么框架优先使用 WindowManager 来实现 Toast](#为什么框架优先使用-windowManager-来实现-toast) #### 框架怎么改名了 @@ -162,6 +164,18 @@ public class ToastStrategy { * Toaster 框架意在解决一些的 Toast 需求,如果 Toaster 无法满足你的需求,你可以考虑使用 [EasyWindow](https://github.com/getActivity/EasyWindow) 悬浮窗框架来实现。 +#### 框架中的 Toast 如何实现跨页面显示 + +* Toaster 中默认 Toast 是只在当前 Activity 上面展示的,如果遇到 Activity 切换,那么在 Toast 随着当前 Activity 销毁而不可见,导致无法在新 Activity 上面展示,框架在 [12.5](https://github.com/getActivity/Toaster/releases/tag/12.5) 版本新增支持了这一功能,具体调用示例如下: + +```java +ToastParams params = new ToastParams(); +params.text = "我是一个能跨页面展示的 Toast"; +// 表示这个 Toast 需要跨页面展示 +params.crossPageShow = true; +Toaster.show(params); +``` + #### 为什么框架优先使用 WindowManager 来实现 Toast * 系统 Toast 的坑太多了,主要问题表现如下: diff --git a/README-en.md b/README-en.md index 1eea6eb..c128a7b 100644 --- a/README-en.md +++ b/README-en.md @@ -4,7 +4,7 @@ * Project address: [Github](https://github.com/getActivity/Toaster) -* [Click here to download demo apk directly](https://github.com/getActivity/Toaster/releases/download/12.3/Toaster.apk) +* [Click here to download demo apk directly](https://github.com/getActivity/Toaster/releases/download/12.5/Toaster.apk) ![](picture/en/demo_toast_activity.jpg) ![](picture/en/demo_toast_style_white.jpg) ![](picture/en/demo_toast_style_black.jpg) @@ -49,7 +49,7 @@ android { dependencies { // Toast framework:https://github.com/getActivity/Toaster - implementation 'com.github.getActivity:Toaster:12.3' + implementation 'com.github.getActivity:Toaster:12.5' } ``` @@ -128,13 +128,21 @@ Toaster.setInterceptor(IToastInterceptor interceptor); Toaster.getInterceptor(); ``` +#### Framework proguard rules + +* Added in the `proguard-rules.pro` file: + +```text +-keep class com.hjq.toast.** {*;} +``` + ## [Please click here to view frequently asked questions](HelpDoc-en.md) #### Comparison between different Toast frameworks | Function or detail | [Toaster](https://github.com/getActivity/Toaster) |[ AndroidUtilCode-ToastUtils ](https://github.com/Blankj/AndroidUtilCode)| [Toasty](https://github.com/GrenderG/Toasty) | | :----: | :------: | :-----: | :-----: | -| Corresponding version | 12.3 | 1.30.6 | 1.5.0 | +| Corresponding version | 12.5 | 1.30.6 | 1.5.0 | | Number of issues | [![](https://img.shields.io/github/issues/getActivity/Toaster.svg)](https://github.com/getActivity/Toaster/issues) |[![](https://img.shields.io/github/issues/Blankj/AndroidUtilCode.svg)](https://github.com/Blankj/AndroidUtilCode/issues)| [![](https://img.shields.io/github/issues/GrenderG/Toasty.svg)](https://github.com/GrenderG/Toasty/issues) | | Framework pack size | 31 KB | 500 KB | 50 KB | | Framework maintenance status| 维护中 | 停止维护 | 停止维护 | @@ -238,12 +246,16 @@ new Toast * Shape view framework: [ShapeView](https://github.com/getActivity/ShapeView)![](https://img.shields.io/github/stars/getActivity/ShapeView.svg)![](https://img.shields.io/github/forks/getActivity/ShapeView.svg) +* Shape drawable framework: [ShapeDrawable](https://github.com/getActivity/ShapeDrawable)![](https://img.shields.io/github/stars/getActivity/ShapeDrawable.svg)![](https://img.shields.io/github/forks/getActivity/ShapeDrawable.svg) + * Language switching framework: [Multi Languages](https://github.com/getActivity/MultiLanguages)![](https://img.shields.io/github/stars/getActivity/MultiLanguages.svg)![](https://img.shields.io/github/forks/getActivity/MultiLanguages.svg) * Gson parsing fault tolerance: [GsonFactory](https://github.com/getActivity/GsonFactory)![](https://img.shields.io/github/stars/getActivity/GsonFactory.svg)![](https://img.shields.io/github/forks/getActivity/GsonFactory.svg) * Logcat viewing framework: [Logcat](https://github.com/getActivity/Logcat)![](https://img.shields.io/github/stars/getActivity/Logcat.svg)![](https://img.shields.io/github/forks/getActivity/Logcat.svg) +* Nested scrolling layout framework:[NestedScrollLayout](https://github.com/getActivity/NestedScrollLayout) ![](https://img.shields.io/github/stars/getActivity/NestedScrollLayout.svg) ![](https://img.shields.io/github/forks/getActivity/NestedScrollLayout.svg) + * Android version guide: [AndroidVersionAdapter](https://github.com/getActivity/AndroidVersionAdapter)![](https://img.shields.io/github/stars/getActivity/AndroidVersionAdapter.svg)![](https://img.shields.io/github/forks/getActivity/AndroidVersionAdapter.svg) * Android code standard: [AndroidCodeStandard](https://github.com/getActivity/AndroidCodeStandard)![](https://img.shields.io/github/stars/getActivity/AndroidCodeStandard.svg)![](https://img.shields.io/github/forks/getActivity/AndroidCodeStandard.svg) diff --git a/README.md b/README.md index 8e0b3f1..ca824b2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ * 博客地址:[只需体验三分钟,你就会跟我一样,爱上这款 Toast](https://www.jianshu.com/p/9b174ee2c571) -* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Toaster/releases/download/12.3/Toaster.apk) +* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Toaster/releases/download/12.5/Toaster.apk) ![](picture/zh/download_demo_apk_qr_code.png) @@ -53,7 +53,7 @@ android { dependencies { // 吐司框架:https://github.com/getActivity/Toaster - implementation 'com.github.getActivity:Toaster:12.3' + implementation 'com.github.getActivity:Toaster:12.5' } ``` @@ -132,13 +132,21 @@ Toaster.setInterceptor(IToastInterceptor interceptor); Toaster.getInterceptor(); ``` +#### 框架混淆规则 + +* 在混淆规则文件 `proguard-rules.pro` 中加入 + +```text +-keep class com.hjq.toast.** {*;} +``` + ## [常见疑问请点击此处查看](HelpDoc-zh.md) #### 不同 Toast 框架之间的对比 | 功能或细节 | [Toaster](https://github.com/getActivity/Toaster) | [AndroidUtilCode-ToastUtils](https://github.com/Blankj/AndroidUtilCode) | [Toasty](https://github.com/GrenderG/Toasty) | | :----: | :------: | :-----: | :-----: | -| 对应版本 | 12.3 | 1.30.6 | 1.5.0 | +| 对应版本 | 12.5 | 1.30.6 | 1.5.0 | | issues 数 | [![](https://img.shields.io/github/issues/getActivity/Toaster.svg)](https://github.com/getActivity/Toaster/issues) | [![](https://img.shields.io/github/issues/Blankj/AndroidUtilCode.svg)](https://github.com/Blankj/AndroidUtilCode/issues) | [![](https://img.shields.io/github/issues/GrenderG/Toasty.svg)](https://github.com/GrenderG/Toasty/issues) | | 框架体积 | 32 KB | 500 KB | 50 KB | | 框架维护状态 | 维护中 | 停止维护 | 停止维护 | @@ -244,7 +252,9 @@ new Toast * 悬浮窗框架:[EasyWindow](https://github.com/getActivity/EasyWindow) ![](https://img.shields.io/github/stars/getActivity/EasyWindow.svg) ![](https://img.shields.io/github/forks/getActivity/EasyWindow.svg) -* Shape 框架:[ShapeView](https://github.com/getActivity/ShapeView) ![](https://img.shields.io/github/stars/getActivity/ShapeView.svg) ![](https://img.shields.io/github/forks/getActivity/ShapeView.svg) +* ShapeView 框架:[ShapeView](https://github.com/getActivity/ShapeView) ![](https://img.shields.io/github/stars/getActivity/ShapeView.svg) ![](https://img.shields.io/github/forks/getActivity/ShapeView.svg) + +* ShapeDrawable 框架:[ShapeDrawable](https://github.com/getActivity/ShapeDrawable) ![](https://img.shields.io/github/stars/getActivity/ShapeDrawable.svg) ![](https://img.shields.io/github/forks/getActivity/ShapeDrawable.svg) * 语种切换框架:[MultiLanguages](https://github.com/getActivity/MultiLanguages) ![](https://img.shields.io/github/stars/getActivity/MultiLanguages.svg) ![](https://img.shields.io/github/forks/getActivity/MultiLanguages.svg) @@ -252,6 +262,8 @@ new Toast * 日志查看框架:[Logcat](https://github.com/getActivity/Logcat) ![](https://img.shields.io/github/stars/getActivity/Logcat.svg) ![](https://img.shields.io/github/forks/getActivity/Logcat.svg) +* 嵌套滚动布局框架:[NestedScrollLayout](https://github.com/getActivity/NestedScrollLayout) ![](https://img.shields.io/github/stars/getActivity/NestedScrollLayout.svg) ![](https://img.shields.io/github/forks/getActivity/NestedScrollLayout.svg) + * Android 版本适配:[AndroidVersionAdapter](https://github.com/getActivity/AndroidVersionAdapter) ![](https://img.shields.io/github/stars/getActivity/AndroidVersionAdapter.svg) ![](https://img.shields.io/github/forks/getActivity/AndroidVersionAdapter.svg) * Android 代码规范:[AndroidCodeStandard](https://github.com/getActivity/AndroidCodeStandard) ![](https://img.shields.io/github/stars/getActivity/AndroidCodeStandard.svg) ![](https://img.shields.io/github/forks/getActivity/AndroidCodeStandard.svg) @@ -276,12 +288,10 @@ new Toast #### Android 技术 Q 群:10047167 -#### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat: +#### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:([点击查看捐赠列表](https://github.com/getActivity/Donate)) ![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_ali.png) ![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_wechat.png) -#### [点击查看捐赠列表](https://github.com/getActivity/Donate) - #### 广告区 * 我现在任腾讯云服务器推广大使,大家如果有购买服务器的需求,可以通过下面的链接购买 diff --git a/app/build.gradle b/app/build.gradle index f110d64..138a8ec 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.hjq.toast.demo" minSdkVersion 16 targetSdkVersion 33 - versionCode 1203 - versionName "12.3" + versionCode 1205 + versionName "12.5" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -62,14 +62,14 @@ dependencies { implementation 'com.google.android.material:material:1.4.0' // 标题栏框架:https://github.com/getActivity/TitleBar - implementation 'com.github.getActivity:TitleBar:10.3' + implementation 'com.github.getActivity:TitleBar:10.5' // 权限请求框架:https://github.com/getActivity/XXPermissions - implementation 'com.github.getActivity:XXPermissions:18.0' + implementation 'com.github.getActivity:XXPermissions:18.3' // 悬浮窗框架:https://github.com/getActivity/EasyWindow - implementation 'com.github.getActivity:EasyWindow:10.0' + implementation 'com.github.getActivity:EasyWindow:10.3' // 内存泄漏捕捉:https://github.com/square/leakcanary - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12' } \ No newline at end of file diff --git a/app/src/main/java/com/hjq/toast/demo/MainActivity.java b/app/src/main/java/com/hjq/toast/demo/MainActivity.java index 1f9d895..f77df07 100644 --- a/app/src/main/java/com/hjq/toast/demo/MainActivity.java +++ b/app/src/main/java/com/hjq/toast/demo/MainActivity.java @@ -7,9 +7,7 @@ import android.util.TypedValue; import android.view.Gravity; import android.view.View; - import androidx.appcompat.app.AppCompatActivity; - import com.google.android.material.snackbar.Snackbar; import com.hjq.bar.OnTitleBarListener; import com.hjq.bar.TitleBar; @@ -59,6 +57,13 @@ public void showLongToast(View v) { Toaster.showLong(R.string.demo_show_long_toast_result); } + public void showCrossPageToast(View v) { + ToastParams params = new ToastParams(); + params.text = getString(R.string.demo_show_cross_page_toast_result); + params.crossPageShow = true; + Toaster.show(params); + } + public void delayShowToast(View v) { Toaster.delayedShow(R.string.demo_show_toast_with_two_second_delay_result, 2000); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 682735a..df79f34 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -54,6 +54,14 @@ android:onClick="showLongToast" android:text="@string/demo_show_long_toast" /> +