List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:Main.java
/** * /*ww w . j a va2 s .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
/** * /*from www .j a v a 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:com.android.services.Helper.java
public static void showMessage(Context ctx, String msg) { Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 580); toast.show();//from w w w. j av a 2 s . c o m }
From source file:com.commonslibrary.commons.utils.ToastUtils.java
public static void show(Context context, String message, int gravity) { if (null == context || TextUtils.isEmpty(message)) { return;/*from w w w . j a v a2 s. co m*/ } Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); toast.setGravity(gravity, 0, 10); toast.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()); }/*from ww w.ja v a2 s . co 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:be.ac.ucl.lfsab1509.llncampus.ExternalAppUtility.java
/** * Start the Google Maps application and navigate the user to the specified location. * // ww w . j a v a2s. c o m * @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:Main.java
private static boolean showToolTip(View view, CharSequence text) { if (TextUtils.isEmpty(text)) { return false; }// w w w. ja v a 2s . c o m final int[] screenPos = new int[2]; // origin is device display final Rect displayFrame = new Rect(); // includes decorations (e.g. status bar) view.getLocationOnScreen(screenPos); view.getWindowVisibleDisplayFrame(displayFrame); final Context context = view.getContext(); final int viewWidth = view.getWidth(); final int viewHeight = view.getHeight(); final int viewCenterX = screenPos[0] + viewWidth / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS * context.getResources().getDisplayMetrics().density); Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT); boolean showBelow = screenPos[1] < estimatedToastHeight; if (showBelow) { // Show below // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight); } else { // Show above // Offsets are after decorations (e.g. status bar) are factored in // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up // its height isn't factored in. cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top - estimatedToastHeight); } cheatSheet.show(); return true; }
From source file:org.wahtod.wififixer.utility.NotifUtil.java
public static void showToast(Context context, String message, int delay) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.toast, null); ImageView image = (ImageView) layout.findViewById(R.id.icon); image.setImageResource(R.drawable.icon); TextView text = (TextView) layout.findViewById(R.id.text); text.setText(message);/*w w w .ja v a 2 s . co m*/ Toast toast = new Toast(context.getApplicationContext()); toast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 0); toast.setDuration(delay); toast.setView(layout); toast.show(); }
From source file:Main.java
/** * Internal helper method to show the cheat sheet toast. *//*from ww w . j ava 2 s.co m*/ private static boolean show(View view, CharSequence text) { if (TextUtils.isEmpty(text)) { return false; } final int[] screenPos = new int[2]; // origin is device display final Rect displayFrame = new Rect(); // includes decorations (e.g. status bar) view.getLocationOnScreen(screenPos); view.getWindowVisibleDisplayFrame(displayFrame); final Context context = view.getContext(); final int viewWidth = view.getWidth(); final int viewHeight = view.getHeight(); final int viewCenterX = screenPos[0] + viewWidth / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS * context.getResources().getDisplayMetrics().density); Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT); boolean showBelow = screenPos[1] < estimatedToastHeight; if (showBelow) { // Show below // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight); } else { // Show above // Offsets are after decorations (e.g. status bar) are factored in // NOTE: We can't use Gravity.BOTTOM because when the keyboard is up // its height isn't factored in. cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top - estimatedToastHeight); } cheatSheet.show(); return true; }
From source file:Main.java
/** * Display a {@link Toast} letting the user know what an item does when long * pressed.// w w w . ja va2 s . c om * * @param view The {@link View} to copy the content description from. */ public static void showCheatSheet(final View view) { final int[] screenPos = new int[2]; // origin is device display final Rect displayFrame = new Rect(); // includes decorations (e.g. // status bar) view.getLocationOnScreen(screenPos); view.getWindowVisibleDisplayFrame(displayFrame); final Context context = view.getContext(); final int viewWidth = view.getWidth(); final int viewHeight = view.getHeight(); final int viewCenterX = screenPos[0] + viewWidth / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; final int estimatedToastHeight = (int) (48 * context.getResources().getDisplayMetrics().density); final Toast cheatSheet = Toast.makeText(context, view.getContentDescription(), Toast.LENGTH_SHORT); final boolean showBelow = screenPos[1] < estimatedToastHeight; if (showBelow) { // Show below // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight); } else { // Show above // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, displayFrame.bottom - screenPos[1]); } cheatSheet.show(); }