Skip to content

Commit efc1343

Browse files
committed
see 06/13 log
1 parent 95b712b commit efc1343

File tree

11 files changed

+230
-109
lines changed

11 files changed

+230
-109
lines changed

README-CN.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,20 @@ getMeasuredHeight: 获取测量视图高度
485485

486486
* ### Snackbar相关→[SnackbarUtils.java][snackbar.java][Demo][snackbar.demo]
487487
```
488-
showShort : 显示短时snackbar
489-
showLong : 显示长时snackbar
490-
showIndefinite: 显示自定义时长snackbar
491-
addView : 为SnackBar添加布局
492-
dismiss : 取消snackbar显示
488+
with : 设置snackbar依赖view
489+
setMessage : 设置消息
490+
setMessageColor: 设置消息颜色
491+
setBgColor : 设置背景色
492+
setBgResource : 设置背景资源
493+
setDuration : 设置显示时长
494+
setAction : 设置行为
495+
show : 显示snackbar
496+
showSuccess : 显示预设成功的snackbar
497+
showWarning : 显示预设警告的snackbar
498+
showError : 显示预设错误的snackbar
499+
dismiss : 消失snackbar
500+
getView : 获取snackbar视图
501+
addView : 添加snackbar视图
493502
```
494503

495504
* ### SpannableString相关→[SpanUtils.java][span.java][Demo][span.demo]

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,20 @@ getMeasuredHeight
485485

486486
* ### About Snackbar→[SnackbarUtils.java][snackbar.java][Demo][snackbar.demo]
487487
```
488-
showShort
489-
showLong
490-
showIndefinite
491-
addView
488+
with
489+
setMessage
490+
setMessageColor
491+
setBgColor
492+
setBgResource
493+
setDuration
494+
setAction
495+
show
496+
showSuccess
497+
showWarning
498+
showError
492499
dismiss
500+
getView
501+
addView
493502
```
494503

495504
* ### About Span→[SpanUtils.java][span.java][Demo][span.demo]

app/src/main/java/com/blankj/androidutilcode/activity/SnackbarActivity.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public void initView(Bundle savedInstanceState, View view) {
4848
findViewById(R.id.btn_indefinite_snackbar_with_action).setOnClickListener(this);
4949
findViewById(R.id.btn_add_view).setOnClickListener(this);
5050
findViewById(R.id.btn_add_view_with_action).setOnClickListener(this);
51+
findViewById(R.id.btn_show_success).setOnClickListener(this);
52+
findViewById(R.id.btn_show_warning).setOnClickListener(this);
53+
findViewById(R.id.btn_show_error).setOnClickListener(this);
5154
findViewById(R.id.btn_cancel_snackbar).setOnClickListener(this);
5255
}
5356

