public class CustomToast {
/**
* Method to display toast message.
*
* @param activity
* the activity context
* @param stringResId
* the string resource id
*/
public static void showToast(final Activity activity, final int stringResId) {
try {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Toast toast = Toast.makeText(activity, stringResId,
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} catch (Exception e) {
VCLog.error(
Category.CAT_GUI,
"CustomToast: showToast: run: Exception->"
+ e.getMessage());
e.printStackTrace();
}
}
});
} catch (Exception e) {
VCLog.error(Category.CAT_GUI, "CustomToast: showToast: Exception->"
+ e.getMessage());
e.printStackTrace();
}
}
/**
* Method to display toast message.
*
* @param activity
* the activity context
* @param message
* the message string
*/
public static void showToast(final Activity activity, final String message) {
try {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Toast.makeText(activity, message, Toast.LENGTH_LONG)
.show();
} catch (Exception e) {
VCLog.error(Category.CAT_GUI,
"CustomToast: showToast (message): run: Exception->"
+ e.getMessage());
e.printStackTrace();
}
}
});
} catch (Exception e) {
VCLog.error(
Category.CAT_GUI,
"CustomToast: showToast (message): Exception->"
+ e.getMessage());
e.printStackTrace();
}
}
}
/**
* Method to display toast message.
*
* @param activity
* the activity context
* @param stringResId
* the string resource id
*/
public static void showToast(final Activity activity, final int stringResId) {
try {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Toast toast = Toast.makeText(activity, stringResId,
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} catch (Exception e) {
VCLog.error(
Category.CAT_GUI,
"CustomToast: showToast: run: Exception->"
+ e.getMessage());
e.printStackTrace();
}
}
});
} catch (Exception e) {
VCLog.error(Category.CAT_GUI, "CustomToast: showToast: Exception->"
+ e.getMessage());
e.printStackTrace();
}
}
/**
* Method to display toast message.
*
* @param activity
* the activity context
* @param message
* the message string
*/
public static void showToast(final Activity activity, final String message) {
try {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Toast.makeText(activity, message, Toast.LENGTH_LONG)
.show();
} catch (Exception e) {
VCLog.error(Category.CAT_GUI,
"CustomToast: showToast (message): run: Exception->"
+ e.getMessage());
e.printStackTrace();
}
}
});
} catch (Exception e) {
VCLog.error(
Category.CAT_GUI,
"CustomToast: showToast (message): Exception->"
+ e.getMessage());
e.printStackTrace();
}
}
}