diff --git a/.github/ISSUE_TEMPLATE/issue_en_template_bug.md b/.github/ISSUE_TEMPLATE/issue_en_template_bug.md index e7133bf..870302a 100644 --- a/.github/ISSUE_TEMPLATE/issue_en_template_bug.md +++ b/.github/ISSUE_TEMPLATE/issue_en_template_bug.md @@ -19,6 +19,8 @@ assignees: getActivity * Whether the problem can be reproduced [Required]: Yes/No +* Android Project targetSdkVersion [Required]: Please fill in your project target sdk version + * Phone information in question [Required]: Please fill in the phone brand and model in question * Android version in question [Required]: Please fill in the Android version in question diff --git a/.github/ISSUE_TEMPLATE/issue_zh_template_bug.md b/.github/ISSUE_TEMPLATE/issue_zh_template_bug.md index 5a28ccc..e10b152 100644 --- a/.github/ISSUE_TEMPLATE/issue_zh_template_bug.md +++ b/.github/ISSUE_TEMPLATE/issue_zh_template_bug.md @@ -18,6 +18,8 @@ assignees: getActivity * 是否必现【必填】:是/否 +* 项目 targetSdkVersion【必填】:XX + * 出现问题的手机信息【必填】:请填写出现问题的品牌和机型 * 出现问题的安卓版本【必填】:请填写出现问题的 Android 版本 diff --git a/README-en.md b/README-en.md index 246d148..55413dc 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.0/Toaster.apk) +* [Click here to download demo apk directly](https://github.com/getActivity/Toaster/releases/download/12.2/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.0' + implementation 'com.github.getActivity:Toaster:12.2' } ``` @@ -134,7 +134,7 @@ Toaster.getInterceptor(); | 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.0 | 1.30.6 | 1.5.0 | +| Corresponding version | 12.2 | 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| 维护中 | 停止维护 | 停止维护 | diff --git a/README.md b/README.md index 72271e8..85d31a2 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.0/Toaster.apk) +* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Toaster/releases/download/12.2/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.0' + implementation 'com.github.getActivity:Toaster:12.2' } ``` @@ -138,9 +138,9 @@ Toaster.getInterceptor(); | 功能或细节 | [Toaster](https://github.com/getActivity/Toaster) | [AndroidUtilCode-ToastUtils](https://github.com/Blankj/AndroidUtilCode) | [Toasty](https://github.com/GrenderG/Toasty) | | :----: | :------: | :-----: | :-----: | -| 对应版本 | 12.0 | 1.30.6 | 1.5.0 | +| 对应版本 | 12.2 | 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) | -| 框架体积 | 31 KB | 500 KB | 50 KB | +| 框架体积 | 32 KB | 500 KB | 50 KB | | 框架维护状态 | 维护中 | 停止维护 | 停止维护 | | 调用代码定位 | ✅ | ❌ | ❌ | | 支持在子线程中调用显示 | ✅ | ✅ | ❌ | @@ -264,6 +264,8 @@ new Toast * 表情包大集合:[EmojiPackage](https://github.com/getActivity/EmojiPackage) ![](https://img.shields.io/github/stars/getActivity/EmojiPackage.svg) ![](https://img.shields.io/github/forks/getActivity/EmojiPackage.svg) +* AI 资源大汇总:[AiIndex](https://github.com/getActivity/AiIndex) ![](https://img.shields.io/github/stars/getActivity/AiIndex.svg) ![](https://img.shields.io/github/forks/getActivity/AiIndex.svg) + * 省市区 Json 数据:[ProvinceJson](https://github.com/getActivity/ProvinceJson) ![](https://img.shields.io/github/stars/getActivity/ProvinceJson.svg) ![](https://img.shields.io/github/forks/getActivity/ProvinceJson.svg) * Markdown 语法文档:[MarkdownDoc](https://github.com/getActivity/MarkdownDoc) ![](https://img.shields.io/github/stars/getActivity/MarkdownDoc.svg) ![](https://img.shields.io/github/forks/getActivity/MarkdownDoc.svg) diff --git a/app/build.gradle b/app/build.gradle index 23d2757..6cc663d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.hjq.toast.demo" minSdkVersion 16 targetSdkVersion 31 - versionCode 1200 - versionName "12.0" + versionCode 1202 + versionName "12.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/library/build.gradle b/library/build.gradle index 5212b8f..e7fac65 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -5,8 +5,8 @@ android { defaultConfig { minSdkVersion 14 - versionCode 1200 - versionName "12.0" + versionCode 1202 + versionName "12.2" } // 使用 JDK 1.8 diff --git a/library/src/main/java/com/hjq/toast/ToastStrategy.java b/library/src/main/java/com/hjq/toast/ToastStrategy.java index b0e913f..319ce67 100644 --- a/library/src/main/java/com/hjq/toast/ToastStrategy.java +++ b/library/src/main/java/com/hjq/toast/ToastStrategy.java @@ -124,8 +124,7 @@ public IToast createToast(IToastStyle style) { } else { toast = new SystemToast(mApplication); } - - if (isSupportToastStyle(toast)) { + if (isSupportToastStyle(toast) || !onlyShowSystemToastStyle()) { diyToastStyle(toast, style); } return toast; @@ -251,6 +250,41 @@ public void run() { } } + /** + * 当前是否只能显示系统 Toast 样式 + */ + protected boolean onlyShowSystemToastStyle() { + // Github issue 地址:https://github.com/getActivity/Toaster/issues/103 + // Toast.CHANGE_TEXT_TOASTS_IN_THE_SYSTEM = 147798919L + return isChangeEnabledCompat(147798919L); + } + + @SuppressLint("PrivateApi") + protected boolean isChangeEnabledCompat(long changeId) { + // 需要注意的是这个 api 是在 android 11 的时候出现的,反射前需要先判断好版本 + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + return true; + } + try { + // 因为 Compatibility.isChangeEnabled() 普通应用根本调用不到,反射也不行 + // 通过 Toast.isSystemRenderedTextToast 也没有办法反射到 + // 最后发现反射 CompatChanges.isChangeEnabled 是可以的 + Class aClass = Class.forName("android.app.compat.CompatChanges"); + Method method = aClass.getMethod("isChangeEnabled", long.class); + method.setAccessible(true); + return Boolean.parseBoolean(String.valueOf(method.invoke(null, changeId))); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return false; + } + /** * 是否有通知栏权限 */ diff --git a/library/src/main/java/com/hjq/toast/config/IToast.java b/library/src/main/java/com/hjq/toast/config/IToast.java index c1d82d9..f413544 100644 --- a/library/src/main/java/com/hjq/toast/config/IToast.java +++ b/library/src/main/java/com/hjq/toast/config/IToast.java @@ -93,6 +93,8 @@ default TextView findMessageView(View view) { view.setId(android.R.id.message); } else if (view.getId() != android.R.id.message) { // 必须将 TextView 的 id 值设置成 android.R.id.message + // 否则 Android 11 手机上在后台 toast.setText 的时候会出现报错 + // java.lang.RuntimeException: This Toast was not created with Toast.makeText() throw new IllegalArgumentException("You must set the ID value of TextView to android.R.id.message"); } return (TextView) view; diff --git a/picture/zh/help_doc_rename_vote.jpg b/picture/zh/help_doc_rename_vote.jpg index 5d73a52..013e989 100644 Binary files a/picture/zh/help_doc_rename_vote.jpg and b/picture/zh/help_doc_rename_vote.jpg differ