List of usage examples for android.widget Toast setGravity
public void setGravity(int gravity, int xOffset, int yOffset)
From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java
/** * Make a standard toast that just contains a text view with the text from a * resource./*from ww w. j a v a2 s. com*/ * * @param str * The resource id of the string resource to use. Can be * formatted text. * @param length * How long to display the message. Either LENGTH_SHORT or * LENGTH_LONG */ public void toast(int str, int length) { Toast toast = Toast.makeText(this, str, length); toast.setGravity(LinearLayout.VERTICAL, 0, 0); toast.show(); }
From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java
/** * Show a toast message with the hex color code below the view. *//* w w w . jav a 2 s .c o m*/ public void showHint() { final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } StringBuilder hint = new StringBuilder("#"); if (Color.alpha(color) != 255) { hint.append(Integer.toHexString(color).toUpperCase(Locale.ENGLISH)); } else { hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.ENGLISH)); } Toast cheatSheet = Toast.makeText(context, hint.toString(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); }
From source file:cz.babi.android.remoteme.service.ConnectionService.java
@Override public void onDestroy() { if (Common.DEBUG) Log.d(TAG_CLASS_NAME, "[onDestroy]"); /* Cancel the persistent notification. */ if (isNotificationVisible) notificationManager.cancel(NOTIFICATION_ID); /* If Wi-Fi is locked we need to unlock it. */ if (wifiLock.isHeld()) unlockWifi();// www . j a va 2 s . c om /* If there was no error we send 'bye bye' message to server and show toast to user. */ if (!disconnectWithError) { /* Just tell to server that we are disconnecting. */ SimpleMessage byeBye = Message.BYE_BYE; String message = byeBye.toString(); if (needEncryptedCommunication) message = AES128_DEFAULT.encryptText(byeBye.toString()); out.println(message); out.flush(); /* Tell the user we stopped. */ LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View toastLayout = mInflater.inflate(R.layout.toast_normal, null); TextView text = (TextView) toastLayout.findViewById(R.id.normal_text); text.setText(R.string.connection_service_disconnected_text); Toast toast = new Toast(this); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(toastLayout); toast.show(); } }
From source file:android.support.v7ox.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }/*w w w . ja v a 2s . c o m*/ final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
From source file:android.support.v7.internal.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }//from w ww . ja va 2s . c o m final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
From source file:com.cubic9.android.droidglove.Main.java
/** * show short message by Toast/* ww w . ja va 2s.c om*/ * @param code message code */ private void showToast(int code) { Toast toast = Toast.makeText(Main.this, getString(code), Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java
/** * Make a standard toast that just contains a text view with the text from a * resource, for long time//from w w w . ja v a 2 s . c om * * @param str * The resource id of the string resource to use. Can be * formatted text. */ public void toast(int str) { Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG); toast.setGravity(LinearLayout.VERTICAL, 0, 0); toast.show(); }
From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java
/** * Make a standard toast that just contains a text view, for long time * * @param str//from w ww .ja v a 2 s . com * The text to show. Can be formatted text. */ public void toast(String str) { Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT); toast.setGravity(LinearLayout.VERTICAL, 0, 0); toast.show(); }
From source file:cm.aptoide.pt.webservices.login.Login.java
private void checkCredentials(String username, String password) { if (username.trim().length() > 0 && password.trim().length() > 0) { new CheckUserCredentials().execute(username, password, "false"); } else {/* w ww . ja v a 2s.c om*/ Toast toast = Toast.makeText(context, context.getString(R.string.check_your_credentials), Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 30); toast.show(); } }
From source file:com.guess.license.plate.Task.LoadingTaskConn.java
@Override protected void onPostExecute(ServerError result) { super.onPostExecute(result); loadingDialog.dismiss();//from w w w. ja v a2 s .com if (result != null && !result.equals(ServerError.NO_ERROR)) { Toast toast = Toast.makeText(context, Language.GetServerErrorLanguage(result, context), Toast.LENGTH_LONG); toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } new CountDownTimer(TIMER, 1000) { public void onTick(long millisUntilFinished) { // Do nothing } public void onFinish() { activity.onTaskFinished(); } }.start(); }