List of usage examples for android.widget Toast show
public void show()
From source file:com.ppshein.PlanetMyanmarDictionary.common.java
public static void addBookmark(String notedword, Context context) { try {/*from w w w. jav a 2s. co m*/ DatabaseUtil dbUtil = new DatabaseUtil(context); dbUtil.open(); Cursor cursor = dbUtil.fetchBookmark(notedword); String getReturn = cursor.getString(1); cursor.close(); dbUtil.close(); Log.v("Existing Bookmarks", getReturn); } catch (Exception e) { DatabaseUtil dbUtil = new DatabaseUtil(context); dbUtil.open(); dbUtil.insertBookmark(notedword); dbUtil.close(); Toast toast = Toast.makeText(context, "Successfully bookmarked", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } }
From source file:com.game.simple.Game3.java
public static void camera() { self.runOnUiThread(new Runnable() { @Override// w w w .j av a 2s. c om public void run() { try { //use standard intent to capture an image Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //we will handle the returned data in onActivityResult self.startActivityForResult(captureIntent, CAMERA_CAPTURE); } catch (ActivityNotFoundException anfe) { //display an error message String errorMessage = "?in thoi khng h tr !"; Toast toast = Toast.makeText(self, errorMessage, Toast.LENGTH_SHORT); toast.show(); } } }); }
From source file:com.frostwire.android.gui.util.UIUtils.java
private 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 ww. j a v a2s.co m toast.show(); } }
From source file:applab.search.client.SynchronizationManager.java
/** * Check if it's okay to proceed with a synchronization episode. isModal determines if this is a foreground or * background synchronization.//from ww w . j a va 2 s. c o m */ private static void synchronize(Context context, Handler completionCallback, boolean isModal, boolean launchedFromTimer) { boolean processAlreadyRunning = false; synchronizeNow = isModal || launchedFromTimer; synchronized (SynchronizationManager.singleton) { // if we don't have a timer, set that up // Moving this to a service // SynchronizationManager.singleton.ensureTimerIsScheduled(); // Now check if we are in the middle of a synchronization episode // and if so, we should attach to the UI // TODO: check isRunning instead? if (SynchronizationManager.isSynchronizing()) { processAlreadyRunning = true; } else { // check if we have any keywords cached locally. If not, we have to become // modal and initialize our local store. if (!StorageManager.hasKeywords()) { synchronizeNow = true; } } if (synchronizeNow && (!processAlreadyRunning)) { SynchronizationManager.singleton.launchedFromTimer = launchedFromTimer; if (isModal) { // start a modal synchronization episode ProgressDialogManager.silentMode = false; } } } if (processAlreadyRunning) { // SynchronizationManager.singleton.attachActivity(context, completionCallback); Toast notification = Toast.makeText(context, context.getResources().getString(R.string.keywords_updating), Toast.LENGTH_LONG); notification.show(); } else if (synchronizeNow) { SynchronizationManager.singleton.startSynchronization(context, completionCallback); } }
From source file:Main.java
/** * Display a {@link Toast} letting the user know what an item does when long * pressed.//from w w w. j av a 2s. c o m * * @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(); }
From source file:com.andrewshu.android.reddit.common.Common.java
public static void showErrorToast(String error, int duration, Context context) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); Toast t = new Toast(context); t.setDuration(duration);/*from w w w . j a va 2s . co m*/ View v = inflater.inflate(R.layout.error_toast, null); TextView errorMessage = (TextView) v.findViewById(R.id.errorMessage); errorMessage.setText(error); t.setView(v); t.show(); }
From source file:csic.ceab.movelab.beepath.Util.java
/** * Displays a brief message on the phone screen. Taken from Human Mobility * Project code written by Chang Y. Chung and Necati E. Ozgencil. * /*from w ww .j a va2 s . c o m*/ * @param context * Interface to application environment * @param msg * The message to be displayed to the user */ public static void toast(Context context, String msg) { TextView tv = new TextView(context); tv.setText(msg); Drawable bknd = context.getResources().getDrawable(R.drawable.white_border); tv.setBackgroundDrawable(bknd); tv.setPadding(20, 20, 20, 20); tv.setTextSize(20); Toast t = new Toast(context); t.setDuration(Toast.LENGTH_LONG); t.setView(tv); t.show(); }
From source file:net.ben.subsonic.androidapp.util.Util.java
public static void toast(Context context, String message) { Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
From source file:Main.java
private static boolean showToolTip(View view, CharSequence text) { if (TextUtils.isEmpty(text)) { return false; }/*from w ww. j av a 2 s . 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:com.pdftron.pdf.utils.Utils.java
public static void showToast(Context context, String string, int duration) { if (context != null) { Toast toast = Toast.makeText(context, string, duration); if (Utils.isRtlLayout(context)) { toast.getView().setTextDirection(View.TEXT_DIRECTION_RTL); }/*from www .j av a2 s. co m*/ toast.show(); } }