Java Code Examples for android.widget.Toast#LENGTH_LONG
The following examples show how to use
android.widget.Toast#LENGTH_LONG .
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: SweetToastManager.java From SweetTips with Apache License 2.0 | 6 votes |
/** * 将当前SweetToast实例添加到queue中 */ protected static void show(@NonNull SweetToast current){ try { if(queue.size() <= 0){ clear(); //队列为空,则将current添加到队列中,同时进行展示 offer(current); current.handleShow(); long delay = (current.getConfiguration().getDuration() == SweetToast.LENGTH_LONG||current.getConfiguration().getDuration() == Toast.LENGTH_LONG) ? SweetToast.LONG_DELAY : ((current.getConfiguration().getDuration() == SweetToast.LENGTH_SHORT || current.getConfiguration().getDuration() == Toast.LENGTH_SHORT)? SweetToast.SHORT_DELAY : current.getConfiguration().getDuration()); queueHandler.postDelayed(mShowNext,delay); }else{ offer(current); } }catch (Exception e){ Log.e("幻海流心","e:"+e.getLocalizedMessage()); } }
Example 2
Source File: SetCardActivity.java From SwipeYours with GNU General Public License v3.0 | 6 votes |
public void setNewCard(View view) { String newSwipeData = ((EditText) findViewById(R.id.swipe_data)).getText().toString().replaceAll("\\s+",""); boolean newDataIsValid = parseTrackData(newSwipeData); String toastMessage; int toastDuration; if (newDataIsValid) { toastMessage = "New Card Set"; toastDuration = Toast.LENGTH_SHORT; storeNewSwipeData(newSwipeData); } else { toastMessage = "Invalid swipe data"; toastDuration = Toast.LENGTH_LONG; } Toast toast = Toast.makeText(getApplicationContext(), toastMessage, toastDuration); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
Example 3
Source File: SweetToastManager.java From SweetTips with Apache License 2.0 | 6 votes |
/** * 将当前SweetToast实例添加到queue中 */ protected static void show(@NonNull SweetToast current){ try { if(queue.size() <= 0){ clear(); //队列为空,则将current添加到队列中,同时进行展示 offer(current); current.handleShow(); long delay = (current.getConfiguration().getDuration() == SweetToast.LENGTH_LONG||current.getConfiguration().getDuration() == Toast.LENGTH_LONG) ? SweetToast.LONG_DELAY : ((current.getConfiguration().getDuration() == SweetToast.LENGTH_SHORT || current.getConfiguration().getDuration() == Toast.LENGTH_SHORT)? SweetToast.SHORT_DELAY : current.getConfiguration().getDuration()); queueHandler.postDelayed(mShowNext,delay); }else{ offer(current); } }catch (Exception e){ Log.e("幻海流心","e:"+e.getLocalizedMessage()); } }
Example 4
Source File: BaseFragment.java From ZfsoftCampusAssit with Apache License 2.0 | 5 votes |
public void showToast(String msg, int duration) { if (msg == null) return; if ( duration == Toast.LENGTH_LONG) { Toast.makeText(getActivity(),msg,Toast.LENGTH_LONG).show(); } else { Toast.makeText(getActivity(),msg,Toast.LENGTH_SHORT).show(); } }
Example 5
Source File: Toaster.java From CommonUtils with Apache License 2.0 | 5 votes |
public void show(@NonNull Context context) { if (shown) { if (CommonUtils.isDebug()) System.out.println("Skipping toast, already shown!"); return; } if (!DialogUtils.isContextValid(context)) { if (CommonUtils.isDebug()) System.out.println("Skipping toast, context is invalid: " + context); return; } if (msg == null) { if (msgRes != 0) { msg = context.getString(msgRes, args); msgRes = 0; args = null; } else { throw new IllegalArgumentException("Missing toast message!"); } } final int duration; if (msg.length() > 48) duration = Toast.LENGTH_LONG; else duration = Toast.LENGTH_SHORT; Runnable action = () -> { if (DialogUtils.isContextValid(context)) Toast.makeText(context, msg, duration).show(); }; if (Looper.myLooper() == Looper.getMainLooper()) action.run(); else handler.post(action); Log.v(TAG, buildLogMessage(context)); shown = true; }
Example 6
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 7
Source File: BaseFragment.java From ZfsoftCampusAssit with Apache License 2.0 | 5 votes |
public void showToast(int resId, int duration) { if ( duration == Toast.LENGTH_LONG) { Toast.makeText(getActivity(),getString(resId),Toast.LENGTH_LONG).show(); } else { Toast.makeText(getActivity(),getString(resId),Toast.LENGTH_SHORT).show(); } }
Example 8
Source File: EasyToast.java From NonViewUtils with Apache License 2.0 | 5 votes |
/** * 显示toast * * @param length toast的显示的时间长度:{Toast.LENGTH_SHORT, Toast.LENGTH_LONG} */ public static void show(@NonNull Context context, String msg, @Length int length) { if (length == Toast.LENGTH_SHORT || length == Toast.LENGTH_LONG) { if (context != null) { Toast.makeText(context, msg, length).show(); } } }
Example 9
Source File: WXModalUIModule.java From weex with Apache License 2.0 | 5 votes |
@WXModuleAnno public void toast(String param) { String message = ""; int duration = Toast.LENGTH_SHORT; if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = new JSONObject(param); message = jsObj.optString(WXConst.MESSAGE); duration = jsObj.optInt(WXConst.DURATION); } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] alert param parse error " + WXLogUtils.getStackTrace(e)); } } if (TextUtils.isEmpty(message)) { WXLogUtils.e("[WXModalUIModule] toast param parse is null "); return; } if (duration > 3) { duration = Toast.LENGTH_LONG; } else { duration = Toast.LENGTH_SHORT; } if(toast== null){ toast =Toast.makeText(mWXSDKInstance.getContext(), message, duration); } else { toast.setDuration(duration); toast.setText(message); } toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
Example 10
Source File: WXModalUIModule.java From weex-uikit with MIT License | 5 votes |
@JSMethod(uiThread = true) public void toast(String param) { String message = ""; int duration = Toast.LENGTH_SHORT; if (!TextUtils.isEmpty(param)) { try { param = URLDecoder.decode(param, "utf-8"); JSONObject jsObj = JSON.parseObject(param); message = jsObj.getString(MESSAGE); duration = jsObj.getInteger(DURATION); } catch (Exception e) { WXLogUtils.e("[WXModalUIModule] alert param parse error ", e); } } if (TextUtils.isEmpty(message)) { WXLogUtils.e("[WXModalUIModule] toast param parse is null "); return; } if (duration > 3) { duration = Toast.LENGTH_LONG; } else { duration = Toast.LENGTH_SHORT; } if (toast == null) { toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration); } else { toast.setDuration(duration); toast.setText(message); } toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
Example 11
Source File: SweetToastManager.java From SweetTips with Apache License 2.0 | 5 votes |
/** * 重用queue中的正在显示的SweetToast实例,直接更新显示的内容 * @param current */ protected static void showByPrevious(@NonNull SweetToast current){ try { clearQueue(); Runnable r = new Runnable() { @Override public void run() { if(System.currentTimeMillis() >= singleHideTimeMillis && singleToast != null){ singleToast.setHideEnabled(true); singleToast.handleHide(); } } }; if(singleToast != null && singleToast.isShowing()){ singleToast.setHideEnabled(false); //暂时仅仅支持默认样式的SweetToast实例间的重用 if(singleToast.getContentView() instanceof LinearLayout && singleToast.getContentView().findViewById(R.id.message) != null && current.getContentView() instanceof LinearLayout && current.getContentView().findViewById(R.id.message) != null){ singleToast.setConfiguration(current.getConfiguration()); TextView textView = (TextView) singleToast.getContentView().findViewById(R.id.message); TextView content = (TextView) current.getContentView().findViewById(R.id.message); textView.setText(content.getText()); } }else { singleToast = null; singleToast = current; singleToast.setHideEnabled(false); singleToast.handleShow(); } long delay = (current.getConfiguration().getDuration() == SweetToast.LENGTH_LONG||current.getConfiguration().getDuration() == Toast.LENGTH_LONG) ? SweetToast.LONG_DELAY : ((current.getConfiguration().getDuration() == SweetToast.LENGTH_SHORT || current.getConfiguration().getDuration() == Toast.LENGTH_SHORT)? SweetToast.SHORT_DELAY : current.getConfiguration().getDuration()); singleHideTimeMillis = delay + System.currentTimeMillis(); singleHandler.postDelayed(r,delay); }catch (Exception e){ Log.e("幻海流心","e:"+e.getLocalizedMessage()); } }
Example 12
Source File: BaseAppCompatActivity.java From ZfsoftCampusAssit with Apache License 2.0 | 5 votes |
@SuppressLint("ShowToast") public void showToast(String msg, int duration) { if (msg == null) return; if (duration == Toast.LENGTH_SHORT || duration == Toast.LENGTH_LONG) { Toast.makeText(this, msg, duration); } else { Toast.makeText(this, msg, Toast.LENGTH_SHORT); } }
Example 13
Source File: Permissions.java From BlackList with Apache License 2.0 | 5 votes |
/** * Checks for permissions and notifies the user if they aren't granted **/ public static void notifyIfNotGranted(@NonNull Context context) { StringBuilder sb = new StringBuilder(); int count = 0; for (String permission : PERMISSIONS) { if (!isGranted(context, permission)) { if (count > 0) { sb.append("\n"); } String info = getPermissionInfo(context, permission); sb.append(info); sb.append(";"); count++; } } if (count > 0) { int duration; String message = context.getString(R.string.app_name) + " "; if (count == 1) { duration = Toast.LENGTH_SHORT; message += context.getString(R.string.needs_permission) + ":\n" + sb.toString(); } else { duration = Toast.LENGTH_LONG; message += context.getString(R.string.needs_permissions) + ":\n" + sb.toString(); } Utils.showToast(context, message, duration); } }
Example 14
Source File: BaseActivity.java From AFBaseLibrary with Apache License 2.0 | 5 votes |
protected void showToast(String message) { if (getAFContext() == null || TextUtils.isEmpty(message)) { return; } int during = Toast.LENGTH_SHORT; if (message.length() > AFConstant.TOAST_LONG_MESSAGE_LENGTH) { during = Toast.LENGTH_LONG; } Toast.makeText(getAFContext(), message, during).show(); }
Example 15
Source File: MainActivity.java From NYU-BusTracker-Android with Apache License 2.0 | 5 votes |
private void displayStopError() { Context context = getApplicationContext(); CharSequence text = getString(R.string.no_stops_available); int duration = Toast.LENGTH_LONG; if (context != null) { Toast.makeText(context, text, duration).show(); } }
Example 16
Source File: FaceSwapperActivity.java From Machine-Learning-Projects-for-Mobile-Applications with MIT License | 5 votes |
/** * Shows a toast with information why the swap failed. * * @param text the messages to be displayed. */ private Toast showInfoToast(CharSequence text) { Context context = getApplicationContext(); int duration = Toast.LENGTH_LONG; final Toast toast = Toast.makeText(context, text, duration); toast.setGravity(Gravity.CENTER, 0, 400); toast.show(); return toast; }
Example 17
Source File: VoiceSettingsActivity.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
private void processTtsLanguages(Set<Locale> ttsAvailableLanguages) { boolean supportedLanguage = false; appendLog(getBaseContext(), TAG, "Locales:ttsAvailableLanguages: " + ttsAvailableLanguages + ":" + ((ttsAvailableLanguages != null) ? ttsAvailableLanguages.size() : "")); for (Locale locale : ttsAvailableLanguages) { appendLog(getBaseContext(), TAG, "Locales: ", locale.getISO3Language(), ":", applicationLocale.getISO3Language()); if (locale.getISO3Language().equals(applicationLocale.getISO3Language())) { supportedLanguage = true; } } if (!supportedLanguage) { int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(getBaseContext(), getString(R.string.pref_title_tts_not_supported), duration); toast.show(); } }
Example 18
Source File: ToastUtil.java From FastLib with Apache License 2.0 | 4 votes |
private static void showToast(CharSequence content, boolean isShowRunningForeground, Builder builder) { //过滤空字符情况 if (TextUtils.isEmpty(content) || TextUtils.isEmpty(content.toString().trim())) { return; } //修复快速点击无法显示的问题,修复超过50之后无法显示的问题 sSystemToast = SingleToast.getInstance(); sTextView = new RadiusTextView(sContext); if (builder == null) { builder = getBuilder(); } int duration = builder.duration == Toast.LENGTH_LONG || builder.duration == Toast.LENGTH_SHORT ? builder.duration : content.length() > 10 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT; sTextView.getDelegate() .setTextColor(builder.textColor) .setRadius(builder.radius) .setStrokeColor(builder.strokeColor) .setBackgroundColor(builder.backgroundColor) .setLeftDrawableHeight(builder.textDrawableGravity == Gravity.LEFT ? builder.textDrawableHeight : 0) .setLeftDrawableWidth(builder.textDrawableGravity == Gravity.LEFT ? builder.textDrawableWidth : 0) .setLeftDrawable(builder.textDrawableGravity == Gravity.LEFT ? builder.textDrawable : null) .setTopDrawableHeight(builder.textDrawableGravity == Gravity.TOP ? builder.textDrawableHeight : 0) .setTopDrawableWidth(builder.textDrawableGravity == Gravity.TOP ? builder.textDrawableWidth : 0) .setTopDrawable(builder.textDrawableGravity == Gravity.TOP ? builder.textDrawable : null) .setRightDrawableHeight(builder.textDrawableGravity == Gravity.RIGHT ? builder.textDrawableHeight : 0) .setRightDrawableWidth(builder.textDrawableGravity == Gravity.RIGHT ? builder.textDrawableWidth : 0) .setRightDrawable(builder.textDrawableGravity == Gravity.RIGHT ? builder.textDrawable : null) .setBottomDrawableHeight(builder.textDrawableGravity == Gravity.BOTTOM ? builder.textDrawableHeight : 0) .setBottomDrawableWidth(builder.textDrawableGravity == Gravity.BOTTOM ? builder.textDrawableWidth : 0) .setBottomDrawable(builder.textDrawableGravity == Gravity.BOTTOM ? builder.textDrawable : null) .setRippleEnable(false) .init(); sTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.textSize); sTextView.setPadding(builder.paddingLeft, builder.paddingTop, builder.paddingRight, builder.paddingBottom); sTextView.setCompoundDrawablePadding(builder.textDrawablePadding); sTextView.setGravity(builder.textGravity); if (builder.background != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { sTextView.setBackground(builder.background); } else { sTextView.setBackgroundDrawable(builder.background); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { sTextView.setElevation(builder.elevation); } sTextView.setMinimumHeight(builder.minHeight); sTextView.setMinimumWidth(builder.minWidth); sTextView.setText(content); sSystemToast.setView(sTextView); sSystemToast.setDuration(duration); sSystemToast.setGravity(builder.gravity, builder.gravityXOffset > -1 ? builder.gravityXOffset : 0, builder.gravityYOffset > -1 ? builder.gravityYOffset : builder.gravity == Gravity.BOTTOM ? SizeUtil.dp2px(64) : 0); ToastControl control = FastManager.getInstance().getToastControl(); if (control != null) { control.setToast(sSystemToast, sTextView); } if (!isShowRunningForeground || (isShowRunningForeground && FastUtil.isRunningForeground(sContext))) { sSystemToast.show(); } }
Example 19
Source File: MainActivity.java From ud867 with MIT License | 3 votes |
public void tellJoke(View view) { Context context = this; CharSequence text = this.getString(R.string.toast_text); int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.show(); }
Example 20
Source File: MainActivity.java From ud867 with MIT License | 3 votes |
public void tellJoke(View view) { Context context = this; CharSequence text = this.getString(R.string.toast_text); int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.show(); }