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 boolean isNetworkOk(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    } else {/*  w  ww . j a va  2 s. c o  m*/
        Toast.makeText(context, "Network is disconnected", Toast.LENGTH_SHORT).show();
        return false;
    }
}

From source file:Main.java

public static boolean instantExec(Context context, String command) {
    try {//from www .j  a  va2s. com
        runSuCommand(context, command.toString());
    } catch (Exception e) {
        Toast.makeText(context, "E:ScriptRunner: " + e.getMessage(), Toast.LENGTH_SHORT).show();
        Log.d(LOGTAG, "E:ScriptRunner: " + e.getMessage());
        return false;
    }
    return true;
}

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 ava 2s . c  om*/
    t.show();

    return t;
}

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  .  ja  v a 2  s .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 show(Context paramContext, CharSequence paramCharSequence) {
    if (paramContext == null) {
        return;/*from w  w  w .  j a v a 2 s .  c  o 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 ShowToast(Context cxt, String str, boolean isLong) {
    if (isLong) {
        Toast.makeText(cxt, str, Toast.LENGTH_LONG).show();
    } else {/*from w w w .  j  a  v  a 2s. co  m*/
        Toast.makeText(cxt, str, Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

public static void toastMessage(Context context, String message) {
    if (context == null) {
        return;//from   www .  j  a va2 s . c om
    }
    if (TextUtils.isEmpty(message)) {
        sToast = null;
        return;
    }
    if (sToast != null) {
        sToast.cancel();
        sToast = null;
    }
    sToast = getToast(context);
    sToast.setDuration(Toast.LENGTH_SHORT);
    sToast.setText(message);
    sToast.show();
}

From source file:Main.java

/**
 * Creates a custom {@link Toast} with a custom layout View
 * /*from   ww w  .  j  ava  2  s . c  o  m*/
 * @param context
 *            the context
 * @param resId
 *            the custom view
 * @return the created {@link Toast}
 */
public static Toast makeCustomToast(Context context, int resId) {
    View view = LayoutInflater.from(context).inflate(resId, null);
    Toast t = new Toast(context);
    t.setDuration(Toast.LENGTH_SHORT);
    t.setView(view);
    t.setGravity(Gravity.CENTER, 0, 0);
    return t;
}

From source file:Main.java

public static void showToast(final Context context, final int messageResId) {
    if (mToast == null) {
        mToast = Toast.makeText(context, messageResId, Toast.LENGTH_SHORT);
    } else {//from ww  w. j a v  a  2 s  . com
        mToast.setText(messageResId);
        mToast.setDuration(Toast.LENGTH_SHORT);
    }
    mToast.show();
}

From source file:Main.java

/**
 * A method to create a toast message on any screen.
 *
 * @param activity : screen on which the toast message should be shown.
 * @param msg      : the message to be shown.
 *//*from  w w  w .  ja v  a2s.  c  o m*/
public static void createToastMessage(final Activity activity, final String msg) {
    if (!isNullOrEmpty(msg))
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast toast = Toast.makeText(activity.getApplicationContext(), msg, Toast.LENGTH_SHORT);
                toast.show();

            }
        });
}