22
33import android .os .Handler ;
44import android .os .Looper ;
5+ import android .support .annotation .StringRes ;
56import android .widget .Toast ;
67
78/**
@@ -52,7 +53,7 @@ public void run() {
5253 *
5354 * @param resId 资源Id
5455 */
55- public static void showShortToastSafe (final int resId ) {
56+ public static void showShortToastSafe (final @ StringRes int resId ) {
5657 sHandler .post (new Runnable () {
5758 @ Override
5859 public void run () {
@@ -67,7 +68,7 @@ public void run() {
6768 * @param resId 资源Id
6869 * @param args 参数
6970 */
70- public static void showShortToastSafe (final int resId , final Object ... args ) {
71+ public static void showShortToastSafe (final @ StringRes int resId , final Object ... args ) {
7172 sHandler .post (new Runnable () {
7273 @ Override
7374 public void run () {
@@ -110,7 +111,7 @@ public void run() {
110111 *
111112 * @param resId 资源Id
112113 */
113- public static void showLongToastSafe (final int resId ) {
114+ public static void showLongToastSafe (final @ StringRes int resId ) {
114115 sHandler .post (new Runnable () {
115116 @ Override
116117 public void run () {
@@ -125,7 +126,7 @@ public void run() {
125126 * @param resId 资源Id
126127 * @param args 参数
127128 */
128- public static void showLongToastSafe (final int resId , final Object ... args ) {
129+ public static void showLongToastSafe (final @ StringRes int resId , final Object ... args ) {
129130 sHandler .post (new Runnable () {
130131 @ Override
131132 public void run () {
@@ -163,7 +164,7 @@ public static void showShortToast(CharSequence text) {
163164 *
164165 * @param resId 资源Id
165166 */
166- public static void showShortToast (int resId ) {
167+ public static void showShortToast (@ StringRes int resId ) {
167168 showToast (resId , Toast .LENGTH_SHORT );
168169 }
169170
@@ -173,7 +174,7 @@ public static void showShortToast(int resId) {
173174 * @param resId 资源Id
174175 * @param args 参数
175176 */
176- public static void showShortToast (int resId , Object ... args ) {
177+ public static void showShortToast (@ StringRes int resId , Object ... args ) {
177178 showToast (resId , Toast .LENGTH_SHORT , args );
178179 }
179180
@@ -201,7 +202,7 @@ public static void showLongToast(CharSequence text) {
201202 *
202203 * @param resId 资源Id
203204 */
204- public static void showLongToast (int resId ) {
205+ public static void showLongToast (@ StringRes int resId ) {
205206 showToast (resId , Toast .LENGTH_LONG );
206207 }
207208
@@ -211,7 +212,7 @@ public static void showLongToast(int resId) {
211212 * @param resId 资源Id
212213 * @param args 参数
213214 */
214- public static void showLongToast (int resId , Object ... args ) {
215+ public static void showLongToast (@ StringRes int resId , Object ... args ) {
215216 showToast (resId , Toast .LENGTH_LONG , args );
216217 }
217218
@@ -225,30 +226,13 @@ public static void showLongToast(String format, Object... args) {
225226 showToast (format , Toast .LENGTH_LONG , args );
226227 }
227228
228- /**
229- * 显示吐司
230- *
231- * @param text 文本
232- * @param duration 显示时长
233- */
234- private static void showToast (CharSequence text , int duration ) {
235- if (isJumpWhenMore ) cancelToast ();
236- if (sToast == null ) {
237- sToast = Toast .makeText (Utils .context , text , duration );
238- } else {
239- sToast .setText (text );
240- sToast .setDuration (duration );
241- }
242- sToast .show ();
243- }
244-
245229 /**
246230 * 显示吐司
247231 *
248232 * @param resId 资源Id
249233 * @param duration 显示时长
250234 */
251- private static void showToast (int resId , int duration ) {
235+ private static void showToast (@ StringRes int resId , int duration ) {
252236 showToast (Utils .context .getResources ().getText (resId ).toString (), duration );
253237 }
254238
@@ -259,7 +243,7 @@ private static void showToast(int resId, int duration) {
259243 * @param duration 显示时长
260244 * @param args 参数
261245 */
262- private static void showToast (int resId , int duration , Object ... args ) {
246+ private static void showToast (@ StringRes int resId , int duration , Object ... args ) {
263247 showToast (String .format (Utils .context .getResources ().getString (resId ), args ), duration );
264248 }
265249
@@ -274,6 +258,23 @@ private static void showToast(String format, int duration, Object... args) {
274258 showToast (String .format (format , args ), duration );
275259 }
276260
261+ /**
262+ * 显示吐司
263+ *
264+ * @param text 文本
265+ * @param duration 显示时长
266+ */
267+ private static void showToast (CharSequence text , int duration ) {
268+ if (isJumpWhenMore ) cancelToast ();
269+ if (sToast == null ) {
270+ sToast = Toast .makeText (Utils .context , text , duration );
271+ } else {
272+ sToast .setText (text );
273+ sToast .setDuration (duration );
274+ }
275+ sToast .show ();
276+ }
277+
277278 /**
278279 * 取消吐司显示
279280 */
0 commit comments