25
25
26
26
public class ToastUtils {
27
27
28
+ private MyHandler mHandler ;
28
29
private static Toast mToast ;
29
30
private static ToastUtils instance ;
30
- private MyHandler mHandler ;
31
31
private static WeakReference <Context > weakContext ;
32
32
33
33
public static ToastUtils initToast (Context context ) {
@@ -38,9 +38,9 @@ public static ToastUtils initToast(Context context) {
38
38
private static ToastUtils getInstance (Context context ) {
39
39
if (instance == null ) {
40
40
synchronized (ToastUtils .class ) {
41
- Log .d ("==w" , "instance为空 > 1 again" );
41
+ // Log.d("==w", "instance为空 > 1 again");
42
42
if (instance == null ) {
43
- Log .d ("==w" , "instance为空 > 2 实例化" );
43
+ // Log.d("==w", "instance为空 > 2 实例化");
44
44
instance = new ToastUtils (context );
45
45
}
46
46
}
@@ -88,7 +88,7 @@ public void handleMessage(Message msg) {
88
88
switch (msg .what ) {
89
89
case 0 :
90
90
if (mToast != null ) {
91
- Log .d ("==w" , "handleMessage: mToast不为空" );
91
+ // Log.d("==w", "handleMessage: mToast不为空");
92
92
toastShow ();
93
93
94
94
ThreadPoolManager .execute (new Runnable () {
@@ -98,10 +98,10 @@ public void run() {
98
98
99
99
if (count <= time ) {
100
100
SystemClock .sleep (100 );
101
- Log .d ("==w" , ">> handleMessage: count: " + count + "\t \t VS\t \t time: " + time );
101
+ // Log.d("==w", ">> handleMessage: count: " + count + "\t\tVS\t\ttime: " + time);
102
102
getInstance (weakContext .get ()).getHandler ().sendEmptyMessage (0 );
103
103
} else {
104
- Log .d ("==w" , "handleMessage: 结束了。。。" );
104
+ // Log.d("==w", "handleMessage: 结束了。。。");
105
105
//重置
106
106
count = 0 ;
107
107
if (mToast != null ) {
@@ -110,8 +110,8 @@ public void run() {
110
110
}
111
111
}
112
112
113
- String threadName = Thread .currentThread ().getName ();
114
- Log .d ("==w" , "run: 当前线程名: " + threadName + "\n " );
113
+ // String threadName = Thread.currentThread().getName();
114
+ // Log.d("==w", "run: 当前线程名: " + threadName + "\n");
115
115
}
116
116
});
117
117
}
@@ -150,7 +150,7 @@ private void showMyToast(String msg, final long millisecond) {
150
150
View mToastView = mToast .getView ();
151
151
TextView mtv = (TextView ) mToastView .findViewById (R .id .toast_message );
152
152
if (!mtv .getText ().equals (msg )) {
153
- Log .d ("==w" , "showMyToast: 与之前的值不相等: " + mtv .getText ());
153
+ // Log.d("==w", "showMyToast: 与之前的值不相等: " + mtv.getText());
154
154
//不相等就表示可以更新Toast了
155
155
mtv .setText (msg );
156
156
}
@@ -182,7 +182,7 @@ private void showMyToast(String msg, final long millisecond) {
182
182
public void run () {
183
183
//表示0.1秒跑一次
184
184
SystemClock .sleep (100 );
185
- Log .d ("==w" , "run: 发送 0 !!" );
185
+ // Log.d("==w", "run: 发送 0 !!");
186
186
getInstance (weakContext .get ()).getHandler ().sendEmptyMessage (0 );
187
187
}
188
188
});
@@ -209,19 +209,19 @@ private String getResourceString(int strId) {
209
209
//主线、子线程中的封装Toast
210
210
private static void toastShow () {
211
211
if (isInMainThread ) {
212
- Log .d ("==w" , "主线程 --- Toast" );
212
+ // Log.d("==w", "主线程 --- Toast");
213
213
mToast .show ();
214
214
} else {
215
215
try {
216
- Log .d ("==w" , "如果处在子线程,那么需要换到主线程中再Toast" );
216
+ // Log.d("==w", "如果处在子线程,那么需要换到主线程中再Toast");
217
217
ThreadUtils .runInUIThread (new Runnable () {
218
218
@ Override
219
219
public void run () {
220
220
mToast .show ();
221
221
}
222
222
});
223
223
} catch (Exception e ) {
224
- Log .d ("==w" , "Toast错误..." );
224
+ // Log.d("==w", "Toast错误...");
225
225
e .printStackTrace ();
226
226
}
227
227
}
@@ -275,7 +275,7 @@ public static void showToast(String msg) {
275
275
*/
276
276
public static void showToastLong (String msg ) {
277
277
//不能直接填标识符,不然会失效(那些表示0、1)
278
- Log .d ("==w" , "toast: " + msg );
278
+ // Log.d("==w", "toast: " + msg);
279
279
getInstance (weakContext .get ()).getHandler ().showMyToast (msg , 3500 );
280
280
}
281
281
0 commit comments