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

/**
 * Show a Toast message/*from w  w w .ja  v a2s  .co m*/
 * @param context The context
 * @param str The string content
 */
public static void showToast(Context context, String str) {
    if (context != null) {
        Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

public static void showToast(Context context, String content, boolean longTime) {
    int time = longTime ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    Toast.makeText(context, content, time).show();
}

From source file:Main.java

public static Toast showShort(Context context, int message) {
    if (null == toast) {
        toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
        // toast.setGravity(Gravity.CENTER, 0, 0);
    } else {/*from   w w  w.  j  a  v a2s. com*/
        toast.setText(message);
    }
    toast.show();
    return toast;
}

From source file:Main.java

/**
 * Show toast message.//  ww w  .  j  a va  2 s  .c om
 *
 * @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 startWebIntent(Context context, String url) {
    try {//  ww  w .j  a v  a 2  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 showSingleToast(Context ctx, @StringRes int msgID, int duration) {
    String msg = ctx.getString(msgID);
    int showDuration = duration <= Toast.LENGTH_SHORT ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    if (null == toast) {
        toast = Toast.makeText(ctx.getApplicationContext(), msgID, showDuration);
        toast.show();//from w  ww  .j  a  v a  2s  . c  om
        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

/** Opens Google Play Services in Google Play, if available. */
public static void openGooglePlayServicesInGooglePlay(final Context context) {
    Uri uri = Uri.parse("market://details?id=com.google.android.gms");
    Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
    try {/*from   ww w .  j  a v a  2  s.  c  o  m*/
        context.startActivity(myAppLinkToMarket);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, "Unable to find app in Google Play", Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

/**
 * /*from  w  w  w .java 2  s  . c  o  m*/
 * @param context
 * @param text
 * @param gravity
 * @param xOffset
 * @param yOffset
 */
public static void showShort(Context context, CharSequence text, int gravity, int xOffset, int yOffset) {
    Toast t = Toast.makeText(context, text, Toast.LENGTH_SHORT);
    t.setGravity(gravity, xOffset, yOffset);
    t.show();
}

From source file:Main.java

public static String getDhcpIpString(Context mContext) {
    WifiManager mWifiManager;//from   ww  w .  jav a  2s.c o  m
    String broadcastIp = null;
    mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    if (mWifiManager.isWifiEnabled()) {
        DhcpInfo myDhcpInfo = mWifiManager.getDhcpInfo();
        if (myDhcpInfo == null) {
            Toast.makeText(mContext, "can not get dhcp info", Toast.LENGTH_SHORT).show();
            return null;
        } else {
            try {
                broadcastIp = getBroadcastAddress(myDhcpInfo).getHostAddress();
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return null;
            }
        }
        return broadcastIp;
    }
    return null;
}

From source file:Main.java

/**
 * /*w  w  w . j  a  va 2 s  .  c  om*/
 * @param context
 * @return
 */
public static Typeface getFAFont(Context context) {
    Typeface tf = null;
    try {
        tf = Typeface.createFromAsset(context.getAssets(), font_awesome);
    } catch (Exception e) {
        Log.e(TAG, "Failed to load FontAwesome Font");
        Toast.makeText(context, "Failed to load FontAwesome Font", Toast.LENGTH_SHORT).show();
    }
    return tf;
}