List of usage examples for android.widget Toast setDuration
public void setDuration(@Duration int duration)
From source file:org.smilec.smile.student.CourseList.java
public void showToast(String msg) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); text.setText(msg);//from w w w .j a v a 2 s .c o m Toast toast = new Toast(getApplicationContext()); if (smile.face != null) text.setTypeface(smile.face); text.setText(msg); toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 100); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
From source file:com.bookkos.bircle.CaptureActivity.java
private void customToast(String toast_text, int icon, boolean bool) { getLayoutInflater();//w ww .j a v a 2 s . com LayoutInflater inflater = getLayoutInflater(); int resource = 0; if (bool == true) { resource = R.layout.success_toast; } else { resource = R.layout.failure_toast; } View layout = inflater.inflate(resource, null); ImageView image = (ImageView) layout.findViewById(R.id.image); image.setImageResource(icon); TextView text = (TextView) layout.findViewById(R.id.text); text.setText(Html.fromHtml(toast_text)); final Toast toast = new Toast(this); layout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toast.cancel(); } }); toast.setView(layout); toast.setGravity(Gravity.CENTER, 0, 0); if (modeFlag == true) { toast.setDuration(Toast.LENGTH_SHORT); } else { toast.setDuration(Toast.LENGTH_LONG); } toast.show(); // Toast.makeText(context, toast_text, Toast.LENGTH_SHORT).show(); }
From source file:com.kll.collect.android.activities.FormEntryActivity.java
/** * Creates a toast with the specified message. * * @param message/*from w w w. j ava 2 s . co m*/ */ private void showCustomToast(String message, int duration) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.toast_view, null); // set the text in the view TextView tv = (TextView) view.findViewById(R.id.message); tv.setText(message); Toast t = new Toast(this); t.setView(view); t.setDuration(duration); t.setGravity(Gravity.CENTER, 0, 0); t.show(); }
From source file:com.sentaroh.android.SMBSync2.ActivityMain.java
private void setHistoryContextButtonListener() { mContextHistoryButtonMoveTop.setOnClickListener(new OnClickListener() { @Override// www . j av a 2 s. c om public void onClick(View v) { setContextButtonEnabled(mContextHistoryButtonMoveTop, false); mGp.syncHistoryListView.setSelection(0); setContextButtonEnabled(mContextHistoryButtonMoveTop, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonMoveTop, mContext.getString(R.string.msgs_hist_cont_label_move_top)); mContextHistoryButtonMoveBottom.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setContextButtonEnabled(mContextHistoryButtonMoveBottom, false); mGp.syncHistoryListView.setSelection(mGp.syncHistoryAdapter.getCount() - 1); setContextButtonEnabled(mContextHistoryButtonMoveBottom, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonMoveBottom, mContext.getString(R.string.msgs_hist_cont_label_move_bottom)); mContextHistoryButtonDeleteHistory.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { confirmDeleteHistory(); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonDeleteHistory, mContext.getString(R.string.msgs_hist_cont_label_delete)); final Toast toast = Toast.makeText(mContext, mContext.getString(R.string.msgs_sync_history_copy_completed), Toast.LENGTH_SHORT); toast.setDuration(1500); mContextHistoryButtonHistiryCopyClipboard.setOnClickListener(new OnClickListener() { private long last_show_time = 0; @Override public void onClick(View v) { setContextButtonEnabled(mContextHistoryButtonHistiryCopyClipboard, false); if (enableMainUi) { ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); StringBuilder out = new StringBuilder(256); for (int i = 0; i < mGp.syncHistoryAdapter.getCount(); i++) { if (mGp.syncHistoryAdapter.getItem(i).isChecked) { SyncHistoryItem hli = mGp.syncHistoryAdapter.getItem(i); out.append(hli.sync_date).append(" "); out.append(hli.sync_time).append(" "); out.append(hli.sync_prof).append("\n"); if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_SUCCESS) { out.append(mContext.getString(R.string.msgs_sync_history_status_success)) .append("\n"); } else if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_ERROR) { out.append(mContext.getString(R.string.msgs_sync_history_status_error)) .append("\n"); } else if (hli.sync_status == SyncHistoryItem.SYNC_STATUS_CANCEL) { out.append(mContext.getString(R.string.msgs_sync_history_status_cancel)) .append("\n"); } out.append(mContext.getString(R.string.msgs_sync_history_count_copied)) .append(Integer.toString(hli.sync_result_no_of_copied)).append(" "); out.append(mContext.getString(R.string.msgs_sync_history_count_deleted)) .append(Integer.toString(hli.sync_result_no_of_deleted)).append(" "); out.append(mContext.getString(R.string.msgs_sync_history_count_ignored)) .append(Integer.toString(hli.sync_result_no_of_ignored)).append(" "); out.append("\n").append(hli.sync_error_text); } } if (out.length() > 0) cm.setText(out); if ((last_show_time + 1500) < System.currentTimeMillis()) { toast.show(); last_show_time = System.currentTimeMillis(); } mGp.syncHistoryAdapter.setAllItemChecked(false); mGp.syncHistoryAdapter.setShowCheckBox(false); mGp.syncHistoryAdapter.notifyDataSetChanged(); setHistoryContextButtonNormalMode(); } setContextButtonEnabled(mContextHistoryButtonHistiryCopyClipboard, true); } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistoryButtonHistiryCopyClipboard, mContext.getString(R.string.msgs_hist_cont_label_copy)); mContextHistiryButtonSelectAll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextHistiryButtonSelectAll, false); setHistoryItemSelectAll(); mGp.syncHistoryAdapter.setShowCheckBox(true); setHistoryContextButtonSelectMode(); setContextButtonEnabled(mContextHistiryButtonSelectAll, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistiryButtonSelectAll, mContext.getString(R.string.msgs_hist_cont_label_select_all)); mContextHistiryButtonUnselectAll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (enableMainUi) { setContextButtonEnabled(mContextHistiryButtonUnselectAll, false); setHistoryItemUnselectAll(); // mGp.syncHistoryAdapter.setShowCheckBox(false); // setHistoryContextButtonNotselected(); setContextButtonEnabled(mContextHistiryButtonUnselectAll, true); } } }); ContextButtonUtil.setButtonLabelListener(mContext, mContextHistiryButtonUnselectAll, mContext.getString(R.string.msgs_hist_cont_label_unselect_all)); }