Skip to content

Commit f8dc96c

Browse files
committed
新增设置对 View 长按监听事件方法
修正子 View 设置点击事件后父 View 触摸监听没有回调的问题
1 parent 8dadf58 commit f8dc96c

File tree

18 files changed

+1156
-955
lines changed

18 files changed

+1156
-955
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
Apache License
3-
Version 2.0, January 2004
3+
Version 2.0, January 2019
44
http://www.apache.org/licenses/
55

66
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright [yyyy] [name of copyright owner]
190+
Copyright 2019 Huang JinQun
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ allprojects {
3232
```groovy
3333
dependencies {
3434
// 悬浮窗框架:https://github.com/getActivity/XToast
35-
implementation 'com.github.getActivity:XToast:8.1'
35+
implementation 'com.github.getActivity:XToast:8.2'
3636
}
3737
```
3838

@@ -44,7 +44,7 @@ dependencies {
4444
// 传入 Activity 对象表示设置成局部的,不需要有悬浮窗权限
4545
// 传入 Application 对象表示设置成全局的,但需要有悬浮窗权限
4646
new XToast<>(XToastActivity.this)
47-
.setView(R.layout.toast_hint)
47+
.setContentView(R.layout.toast_hint)
4848
// 设置成可拖拽的
4949
//.setDraggable()
5050
// 设置显示时长
@@ -74,7 +74,7 @@ new XToast<>(XToastActivity.this)
7474

7575
```kotlin
7676
XToast<XToast<*>>(activity).apply {
77-
setView(R.layout.toast_hint)
77+
setContentView(R.layout.toast_hint)
7878
// 设置成可拖拽的
7979
//setDraggable()
8080
// 设置显示时长
@@ -98,7 +98,7 @@ XToast<XToast<*>>(activity).apply {
9898

9999
```kotlin
100100
XToast<XToast<*>>(activity)
101-
.setView(R.layout.toast_hint)
101+
.setContentView(R.layout.toast_hint)
102102
// 设置成可拖拽的
103103
//.setDraggable()
104104
// 设置显示时长
@@ -190,6 +190,8 @@ public final class FloatingLifecycle implements Application.ActivityLifecycleCal
190190

191191
* 国际化框架:[MultiLanguages](https://github.com/getActivity/MultiLanguages)
192192

193+
* Shape 框架:[ShapeView](https://github.com/getActivity/ShapeView)
194+
193195
* Gson 解析容错:[GsonFactory](https://github.com/getActivity/GsonFactory)
194196

195197
* 日志查看框架:[Logcat](https://github.com/getActivity/Logcat)

XToast.apk

4.32 KB
Binary file not shown.

app/AppSignature.jks

2.13 KB
Binary file not shown.

app/build.gradle

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,45 @@ android {
77
applicationId "com.hjq.xtoast.demo"
88
minSdkVersion 16
99
targetSdkVersion 30
10-
versionCode 81
11-
versionName "8.1"
10+
versionCode 82
11+
versionName "8.2"
1212
}
13+
14+
// 支持 Java JDK 8
15+
compileOptions {
16+
targetCompatibility JavaVersion.VERSION_1_8
17+
sourceCompatibility JavaVersion.VERSION_1_8
18+
}
19+
20+
// Apk 签名的那些事:https://www.jianshu.com/p/a1f8e5896aa2
21+
signingConfigs {
22+
config {
23+
storeFile file(StoreFile)
24+
storePassword StorePassword
25+
keyAlias KeyAlias
26+
keyPassword KeyPassword
27+
}
28+
}
29+
1330
buildTypes {
14-
release {
31+
debug {
1532
minifyEnabled false
1633
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34+
signingConfig signingConfigs.config
35+
}
36+
37+
release {
38+
minifyEnabled true
39+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
40+
signingConfig signingConfigs.config
1741
}
1842
}
1943

20-
// 支持 Java JDK 8
21-
compileOptions {
22-
targetCompatibility JavaVersion.VERSION_1_8
23-
sourceCompatibility JavaVersion.VERSION_1_8
44+
applicationVariants.all { variant ->
45+
// apk 输出文件名配置
46+
variant.outputs.all { output ->
47+
outputFileName = rootProject.getName() + '.apk'
48+
}
2449
}
2550
}
2651

@@ -35,10 +60,10 @@ dependencies {
3560
implementation 'com.google.android.material:material:1.3.0'
3661

3762
// 权限请求框架:https://github.com/getActivity/XXPermissions
38-
implementation 'com.github.getActivity:XXPermissions:11.6'
63+
implementation 'com.github.getActivity:XXPermissions:12.2'
3964

4065
// 标题栏框架:https://github.com/getActivity/TitleBar
41-
implementation 'com.github.getActivity:TitleBar:8.6'
66+
implementation 'com.github.getActivity:TitleBar:9.0'
4267

4368
// 吐司框架:https://github.com/getActivity/ToastUtils
4469
implementation 'com.github.getActivity:ToastUtils:9.5'

app/gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
StoreFile = AppSignature.jks
2+
StorePassword = AndroidProject
3+
KeyAlias = AndroidProject
4+
KeyPassword = AndroidProject

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public final class IOSToast {
1717
public static void showSucceed(Activity activity, CharSequence text) {
1818
new XToast<>(activity)
1919
.setDuration(TIME)
20-
.setView(R.layout.toast_hint)
20+
.setContentView(R.layout.toast_hint)
2121
.setAnimStyle(android.R.style.Animation_Translucent)
2222
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)
2323
.setText(android.R.id.message, text)
@@ -27,7 +27,7 @@ public static void showSucceed(Activity activity, CharSequence text) {
2727
public static void showFail(Activity activity, CharSequence text) {
2828
new XToast<>(activity)
2929
.setDuration(TIME)
30-
.setView(R.layout.toast_hint)
30+
.setContentView(R.layout.toast_hint)
3131
.setAnimStyle(android.R.style.Animation_Activity)
3232
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_error)
3333
.setText(android.R.id.message, text)
@@ -37,7 +37,7 @@ public static void showFail(Activity activity, CharSequence text) {
3737
public static void showWarn(Activity activity, CharSequence text) {
3838
new XToast<>(activity)
3939
.setDuration(TIME)
40-
.setView(R.layout.toast_hint)
40+
.setContentView(R.layout.toast_hint)
4141
.setAnimStyle(android.R.style.Animation_Dialog)
4242
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_warning)
4343
.setText(android.R.id.message, text)

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected void onCreate(Bundle savedInstanceState) {
3636
public void show1(View v) {
3737
new XToast<>(this)
3838
.setDuration(3000)
39-
.setView(R.layout.toast_hint)
39+
.setContentView(R.layout.toast_hint)
4040
.setAnimStyle(android.R.style.Animation_Translucent)
4141
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)
4242
.setText(android.R.id.message, "这个动画是不是很骚")
@@ -46,7 +46,7 @@ public void show1(View v) {
4646
public void show2(View v) {
4747
new XToast<>(this)
4848
.setDuration(1000)
49-
.setView(R.layout.toast_hint)
49+
.setContentView(R.layout.toast_hint)
5050
.setAnimStyle(android.R.style.Animation_Activity)
5151
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_error)
5252
.setText(android.R.id.message, "一秒后消失")
@@ -56,7 +56,7 @@ public void show2(View v) {
5656
public void show3(View v) {
5757
new XToast<>(this)
5858
.setDuration(3000)
59-
.setView(R.layout.toast_hint)
59+
.setContentView(R.layout.toast_hint)
6060
.setAnimStyle(android.R.style.Animation_Dialog)
6161
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_warning)
6262
.setText(android.R.id.message, "是不是感觉很牛逼")
@@ -77,7 +77,7 @@ public void onDismiss(XToast<?> toast) {
7777

7878
public void show4(View v) {
7979
new XToast<>(this)
80-
.setView(R.layout.toast_hint)
80+
.setContentView(R.layout.toast_hint)
8181
.setAnimStyle(android.R.style.Animation_Translucent)
8282
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)
8383
.setText(android.R.id.message, "点我点我点我")
@@ -99,7 +99,7 @@ public void run() {
9999

100100
public void show5(View v) {
101101
new XToast<>(this)
102-
.setView(R.layout.toast_hint)
102+
.setContentView(R.layout.toast_hint)
103103
.setAnimStyle(android.R.style.Animation_Translucent)
104104
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)
105105
.setDuration(2000)
@@ -116,7 +116,7 @@ public void onClick(final XToast<?> toast, TextView view) {
116116

117117
public void show6(View v) {
118118
new XToast<>(this)
119-
.setView(R.layout.toast_hint)
119+
.setContentView(R.layout.toast_hint)
120120
.setAnimStyle(android.R.style.Animation_Translucent)
121121
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)
122122
.setText(android.R.id.message, "点我消失")
@@ -145,7 +145,7 @@ public void show7(View v) {
145145
public void onGranted(List<String> granted, boolean all) {
146146
// 传入 Application 表示这个是一个全局的 Toast
147147
new XToast<>(getApplication())
148-
.setView(R.layout.toast_phone)
148+
.setContentView(R.layout.toast_phone)
149149
.setGravity(Gravity.END | Gravity.BOTTOM)
150150
.setYOffset(200)
151151
// 设置指定的拖拽规则
@@ -163,14 +163,21 @@ public void onClick(XToast<?> toast, ImageView view) {
163163
// https://developer.android.google.cn/about/versions/10/privacy/changes#background-activity-starts
164164
}
165165
})
166+
.setOnLongClickListener(android.R.id.icon, new XToast.OnLongClickListener<View>() {
167+
@Override
168+
public boolean onLongClick(XToast<?> toast, View view) {
169+
ToastUtils.show("我被长按了");
170+
return true;
171+
}
172+
})
166173
.show();
167174
}
168175

169176
@Override
170177
public void onDenied(List<String> denied, boolean never) {
171178
new XToast<>(MainActivity.this)
172179
.setDuration(1000)
173-
.setView(R.layout.toast_hint)
180+
.setContentView(R.layout.toast_hint)
174181
.setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_error)
175182
.setText(android.R.id.message, "请先授予悬浮窗权限")
176183
.show();
@@ -182,7 +189,7 @@ public void show8(View v) {
182189
// 将 ToastUtils 中的 View 转移给 XToast 来显示
183190
new XToast<>(this)
184191
.setDuration(1000)
185-
.setView(ToastUtils.getStyle().createView(this))
192+
.setContentView(ToastUtils.getStyle().createView(this))
186193
.setAnimStyle(android.R.style.Animation_Translucent)
187194
.setText(android.R.id.message, "就问你溜不溜")
188195
.setGravity(Gravity.BOTTOM)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<com.hjq.bar.TitleBar
1212
android:layout_width="match_parent"
1313
android:layout_height="wrap_content"
14-
app:backButton="false"
14+
app:leftIcon="@null"
1515
app:title="https://github.com/getActivity/XToast" />
1616

1717
<ScrollView

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
android:layout_width="wrap_content"
55
android:layout_height="wrap_content"
66
android:layout_gravity="center"
7-
android:layout_margin="100dp"
87
android:background="@drawable/dialog_toast_bg"
98
android:gravity="center"
9+
android:layout_margin="100dp"
1010
android:minWidth="120dp"
1111
android:minHeight="120dp"
1212
android:orientation="vertical">

0 commit comments

Comments
 (0)