33import android .annotation .TargetApi ;
44import android .content .Context ;
55import android .os .Build ;
6+ import android .os .Handler ;
67import android .view .LayoutInflater ;
78import android .view .View ;
89import android .widget .Button ;
@@ -54,6 +55,31 @@ public static void ok(Context context, String msg) {
5455 mToast .show ();
5556 }
5657
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+
5783 public static void error (Context context , String msg ) {
5884 mInflater = LayoutInflater .from (context );
5985 mView = mInflater .inflate (R .layout .toast_error , null );
@@ -64,18 +90,29 @@ public static void error(Context context, String msg) {
6490 mToast .show ();
6591 }
6692
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 ){
6994 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+ }
71103 initSetButtonMsg (msg );
72- IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
73- img .setText (icon );
74- img .setTextSize (20 );
75104 mToast = new Toast (context );
76105 mToast .setView (mView );
77106 mToast .setDuration (Toast .LENGTH_SHORT );
78107 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+ }
79116 }
80117
81118 public static void info (Context context , String msg ) {
@@ -88,19 +125,29 @@ public static void info(Context context, String msg) {
88125 mToast .show ();
89126 }
90127
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 ){
93129 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+ }
95138 initSetButtonMsg (msg );
96- ;
97- IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
98- img .setText (icon );
99- img .setTextSize (20 );
100139 mToast = new Toast (context );
101140 mToast .setView (mView );
102141 mToast .setDuration (Toast .LENGTH_SHORT );
103142 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+ }
104151 }
105152
106153 public static void muted (Context context , String msg ) {
@@ -113,18 +160,29 @@ public static void muted(Context context, String msg) {
113160 mToast .show ();
114161 }
115162
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 ){
118164 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+ }
120173 initSetButtonMsg (msg );
121- IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
122- img .setText (icon );
123- img .setTextSize (20 );
124174 mToast = new Toast (context );
125175 mToast .setView (mView );
126176 mToast .setDuration (Toast .LENGTH_SHORT );
127177 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+ }
128186 }
129187
130188 public static void warning (Context context , String msg ) {
@@ -137,18 +195,29 @@ public static void warning(Context context, String msg) {
137195 mToast .show ();
138196 }
139197
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 ){
142199 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+ }
144208 initSetButtonMsg (msg );
145- IconTextView img = (IconTextView ) mView .findViewById (R .id .img );
146- img .setText (icon );
147- img .setTextSize (20 );
148209 mToast = new Toast (context );
149210 mToast .setView (mView );
150211 mToast .setDuration (Toast .LENGTH_SHORT );
151212 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+ }
152221 }
153222
154223 private static Button initSetButtonMsg (String msg ) {
0 commit comments