/** * Show an alert dialog to the user * @param messageId String id to display inside the alert dialog * @param optionalParam Optional attribute for the string */ @UiThread void alert(@StringRes int messageId, @Nullable Object optionalParam) { if (Looper.getMainLooper().getThread() != Thread.currentThread()) { throw new RuntimeException("Dialog could be shown only from the main thread"); } AlertDialog.Builder bld = new AlertDialog.Builder(this); bld.setNeutralButton("OK", null); if (optionalParam == null) { bld.setMessage(messageId); } else { bld.setMessage(getResources().getString(messageId, optionalParam)); } bld.create().show(); }
/** * 安全地显示长时吐司 * * @param resId 资源Id */ public static void showLongSafe(@StringRes final int resId) { sHandler.post(new Runnable() { @Override public void run() { show(resId, Toast.LENGTH_LONG); } }); }
public static TextInputDialogFragment newInstance(@StringRes int summary, TextInputDialogListener listener) { TextInputDialogFragment f = new TextInputDialogFragment(); Bundle args = new Bundle(); args.putInt(SUMMARY_RES, summary); f.setArguments(args); f.mListener = listener; return f; }
@NonNull @Override public BuilderJoinerAndroid setPositiveButton( @StringRes int textId, @Nullable DialogInterface.OnClickListener listener) { return (BuilderJoinerAndroid) super.setPositiveButton(textId, listener); }
/** * 安全地显示短时吐司 * * @param resId 资源Id * @param args 参数 */ public static void showShortSafe(final @StringRes int resId, final Object... args) { sHandler.post(new Runnable() { @Override public void run() { show(resId, Toast.LENGTH_SHORT, args); } }); }
public void onLoadingEmpty(@StringRes int error){ if (mTvError != null){ mTvError.setText(error); mTvError.setVisibility(View.VISIBLE); mProgressLoading.setVisibility(View.GONE); mContainSubView.setVisibility(View.GONE); } }
/** * Provide an array of suggestions to be shown while the user is typing * This enables the auto-complete behaviour. * * @param suggestionStringResArray array of string resources to suggest */ public Input suggest(@StringRes int... suggestionStringResArray){ if (suggestionStringResArray != null && suggestionStringResArray.length > 0) { this.suggestionStringResArray = suggestionStringResArray; } return this; }
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) public static Matcher<? super View> withUsageHintOnLongClick(@StringRes final int resourceId) { return new TypeSafeMatcher<View>() { private String resourceName; private String expectedText; @Override protected boolean matchesSafely(View view) { if (!view.isLongClickable()) { return false; } expectedText = view.getResources().getString(resourceId); resourceName = view.getResources().getResourceEntryName(resourceId); if (expectedText == null) { return false; } AccessibilityNodeInfo.AccessibilityAction clickAction = findAction(view, AccessibilityNodeInfo.ACTION_LONG_CLICK); return expectedText.equals(clickAction.getLabel()); } @Override public void describeTo(Description description) { description.appendText("is long clickable and has custom usage hint for ACTION_LONG_CLICK from resource id: ").appendValue(resourceId); appendResourceNameAndExpectedTextToDescription(description, resourceName, expectedText); } }; }
@UiThread public static void showLong(Context context, @StringRes int message) { Toast toast = getToast(context); if (toast != null) { toast.setText(message); toast.setDuration(Toast.LENGTH_LONG); toast.show(); } }
private static MaterialSimpleListItem getThemeDialogAdapterItem(@StringRes int title, @DrawableRes int icon, String currentTheme, Activity activity) { MaterialSimpleListItem.Builder builder = new MaterialSimpleListItem.Builder(activity) .content(title) .icon(icon); return builder.build(); }
@Override public void setToolbarSubtitle(@StringRes int titleRes, Object... params) { ActionBar actionBar = ActivityUtils.supportToolbarFor(this); if (Objects.nonNull(actionBar)) { actionBar.setSubtitle(getString(titleRes, params)); } }
/** * 单个按钮,显示需要调用show() * * @param context * @param messageResId * @param postBtResId * @param postListener */ public static AlertDialog getDialog(final Context context, @StringRes int messageResId, @StringRes int postBtResId , DialogInterface.OnClickListener postListener, boolean cancelable) { AlertDialog dialog = new AlertDialog.Builder(context) .setPositiveButton(postBtResId, postListener) .setCancelable(cancelable) .setMessage(messageResId) .create(); return dialog; }
@UiThread public static void showShort(Context context, @StringRes int message) { Toast toast = getToast(context); if (toast != null) { toast.setText(message); toast.setDuration(Toast.LENGTH_SHORT); toast.show(); } }
public static AwesomeDialogFragment newInstance(@StringRes int message, @StringRes int positive, @StringRes int negative) { AwesomeDialogFragment fragment = new AwesomeDialogFragment(); Bundle bundle = new Bundle(); bundle.putInt(KEY_MESSAGE, message); bundle.putInt(KEY_POSITIVE, positive); bundle.putInt(KEY_NEGATIVE, negative); fragment.setArguments(bundle); return fragment; }
/** * 安全地显示短时吐司 * * @param resId 资源Id */ public static void showShortSafe(final @StringRes int resId) { sHandler.post(new Runnable() { @Override public void run() { show(resId, Toast.LENGTH_SHORT); } }); }
public ValiFieldText addMinLengthValidator(@StringRes int errorResource, int minLength) { String errorMessage = getString(errorResource, minLength); return addMinLengthValidator(errorMessage, minLength); }
private void setButtonText(@StringRes int buttonText) { this.buttonText = buttonText; }
public ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, @DrawableRes int drawerImageRes, @StringRes int openDrawerContentDescRes, @StringRes int closeDrawerContentDescRes) { this(activity, drawerLayout, !assumeMaterial(activity), drawerImageRes, openDrawerContentDescRes, closeDrawerContentDescRes); }
@Override public void notify(@StringRes int id) { Toast.makeText(this, id, Toast.LENGTH_SHORT).show(); }
public ProgressDialog(Context context, @StringRes int titleRes) { this(context, context.getString(titleRes)); }
@Override public void onError(@StringRes int resId) { if (baseActivity != null) { baseActivity.onError(resId); } }
public Set<String> getStringSet(@StringRes int key) { return getStringSet(mContext.getString(key)); }
public boolean contains(@StringRes int key) { return contains(mContext.getString(key)); }
public static void toast(Context context, @StringRes int stringRes) { toast(context, context.getResources().getString(stringRes), Toast.LENGTH_SHORT); }
private void showSnackbar(@StringRes int messageId) { Snackbar.make(getView(), messageId, Snackbar.LENGTH_SHORT).show(); }
@IdeSuggestion @Override public final Cortado.And.ViewInteraction withHint(@StringRes int resourceId) { return super.withHint(resourceId); }
public static void copyToClipboard(@NonNull Context context, @StringRes int resId, String text) { copyToClipboard(context, context.getString(resId), text); }
@Override public void showMessage(@StringRes int resId) { if (mParentMvpView != null) { mParentMvpView.showMessage(resId); } }
@UiThread public final void setContent(@StringRes int newContentRes, @Nullable Object... formatArgs) { setContent(builder.context.getString(newContentRes, formatArgs)); }
@IdeSuggestion @Override public final Cortado.Or.ViewInteraction withHint(@StringRes int resourceId) { return super.withHint(resourceId); }
public BaseViewHolder setText(@IdRes int viewId, @StringRes int strId) { TextView view = getView(viewId); view.setText(strId); return this; }
protected void setMessageForCoachMarkText(@StringRes int messageForCoachMarkTextRes) { mPresentation.setCoachMarkMessage( mStringResourceProvider.getStringFromResource(messageForCoachMarkTextRes)); }
@UiThread public final void setTitle(@StringRes int newTitleRes, @Nullable Object... formatArgs) { setTitle(builder.context.getString(newTitleRes, formatArgs)); }
public Builder setTitle(@StringRes int titleRes) { setTitle(this.context.getString(titleRes)); return this; }
public int getColor(@StringRes int keyResourceId, @ColorRes int defaultColor, final SharedPreferences... pref) { return gp(pref).getInt(rstr(keyResourceId), rcolor(defaultColor)); }
@StringRes public int getTitle() { return title; }
@NonNull public LexList twoItemSeparator(@StringRes int stringRes) { return twoItemSeparator(Lex.resources.getString(stringRes)); }
public BigText bigContentTitle (@StringRes int title) { return bigContentTitle(getCenter().getContext().getText(title)); }
public void setLabel(@StringRes int label) { this.label = label; }