/** * Returns a {@value #TAG} with a specified style. * * @param activity {@link android.app.Activity} * @param textCharSequence {@link CharSequence} * @param durationInteger {@link com.github.johnpersano.supertoasts.SuperToast.Duration} * @param style {@link com.github.johnpersano.supertoasts.util.Style} * * @return {@link SuperActivityToast} */ public static SuperActivityToast create(Activity activity, CharSequence textCharSequence, int durationInteger, Style style) { final SuperActivityToast superActivityToast = new SuperActivityToast(activity); superActivityToast.setText(textCharSequence); superActivityToast.setDuration(durationInteger); superActivityToast.setStyle(style); return superActivityToast; }
public void run() { toast.dismiss(); } });
public boolean isToastShown() { final SuperActivityToast toast = myToast; return toast != null && toast.isShowing(); }
/** * Returns a standard {@value #TAG}. * * @param activity {@link android.app.Activity} * @param textCharSequence {@link CharSequence} * @param durationInteger {@link com.github.johnpersano.supertoasts.SuperToast.Duration} * * @return {@link SuperActivityToast} */ public static SuperActivityToast create(Activity activity, CharSequence textCharSequence, int durationInteger) { final SuperActivityToast superActivityToast = new SuperActivityToast(activity); superActivityToast.setText(textCharSequence); superActivityToast.setDuration(durationInteger); return superActivityToast; }
/** * Returns a standard {@value #TAG} with specified animations. * * @param activity {@link android.app.Activity} * @param textCharSequence {@link CharSequence} * @param durationInteger {@link com.github.johnpersano.supertoasts.SuperToast.Duration} * @param animations {@link com.github.johnpersano.supertoasts.SuperToast.Animations} * * @return {@link SuperActivityToast} */ public static SuperActivityToast create(Activity activity, CharSequence textCharSequence, int durationInteger, Animations animations) { final SuperActivityToast superActivityToast = new SuperActivityToast(activity); superActivityToast.setText(textCharSequence); superActivityToast.setDuration(durationInteger); superActivityToast.setAnimations(animations); return superActivityToast; }
superActivityToast = new SuperActivityToast(activity, Type.BUTTON); superActivityToast.setButtonText(referenceHolder.mButtonText); superActivityToast.setButtonTextSizeFloat(referenceHolder.mButtonTextSize); superActivityToast.setButtonTextColor(referenceHolder.mButtonTextColor); superActivityToast.setButtonIcon(referenceHolder.mButtonIcon); superActivityToast.setDividerColor(referenceHolder.mDivider); superActivityToast.setButtonTypefaceStyle(referenceHolder.mButtonTypefaceStyle); superActivityToast.getRootLayout().setLayoutParams(layoutParams); superActivityToast.setOnClickWrapper(onClickWrapper, referenceHolder.mToken); superActivityToast = new SuperActivityToast(activity); superActivityToast.setOnDismissWrapper(onDismissWrapper); superActivityToast.setAnimations(referenceHolder.mAnimations); superActivityToast.setText(referenceHolder.mText); superActivityToast.setTypefaceStyle(referenceHolder.mTypefaceStyle); superActivityToast.setDuration(referenceHolder.mDuration); superActivityToast.setTextColor(referenceHolder.mTextColor); superActivityToast.setTextSizeFloat(referenceHolder.mTextSize); superActivityToast.setIndeterminate(referenceHolder.mIsIndeterminate); superActivityToast.setIcon(referenceHolder.mIcon, referenceHolder.mIconPosition); superActivityToast.setBackground(referenceHolder.mBackground); superActivityToast.setTouchToDismiss(referenceHolder.mIsTouchDismissible); superActivityToast.setShowImmediate(true);
new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON); toast.setText(bookmark.getText()); toast.setDuration(SuperToast.Duration.EXTRA_LONG); toast.setButtonIcon( android.R.drawable.ic_menu_edit, ZLResource.resource("dialog").getResource("button").getResource("edit").getValue() ); toast.setOnClickWrapper(new OnClickWrapper("bkmk", new SuperToast.OnClickListener() { @Override public void onClick(View view, Parcelable token) {
/** * Displays a SuperActivityToast. */ private void displaySuperToast(SuperActivityToast superActivityToast) { /* If this SuperActivityToast is somehow already showing do nothing */ if(superActivityToast.isShowing()) { return; } final ViewGroup viewGroup = superActivityToast.getViewGroup(); final View toastView = superActivityToast.getView(); if(viewGroup != null) { try { viewGroup.addView(toastView); if(!superActivityToast.getShowImmediate()) { toastView.startAnimation(getShowAnimation(superActivityToast)); } } catch(IllegalStateException e) { this.cancelAllSuperActivityToastsForActivity(superActivityToast.getActivity()); } } /* Dismiss the SuperActivityToast at the set duration time unless indeterminate */ if(!superActivityToast.isIndeterminate()) { Message message = obtainMessage(Messages.REMOVE); message.obj = superActivityToast; sendMessageDelayed(message, superActivityToast.getDuration() + getShowAnimation(superActivityToast).getDuration()); } }
/** * Removes all SuperActivityToasts and clears the list for a specific activity */ void cancelAllSuperActivityToastsForActivity(Activity activity) { Iterator<SuperActivityToast> superActivityToastIterator = mList .iterator(); while (superActivityToastIterator.hasNext()) { SuperActivityToast superActivityToast = superActivityToastIterator .next(); if ((superActivityToast.getActivity()) != null && superActivityToast.getActivity().equals(activity)) { if (superActivityToast.isShowing()) { superActivityToast.getViewGroup().removeView( superActivityToast.getView()); } removeMessages(Messages.DISPLAY, superActivityToast); removeMessages(Messages.REMOVE, superActivityToast); superActivityToastIterator.remove(); } } }
/** * Removes all SuperActivityToasts and clears the list */ void cancelAllSuperActivityToasts() { removeMessages(Messages.DISPLAY); removeMessages(Messages.REMOVE); for (SuperActivityToast superActivityToast : mList) { if (superActivityToast.isShowing()) { superActivityToast.getViewGroup().removeView( superActivityToast.getView()); superActivityToast.getViewGroup().invalidate(); } } mList.clear(); }
public void showToast(final SuperActivityToast toast) { hideToast(); myToast = toast; // TODO: avoid this hack (accessing text style via option) final int dpi = getZLibrary().getDisplayDPI(); final int defaultFontSize = dpi * 18 / 160; final int fontSize = new ZLIntegerOption("Style", "Base:fontSize", defaultFontSize).getValue(); final int percent = new ZLIntegerRangeOption("Options", "ToastFontSizePercent", 25, 100, 90).getValue(); final int dpFontSize = fontSize * 160 * percent / dpi / 100; toast.setTextSize(dpFontSize); toast.setButtonTextSize(dpFontSize * 7 / 8); final String fontFamily = new ZLStringOption("Style", "Base:fontFamily", "sans-serif").getValue(); // toast.setTypeface(AndroidFontUtil.systemTypeface(fontFamily, false, false)); runOnUiThread(new Runnable() { public void run() { toast.show(); } }); } /* ------ SUPER TOAST ------ */
public void showToast(final SuperActivityToast toast) { hideToast(); myToast = toast; // TODO: avoid this hack (accessing text style via option) final int dpi = getZLibrary().getDisplayDPI(); final int defaultFontSize = dpi * 18 / 160; final int fontSize = new ZLIntegerOption("Style", "Base:fontSize", defaultFontSize).getValue(); final int percent = new ZLIntegerRangeOption("Options", "ToastFontSizePercent", 25, 100, 90).getValue(); final int dpFontSize = fontSize * 160 * percent / dpi / 100; toast.setTextSize(dpFontSize); toast.setButtonTextSize(dpFontSize * 7 / 8); final String fontFamily = new ZLStringOption("Style", "Base:fontFamily", "sans-serif").getValue(); toast.setTypeface(AndroidFontUtil.systemTypeface(fontFamily, false, false)); runOnUiThread(new Runnable() { public void run() { toast.show(); } }); } /* ------ SUPER TOAST ------ */
public void run() { toast.show(); } });
/** * Shows the next SuperActivityToast in the list. Called by add() and when the dismiss animation * of a previously showing SuperActivityToast ends. */ private void showNextSuperToast() { final SuperActivityToast superActivityToast = mList.peek(); if (mList.isEmpty() || superActivityToast.getActivity() == null) { return; } if (!superActivityToast.isShowing()) { final Message message = obtainMessage(Messages.DISPLAY); message.obj = superActivityToast; sendMessage(message); } }
/** * Recreates pending/showing {@value #TAG} from orientation change. * * @param bundle {@link android.os.Bundle} * @param activity {@link android.app.Activity} */ public static void onRestoreState(Bundle bundle, Activity activity) { if (bundle == null) { return; } Parcelable[] savedArray = bundle.getParcelableArray(BUNDLE_TAG); int i = 0; if (savedArray != null) { for (Parcelable parcelable : savedArray) { i++; new SuperActivityToast(activity, (ReferenceHolder) parcelable, null, i); } } }
new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON); toast.setText(bookmark.getText()); toast.setDuration(SuperToast.Duration.EXTRA_LONG); toast.setButtonIcon( android.R.drawable.ic_menu_edit, ZLResource.resource("dialog").getResource("button").getResource("edit").getValue() ); toast.setOnClickWrapper(new OnClickWrapper("bkmk", new SuperToast.OnClickListener() { @Override public void onClick(View view, Parcelable token) {
private static void showError(final FBReaderMainActivity fbreader, int code, Intent data) { final ZLResource resource = ZLResource.resource("dictanErrors"); String message; switch (code) { default: message = data.getStringExtra("error.message"); if (message == null) { message = resource.getResource("unknown").getValue(); } break; case 100: { final String word = data.getStringExtra("article.word"); message = resource.getResource("noArticle").getValue().replaceAll("%s", word); break; } case 130: message = resource.getResource("cannotOpenDictionary").getValue(); break; case 131: message = resource.getResource("noDictionarySelected").getValue(); break; } final SuperActivityToast toast = new SuperActivityToast(fbreader, SuperToast.Type.STANDARD); toast.setText("Dictan: " + message); toast.setDuration(DictionaryUtil.ErrorToastDurationOption.getValue().Value); InternalUtil.showToast(toast, fbreader); } }
if(!superActivityToast.isShowing()) { final ViewGroup viewGroup = superActivityToast.getViewGroup(); final View toastView = superActivityToast.getView();
public void showToast(final SuperActivityToast toast) { hideToast(); myToast = toast; // TODO: avoid this hack (accessing text style via option) final int dpi = getZLibrary().getDisplayDPI(); final int defaultFontSize = dpi * 18 / 160; final int fontSize = new ZLIntegerOption("Style", "Base:fontSize", defaultFontSize).getValue(); final int percent = new ZLIntegerRangeOption("Options", "ToastFontSizePercent", 25, 100, 90).getValue(); final int dpFontSize = fontSize * 160 * percent / dpi / 100; toast.setTextSize(dpFontSize); toast.setButtonTextSize(dpFontSize * 7 / 8); final String fontFamily = new ZLStringOption("Style", "Base:fontFamily", "sans-serif").getValue(); // toast.setTypeface(AndroidFontUtil.systemTypeface(fontFamily, false, false)); runOnUiThread(new Runnable() { public void run() { toast.show(); } }); } /* ------ SUPER TOAST ------ */
public void run() { toast.show(); } });