Last active
August 29, 2015 14:06
-
-
Save sbelloz/e2191d54afb235856f0a to your computer and use it in GitHub Desktop.
Util class that shows a toast message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.widget.Toast; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: SimoneBellotti | |
* Date: 23/12/2014 | |
* Time: 17.26 | |
*/ | |
public class ToastUtils { | |
public static void showWorkInProgress(final Activity context) { | |
show(context, "Work In Progress"); | |
} | |
public static void show(final Activity context, final int resId) { | |
if (context != null) { | |
show(context, context.getString(resId), Toast.LENGTH_SHORT); | |
} | |
} | |
public static void show(final Activity context, int resId, Object... args) { | |
if (context != null) { | |
final String msg = String.format(context.getString(resId), args); | |
show(context, msg, Toast.LENGTH_SHORT); | |
} | |
} | |
public static void show(final Activity context, final String message) { | |
show(context, message, Toast.LENGTH_SHORT); | |
} | |
public static void show(final Activity context, final String message, final int duration) { | |
if (context != null) { | |
context.runOnUiThread(new Runnable() { | |
public void run() { | |
Toast.makeText(context, message, duration).show(); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment