List of usage examples for android.widget Toast LENGTH_SHORT
int LENGTH_SHORT
To view the source code for android.widget Toast LENGTH_SHORT.
Click Source Link
From source file:Main.java
public static void ToastMsg(final Activity activity, final String msg) { if (activity == null || TextUtils.isEmpty(msg)) { return;/*from w w w . j a va 2s . c o m*/ } activity.runOnUiThread(new Runnable() { @Override public void run() { if (mToast != null) { mToast.cancel(); mToast = null; } mToast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT); mToast.show(); } }); }
From source file:Main.java
public static void toaster(Context context, int stringId) { toaster(context, stringId, Toast.LENGTH_SHORT); }
From source file:AlarmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (ACTION_ALARM.equals(intent.getAction())) { Toast.makeText(context, ACTION_ALARM, Toast.LENGTH_SHORT).show(); }//from w ww . j a v a2 s . co m }
From source file:Main.java
public static void toast(Context context, String message, boolean shortDuration) { if (toast == null) { toast = Toast.makeText(context, message, shortDuration ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); } else {/*from ww w . j a v a2 s . c om*/ toast.setText(message); toast.setDuration(shortDuration ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG); } toast.show(); }
From source file:Main.java
/** * Copy a text to the clipboard.//from w w w . ja v a 2 s. c o m * * @param context * The current context. * @param text * The text to copy. * @param toastMessage * The message to show in a Toast notification. If empty or null, does not display notification. */ public static void copyTextToClipboard(Context context, String text, String toastMessage) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText(text, text)); if ((toastMessage != null) && (toastMessage.length() > 0)) { Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show(); } }
From source file:Main.java
public static void showSingleToast(Context ctx, String msg, int duration) { int showDuration = duration <= Toast.LENGTH_SHORT ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT; if (null == toast) { toast = Toast.makeText(ctx.getApplicationContext(), msg, showDuration); toast.show();/* ww w . j av a 2 s . c o m*/ oneTime = System.currentTimeMillis(); } else { twoTime = System.currentTimeMillis(); if (msg.equals(oldMsg)) { if (twoTime - oneTime > showDuration) { toast.show(); } } else { oldMsg = msg; toast.setText(msg); toast.show(); } } oneTime = twoTime; }
From source file:Main.java
public static void showShortToast(final Context context, final String string, final boolean isForceDismissProgressDialog) { if (context == null) { return;/*www. j a v a 2 s . c om*/ } Toast.makeText(context, "" + string, Toast.LENGTH_SHORT).show(); }
From source file:Main.java
/** * Short toast message/*from w w w .j ava 2s . co m*/ * (Predefined in AOS to 2000 ms = 2 sec) * * @param context Application Context * @param msg Message to send */ public static void msgShort(final Context context, final String msg) { if (context != null && msg != null) { new Handler(context.getMainLooper()).post(new Runnable() { @Override public void run() { Toast.makeText(context, msg.trim(), Toast.LENGTH_SHORT).show(); } }); } }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override// w ww.j a v a 2 s. c o m public void onClick(View v) { Toast.makeText(MainActivity.this, "Click", Toast.LENGTH_SHORT).show(); } }); button.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(MainActivity.this, "Long Press", Toast.LENGTH_SHORT).show(); return true; } }); }
From source file:MainActivity.java
public void checkOrientation(View view) { int orientation = getResources().getConfiguration().orientation; switch (orientation) { case Configuration.ORIENTATION_LANDSCAPE: Toast.makeText(MainActivity.this, "ORIENTATION_LANDSCAPE", Toast.LENGTH_SHORT).show(); break;//from www.j a v a 2 s . c o m case Configuration.ORIENTATION_PORTRAIT: Toast.makeText(MainActivity.this, "ORIENTATION_PORTRAIT", Toast.LENGTH_SHORT).show(); break; case Configuration.ORIENTATION_UNDEFINED: Toast.makeText(MainActivity.this, "ORIENTATION_UNDEFINED", Toast.LENGTH_SHORT).show(); break; } }