List of usage examples for android.widget Toast show
public void show()
From source file:Main.java
public static void toast(Activity activity, String txt) { Toast toast = Toast.makeText(activity, txt, Toast.LENGTH_SHORT); int xoffset = 30, yoffset = 30; toast.setGravity(Gravity.RIGHT, xoffset, yoffset); toast.show(); }
From source file:Main.java
/** * //w w w. jav a 2s . c o m * @param context * @param text * @param gravity * @param xOffset * @param yOffset */ public static void showLong(Context context, CharSequence text, int gravity, int xOffset, int yOffset) { Toast t = Toast.makeText(context, text, Toast.LENGTH_LONG); t.setGravity(gravity, xOffset, yOffset); t.show(); }
From source file:Main.java
/** * //w ww. j a v a 2s . co 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 void runInUIThread(Context context, final Toast toast) { final Activity activity = (Activity) context; activity.runOnUiThread(new Runnable() { public void run() { toast.show(); }/* w w w . ja va 2 s .c o m*/ }); }
From source file:Main.java
public static final void showToast(Context context, String tip, boolean isCenter) { int duration = Toast.LENGTH_SHORT; if (TextUtils.isEmpty(tip)) { return;// w ww.j a v a2 s . co m } if (tip.length() >= 15) { duration = Toast.LENGTH_LONG; } Toast toast = Toast.makeText(context, tip, duration); if (isCenter) { toast.setGravity(Gravity.CENTER, 0, 0); } toast.show(); }
From source file:Main.java
/** * Reads a file that is embedded in our application and writes it to the device storage * @param context/* w w w . ja v a 2 s. c o m*/ * @param file * @param assetFileDescriptor */ private static void saveFileToDevice(Context context, File file, AssetFileDescriptor assetFileDescriptor) { // The output stream is used to write the new file to the device storage FileOutputStream outputStream = null; // The input stream is used for reading the file that is embedded in our application FileInputStream inputStream = null; try { byte[] buffer = new byte[1024]; // Create the input stream inputStream = (assetFileDescriptor != null) ? assetFileDescriptor.createInputStream() : null; // Create the output stream outputStream = new FileOutputStream(file, false); // Read the file into buffer int i = (inputStream != null) ? inputStream.read(buffer) : 0; // Continue writing and reading the file until we reach the end while (i != -1) { outputStream.write(buffer, 0, i); i = (inputStream != null) ? inputStream.read(buffer) : 0; } outputStream.flush(); } catch (IOException io) { // Display a message to the user Toast toast = Toast.makeText(context, "Could not save the file", Toast.LENGTH_SHORT); toast.show(); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException ex) { // We should really never get this far, but we might consider adding a // warning/log entry here... } } if (inputStream != null) { try { inputStream.close(); } catch (IOException ex) { // We should really never get this far, but we might consider adding a // warning/log entry here... } } } }
From source file:Main.java
public static void showToast(final Context context, Toast toast, final String s) { if (Looper.getMainLooper() == Looper.myLooper()) { hideToast();//from w w w. ja v a 2s. co 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 showToastView(Context context, String text) { Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); View view = toast.getView();//from www. j a va2 s. c o m view.setBackgroundColor(Color.GREEN); toast.setView(view); toast.show(); }
From source file:Main.java
public static void showToast(Context context, View view) { Toast toast = new Toast(context); toast.setView(view);/*from w ww . j a v a2s . c o m*/ toast.setGravity(Gravity.CENTER, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.show(); }
From source file:Main.java
public static void showToast(final Activity activity, final String message) { activity.runOnUiThread(new Runnable() { @Override//from w w w . j a va 2s . c o m public void run() { Toast toast = Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.BOTTOM, 0, 80); toast.show(); } }); }