Skip to content

Commit 5804d7c

Browse files
committed
新增支持设置 Toast 跨页面显示
1 parent 17adbca commit 5804d7c

File tree

17 files changed

+116
-38
lines changed

17 files changed

+116
-38
lines changed

HelpDoc-en.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
* [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)
1212

13+
* [How to implement cross page display of toast in the framework](#how-to-implement-cross-page-display-of-toast-in-the-framework)
14+
1315
* [Why the framework prefers to use window manager to implement toast](#why-the-framework-prefers-to-use-window-manager-to-implement-toast)
1416

1517
#### How to customize toast display animation
@@ -146,6 +148,17 @@ public class ToastStrategy {
146148

147149
* 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.
148150

151+
#### How to implement cross page display of toast in the framework
152+
153+
* 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:
154+
155+
```java
156+
ToastParams params = new ToastParams();
157+
params.text = "I am a Toast that can be displayed across pages";
158+
// Indicates that this Toast needs to be displayed across pages
159+
params.crossPageShow = true;
160+
Toaster.show(params);
161+
149162
#### Why the framework prefers to use window manager to implement toast
150163

151164
* There are too many pits in the system toast, the main problems are as follows:

HelpDoc-zh.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
* [框架无法满足我当前使用的场景怎么办](#框架无法满足我当前使用的场景怎么办)
1414

15+
* [框架中的 Toast 如何实现跨页面显示](#框架中的-toast-如何实现跨页面显示)
16+
1517
* [为什么框架优先使用 WindowManager 来实现 Toast](#为什么框架优先使用-windowManager-来实现-toast)
1618

1719
#### 框架怎么改名了
@@ -162,6 +164,18 @@ public class ToastStrategy {
162164

163165
* Toaster 框架意在解决一些的 Toast 需求,如果 Toaster 无法满足你的需求,你可以考虑使用 [EasyWindow](https://github.com/getActivity/EasyWindow) 悬浮窗框架来实现。
164166

167+
#### 框架中的 Toast 如何实现跨页面显示
168+
169+
* Toaster 中默认 Toast 是只在当前 Activity 上面展示的,如果遇到 Activity 切换,那么在 Toast 随着当前 Activity 销毁而不可见,导致无法在新 Activity 上面展示,框架在 [12.5](https://github.com/getActivity/Toaster/releases/tag/12.5) 版本新增支持了这一功能,具体调用示例如下:
170+
171+
```java
172+
ToastParams params = new ToastParams();
173+
params.text = "我是一个能跨页面展示的 Toast";
174+
// 表示这个 Toast 需要跨页面展示
175+
params.crossPageShow = true;
176+
Toaster.show(params);
177+
```
178+
165179
#### 为什么框架优先使用 WindowManager 来实现 Toast
166180

167181
* 系统 Toast 的坑太多了,主要问题表现如下:

README-en.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* Project address: [Github](https://github.com/getActivity/Toaster)
66

7-
* [Click here to download demo apk directly](https://github.com/getActivity/Toaster/releases/download/12.3/Toaster.apk)
7+
* [Click here to download demo apk directly](https://github.com/getActivity/Toaster/releases/download/12.5/Toaster.apk)
88

99
![](picture/en/demo_toast_activity.jpg) ![](picture/en/demo_toast_style_white.jpg) ![](picture/en/demo_toast_style_black.jpg)
1010

@@ -49,7 +49,7 @@ android {
4949
5050
dependencies {
5151
// Toast framework:https://github.com/getActivity/Toaster
52-
implementation 'com.github.getActivity:Toaster:12.3'
52+
implementation 'com.github.getActivity:Toaster:12.5'
5353
}
5454
```
5555

@@ -128,13 +128,21 @@ Toaster.setInterceptor(IToastInterceptor interceptor);
128128
Toaster.getInterceptor();
129129
```
130130

131+
#### Framework proguard rules
132+
133+
* Added in the `proguard-rules.pro` file:
134+
135+
```text
136+
-keep class com.hjq.toast.** {*;}
137+
```
138+
131139
## [Please click here to view frequently asked questions](HelpDoc-en.md)
132140

133141
#### Comparison between different Toast frameworks
134142

135143
| Function or detail | [Toaster](https://github.com/getActivity/Toaster) |[ AndroidUtilCode-ToastUtils ](https://github.com/Blankj/AndroidUtilCode)| [Toasty](https://github.com/GrenderG/Toasty) |
136144
| :----: | :------: | :-----: | :-----: |
137-
| Corresponding version | 12.3 | 1.30.6 | 1.5.0 |
145+
| Corresponding version | 12.5 | 1.30.6 | 1.5.0 |
138146
| 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) |
139147
| Framework pack size | 31 KB | 500 KB | 50 KB |
140148
| Framework maintenance status| 维护中 | 停止维护 | 停止维护 |
@@ -238,12 +246,16 @@ new Toast
238246

239247
* 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)
240248

249+
* 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)
250+
241251
* 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)
242252

243253
* 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)
244254

245255
* 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)
246256

257+
* 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)
258+
247259
* 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)
248260

249261
* 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)

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
* 博客地址:[只需体验三分钟,你就会跟我一样,爱上这款 Toast](https://www.jianshu.com/p/9b174ee2c571)
88

9-
* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Toaster/releases/download/12.3/Toaster.apk)
9+
* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Toaster/releases/download/12.5/Toaster.apk)
1010

1111
![](picture/zh/download_demo_apk_qr_code.png)
1212

@@ -53,7 +53,7 @@ android {
5353
5454
dependencies {
5555
// 吐司框架:https://github.com/getActivity/Toaster
56-
implementation 'com.github.getActivity:Toaster:12.3'
56+
implementation 'com.github.getActivity:Toaster:12.5'
5757
}
5858
```
5959

@@ -132,13 +132,21 @@ Toaster.setInterceptor(IToastInterceptor interceptor);
132132
Toaster.getInterceptor();
133133
```
134134

135+
#### 框架混淆规则
136+
137+
* 在混淆规则文件 `proguard-rules.pro` 中加入
138+
139+
```text
140+
-keep class com.hjq.toast.** {*;}
141+
```
142+
135143
## [常见疑问请点击此处查看](HelpDoc-zh.md)
136144

137145
#### 不同 Toast 框架之间的对比
138146

139147
| 功能或细节 | [Toaster](https://github.com/getActivity/Toaster) | [AndroidUtilCode-ToastUtils](https://github.com/Blankj/AndroidUtilCode) | [Toasty](https://github.com/GrenderG/Toasty) |
140148
| :----: | :------: | :-----: | :-----: |
141-
| 对应版本 | 12.3 | 1.30.6 | 1.5.0 |
149+
| 对应版本 | 12.5 | 1.30.6 | 1.5.0 |
142150
| 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) |
143151
| 框架体积 | 32 KB | 500 KB | 50 KB |
144152
| 框架维护状态 | 维护中 | 停止维护 | 停止维护 |
@@ -244,14 +252,18 @@ new Toast
244252

245253
* 悬浮窗框架:[EasyWindow](https://github.com/getActivity/EasyWindow) ![](https://img.shields.io/github/stars/getActivity/EasyWindow.svg) ![](https://img.shields.io/github/forks/getActivity/EasyWindow.svg)
246254

247-
* 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)
255+
* 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)
256+
257+
* 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)
248258

249259
* 语种切换框架:[MultiLanguages](https://github.com/getActivity/MultiLanguages) ![](https://img.shields.io/github/stars/getActivity/MultiLanguages.svg) ![](https://img.shields.io/github/forks/getActivity/MultiLanguages.svg)
250260

251261
* Gson 解析容错:[GsonFactory](https://github.com/getActivity/GsonFactory) ![](https://img.shields.io/github/stars/getActivity/GsonFactory.svg) ![](https://img.shields.io/github/forks/getActivity/GsonFactory.svg)
252262

253263
* 日志查看框架:[Logcat](https://github.com/getActivity/Logcat) ![](https://img.shields.io/github/stars/getActivity/Logcat.svg) ![](https://img.shields.io/github/forks/getActivity/Logcat.svg)
254264

265+
* 嵌套滚动布局框架:[NestedScrollLayout](https://github.com/getActivity/NestedScrollLayout) ![](https://img.shields.io/github/stars/getActivity/NestedScrollLayout.svg) ![](https://img.shields.io/github/forks/getActivity/NestedScrollLayout.svg)
266+
255267
* 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)
256268

257269
* 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
276288

277289
#### Android 技术 Q 群:10047167
278290

279-
#### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:
291+
#### 如果您觉得我的开源库帮你节省了大量的开发时间,请扫描下方的二维码随意打赏,要是能打赏个 10.24 :monkey_face:就太:thumbsup:了。您的支持将鼓励我继续创作:octocat:[点击查看捐赠列表](https://github.com/getActivity/Donate)
280292

281293
![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_ali.png) ![](https://raw.githubusercontent.com/getActivity/Donate/master/picture/pay_wechat.png)
282294

283-
#### [点击查看捐赠列表](https://github.com/getActivity/Donate)
284-
285295
#### 广告区
286296

287297
* 我现在任腾讯云服务器推广大使,大家如果有购买服务器的需求,可以通过下面的链接购买

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.hjq.toast.demo"
88
minSdkVersion 16
99
targetSdkVersion 33
10-
versionCode 1203
11-
versionName "12.3"
10+
versionCode 1205
11+
versionName "12.5"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414

@@ -62,14 +62,14 @@ dependencies {
6262
implementation 'com.google.android.material:material:1.4.0'
6363

6464
// 标题栏框架:https://github.com/getActivity/TitleBar
65-
implementation 'com.github.getActivity:TitleBar:10.3'
65+
implementation 'com.github.getActivity:TitleBar:10.5'
6666

6767
// 权限请求框架:https://github.com/getActivity/XXPermissions
68-
implementation 'com.github.getActivity:XXPermissions:18.0'
68+
implementation 'com.github.getActivity:XXPermissions:18.3'
6969

7070
// 悬浮窗框架:https://github.com/getActivity/EasyWindow
71-
implementation 'com.github.getActivity:EasyWindow:10.0'
71+
implementation 'com.github.getActivity:EasyWindow:10.3'
7272

7373
// 内存泄漏捕捉:https://github.com/square/leakcanary
74-
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
74+
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
7575
}

app/src/main/java/com/hjq/toast/demo/MainActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import android.util.TypedValue;
88
import android.view.Gravity;
99
import android.view.View;
10-
1110
import androidx.appcompat.app.AppCompatActivity;
12-
1311
import com.google.android.material.snackbar.Snackbar;
1412
import com.hjq.bar.OnTitleBarListener;
1513
import com.hjq.bar.TitleBar;
@@ -59,6 +57,13 @@ public void showLongToast(View v) {
5957
Toaster.showLong(R.string.demo_show_long_toast_result);
6058
}
6159

60+
public void showCrossPageToast(View v) {
61+
ToastParams params = new ToastParams();
62+
params.text = getString(R.string.demo_show_cross_page_toast_result);
63+
params.crossPageShow = true;
64+
Toaster.show(params);
65+
}
66+
6267
public void delayShowToast(View v) {
6368
Toaster.delayedShow(R.string.demo_show_toast_with_two_second_delay_result, 2000);
6469
}

app/src/main/res/layout/activity_main.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
android:onClick="showLongToast"
5555
android:text="@string/demo_show_long_toast" />
5656

57+
<Button
58+
android:layout_width="wrap_content"
59+
android:layout_height="wrap_content"
60+
android:layout_gravity="center_horizontal"
61+
android:layout_marginTop="10dp"
62+
android:onClick="showCrossPageToast"
63+
android:text="@string/demo_show_cross_page_toast" />
64+
5765
<Button
5866
android:layout_width="wrap_content"
5967
android:layout_height="wrap_content"

app/src/main/res/values-zh/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<string name="demo_show_toast">简单显示一个 Toast</string>
55
<string name="demo_show_short_toast">显示一个短 Toast</string>
66
<string name="demo_show_long_toast">显示一个长 Toast</string>
7+
<string name="demo_show_cross_page_toast">显示一个跨页面的 Toast</string>
78
<string name="demo_show_toast_with_two_second_delay">延迟 2 秒显示 Toast</string>
89
<string name="demo_show_toast_in_the_subthread">在子线程中显示吐司</string>
910
<string name="demo_switch_to_white_style">切换为白色样式(局部生效)</string>
@@ -21,6 +22,7 @@
2122
<string name="demo_show_toast_result">我是普通的 Toast我是普通的 Toast我是普通的 Toast我是普通的 Toast我是普通的 Toast</string>
2223
<string name="demo_show_short_toast_result">我是一个短 Toast</string>
2324
<string name="demo_show_long_toast_result">我是一个长 Toast</string>
25+
<string name="demo_show_cross_page_toast_result">我是跨页面显示的 Toast</string>
2426
<string name="demo_show_toast_with_two_second_delay_result">我是延迟 2 秒显示的 Toast</string>
2527
<string name="demo_show_toast_in_the_subthread_result">我是子线程中弹出的吐司</string>
2628
<string name="demo_switch_to_white_style_result">我是白色样式的 Toast</string>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<string name="demo_show_toast">Simple show a toast</string>
66
<string name="demo_show_short_toast">Show a short toast</string>
77
<string name="demo_show_long_toast">Show a long toast</string>
8+
<string name="demo_show_cross_page_toast">Show a cross page toast</string>
89
<string name="demo_show_toast_with_two_second_delay">Show toast with 2 second delay</string>
910
<string name="demo_show_toast_in_the_subthread">Show toast in the subthread</string>
1011
<string name="demo_switch_to_white_style">Switch to white style (local effect)</string>
@@ -22,6 +23,7 @@
2223
<string name="demo_show_toast_result">I am an normal toast</string>
2324
<string name="demo_show_short_toast_result">I am a short toast</string>
2425
<string name="demo_show_long_toast_result">I am a long toast</string>
26+
<string name="demo_show_cross_page_toast_result">I am a cross page toast</string>
2527
<string name="demo_show_toast_with_two_second_delay_result">I am a toast displayed with a delay of 2 seconds</string>
2628
<string name="demo_show_toast_in_the_subthread_result">I am the toast that pops up in the subthread</string>
2729
<string name="demo_switch_to_white_style_result">I am toast in white style</string>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ allprojects {
3535
setBuildDir(new File(rootDir, "build/${path.replaceAll(':', '/')}"))
3636
}
3737

38-
task clean(type: Delete) {
38+
tasks.register('clean', Delete) {
3939
delete rootProject.buildDir
4040
}

0 commit comments

Comments
 (0)