Skip to content

Commit ce90c9e

Browse files
committed
处理项目出现的代码警告
新增 showAsDropDown 方法 优化判断 View 是否移动代码的逻辑
1 parent b19cb6c commit ce90c9e

File tree

13 files changed

+166
-70
lines changed

13 files changed

+166
-70
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 悬浮窗框架
22

3-
* 码云地址:[Gitee](https://gitee.com/getActivity/XToast)
3+
* 项目地址:[Github](https://github.com/getActivity/XToast)[码云](https://gitee.com/getActivity/XToast)
44

55
* 博客地址:[悬浮窗需求终结者](https://www.jianshu.com/p/247d705b87b6)
66

@@ -16,11 +16,12 @@
1616

1717
```groovy
1818
buildscript {
19-
......
19+
repositories {
20+
maven { url 'https://jitpack.io' }
21+
}
2022
}
2123
allprojects {
2224
repositories {
23-
// JitPack 远程仓库:https://jitpack.io
2425
maven { url 'https://jitpack.io' }
2526
}
2627
}
@@ -31,7 +32,7 @@ allprojects {
3132
```groovy
3233
dependencies {
3334
// 悬浮窗框架:https://github.com/getActivity/XToast
34-
implementation 'com.github.getActivity:XToast:6.9'
35+
implementation 'com.github.getActivity:XToast:8.0'
3536
}
3637
```
3738

@@ -137,7 +138,7 @@ public final class FloatingLifecycle implements Application.ActivityLifecycleCal
137138
@Override
138139
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
139140
new XToast<>(activity)
140-
.setXXXX()
141+
.setXxx()
141142
.show();
142143
}
143144

@@ -221,4 +222,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
221222
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
222223
See the License for the specific language governing permissions and
223224
limitations under the License.
224-
```
225+
```

XToast.apk

720 KB
Binary file not shown.

app/build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.hjq.xtoast.demo"
88
minSdkVersion 16
99
targetSdkVersion 30
10-
versionCode 69
11-
versionName "6.9"
10+
versionCode 80
11+
versionName "8.0"
1212
}
1313
buildTypes {
1414
release {
@@ -29,18 +29,19 @@ dependencies {
2929
implementation fileTree(include: ['*.aar'], dir: 'libs')
3030
implementation project(':library')
3131

32-
// 谷歌兼容库:https://developer.android.google.cn/jetpack/androidx/releases/appcompat?hl=zh-cn
33-
implementation 'androidx.appcompat:appcompat:1.2.0'
34-
implementation 'com.google.android.material:material:1.2.1'
32+
// AppCompat 库:https://developer.android.google.cn/jetpack/androidx/releases/appcompat?hl=zh-cn
33+
implementation 'androidx.appcompat:appcompat:1.3.0'
34+
// Material 库:https://github.com/material-components/material-components-android
35+
implementation 'com.google.android.material:material:1.3.0'
3536

3637
// 权限请求框架:https://github.com/getActivity/XXPermissions
37-
implementation 'com.github.getActivity:XXPermissions:10.6'
38+
implementation 'com.github.getActivity:XXPermissions:11.6'
3839

3940
// 标题栏框架:https://github.com/getActivity/TitleBar
40-
implementation 'com.github.getActivity:TitleBar:8.5'
41+
implementation 'com.github.getActivity:TitleBar:8.6'
4142

4243
// 吐司框架:https://github.com/getActivity/ToastUtils
43-
implementation 'com.github.getActivity:ToastUtils:9.0'
44+
implementation 'com.github.getActivity:ToastUtils:9.5'
4445

4546
// 内存泄漏捕捉:https://github.com/square/leakcanary
4647
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void show4(View v) {
8686
@Override
8787
public void onClick(final XToast<?> toast, TextView view) {
8888
view.setText("那么听话啊");
89-
getWindow().getDecorView().postDelayed(new Runnable() {
89+
toast.postDelayed(new Runnable() {
9090
@Override
9191
public void run() {
9292
toast.cancel();
@@ -98,6 +98,23 @@ public void run() {
9898
}
9999

100100
public void show5(View v) {
101+
new XToast<>(this)
102+
.setView(R.layout.toast_hint)
103+
.setAnimStyle(android.R.style.Animation_Translucent)
104+
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)
105+
.setDuration(2000)
106+
.setText(android.R.id.message, "位置算的准不准")
107+
.setOnClickListener(android.R.id.message, new XToast.OnClickListener<TextView>() {
108+
109+
@Override
110+
public void onClick(final XToast<?> toast, TextView view) {
111+
toast.cancel();
112+
}
113+
})
114+
.showAsDropDown(v, Gravity.BOTTOM);
115+
}
116+
117+
public void show6(View v) {
101118
new XToast<>(this)
102119
.setView(R.layout.toast_hint)
103120
.setAnimStyle(android.R.style.Animation_Translucent)
@@ -119,7 +136,7 @@ public void onClick(XToast<?> toast, TextView view) {
119136
.show();
120137
}
121138

122-
public void show6(View v) {
139+
public void show7(View v) {
123140
XXPermissions.with(this)
124141
.permission(Permission.SYSTEM_ALERT_WINDOW)
125142
.request(new OnPermissionCallback() {
@@ -161,7 +178,7 @@ public void onDenied(List<String> denied, boolean never) {
161178
});
162179
}
163180

164-
public void show7(View v) {
181+
public void show8(View v) {
165182
// 将 ToastUtils 中的 View 转移给 XToast 来显示
166183
new XToast<>(this)
167184
.setDuration(1000)

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,30 @@
6161
android:layout_gravity="center_horizontal"
6262
android:layout_marginTop="30dp"
6363
android:onClick="show5"
64-
android:text="可自由拖拽的 Toast" />
64+
android:text="显示在 View 下方" />
6565

6666
<Button
6767
android:layout_width="wrap_content"
6868
android:layout_height="wrap_content"
6969
android:layout_gravity="center_horizontal"
7070
android:layout_marginTop="30dp"
7171
android:onClick="show6"
72-
android:text="全局可拖拽的 Toast" />
72+
android:text="可自由拖拽的 Toast" />
7373

7474
<Button
7575
android:layout_width="wrap_content"
7676
android:layout_height="wrap_content"
7777
android:layout_gravity="center_horizontal"
7878
android:layout_marginTop="30dp"
7979
android:onClick="show7"
80+
android:text="全局可拖拽的 Toast" />
81+
82+
<Button
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
android:layout_gravity="center_horizontal"
86+
android:layout_marginTop="30dp"
87+
android:onClick="show8"
8088
android:text="搭配 ToastUtils 吐司框架" />
8189
</LinearLayout>
8290

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ buildscript {
99
maven { url 'https://jitpack.io' }
1010
mavenCentral()
1111
google()
12+
// noinspection JcenterRepositoryObsolete
1213
jcenter()
1314
}
1415
dependencies {
@@ -24,6 +25,7 @@ allprojects {
2425
maven { url 'https://jitpack.io' }
2526
mavenCentral()
2627
google()
28+
// noinspection JcenterRepositoryObsolete
2729
jcenter()
2830
}
2931
}

library/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ android {
55

66
defaultConfig {
77
minSdkVersion 14
8-
versionCode 69
9-
versionName "6.9"
8+
versionCode 80
9+
versionName "8.0"
10+
}
11+
12+
android.libraryVariants.all { variant ->
13+
// aar 输出文件名配置
14+
variant.outputs.all { output ->
15+
outputFileName = "xtoast-${android.defaultConfig.versionName}.aar"
16+
}
1017
}
1118
}
1219

library/src/main/java/com/hjq/xtoast/CancelRunnable.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

library/src/main/java/com/hjq/xtoast/ToastLifecycle.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ public void onActivityDestroyed(Activity activity) {
8686
if (mToast == null) {
8787
return;
8888
}
89-
if (mToast.isShow()) {
90-
mToast.cancel();
91-
}
9289
mToast.recycle();
9390
mToast = null;
9491
}

0 commit comments

Comments
 (0)