List of usage examples for android.widget Toast makeText
public static Toast makeText(Context context, @StringRes int resId, @Duration int duration) throws Resources.NotFoundException
From source file:Main.java
public static void Toast(Context context, int resourceID) { Toast toast = Toast.makeText(context, resourceID, Toast.LENGTH_LONG); toast.show(); }
From source file:Main.java
public static Toast alert(Context ctx, int nResID) { Toast t = Toast.makeText(ctx, nResID, Toast.LENGTH_SHORT); TextView v = (TextView) t.getView().findViewById(android.R.id.message); if (v != null) v.setGravity(Gravity.CENTER);/*from w ww. j a va 2s. c o m*/ t.show(); return t; }
From source file:Main.java
public static void showClosableToast(Context context, String text, int duration) { if (staticToast != null) staticToast.cancel();/* w w w . java2 s . c o m*/ staticToast = new Toast(context); switch (duration) { case 1: duration = Toast.LENGTH_SHORT; break; case 2: duration = Toast.LENGTH_LONG; break; } staticToast = Toast.makeText(context, text, duration); staticToast.show(); }
From source file:Main.java
public static void show(Context paramContext, CharSequence paramCharSequence) { if (paramContext == null) { return;/*from w ww. j av a2 s. co m*/ } if (toast == null) { toast = Toast.makeText(paramContext, paramCharSequence, Toast.LENGTH_SHORT); } else { toast.setText(paramCharSequence); } toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
From source file:Main.java
public static void startWebIntent(Context context, String url) { try {/*ww w . j av a2 s .c o m*/ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); context.startActivity(intent); } catch (Exception ex) { Log.e(TAG, "Error starting url intent.", ex); Toast.makeText(context, "Sorry, we couldn't find any app for viewing this url!", Toast.LENGTH_SHORT) .show(); } }
From source file:Main.java
public static void showToast(final Context mContext, final int resId) { sharedHandler(mContext).post(() -> { if (toast != null) { toast.setText(resId);/*from www .j a v a2s . co m*/ toast.setDuration(Toast.LENGTH_SHORT); } else { toast = Toast.makeText(mContext.getApplicationContext(), resId, Toast.LENGTH_SHORT); } toast.show(); }); }
From source file:Main.java
/** * Show toast message.//from w w w .j a v a2s. c o m * * @param context Context * @param message Text to display */ public static void ShowMessage(Context context, String message) { if (context != null) { if (TOAST != null) { TOAST.cancel(); } Toast newToast = Toast.makeText(context, message, message.length() < 15 ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG); TextView textView = (TextView) newToast.getView().findViewById(android.R.id.message); textView.setGravity(Gravity.CENTER); textView.setSingleLine(false); newToast.show(); TOAST = newToast; } }
From source file:Main.java
public static void showToast(final Context context, final String s) { if (Looper.getMainLooper() == Looper.myLooper()) { Toast toast = Toast.makeText(context, s, Toast.LENGTH_SHORT); hideToast();/*from w ww. j a va 2s.c o m*/ toast.show(); sToastRef = new SoftReference<Toast>(toast); } else { if (context instanceof Activity) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { showToast(context, s); } }); } } }
From source file:Main.java
public static void showLongToast(final Context mContext, final int resId) { sharedHandler(mContext).post(() -> { if (toast != null) { toast.setText(resId);//from w w w. j av a 2s .co m toast.setDuration(Toast.LENGTH_LONG); } else { toast = Toast.makeText(mContext.getApplicationContext(), resId, Toast.LENGTH_LONG); } toast.show(); }); }
From source file:Main.java
public static void showToast(Activity activity, String msg) { String s = String.format("PhotoNote: %s", msg); Toast.makeText(activity, s, Toast.LENGTH_LONG).show(); }