3
3
import android .annotation .TargetApi ;
4
4
import android .content .Context ;
5
5
import android .os .Build ;
6
+ import android .os .Handler ;
6
7
import android .view .LayoutInflater ;
7
8
import android .view .View ;
8
9
import android .widget .Button ;
@@ -54,6 +55,31 @@ public static void ok(Context context, String msg) {
54
55
mToast .show ();
55
56
}
56
57
58
+ public static void ok (Context context , String msg , String icon , int time ){
59
+ mInflater = LayoutInflater .from (context );
60
+ if (!icon .equals ("" )) {
61
+ mView = mInflater .inflate (R .layout .toast_ok_icon , null );
62
+ IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
63
+ img .setText (icon );
64
+ img .setTextSize (20 );
65
+ } else {
66
+ mView = mInflater .inflate (R .layout .toast_ok , null );
67
+ }
68
+ initSetButtonMsg (msg );
69
+ mToast = new Toast (context );
70
+ mToast .setView (mView );
71
+ mToast .setDuration (Toast .LENGTH_SHORT );
72
+ mToast .show ();
73
+ if (time != 0 ) {
74
+ Handler handler = new Handler ();
75
+ handler .postDelayed (new Runnable () {
76
+ @ Override public void run () {
77
+ mToast .cancel ();
78
+ }
79
+ }, time );
80
+ }
81
+ }
82
+
57
83
public static void error (Context context , String msg ) {
58
84
mInflater = LayoutInflater .from (context );
59
85
mView = mInflater .inflate (R .layout .toast_error , null );
@@ -64,18 +90,29 @@ public static void error(Context context, String msg) {
64
90
mToast .show ();
65
91
}
66
92
67
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN ) public static void error (Context context , String msg ,
68
- String icon ) {
93
+ @ TargetApi (Build .VERSION_CODES .JELLY_BEAN ) public static void error (Context context , String msg , String icon , int time ){
69
94
mInflater = LayoutInflater .from (context );
70
- mView = mInflater .inflate (R .layout .toast_error_icon , null );
95
+ if (!icon .equals ("" )) {
96
+ mView = mInflater .inflate (R .layout .toast_error_icon , null );
97
+ IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
98
+ img .setText (icon );
99
+ img .setTextSize (20 );
100
+ } else {
101
+ mView = mInflater .inflate (R .layout .toast_error , null );
102
+ }
71
103
initSetButtonMsg (msg );
72
- IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
73
- img .setText (icon );
74
- img .setTextSize (20 );
75
104
mToast = new Toast (context );
76
105
mToast .setView (mView );
77
106
mToast .setDuration (Toast .LENGTH_SHORT );
78
107
mToast .show ();
108
+ if (time != 0 ) {
109
+ Handler handler = new Handler ();
110
+ handler .postDelayed (new Runnable () {
111
+ @ Override public void run () {
112
+ mToast .cancel ();
113
+ }
114
+ }, time );
115
+ }
79
116
}
80
117
81
118
public static void info (Context context , String msg ) {
@@ -88,19 +125,29 @@ public static void info(Context context, String msg) {
88
125
mToast .show ();
89
126
}
90
127
91
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN ) public static void info (Context context , String msg ,
92
- String icon ) {
128
+ @ TargetApi (Build .VERSION_CODES .JELLY_BEAN ) public static void info (Context context , String msg , String icon , int time ){
93
129
mInflater = LayoutInflater .from (context );
94
- mView = mInflater .inflate (R .layout .toast_info_icon , null );
130
+ if (!icon .equals ("" )) {
131
+ mView = mInflater .inflate (R .layout .toast_info_icon , null );
132
+ IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
133
+ img .setText (icon );
134
+ img .setTextSize (20 );
135
+ } else {
136
+ mView = mInflater .inflate (R .layout .toast_info , null );
137
+ }
95
138
initSetButtonMsg (msg );
96
- ;
97
- IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
98
- img .setText (icon );
99
- img .setTextSize (20 );
100
139
mToast = new Toast (context );
101
140
mToast .setView (mView );
102
141
mToast .setDuration (Toast .LENGTH_SHORT );
103
142
mToast .show ();
143
+ if (time != 0 ) {
144
+ Handler handler = new Handler ();
145
+ handler .postDelayed (new Runnable () {
146
+ @ Override public void run () {
147
+ mToast .cancel ();
148
+ }
149
+ }, time );
150
+ }
104
151
}
105
152
106
153
public static void muted (Context context , String msg ) {
@@ -113,18 +160,29 @@ public static void muted(Context context, String msg) {
113
160
mToast .show ();
114
161
}
115
162
116
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN ) public static void muted (Context context , String msg ,
117
- String icon ) {
163
+ @ TargetApi (Build .VERSION_CODES .JELLY_BEAN ) public static void muted (Context context , String msg , String icon , int time ){
118
164
mInflater = LayoutInflater .from (context );
119
- mView = mInflater .inflate (R .layout .toast_muted_icon , null );
165
+ if (!icon .equals ("" )) {
166
+ mView = mInflater .inflate (R .layout .toast_muted_icon , null );
167
+ IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
168
+ img .setText (icon );
169
+ img .setTextSize (20 );
170
+ } else {
171
+ mView = mInflater .inflate (R .layout .toast_muted , null );
172
+ }
120
173
initSetButtonMsg (msg );
121
- IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
122
- img .setText (icon );
123
- img .setTextSize (20 );
124
174
mToast = new Toast (context );
125
175
mToast .setView (mView );
126
176
mToast .setDuration (Toast .LENGTH_SHORT );
127
177
mToast .show ();
178
+ if (time != 0 ) {
179
+ Handler handler = new Handler ();
180
+ handler .postDelayed (new Runnable () {
181
+ @ Override public void run () {
182
+ mToast .cancel ();
183
+ }
184
+ }, time );
185
+ }
128
186
}
129
187
130
188
public static void warning (Context context , String msg ) {
@@ -137,18 +195,29 @@ public static void warning(Context context, String msg) {
137
195
mToast .show ();
138
196
}
139
197
140
- @ TargetApi (Build .VERSION_CODES .JELLY_BEAN ) public static void warning (Context context , String msg ,
141
- String icon ) {
198
+ @ TargetApi (Build .VERSION_CODES .JELLY_BEAN ) public static void warning (Context context , String msg , String icon , int time ){
142
199
mInflater = LayoutInflater .from (context );
143
- mView = mInflater .inflate (R .layout .toast_warning_icon , null );
200
+ if (!icon .equals ("" )) {
201
+ mView = mInflater .inflate (R .layout .toast_warning_icon , null );
202
+ IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
203
+ img .setText (icon );
204
+ img .setTextSize (20 );
205
+ } else {
206
+ mView = mInflater .inflate (R .layout .toast_warning , null );
207
+ }
144
208
initSetButtonMsg (msg );
145
- IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
146
- img .setText (icon );
147
- img .setTextSize (20 );
148
209
mToast = new Toast (context );
149
210
mToast .setView (mView );
150
211
mToast .setDuration (Toast .LENGTH_SHORT );
151
212
mToast .show ();
213
+ if (time != 0 ) {
214
+ Handler handler = new Handler ();
215
+ handler .postDelayed (new Runnable () {
216
+ @ Override public void run () {
217
+ mToast .cancel ();
218
+ }
219
+ }, time );
220
+ }
152
221
}
153
222
154
223
private static Button initSetButtonMsg (String msg ) {
0 commit comments