List of usage examples for android.widget Toast show
public void show()
From source file:Main.java
public static void showLongToastTop(Context context, int resId) { Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 100); TextView v = toast.getView().findViewById(android.R.id.message); if (v != null) v.setGravity(Gravity.CENTER);/*from w w w . ja v a 2s. c om*/ toast.show(); }
From source file:Main.java
/** * Shows long toast message on screen/*from w w w.java 2 s .c o m*/ */ public final static void showToastMessage(CharSequence message, Boolean durationLong, Context activityContext) { Toast toast; int duration; if (durationLong) { duration = Toast.LENGTH_LONG; } else { duration = Toast.LENGTH_SHORT; } toast = Toast.makeText(activityContext, message, duration); toast.show(); }
From source file:au.id.micolous.frogjump.Util.java
public static void showToast(Context context, int resId) { Looper.prepare();/*from w ww .j ava 2 s. com*/ String message = context.getString(resId); Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.show(); }
From source file:be.ac.ucl.lfsab1509.llncampus.ExternalAppUtility.java
/** * Start the Google Maps application and navigate the user to the specified location. * // w ww. j a va 2s .com * @param lat * Destination latitude. * @param lon * Destination longitude. * @param c * Current context. */ public static void startNavigation(float lat, float lon, Context c) { try { Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + lat + "," + lon + "&dirflg=w")); intent.setComponent( new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity")); c.startActivity(intent); } catch (ActivityNotFoundException e) { // If we don't have Google Maps Log.e("ExternalAppUtility", c.getString(R.string.no_google_maps)); Toast t = Toast.makeText(LLNCampus.getContext().getApplicationContext(), R.string.no_google_maps, Toast.LENGTH_LONG); t.setGravity(Gravity.CENTER, 0, 0); t.show(); } }
From source file:fr.free.nrw.commons.Utils.java
/** * Opens Custom Tab Activity with in-app browser for the specified URL. * Launches intent for web URL/*from w w w . j a va 2 s . com*/ * @param context * @param url */ public static void handleWebUrl(Context context, Uri url) { Timber.d("Launching web url %s", url.toString()); Intent browserIntent = new Intent(Intent.ACTION_VIEW, url); if (browserIntent.resolveActivity(context.getPackageManager()) == null) { Toast toast = Toast.makeText(context, context.getString(R.string.no_web_browser), LENGTH_SHORT); toast.show(); return; } CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(context, R.color.primaryColor)); builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor)); builder.setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right); CustomTabsIntent customTabsIntent = builder.build(); // Clear previous browser tasks, so that back/exit buttons work as intended. customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); customTabsIntent.launchUrl(context, url); }
From source file:Main.java
/** * Show toast message./* w w w . ja v a 2s. c o m*/ * * @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:fr.free.nrw.commons.Utils.java
public static void handleGeoCoordinates(Context context, String coords) { try {/*from www .ja v a 2s . c o m*/ Uri gmmIntentUri = Uri.parse("google.streetview:cbll=" + coords); Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); mapIntent.setPackage("com.google.android.apps.maps"); context.startActivity(mapIntent); } catch (ActivityNotFoundException ex) { Toast toast = Toast.makeText(context, context.getString(R.string.map_application_missing), LENGTH_SHORT); toast.show(); } }
From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java
public static void copyImageURL(Fragment fragment, JSONParcelable imageData) { final Activity activity = fragment.getActivity(); final JSONParcelable data = imageData; final Fragment frag = fragment; String[] copyTypes = fragment.getResources().getStringArray(R.array.copyTypes); try {/*from w w w.j a va 2 s . c om*/ copyTypes[0] = copyTypes[0] + "\nhttp://imgur.com/" + imageData.getJSONObject().getString("id"); copyTypes[1] = copyTypes[1] + "\n" + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); copyTypes[2] = copyTypes[2] + "\n<a href=\"http://imgur.com/" + imageData.getJSONObject().getString("id") + "\"><img src=\"" + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "\" title=\"Hosted by imgur.com\"/></a>"; copyTypes[3] = copyTypes[3] + "\n[IMG]" + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "[/IMG]"; copyTypes[4] = copyTypes[4] + "\n[URL=http://imgur.com/" + imageData.getJSONObject().getString("id") + "][IMG]" + imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "[/IMG][/URL]"; copyTypes[5] = copyTypes[5] + "\n[Imgur](http://i.imgur.com/" + imageData.getJSONObject().getString("id") + ")"; } catch (JSONException e) { Log.e("Error!", e.toString()); } new AlertDialog.Builder(activity).setTitle("Set Link Type to Copy") .setItems(copyTypes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); try { String link = ""; switch (whichButton) { case 0: link = "http://imgur.com/" + data.getJSONObject().getString("id"); break; case 1: link = data.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); break; case 2: link = "<a href=\"http://imgur.com/" + data.getJSONObject().getString("id") + "\"><img src=\"" + data.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "\" title=\"Hosted by imgur.com\"/></a>"; break; case 3: link = "[IMG]" + data.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "[/IMG]"; break; case 4: link = "[URL=http://imgur.com/" + data.getJSONObject().getString("id") + "][IMG]" + data.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK) + "[/IMG][/URL]"; break; case 5: link = "[Imgur](http://i.imgur.com/" + data.getJSONObject().getString("id") + ")"; break; default: break; } int duration = Toast.LENGTH_SHORT; Toast toast; toast = Toast.makeText(frag.getActivity(), "URL Copied!", duration); toast.show(); ClipData clip = ClipData.newPlainText("imgur Link", link); clipboard.setPrimaryClip(clip); } catch (JSONException e) { Log.e("Error!", "No link in image data!"); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); }
From source file:com.monmonja.library.utils.ViewUtils.java
public static void makeToast(Context context, int resId) { TypedValue tv = new TypedValue(); int offsetY = 0; if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offsetY = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); }/*ww w . j a va 2s . c o m*/ Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); View view = toast.getView(); view.setBackgroundColor(context.getResources().getColor(R.color.toast_background)); TextView text = (TextView) view.findViewById(android.R.id.message); text.setTextColor(context.getResources().getColor(android.R.color.white)); toast.show(); }
From source file:com.bt.download.android.gui.util.UIUtils.java
public static void showToastMessage(Context context, String message, int duration, int gravity, int xOffset, int yOffset) { if (context != null && message != null) { Toast toast = Toast.makeText(context, message, duration); if (gravity != (Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)) { toast.setGravity(gravity, xOffset, yOffset); }/*from w w w .jav a 2 s. co m*/ toast.show(); } }