@@ -72,7 +75,7 @@ public void onWidgetClick(View view) {
7275
.setMessage(getMsg(R.string.snackbar_short))
7376
.setMessageColor(Color.WHITE)
7477
.setBgResource(R.drawable.shape_top_round_rect)
75-
.setAction(getActionText(), Color.YELLOW, new View.OnClickListener() {
78+
.setAction(getString(R.string.snackbar_click), Color.YELLOW, new View.OnClickListener() {
7679
@Override
7780
public void onClick(View v) {
7881
ToastUtils.showShort(getString(R.string.snackbar_click));
@@ -96,7 +99,7 @@ public void onClick(View v) {
9699
.setMessageColor(Color.WHITE)
97100
.setBgResource(R.drawable.shape_top_round_rect)
98101
.setDuration(SnackbarUtils.LENGTH_LONG)
99-
.setAction(getActionText(), Color.YELLOW, new View.OnClickListener() {
102+
.setAction(getString(R.string.snackbar_click), Color.YELLOW, new View.OnClickListener() {
100103
@Override
101104
public void onClick(View v) {
102105
ToastUtils.showShort(getString(R.string.snackbar_click));
@@ -120,7 +123,7 @@ public void onClick(View v) {
120123
.setMessageColor(Color.WHITE)
121124
.setDuration(SnackbarUtils.LENGTH_INDEFINITE)
122125
.setBgResource(R.drawable.shape_top_round_rect)
123-
.setAction(getActionText(), Color.YELLOW, new View.OnClickListener() {
126+
.setAction(getString(R.string.snackbar_click), Color.YELLOW, new View.OnClickListener() {
124127
@Override
125128
public void onClick(View v) {
126129
ToastUtils.showShort(getString(R.string.snackbar_click));
@@ -158,6 +161,24 @@ public void onClick(View v) {
158161
}
159162
break;
160163

164+
case R.id.btn_show_success:
165+
SnackbarUtils.with(snackBarRootView)
166+
.setMessage(getMsg(R.string.snackbar_success))
167+
.showSuccess();
168+
break;
169+
170+
case R.id.btn_show_warning:
171+
SnackbarUtils.with(snackBarRootView)
172+
.setMessage(getMsg(R.string.snackbar_warning))
173+
.showWarning();
174+
break;
175+
176+
case R.id.btn_show_error:
177+
SnackbarUtils.with(snackBarRootView)
178+
.setMessage(getMsg(R.string.snackbar_error))
179+
.showError();
180+
break;
181+
161182
case R.id.btn_cancel_snackbar:
162183
SnackbarUtils.dismiss();
163184
break;
@@ -166,17 +187,10 @@ public void onClick(View v) {
166187

167188
private SpannableStringBuilder getMsg(@StringRes int resId) {
168189
return new SpanUtils()
169-
.append(getString(resId))
190+
.appendLine(getString(resId))
170191
.setFontSize(24, true)
171192
.setIconMargin(R.mipmap.ic_launcher, 32, SpanUtils.ALIGN_CENTER)
172-
.create();
173-
}
174-
175-
private SpannableStringBuilder getActionText() {
176-
return new SpanUtils()
177-
.append("Click")
178-
.setFontSize(100, true)
179-
.setBold()
193+
.append(" ").setFontSize(0)
180194
.create();
181195
}
182196
}
Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.blankj.androidutilcode.activity;
22

33
import android.content.Context;
4+
import android.graphics.Color;
45
import android.os.Bundle;
56
import android.view.Gravity;
67
import android.view.View;
7-
import android.widget.TextView;
88

99
import com.blankj.androidutilcode.R;
1010
import com.blankj.androidutilcode.base.BaseActivity;
11+
import com.blankj.utilcode.util.SpanUtils;
1112
import com.blankj.utilcode.util.ToastUtils;
1213

1314
/**
@@ -20,14 +21,9 @@
2021
*/
2122
public class ToastActivity extends BaseActivity {
2223

23-
private boolean isDefaultLocation;
24-
private boolean isDefaultView;
25-
private TextView tvAboutToast;
26-
2724
@Override
2825
public void initData(Bundle bundle) {
29-
isDefaultLocation = true;
30-
isDefaultView = true;
26+
3127
}
3228

3329
@Override
@@ -37,17 +33,16 @@ public int bindLayout() {
3733

3834
@Override
3935
public void initView(Bundle savedInstanceState, View view) {
40-
findViewById(R.id.btn_toggle_location).setOnClickListener(this);
41-
findViewById(R.id.btn_toggle_view).setOnClickListener(this);
42-
findViewById(R.id.btn_show_short_toast_safe).setOnClickListener(this);
43-
findViewById(R.id.btn_show_long_toast_safe).setOnClickListener(this);
44-
findViewById(R.id.btn_show_short_toast).setOnClickListener(this);
45-
findViewById(R.id.btn_show_long_toast).setOnClickListener(this);
46-
findViewById(R.id.btn_cancel_toast).setOnClickListener(this);
47-
tvAboutToast = (TextView) findViewById(R.id.tv_about_toast);
48-
tvAboutToast.setText("is default location: " + isDefaultLocation
49-
+ "\nis default view: " + isDefaultView
50-
);
36+
view.findViewById(R.id.btn_show_short_toast_safe).setOnClickListener(this);
37+
view.findViewById(R.id.btn_show_short_toast).setOnClickListener(this);
38+
view.findViewById(R.id.btn_show_long_toast_safe).setOnClickListener(this);
39+
view.findViewById(R.id.btn_show_long_toast).setOnClickListener(this);
40+
view.findViewById(R.id.btn_show_green_font).setOnClickListener(this);
41+
view.findViewById(R.id.btn_show_custom_bg).setOnClickListener(this);
42+
view.findViewById(R.id.btn_show_span).setOnClickListener(this);
43+
view.findViewById(R.id.btn_show_custom_view).setOnClickListener(this);
44+
view.findViewById(R.id.btn_show_middle).setOnClickListener(this);
45+
view.findViewById(R.id.btn_cancel_toast).setOnClickListener(this);
5146
}
5247

5348
@Override
@@ -57,23 +52,8 @@ public void doBusiness(Context context) {
5752

5853
@Override
5954
public void onWidgetClick(View view) {
55+
resetToast();
6056
switch (view.getId()) {
61-
case R.id.btn_toggle_location:
62-
if (isDefaultLocation) {
63-
ToastUtils.setGravity(Gravity.CENTER, 0, 0);
64-
} else {
65-
ToastUtils.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, getResources().getDimensionPixelSize(R.dimen.offset_64));
66-
}
67-
isDefaultLocation = !isDefaultLocation;
68-
break;
69-
case R.id.btn_toggle_view:
70-
if (isDefaultView) {
71-
ToastUtils.setView(R.layout.toast_custom);
72-
} else {
73-
ToastUtils.setView(null);
74-
}
75-
isDefaultView = !isDefaultView;
76-
break;
7757
case R.id.btn_show_short_toast_safe:
7858
new Thread(new Runnable() {
7959
@Override
@@ -82,6 +62,9 @@ public void run() {
8262
}
8363
}).start();
8464
break;
65+
case R.id.btn_show_short_toast:
66+
ToastUtils.showShort(R.string.toast_short);
67+
break;
8568
case R.id.btn_show_long_toast_safe:
8669
new Thread(new Runnable() {
8770
@Override
@@ -90,25 +73,49 @@ public void run() {
9073
}
9174
}).start();
9275
break;
93-
case R.id.btn_show_short_toast:
94-
ToastUtils.showShort(R.string.toast_short);
95-
break;
9676
case R.id.btn_show_long_toast:
97-
ToastUtils.showShort(R.string.toast_long);
77+
ToastUtils.showLong(R.string.toast_long);
78+
break;
79+
case R.id.btn_show_green_font:
80+
ToastUtils.setMessageColor(Color.GREEN);
81+
ToastUtils.showLong(R.string.toast_green_font);
82+
break;
83+
case R.id.btn_show_custom_bg:
84+
ToastUtils.setBgResource(R.drawable.shape_round_rect);
85+
ToastUtils.showLong(R.string.toast_custom_bg);
86+
break;
87+
case R.id.btn_show_span:
88+
ToastUtils.showLong(new SpanUtils()
89+
.appendLine(getString(R.string.toast_span))
90+
.setFontSize(24, true)
91+
.setIconMargin(R.mipmap.ic_launcher, 32, SpanUtils.ALIGN_CENTER)
92+
.append(" ").setFontSize(0)
93+
.create());
94+
break;
95+
case R.id.btn_show_custom_view:
96+
ToastUtils.setView(R.layout.toast_custom);
97+
ToastUtils.showLong("");
98+
break;
99+
case R.id.btn_show_middle:
100+
ToastUtils.setGravity(Gravity.CENTER, 0, 0);
101+
ToastUtils.showLong(R.string.toast_middle);
98102
break;
99103
case R.id.btn_cancel_toast:
100104
ToastUtils.cancel();
101105
break;
102106
}
103-
tvAboutToast.setText("is default location: " + isDefaultLocation
104-
+ "\nis default view: " + isDefaultView
105-
);
106107
}
107108

108109
@Override
109110
protected void onDestroy() {
111+
resetToast();
112+
super.onDestroy();
113+
}
114+
115+
private void resetToast() {
116+
ToastUtils.setMessageColor(0x12000000);
117+
ToastUtils.setBgResource(-1);
110118
ToastUtils.setView(null);
111119
ToastUtils.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, getResources().getDimensionPixelSize(R.dimen.offset_64));
112-
super.onDestroy();
113120
}
114121
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@
6767
android:layout_height="wrap_content"
6868
android:text="@string/snackbar_add_view_with_action"/>
6969

70+
<Button
71+
android:id="@+id/btn_show_success"
72+
style="@style/WideBtnStyle"
73+
android:layout_width="match_parent"
74+
android:layout_height="wrap_content"
75+
android:text="@string/snackbar_show_success"/>
76+
77+
<Button
78+
android:id="@+id/btn_show_warning"
79+
style="@style/WideBtnStyle"
80+
android:layout_width="match_parent"
81+
android:layout_height="wrap_content"
82+
android:text="@string/snackbar_show_warning"/>
83+
84+
<Button
85+
android:id="@+id/btn_show_error"
86+
style="@style/WideBtnStyle"
87+
android:layout_width="match_parent"
88+
android:layout_height="wrap_content"
89+
android:text="@string/snackbar_show_error"/>
90+
7091

7192
<Button
7293
android:id="@+id/btn_cancel_snackbar"

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,68 @@
1111
android:orientation="vertical"
1212
android:padding="@dimen/spacing_16">
1313

14-
<TextView
15-
android:id="@+id/tv_about_toast"
16-
style="@style/TextStyle"
14+
<Button
15+
android:id="@+id/btn_show_short_toast_safe"
16+
style="@style/WideBtnStyle"
1717
android:layout_width="match_parent"
1818
android:layout_height="wrap_content"
19-
android:gravity="center"/>
19+
android:text="@string/toast_show_short_safe"/>
2020

2121
<Button
22-
android:id="@+id/btn_toggle_location"
22+
android:id="@+id/btn_show_short_toast"
2323
style="@style/WideBtnStyle"
2424
android:layout_width="match_parent"
2525
android:layout_height="wrap_content"
26-
android:text="@string/toast_toggle_location"/>
26+
android:text="@string/toast_show_short"/>
2727

2828
<Button
29-
android:id="@+id/btn_toggle_view"
29+
android:id="@+id/btn_show_long_toast_safe"
3030
style="@style/WideBtnStyle"
3131
android:layout_width="match_parent"
3232
android:layout_height="wrap_content"
33-
android:text="@string/toast_toggle_view"/>
33+
android:text="@string/toast_show_long_safe"/>
3434

3535
<Button
36-
android:id="@+id/btn_show_short_toast_safe"
36+
android:id="@+id/btn_show_long_toast"
3737
style="@style/WideBtnStyle"
3838
android:layout_width="match_parent"
3939
android:layout_height="wrap_content"
40-
android:text="@string/toast_show_short_safe"/>
40+
android:text="@string/toast_show_long"/>
4141

4242
<Button
43-
android:id="@+id/btn_show_long_toast_safe"
43+
android:id="@+id/btn_show_green_font"
4444
style="@style/WideBtnStyle"
4545
android:layout_width="match_parent"
4646
android:layout_height="wrap_content"
47-
android:text="@string/toast_show_long_safe"/>
47+
android:text="@string/toast_show_green_font"/>
4848

4949
<Button
50-
android:id="@+id/btn_show_short_toast"
50+
android:id="@+id/btn_show_custom_bg"
5151
style="@style/WideBtnStyle"
5252
android:layout_width="match_parent"
5353
android:layout_height="wrap_content"
54-
android:text="@string/toast_show_short"/>
54+
android:text="@string/toast_show_custom_bg"/>
5555

5656
<Button
57-
android:id="@+id/btn_show_long_toast"
57+
android:id="@+id/btn_show_span"
5858
style="@style/WideBtnStyle"
5959
android:layout_width="match_parent"
6060
android:layout_height="wrap_content"
61-
android:text="@string/toast_show_long"/>
61+
android:text="@string/toast_show_span"/>
62+
63+
<Button
64+
android:id="@+id/btn_show_custom_view"
65+
style="@style/WideBtnStyle"
66+
android:layout_width="match_parent"
67+
android:layout_height="wrap_content"
68+
android:text="@string/toast_show_custom_view"/>
69+
70+
<Button
71+
android:id="@+id/btn_show_middle"
72+
style="@style/WideBtnStyle"
73+
android:layout_width="match_parent"
74+
android:layout_height="wrap_content"
75+
android:text="@string/toast_show_middle"/>
6276

6377
<Button
6478
android:id="@+id/btn_cancel_toast"

0 commit comments

Comments
 (0)