Java Code Examples for android.widget.Toast#show()
The following examples show how to use
android.widget.Toast#show() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UploadService.java From secureit with MIT License | 6 votes |
/** * Called on service creation, sends a notification */ @Override public void onCreate() { manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); prefs = new SecureItPreferences(this); try { new BluetoothServerTask(this).start(); } catch (NoBluetoothException e) { Log.i("UploadService", "Background bluetooth server not started"); CharSequence text = "Background bluetooth server not started"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(this, text, duration); toast.show(); } showNotification(); }
Example 2
Source File: ContinuousCaptureActivity.java From pause-resume-video-recording with Apache License 2.0 | 6 votes |
/** * The file save has completed. We can resume recording. */ private void fileSaveComplete(int status) { Log.d(TAG, "fileSaveComplete " + status); if (!mFileSaveInProgress) { throw new RuntimeException("WEIRD: got fileSaveCmplete when not in progress"); } mFileSaveInProgress = false; updateControls(); TextView tv = (TextView) findViewById(R.id.recording_text); String str = getString(R.string.nowRecording); tv.setText(str); if (status == 0) { str = getString(R.string.recordingSucceeded); } else { str = getString(R.string.recordingFailed, status); } Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT); toast.show(); }
Example 3
Source File: StreamFragment.java From Twire with GNU General Public License v3.0 | 6 votes |
private void playWithExternalPlayer() { Toast errorToast = Toast.makeText(getContext(), R.string.error_external_playback_failed, Toast.LENGTH_LONG); if (qualityURLs == null) { errorToast.show(); return; } String castQuality = getBestCastQuality(qualityURLs, settings.getPrefStreamQuality(), 0); if (castQuality == null) { errorToast.show(); return; } updateSelectedQuality(castQuality); String url = qualityURLs.get(castQuality).URL; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(url), "video/*"); startActivity(Intent.createChooser(intent, getString(R.string.stream_external_play_using))); }
Example 4
Source File: Tips.java From BaseRecyclerViewAdapterHelper with MIT License | 5 votes |
/** * 显示 Toast * @param message 提示信息 * @param duration 显示时间长短 */ public static void show(String message, int duration) { Toast toast = new Toast(Utils.getContext()); toast.setDuration(duration); toast.setGravity(Gravity.CENTER, 0, 0); toast.setView(createTextToastView(message)); toast.show(); }
Example 5
Source File: DatabaseHelper.java From Focus with GNU General Public License v3.0 | 5 votes |
public boolean execSQL(String sql) { try { db.execSQL(sql); } catch (SQLException e) { Toast toast = Toast.makeText(_context, "android.database.sqlite.SQLiteException", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); Log.i("sqlerr_log------->", e.toString()); Log.i("err_sql------->", sql); return false; } return true; }
Example 6
Source File: MainActivity.java From RemoteLogger with MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean result; int id = item.getItemId(); switch(id) { case R.id.menu_opt_log_startstop: if (!RemoteLogger.toggleLogging(this)) { RemoteLogger.launchSendLogWithAttachment(this); item.setTitle("Start logging"); } else { item.setTitle("Stop logging"); } result = true; break; case R.id.menu_opt_deletelog: RemoteLogger.deleteLog(this); Toast toast = Toast.makeText(this, "Log file deleted.", Toast.LENGTH_SHORT); toast.show(); result = true; break; default: result = super.onOptionsItemSelected(item); } return result; }
Example 7
Source File: CheatSheet.java From Puff-Android with MIT License | 5 votes |
/** * Internal helper method to show the cheat sheet toast. */ private static boolean showCheatSheet(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; }
Example 8
Source File: Helpers.java From test-samples with Apache License 2.0 | 5 votes |
public static void toastDefault(Context context, String text, int duration) { LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.toast_default, null); TextView textView = (TextView) view.findViewById(R.id.toast_default_text); textView.setText(text); Toast toast = new Toast(context); // toast.setGravity(Gravity.TOP, 0, 250); toast.setDuration(duration); toast.setView(view); toast.show(); }
Example 9
Source File: MainGameActivity.java From Trivia-Knowledge with Apache License 2.0 | 5 votes |
@Override public void onUnityAdsFinish(String s, UnityAds.FinishState finishState) { //Called when a video vinishes playing //you get a reward // final Typeface typeface2 = Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Semibold.ttf"); Toast toast = Toast.makeText(getApplication(), "+1 gem added in your bucket.", Toast.LENGTH_LONG); toast.getView().setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.darkpink)); TextView v = (TextView) toast.getView().findViewById(android.R.id.message); v.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white)); v.setTypeface(openSansSemiBold); v.setTextSize(10); toast.show(); }
Example 10
Source File: TextToast.java From ONE-Unofficial with Apache License 2.0 | 5 votes |
public static void shortShow(String content){ if (context==null){ throw new IllegalStateException("TextToast was not initialized"); } Toast toast= Toast.makeText(context, content, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
Example 11
Source File: ApolloUtils.java From mobile-manager-tool with MIT License | 5 votes |
/** * @param message */ public static void showToast(int message, Toast mToast, Context context) { if (mToast == null) { mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT); } mToast.setText(context.getString(message)); mToast.show(); }
Example 12
Source File: BaseActivity.java From StreamHub-Android-SDK with MIT License | 5 votes |
/** * Custom toast as per requirement */ protected void customToast() { LayoutInflater li = getLayoutInflater(); View layout = li.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.custom_toast_layout)); Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setView(layout); toast.show(); }
Example 13
Source File: GPSTesterActivityController.java From android-gps-test-tool with Apache License 2.0 | 5 votes |
/** * Helper method that displays a TOAST message. Default is TOAST.LENGTH_LONG. * @param message The message you wish to be displayed in TOAST. * @param toastLength (Optional) valid options are Toast.LENGTH_LONG or Toast.LENGTH_SHORT. */ public void displayToast(String message,int... toastLength) { int length = Toast.LENGTH_LONG; if(toastLength.length != 0){ length = toastLength[0]; } Toast toast = Toast.makeText(_context, message, length); toast.show(); }
Example 14
Source File: LFXSDKLightEditLabelActivity.java From lifx-sdk-android with MIT License | 4 votes |
@Override public void networkContextDidConnect( LFXNetworkContext networkContext) { Toast toast = Toast.makeText( this, "CONNECTED", Toast.LENGTH_SHORT); toast.show(); }
Example 15
Source File: PcapExporter.java From sniffer154 with GNU General Public License v3.0 | 4 votes |
private void toastMessage(String mess) { Toast toast = Toast.makeText(getApplicationContext(), mess, Toast.LENGTH_LONG); toast.show(); }
Example 16
Source File: NewOrderFragment.java From CourierApplication with Mozilla Public License 2.0 | 4 votes |
public void makeToast(String message) { Toast toast = Toast.makeText(getContext(), message, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
Example 17
Source File: CheatSheet.java From iBeebo with GNU General Public License v3.0 | 4 votes |
/** * Internal helper method to show the cheat sheet toast. */ private static boolean showCheatSheet(Activity activity, 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 // softkeyboard height int height = SmileyPickerUtility.getScreenHeight(activity) - SmileyPickerUtility.getStatusBarHeight(activity) - SmileyPickerUtility.getAppHeight(activity); cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, displayFrame.bottom - screenPos[1] + height); } cheatSheet.show(); return true; }
Example 18
Source File: OpenWithActivity.java From dropbox-sdk-java with MIT License | 4 votes |
private void showToast(String msg) { Toast error = Toast.makeText(this, msg, Toast.LENGTH_LONG); error.show(); }
Example 19
Source File: LFXSDKLightPowerActivity.java From lifx-sdk-android with MIT License | 4 votes |
@Override public void networkContextDidConnect( LFXNetworkContext networkContext) { Toast toast = Toast.makeText( this, "CONNECTED", Toast.LENGTH_SHORT); toast.show(); }
Example 20
Source File: RecipeActivity.java From app-indexing with Apache License 2.0 | 4 votes |
private void showRecipe(Uri recipeUri) { Log.d("Recipe Uri", recipeUri.toString()); String[] projection = {RecipeTable.ID, RecipeTable.TITLE, RecipeTable.DESCRIPTION, RecipeTable.PHOTO, RecipeTable.PREP_TIME}; Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null); if (cursor != null && cursor.moveToFirst()) { mRecipe = Recipe.fromCursor(cursor); Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath ("ingredients").appendPath(mRecipe.getId()).build(); Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection, null, null, null); if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) { do { Recipe.Ingredient ingredient = new Recipe.Ingredient(); ingredient.setAmount(ingredientsCursor.getString(0)); ingredient.setDescription(ingredientsCursor.getString(1)); mRecipe.addIngredient(ingredient); ingredientsCursor.moveToNext(); } while (!ingredientsCursor.isAfterLast()); ingredientsCursor.close(); } Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath ("instructions").appendPath(mRecipe.getId()).build(); Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection, null, null, null); if (instructionsCursor != null && instructionsCursor.moveToFirst()) { do { Recipe.Step step = new Recipe.Step(); step.setDescription(instructionsCursor.getString(1)); step.setPhoto(instructionsCursor.getString(2)); mRecipe.addStep(step); instructionsCursor.moveToNext(); } while (!instructionsCursor.isAfterLast()); instructionsCursor.close(); } Uri noteUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("notes") .appendPath(mRecipe.getId()).build(); Cursor noteCursor = getContentResolver().query(noteUri, projection, null, null, null); if (noteCursor != null && noteCursor.moveToFirst()) { Note note = Note.fromCursor(noteCursor); mRecipe.setNote(note); noteCursor.close(); } // always close the cursor cursor.close(); } else { Toast toast = Toast.makeText(getApplicationContext(), "No match for deep link " + recipeUri.toString(), Toast.LENGTH_SHORT); toast.show(); } if (mRecipe != null) { // Create the adapter that will return a fragment for each of the steps of the recipe. mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); // Set the recipe title TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle); recipeTitle.setText(mRecipe.getTitle()); // Set the recipe prep time TextView recipeTime = (TextView) findViewById(R.id.recipeTime); recipeTime.setText(" " + mRecipe.getPrepTime()); //Set the note button toggle ToggleButton addNoteToggle = (ToggleButton) findViewById(R.id.addNoteToggle); addNoteToggle.setChecked(mRecipe.getNote() != null); addNoteToggle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mRecipe.getNote() != null) { displayNoteDialog(getString(R.string.dialog_update_note), getString(R .string.dialog_delete_note)); } else { displayNoteDialog(getString(R.string.dialog_add_note), getString(R.string .dialog_cancel_note)); } } }); } }