List of usage examples for android.widget Toast setDuration
public void setDuration(@Duration int duration)
From source file:com.akop.bach.fragment.playstation.TrophiesFragment.java
private void showTrophyDetails(CharSequence title, CharSequence description) { LayoutInflater inflater = getActivity().getLayoutInflater(); View layout = inflater.inflate(R.layout.psn_trophy_toast, (ViewGroup) getActivity().findViewById(R.id.toast_root)); TextView text = (TextView) layout.findViewById(R.id.trophy_title); text.setText(title);/*from w w w .j a v a 2s . c o m*/ text = (TextView) layout.findViewById(R.id.trophy_description); text.setText(description); Toast toast = new Toast(getActivity()); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
From source file:org.apps8os.motivator.ui.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent;/* w w w. ja v a 2 s. c o m*/ AlertDialog.Builder builder; final Context context = this; switch (item.getItemId()) { case R.id.action_settings: intent = new Intent(this, SettingsActivity.class); startActivity(intent); return true; case R.id.action_start_sprint: builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.start_a_new_sprint)) .setMessage(getString(R.string.current_sprint_will_end)) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(context, StartingSprintActivity.class); startActivity(intent); } }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); Dialog dialog = builder.create(); dialog.show(); return true; case R.id.action_show_help: showHelp(); return true; case R.id.action_info: intent = new Intent(this, InfoActivity.class); startActivity(intent); return true; case R.id.action_show_substance_help: // Set up a dialog with info on where to get help if user answers everything is not ok builder = new AlertDialog.Builder(this); LinearLayout helpDialogLayout = (LinearLayout) getLayoutInflater() .inflate(R.layout.element_alcohol_help_dialog, null); builder.setView(helpDialogLayout); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { View toastLayout = (View) getLayoutInflater().inflate(R.layout.element_mood_toast, null); TextView toastText = (TextView) toastLayout.findViewById(R.id.mood_toast_text); toastText.setText(getString(R.string.questionnaire_done_toast_bad_mood)); toastText.setTextColor(Color.WHITE); Toast moodToast = new Toast(context); moodToast.setDuration(Toast.LENGTH_SHORT); moodToast.setView(toastLayout); moodToast.show(); } }); Dialog helpDialog = builder.create(); helpDialog.show(); return true; } return super.onOptionsItemSelected(item); }
From source file:org.madmatrix.zxing.android.CaptureActivity.java
public void showMyToast(String content) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout)); TextView toast_content = (TextView) layout.findViewById(R.id.toast_content); toast_content.setText(content);/* w ww . ja va 2s .c om*/ Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); }
From source file:com.example.jesse.barscan.BarcodeCaptureActivity.java
/** * onTap returns the tapped barcode result to the calling Activity. *///from w w w . j a va2 s .c o m public boolean onTap(float rawX, float rawY) { // Find tap point in preview frame coordinates. int[] location = new int[2]; mGraphicOverlay.getLocationOnScreen(location); float x = (rawX - location[0]) / mGraphicOverlay.getWidthScaleFactor(); float y = (rawY - location[1]) / mGraphicOverlay.getHeightScaleFactor(); // Find the barcode whose center is closest to the tapped point. Barcode best = null; float bestDistance = Float.MAX_VALUE; for (BarcodeGraphic graphic : mGraphicOverlay.getGraphics()) { Barcode barcode = graphic.getBarcode(); if (barcode.getBoundingBox().contains((int) x, (int) y)) { // Exact hit, no need to keep looking. best = barcode; break; } float dx = x - barcode.getBoundingBox().centerX(); float dy = y - barcode.getBoundingBox().centerY(); float distance = (dx * dx) + (dy * dy); // actually squared distance if (distance < bestDistance) { best = barcode; bestDistance = distance; } } if (best != null) { Intent data = new Intent(); data.putExtra(BarcodeObject, best); setResult(CommonStatusCodes.SUCCESS, data); LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.barcode_toast, (ViewGroup) findViewById(R.id.custom_toast_container)); Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject); //Barcode.DriverLicense dlBarcode = barcode.driverLicense; Barcode.DriverLicense sample = barcode.driverLicense; TextView name = (TextView) layout.findViewById(R.id.name); TextView address = (TextView) layout.findViewById(R.id.address); TextView cityStateZip = (TextView) layout.findViewById(R.id.cityStateZip); TextView gender = (TextView) layout.findViewById(R.id.gender); TextView dob = (TextView) layout.findViewById(R.id.dob); TableLayout tbl = (TableLayout) layout.findViewById(R.id.tableLayout); try { int age = DateDifference.generateAge(sample.birthDate); if (age < minAge) tbl.setBackgroundColor(Color.parseColor("#980517")); else tbl.setBackgroundColor(Color.parseColor("#617C17")); } catch (ParseException e) { e.printStackTrace(); } String cityContent = new String( sample.addressCity + ", " + sample.addressState + " " + (sample.addressZip).substring(0, 5)); address.setText(sample.addressStreet); cityStateZip.setText(cityContent); String genderString; if ((sample.gender).equals("1")) genderString = "Male"; else if ((sample.gender).equals("2")) genderString = "Female"; else genderString = "Other"; gender.setText(genderString); dob.setText((sample.birthDate).substring(0, 2) + "/" + (sample.birthDate).substring(2, 4) + "/" + (sample.birthDate).substring(4, 8)); String nameString = new String(sample.firstName + " " + sample.middleName + " " + sample.lastName); name.setText(nameString); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); Date today = Calendar.getInstance().getTime(); String reportDate = df.format(today); SQLiteDatabase db = helper.getWritableDatabase(); ContentValues row = new ContentValues(); row.put("dateVar", reportDate); row.put("dobVar", sample.birthDate); row.put("zipVar", sample.addressZip); row.put("genderVar", genderString); db.insert("test", null, row); db.close(); return true; } return false; }
From source file:com.adamas.client.android.ui.ConnectorsFragment.java
private void toast(String msg, ToastType toastType) { LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate the Layout View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) getActivity().findViewById(R.id.custom_toast_layout)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (toastType.equals(ToastType.error)) { layout.setBackground(getActivity().getDrawable(R.drawable.toast_error)); } else if (toastType.equals(ToastType.info)) { layout.setBackground(getActivity().getDrawable(R.drawable.toast_info)); } else if (toastType.equals(ToastType.warning)) { layout.setBackground(getActivity().getDrawable(R.drawable.toast_warning)); } else {// w w w . j a v a 2 s . com layout.setBackground(getActivity().getDrawable(R.drawable.toast_info)); } } TextView text = (TextView) layout.findViewById(R.id.textToShow); // Set the Text to show in TextView text.setText(msg); Toast toast = new Toast(getActivity().getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); }
From source file:xj.property.activity.HXBaseActivity.HXBaseActivity.java
/** * Toast ,, ?.//from w ww. j a va2 s. c o m * * @param showT * @param gravity ? */ protected void showCommonToast(String showT, int gravity) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.common_welfare_toast_lay, null); TextView title = (TextView) layout.findViewById(R.id.toast_title_tv); title.setText(showT); Toast toast = new Toast(getApplicationContext()); toast.setGravity(gravity, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
From source file:com.sender.team.sender.gcm.MyGcmListenerService.java
private void sendToast(final ChattingReceiveData data, final ChattingReceiveMessage c) { handler.post(new Runnable() { @Override/*from ww w. j a v a 2 s .c o m*/ public void run() { View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.toast_notify, null); ImageView imageProfile = (ImageView) view.findViewById(R.id.imageProfile); TextView textName = (TextView) view.findViewById(R.id.textName); TextView textMessage = (TextView) view.findViewById(R.id.textMessage); Glide.with(getApplicationContext()).load(data.getSender().getFileUrl()).into(imageProfile); if (!TextUtils.isEmpty(data.getSender().getName())) { textName.setText(data.getSender().getName()); } if (!TextUtils.isEmpty(c.getMessage())) { textMessage.setText(c.getMessage()); } else { textMessage.setText(""); } Toast toast = new Toast(getApplicationContext()); float dp = 65; int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, pixel); toast.setDuration(Toast.LENGTH_LONG); toast.setView(view); toast.show(); } }); }
From source file:com.akop.bach.fragment.xboxlive.AchievementsFragment.java
private void showAchievementDetails(CharSequence title, CharSequence description) { LayoutInflater inflater = getActivity().getLayoutInflater(); View layout = inflater.inflate(R.layout.xbl_achievement_toast, (ViewGroup) getActivity().findViewById(R.id.toast_root)); TextView text = (TextView) layout.findViewById(R.id.achievement_title); text.setText(title);/*from w w w . j a v a2s . com*/ text = (TextView) layout.findViewById(R.id.achievement_description); text.setText(description); Toast toast = new Toast(getActivity()); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
From source file:net.mypapit.mobile.callsignview.MainActivity.java
private void showToast(String message) { Context context = getApplicationContext(); LayoutInflater inflater = getLayoutInflater(); View customToastroot = inflater.inflate(R.layout.custom_toast, null); TextView tvToast = (TextView) customToastroot.findViewById(R.id.tvToast); tvToast.setText(message);//from w ww.j av a 2 s. c om Toast customtoast = new Toast(context); customtoast.setView(customToastroot); customtoast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0); customtoast.setDuration(Toast.LENGTH_SHORT); customtoast.show(); }
From source file:com.wewow.BaseActivity.java
private void showCacheClearedToast() { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.clear_cache_toast_view, null); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout);/*from www. j a v a2 s.c o m*/ toast.show(); }