23
23
* author: Blankj
24
24
* blog : http://blankj.com
25
25
* time : 2016/10/16
26
- * desc : Snackbar 相关工具类
26
+ * desc : utils about snackbar
27
27
* </pre>
28
28
*/
29
29
public final class SnackbarUtils {
@@ -45,7 +45,7 @@ public final class SnackbarUtils {
45
45
46
46
private static WeakReference <Snackbar > sReference ;
47
47
48
- private View parent ;
48
+ private View view ;
49
49
private CharSequence message ;
50
50
private int messageColor ;
51
51
private int bgColor ;
@@ -58,7 +58,7 @@ public final class SnackbarUtils {
58
58
59
59
private SnackbarUtils (final View parent ) {
60
60
setDefault ();
61
- this .parent = parent ;
61
+ this .view = parent ;
62
62
}
63
63
64
64
private void setDefault () {
@@ -73,94 +73,94 @@ private void setDefault() {
73
73
}
74
74
75
75
/**
76
- * 设置 snackbar 依赖 view
76
+ * Set the view to find a parent from.
77
77
*
78
- * @param parent 依赖 view
79
- * @return {@link SnackbarUtils}
78
+ * @param view The view to find a parent from.
79
+ * @return the single {@link SnackbarUtils} instance
80
80
*/
81
- public static SnackbarUtils with (@ NonNull final View parent ) {
82
- return new SnackbarUtils (parent );
81
+ public static SnackbarUtils with (@ NonNull final View view ) {
82
+ return new SnackbarUtils (view );
83
83
}
84
84
85
85
/**
86
- * 设置消息
86
+ * Set the message.
87
87
*
88
- * @param msg 消息
89
- * @return {@link SnackbarUtils}
88
+ * @param msg The message.
89
+ * @return the single {@link SnackbarUtils} instance
90
90
*/
91
91
public SnackbarUtils setMessage (@ NonNull final CharSequence msg ) {
92
92
this .message = msg ;
93
93
return this ;
94
94
}
95
95
96
96
/**
97
- * 设置消息颜色
97
+ * Set the color of message.
98
98
*
99
- * @param color 颜色
100
- * @return {@link SnackbarUtils}
99
+ * @param color The color of message.
100
+ * @return the single {@link SnackbarUtils} instance
101
101
*/
102
102
public SnackbarUtils setMessageColor (@ ColorInt final int color ) {
103
103
this .messageColor = color ;
104
104
return this ;
105
105
}
106
106
107
107
/**
108
- * 设置背景色
108
+ * Set the color of background.
109
109
*
110
- * @param color 背景色
111
- * @return {@link SnackbarUtils}
110
+ * @param color The color of background.
111
+ * @return the single {@link SnackbarUtils} instance
112
112
*/
113
113
public SnackbarUtils setBgColor (@ ColorInt final int color ) {
114
114
this .bgColor = color ;
115
115
return this ;
116
116
}
117
117
118
118
/**
119
- * 设置背景资源
119
+ * Set the resource of background.
120
120
*
121
- * @param bgResource 背景资源
122
- * @return {@link SnackbarUtils}
121
+ * @param bgResource The resource of background.
122
+ * @return the single {@link SnackbarUtils} instance
123
123
*/
124
124
public SnackbarUtils setBgResource (@ DrawableRes final int bgResource ) {
125
125
this .bgResource = bgResource ;
126
126
return this ;
127
127
}
128
128
129
129
/**
130
- * 设置显示时长
130
+ * Set the duration.
131
131
*
132
- * @param duration 时长
132
+ * @param duration The duration.
133
133
* <ul>
134
- * <li>{@link Duration#LENGTH_INDEFINITE}永久 </li>
135
- * <li>{@link Duration#LENGTH_SHORT}短时 </li>
136
- * <li>{@link Duration#LENGTH_LONG}长时 </li>
134
+ * <li>{@link Duration#LENGTH_INDEFINITE}</li>
135
+ * <li>{@link Duration#LENGTH_SHORT } </li>
136
+ * <li>{@link Duration#LENGTH_LONG } </li>
137
137
* </ul>
138
- * @return {@link SnackbarUtils}
138
+ * @return the single {@link SnackbarUtils} instance
139
139
*/
140
140
public SnackbarUtils setDuration (@ Duration final int duration ) {
141
141
this .duration = duration ;
142
142
return this ;
143
143
}
144
144
145
145
/**
146
- * 设置行为
146
+ * Set the action.
147
147
*
148
- * @param text 文本
149
- * @param listener 事件
150
- * @return {@link SnackbarUtils}
148
+ * @param text The text.
149
+ * @param listener The click listener.
150
+ * @return the single {@link SnackbarUtils} instance
151
151
*/
152
152
public SnackbarUtils setAction (@ NonNull final CharSequence text ,
153
153
@ NonNull final View .OnClickListener listener ) {
154
154
return setAction (text , COLOR_DEFAULT , listener );
155
155
}
156
156
157
157
/**
158
- * 设置行为
158
+ * Set the action.
159
159
*
160
- * @param text 文本
161
- * @param color 文本颜色
162
- * @param listener 事件
163
- * @return {@link SnackbarUtils}
160
+ * @param text The text.
161
+ * @param color The color of text.
162
+ * @param listener The click listener.
163
+ * @return the single {@link SnackbarUtils} instance
164
164
*/
165
165
166
166
public SnackbarUtils setAction (@ NonNull final CharSequence text ,
@@ -173,20 +173,20 @@ public SnackbarUtils setAction(@NonNull final CharSequence text,
173
173
}
174
174
175
175
/**
176
- * 设置底边距
176
+ * Set the bottom margin.
177
177
*
178
- * @param bottomMargin 底边距
178
+ * @param bottomMargin The size of bottom margin, in pixel.
179
179
*/
180
180
public SnackbarUtils setBottomMargin (@ IntRange (from = 1 ) final int bottomMargin ) {
181
181
this .bottomMargin = bottomMargin ;
182
182
return this ;
183
183
}
184
184
185
185
/**
186
- * 显示 snackbar
186
+ * Show the snackbar.
187
187
*/
188
188
public void show () {
189
- final View view = parent ;
189
+ final View view = this . view ;
190
190
if (view == null ) return ;
191
191
if (messageColor != COLOR_DEFAULT ) {
192
192
SpannableString spannableString = new SpannableString (message );
@@ -220,7 +220,7 @@ public void show() {
220
220
}
221
221
222
222
/**
223
- * 显示预设成功的 snackbar
223
+ * Show the snackbar with success style.
224
224
*/
225
225
public void showSuccess () {
226
226
bgColor = COLOR_SUCCESS ;
@@ -230,7 +230,7 @@ public void showSuccess() {
230
230
}
231
231
232
232
/**
233
- * 显示预设警告的 snackbar
233
+ * Show the snackbar with warning style.
234
234
*/
235
235
public void showWarning () {
236
236
bgColor = COLOR_WARNING ;
@@ -240,7 +240,7 @@ public void showWarning() {
240
240
}
241
241
242
242
/**
243
- * 显示预设错误的 snackbar
243
+ * Show the snackbar with error style.
244
244
*/
245
245
public void showError () {
246
246
bgColor = COLOR_ERROR ;
@@ -250,7 +250,7 @@ public void showError() {
250
250
}
251
251
252
252
/**
253
- * 消失 snackbar
253
+ * Dismiss the snackbar.
254
254
*/
255
255
public static void dismiss () {
256
256
if (sReference != null && sReference .get () != null ) {
@@ -260,9 +260,9 @@ public static void dismiss() {
260
260
}
261
261
262
262
/**
263
- * 获取 snackbar 视图
263
+ * Return the view of snackbar.
264
264
*
265
- * @return snackbar 视图
265
+ * @return the view of snackbar
266
266
*/
267
267
public static View getView () {
268
268
Snackbar snackbar = sReference .get ();
@@ -271,11 +271,11 @@ public static View getView() {
271
271
}
272
272
273
273
/**
274
- * 添加 snackbar 视图
275
- * <p>在 {@link #show()}之后调用 </p>
274
+ * Add view to the snackbar.
275
+ * <p>call it after {@link #show()}</p>
276
276
*
277
- * @param layoutId 布局文件
278
- * @param params 布局参数
277
+ * @param layoutId The id of layout.
278
+ * @param params The params.
279
279
*/
280
280
public static void addView (@ LayoutRes final int layoutId ,
281
281
@ NonNull final ViewGroup .LayoutParams params ) {
@@ -289,11 +289,11 @@ public static void addView(@LayoutRes final int layoutId,
289
289
}
290
290
291
291
/**
292
- * 添加 snackbar 视图
293
- * <p>在 {@link #show()}之后调用 </p>
292
+ * Add view to the snackbar.
293
+ * <p>call it after {@link #show()}</p>
294
294
*
295
- * @param child 要添加的 view
296
- * @param params 布局参数
295
+ * @param child The child view.
296
+ * @param params The params.
297
297
*/
298
298
public static void addView (@ NonNull final View child ,
299
299
@ NonNull final ViewGroup .LayoutParams params ) {
0 commit comments