Example usage for android.widget Toast LENGTH_SHORT

List of usage examples for android.widget Toast LENGTH_SHORT

Introduction

In this page you can find the example usage for android.widget Toast LENGTH_SHORT.

Prototype

int LENGTH_SHORT

To view the source code for android.widget Toast LENGTH_SHORT.

Click Source Link

Document

Show the view or text notification for a short period of time.

Usage

From source file:Main.java

public static void showToast(final Activity activity, final String message) {
    activity.runOnUiThread(new Runnable() {
        @Override/* w  ww. j  a va2 s.  c  om*/
        public void run() {
            Toast toast = Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.BOTTOM, 0, 80);
            toast.show();
        }
    });
}

From source file:Main.java

public static boolean checkCameraHardware(Context context) {
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        return true;
    } else {//from w ww .  j  ava 2s  .c  om
        Toast.makeText(context, "No camera on this device", Toast.LENGTH_SHORT).show();
        return false;
    }
}

From source file:Main.java

public static void showShort(Context context, int message) {
    if (isShow)//from  w w  w .ja  va  2 s  .  co  m
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

public static void showToast(final String text) {
    handler.post(new Runnable() {

        @Override/*from   ww w  .  j a  v  a2s . c o m*/
        public void run() {
            Toast.makeText(context, text, Toast.LENGTH_SHORT).show();

        }
    });

}

From source file:Main.java

public static void makeToast(Context ctx, String text, boolean length_long) {
    /*//from w w w . j av a2 s. c om
     * Run a toast; long / short depending on boolean
     */
    if (length_long) {
        Toast.makeText(ctx, text, Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(ctx, text, Toast.LENGTH_SHORT).show();
    }

}

From source file:Main.java

public static void showToast(Context context, int resId) {
    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();//from   www.  ja v a2s  .co m
}

From source file:Main.java

public static boolean isValidSignUp(String username, String password, String confirmPassword,
        Context thisActivtiy) {//from   w w  w. ja  v a  2  s.  c o  m
    //One of the field is left blank
    if (username.equals("") || password.equals("") || confirmPassword.equals("")) {
        Toast.makeText(thisActivtiy, "Please fill in all fields.", Toast.LENGTH_SHORT).show();
        return false;
    }

    //The info is not of the right format
    //Need to finish this later
    else if (false) {
        Toast.makeText(thisActivtiy, "Please fill in all fields.", Toast.LENGTH_SHORT).show();
        return false;
    }

    //The passwords entered do not match
    else if (!password.equals(confirmPassword)) {
        Toast.makeText(thisActivtiy, "The passwords you entered do not match.", Toast.LENGTH_SHORT).show();
        return false;
    }

    else
        return true;
}

From source file:Main.java

private static final void toast(final boolean isAutoTweet, final Context context, final String text) {
    if (isAutoTweet == false) {
        if (!((Activity) context).isFinishing()) {
            if (currentThreadIsUiThread()) {
                Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
            } else {
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override/*from   ww  w  .j av  a 2s.  c om*/
                    public final void run() {
                        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    }
}

From source file:Main.java

public static void ToastMessage(Context cont, int msg) {
    if (cont == null || msg <= 0) {
        return;//from ww w  . ja  v  a 2 s.  c  om
    }
    Toast.makeText(cont, msg, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

/**
 * Shows a toast with the methane level//  www.  j av  a 2  s.co m
 *
 * @param methane the methane level
 *
 * @param context the context
 */
public static void showMethaneToast(Integer methane, Context context) {
    String message = "Methane level: " + Integer.toString(methane);
    Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}