@BindingAdapter({"bind:onLongClick"}) public static void onLongClick(@NonNull final View view, @NonNull final OnClickListener onClickListener) { view.setOnLongClickListener(clickView -> { onClickListener.onClick(clickView); return true; }); }
@BindingAdapter({"message"}) public static void setMessage(TextView tv, MessageInfo data) { tv.setText(Html.fromHtml("<font color='#000000'>" + data.creater.username + ":<br/><br/>" + "</font>" + data.message)); }
@BindingAdapter({"comment"}) public static void setComment(TextView tv, CommentInfo data) { tv.setText(Html.fromHtml("<font color='#000000'>" + data.creater.username + ":<br/><br/>" + "</font>" + data.content)); }
@BindingAdapter("bind:font") public static void setTypeface(TextView textView, String fontName) { final AssetManager assets = textView.getContext().getAssets(); textView.setTypeface(Typeface.createFromAsset(assets, "fonts/" + fontName)); }
@BindingAdapter({"article"}) public static void setArticle(TextView tv, String url) { if (TextUtils.isEmpty(url)) return; String article = url.replace("<br>", "\n").replaceAll(" ", "").replaceAll("//", ""); if (!TextUtils.isEmpty(article) && article.indexOf(">") > 0) { article = article.substring(article.indexOf(">") + 4, article.length()); } tv.setText(article); }
@BindingAdapter({"imageUrl"}) public static void loadImage(ImageView view, String imageUrl) { Picasso.with(view.getContext()) .load(imageUrl) .placeholder(R.drawable.placeholder) .into(view); }
@BindingAdapter({"imageUrl"}) public static void loadImg(ImageView v, String url) { v.setColorFilter(v.getContext().getResources().getColor(SpUtil.isNight() ? R.color.CoverColor : R.color.colorWhite), PorterDuff.Mode.MULTIPLY); Glide.with(v.getContext()) .load(getFuckUrl(url)) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(v); }
/** * This method will be used by data binding when we use app:html in XML. * BindingAdapters only need to be declared once and usable in the whole app. * Its better to put all BindingAdapters in a single Java file. * * @param view The {@link HtmlTextView} * @param html The value from {@link NewsItem#getHtml()} */ @BindingAdapter({"html"}) public static void displayHtml(HtmlTextView view, @Nullable String html) { view.setHtml(html, new HtmlResImageGetter(view)); }
@BindingAdapter({"app:imageUrl", "app:placeholder", "app:error"}) public static void bindImageView(ImageView iv, String url, Drawable placeholder, Drawable error) { Picasso.with(iv.getContext()) .load(url) .fit() .centerCrop() .placeholder(placeholder) .error(error) .into(iv); }
@BindingAdapter({"app:imageUrl", "app:placeholder", "app:error"}) public static void bindImageView(ImageView iv, String url, Drawable placeholder, Drawable error) { Picasso.with(iv.getContext()) .load(url) .fit() .centerCrop() .placeholder(placeholder) .error(error) .into(iv); }
@BindingAdapter({"app:imageUrl", "app:placeholder", "app:error"}) public static void bindImageView(ImageView iv, String url, Drawable placeholder, Drawable error) { Picasso.with(iv.getContext()) .load(url) .fit() .centerCrop() .placeholder(placeholder) .error(error) .into(iv); }
@BindingAdapter({"app:imageUrl", "app:placeholder", "app:error"}) public static void bindImageView(ImageView iv, String url, Drawable placeholder, Drawable error) { Picasso.with(iv.getContext()) .load(url) .fit() .centerCrop() .placeholder(placeholder) .error(error) .into(iv); }
@BindingAdapter({"app:imageUrl", "app:placeholder", "app:error"}) public static void bindImageView(ImageView iv, String url, Drawable placeholder, Drawable error) { Picasso.with(iv.getContext()) .load(url) .fit() .centerCrop() .placeholder(placeholder) .error(error) .into(iv); }
@BindingAdapter("app:requestFocus") public static void bindRequestFocus(View v, String focusMode) { Configuration cfg=v.getResources().getConfiguration(); boolean hasNoKeyboard= cfg.keyboard==Configuration.KEYBOARD_NOKEYS; boolean keyboardHidden= cfg.hardKeyboardHidden==Configuration.HARDKEYBOARDHIDDEN_YES; boolean result=false; if (TRUE.equals(focusMode)) { result=true; } else if (IF_HARD_KEYBOARD.equals(focusMode)) { if (!hasNoKeyboard && !keyboardHidden) { result=true; } } else if (IF_NO_HARD_KEYBOARD.equals(focusMode)) { if (hasNoKeyboard || keyboardHidden) { result=true; if (hasNoKeyboard) v.setFocusableInTouchMode(true); } } else { throw new IllegalArgumentException("Unexpected focusMode value: "+focusMode); } if (result) { v.setFocusable(true); v.requestFocus(); } }
@BindingAdapter({"roundImageUrl"}) public static void loadRoundImg(ImageView v, String url) { v.setColorFilter(v.getContext().getResources().getColor(SpUtil.isNight() ? R.color.CoverColor : R.color.colorWhite), PorterDuff.Mode.MULTIPLY); Glide.with(v.getContext()) .load(getFuckUrl(url)) .diskCacheStrategy(DiskCacheStrategy.ALL) .transform(new GlideCircleTransform(v.getContext())) .error(R.mipmap.ic_launcher) .into(v); }
@BindingAdapter({"bga_refresh_delegate"}) public static void setDelegate(BGARefreshLayout refreshLayout, BGARefreshLayout.BGARefreshLayoutDelegate delegate) { refreshLayout.setDelegate(delegate); }
@BindingAdapter({"entries", "layout"}) public static <T> void setEntries(ViewGroup viewGroup, List<T> oldEntries, int oldLayoutId,
@BindingAdapter("android:src") public static void loadImage(TestComponent component, ImageView view, String url) { /// ... } }
@BindingAdapter({"firstItemTop"}) public static void setFirstItemTop(RecyclerView recyclerView, int firstItemTop) { // if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) { // LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager(); // if (recyclerView.getChildAt(0) != null) { // if (recyclerView.getChildAt(0).getTop() != firstItemTop) { // manager.scrollToPositionWithOffset(0, firstItemTop); // } // } // } } }
@BindingAdapter("invisible") public static void setInvisible(View view, boolean invisible) { view.setVisibility(invisible ? View.INVISIBLE : View.VISIBLE); } }