Java Code Examples for android.databinding.BindingAdapter

The following are top voted examples for showing how to use android.databinding.BindingAdapter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Flubber   File: BindingAdapters.java   Source Code and License 6 votes vote down vote up
@BindingAdapter({"checked", "model"})
public static <T> void setChecked(RadioButton radioButton, final ObservableField<T> checked, final T model) {

    if (checked == null) {
        return;
    }

    radioButton.setOnCheckedChangeListener(
            (buttonView, isChecked) -> {
                if ((checked.get() == null || !checked.get().equals(model))
                        && isChecked) {

                    checked.set(model);
                }
            });

    final T checkedModel = checked.get();
    final boolean shouldBeChecked = checkedModel != null && checkedModel.equals(model);

    if (shouldBeChecked != radioButton.isChecked()) {
        radioButton.setChecked(shouldBeChecked);
    }
}
 
Example 2
Project: Flubber   File: BindingAdapters.java   Source Code and License 6 votes vote down vote up
@BindingAdapter("model")
public static void bindToModel(DiscreteSeekBar seekBar, final SeekBarModel model) {
    DiscreteSeekBar.NumericTransformer transformer = seekBar.getNumericTransformer();

    if (!(transformer instanceof NumericTransformer)) {
        transformer = new NumericTransformer();
        seekBar.setNumericTransformer(transformer);
    }

    final NumericTransformer customTransformer = (NumericTransformer) transformer;
    customTransformer.setValues(model.getMinValue(), model.getMaxValue());

    seekBar.setMin(0);
    seekBar.setMax(100);

    final int percentage = (int) customTransformer.transformToPercentage(model.getValue().get());
    // Bug in the library
    seekBar.setProgress(1);
    seekBar.setProgress(percentage);

    seekBar.setOnProgressChangeListener(
            SimpleOnProgressChangeListener.forStopTrackingTouch(seekBar1 -> {
                model.getValue().set(customTransformer.transformFromPercentage(seekBar.getProgress()));
            }));
}
 
Example 3
Project: LiteReader   File: BaseBindingAdapter.java   Source Code and License 6 votes vote down vote up
@BindingAdapter("elevation")
public static void elevationBoolean(View view, boolean elevation) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && elevation) {
        view.setElevation(view.getContext().getResources().getInteger(R.integer.common_elevation));
    } else {
        jLogger.w("Sorry, the system version of the device is under API 21, elevation will take no effect.");
    }
}
 
Example 4
Project: LiteReader   File: BaseBindingAdapter.java   Source Code and License 6 votes vote down vote up
@BindingAdapter("android:visibility")
public static void setVisibility(View view, int visibility) {
    switch (visibility) {
        case 0:
            view.setVisibility(View.VISIBLE);
            break;
        case 4:
            view.setVisibility(View.INVISIBLE);
            break;
        case 8:
            view.setVisibility(View.GONE);
            break;
        default:
            view.setVisibility(View.GONE);
            break;
    }
}
 
Example 5
Project: exchange-rates-mvvm   File: LineChartExtensions.java   Source Code and License 6 votes vote down vote up
@BindingAdapter({"bind:items"})
public static void populateDiagram(LineChart view, List<SingleValue> items) {

    if (null == items || items.size() == 0) {
        return;
    }
    List<Entry> entries = new ArrayList<>();
    for (int i = 0; i < items.size(); i++) {
        final SingleValue item = items.get(i);
        final Entry entry = new Entry(i, (float) item.getValue(), item);
        entries.add(entry);
    }
    LineDataSet dataSet = new LineDataSet(entries, view.getContext().getString(R.string.currency_value));
    LineData lineData = new LineData(dataSet);

    formatXAxisLabels(view, items);
    view.setData(lineData);
    view.invalidate();
}
 
Example 6
Project: MVVM-JueJin   File: ViewGroupAdapter.java   Source Code and License 6 votes vote down vote up
/**
 * (伪)双向 databinding: 同 {@link RecyclerViewAdapter#setDataTwoWay(RecyclerView, ListVM, List)}
 *
 * @param container
 * @param vm
 * @param datas
 * @param <T>
 */
@BindingAdapter({"vm", "data"})
public static <T> void setDataTwoWay(final ViewGroup container, final ListVM<T> vm, List<T> datas){
    if(vm == null){
        return ;
    }
    bind(container, vm, datas);

    if(vm instanceof TwoWayListVM){
        boolean isInited = container.getTag(R.id.db_inited) != null;
        if(!isInited) {
            container.setTag(R.id.db_inited, true);
            loadData(container, (TwoWayListVM<T>)vm, null, null);
        }
    }
}
 
Example 7
Project: OpenYOLO-Android   File: DataBindingAdapters.java   Source Code and License 6 votes vote down vote up
/**
 * Facilitates binding editor action listeners on EditText fields.
 */
@BindingAdapter("onEditorAction")
public static void setOnEditorActionListener(
        EditText layout,
        TextView.OnEditorActionListener listener) {
    layout.setOnEditorActionListener(listener);
}
 
Example 8
Project: Discover   File: DatabindingUtil.java   Source Code and License 6 votes vote down vote up
@BindingAdapter("imageUrl")
public static void setImage(ImageView view, String url) {
    Glide.with(view.getContext()).load(url)
            .crossFade(800)
            .placeholder(R.drawable.cross_image)
            .error(R.drawable.cross_image)
            .into(view);
}
 
Example 9
Project: Discover   File: DatabindingUtil.java   Source Code and License 6 votes vote down vote up
@BindingAdapter("circleImageUrl")
public static void setCircleImage(CircleImageView view, String url) {
    Glide.with(view.getContext()).load(url)
            .crossFade(800)
            .dontAnimate()
            .placeholder(R.drawable.cross_image)
            .error(R.drawable.close_press)
            .into(view);
    /*Glide.with(view.getContext()).load(url)
            .asBitmap()
            .placeholder(R.drawable.cross_image)
            .error(R.drawable.close_press)
            .into(new BitmapImageViewTarget(view) {
                @Override
                protected void setResource(Bitmap resource) {
                    super.setResource(resource);
                    RoundedBitmapDrawable circleImage = RoundedBitmapDrawableFactory.create(view.getResources(), resource);
                    circleImage.setCircular(true);
                    view.setImageDrawable(circleImage);
                }
            });*/
}
 
Example 10
Project: RetrofitSample   File: DataBindingAdapter.java   Source Code and License 6 votes vote down vote up
@BindingAdapter(value = {"imageUrl", "defaultImg", "radius"}, requireAll = false)
public static void setImage(ImageView imageView, String imageUrl, Drawable defaultImg, int radius) {
    DrawableRequestBuilder drawableTypeRequest = Glide.with(imageView.getContext()).load(imageUrl).crossFade();
    if (defaultImg != null) {
        drawableTypeRequest.placeholder(defaultImg).error(defaultImg);
    } else {
        drawableTypeRequest.placeholder(R.drawable.bg_defautl_imageview).error(R.drawable.bg_defautl_imageview);
    }
    if (radius > 0) {
        drawableTypeRequest.bitmapTransform(new CenterCrop(imageView.getContext()),
                new RoundedCornersTransformation(imageView.getContext(), PixelUtil.dp2px(radius), 0));
    } else {
        drawableTypeRequest.bitmapTransform(new CenterCrop(imageView.getContext()));
    }
    drawableTypeRequest.into(imageView);
}
 
Example 11
Project: ClouldReader   File: ImgLoadUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 电影详情页显示电影图片(等待被替换)(测试的还在,已可以弃用)
 * 没有加载中的图
 */
@BindingAdapter("android:showImg")
public static void showImg(ImageView imageView, String url) {
    Glide.with(imageView.getContext())
            .load(url)
            .crossFade(500)
            .error(getDefaultPic(0))
            .into(imageView);
}
 
Example 12
Project: ClouldReader   File: ImgLoadUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 书籍列表图片
 */
@BindingAdapter("android:showBookImg")
public static void showBookImg(ImageView imageView, String url) {
    Glide.with(imageView.getContext())
            .load(url)
            .crossFade(500)
            .override((int) CommonUtils.getDimens(R.dimen.book_detail_width), (int) CommonUtils.getDimens(R.dimen.book_detail_height))
            .placeholder(getDefaultPic(2))
            .error(getDefaultPic(2))
            .into(imageView);
}
 
Example 13
Project: AndroidModules-Samples   File: BindingAdapters.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("src")
public static void setImageSrc(ImageView view, File file) {
    if (file != null) {
        Glide.with(view).load(file).into(view);
    } else {
        Glide.with(view).clear(view);
    }
}
 
Example 14
Project: data-binding-validator   File: LengthBindings.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"validateMinLength", "validateMinLengthMessage", "validateMinLengthAutoDismiss"}, requireAll = false)
public static void bindingMinLength(TextView view, int minLength, String errorMessage, boolean autoDismiss) {
    if (autoDismiss) {
        EditTextHandler.disableErrorOnChanged(view);
    }

    String handledErrorMessage = ErrorMessageHelper.getStringOrDefault(view,
            errorMessage, R.string.error_message_min_length, minLength);
    ViewTagHelper.appendValue(R.id.validator_rule, view, new MinLengthRule(view, minLength, handledErrorMessage));
}
 
Example 15
Project: GitHub   File: CommentViewModel.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("containerMargin")
public static void setContainerMargin(View view, boolean isTopLevelComment) {
    if (view.getTag() == null) {
        view.setTag(true);
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams)
                view.getLayoutParams();
        float horizontalMargin = view.getContext().getResources().getDimension(R.dimen.activity_horizontal_margin);
        float topMargin = isTopLevelComment
                ? view.getContext().getResources().getDimension(R.dimen.activity_vertical_margin) : 0;
        layoutParams.setMargins((int) horizontalMargin, (int) topMargin, (int) horizontalMargin, 0);
        view.setLayoutParams(layoutParams);
    }
}
 
Example 16
Project: GitHub   File: ImgLoadUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 电影详情页显示电影图片(等待被替换)(测试的还在,已可以弃用)
 * 没有加载中的图
 */
@BindingAdapter("android:showImg")
public static void showImg(ImageView imageView, String url) {
    Glide.with(imageView.getContext())
            .load(url)
            .crossFade(500)
            .error(getDefaultPic(0))
            .into(imageView);
}
 
Example 17
Project: liveomvp   File: BaseModel.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("imageLoadRounded")
public static void setImageLoadRounded(final ImageView imageView, String urlImage){
    if (!TextUtils.isEmpty(urlImage)) {
        Glide.with(imageView.getContext()).load(urlImage).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circularBitmapDrawable =
                        RoundedBitmapDrawableFactory.create(imageView.getContext().getResources(), resource);
                circularBitmapDrawable.setCircular(true);
                imageView.setImageDrawable(circularBitmapDrawable);
            }
        });
    }
}
 
Example 18
Project: GitHub   File: BindingUtils.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 19
Project: ForgetAdapters   File: BindingAdapters.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"items", "viewProvider"}, requireAll = true)
public static <TModel, TView extends View & IDataViewModelProvider<TModel>> void setItems(RecyclerView recyclerView, ObservableArrayList<TModel> items, RecyclerViewProvider<TModel, TView> viewProvider) {

    if (recyclerView.getAdapter() != null &&
            recyclerView.getAdapter() instanceof RecyclerViewListAdapter &&
            ((RecyclerViewListAdapter)recyclerView.getAdapter()).getList() == items)
        return;

    RecyclerViewListAdapter<TModel, TView> adapter = new RecyclerViewListAdapter<>(items, viewProvider);
    recyclerView.setAdapter(adapter);
}
 
Example 20
Project: GitHub   File: BindingUtils.java   Source Code and License 5 votes vote down vote up
@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("&gt;") > 0) {
        article = article.substring(article.indexOf("&gt;") + 4, article.length());
    }
    tv.setText(article);
}
 
Example 21
Project: GitHub   File: BindingUtils.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 22
Project: BaseCore   File: ImageViewBindingAdapter.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"imageUrl", "placeHolder", "error"}, requireAll = false)
/**
 * 不支持mipmap下的图片
 */
public static void loadImage(ImageView imageView, String url, Drawable holderDrawable, Drawable errorDrawable) {

    Glide.with(imageView.getContext())
            .load(url)
            .apply(GlideRequestOption.getRequestOptions().placeholder(holderDrawable)
                    .error(errorDrawable))
            .into(imageView);
}
 
Example 23
Project: ui-atoms-android   File: AtomListView.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("selectedItems")
public static <T> void setSelectedItems(
        AtomListView view,
        @Nullable ObservableList<T> list){
    if(view.getSelectedItems() == list)
        return;
    view.setSelectedItems(list);
}
 
Example 24
Project: GitHub   File: BindingUtils.java   Source Code and License 5 votes vote down vote up
@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("&gt;") > 0) {
        article = article.substring(article.indexOf("&gt;") + 4, article.length());
    }
    tv.setText(article);
}
 
Example 25
Project: Mvvm   File: BindingAdapters.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@BindingAdapter(value = {"bindingItem", "items", "adapter", "itemIds", "viewHolder"}, requireAll = false)
public static <T> void setAdapter(RecyclerView recyclerView,
                                  BindingItem<T> bindingItem,
                                  List<T> items,
                                  MvvmAdapter<T> adapter,
                                  MvvmAdapter.ItemIds<? super T> itemIds,
                                  MvvmAdapter.ViewHolderFactory viewHolderFactory) {
    if (bindingItem == null) {
        throw new IllegalArgumentException("bindingItem must not be null");
    }
    MvvmAdapter oldAdapter = (MvvmAdapter) recyclerView.getAdapter();
    if (adapter == null) {
        if (oldAdapter == null) {
            adapter = new MvvmAdapter<>();
        } else {
            adapter = oldAdapter;
        }
    }
    adapter.setBindingItem(bindingItem);
    adapter.setItems(items);
    adapter.setItemIds(itemIds);
    adapter.setViewHolderFactory(viewHolderFactory);
    if (oldAdapter != adapter) {
        recyclerView.setAdapter(adapter);
    }
}
 
Example 26
Project: PhotoExample   File: ListBindingAdapter.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = "resource")
public static void setResource(RecyclerView recyclerView, Resource resource){
    RecyclerView.Adapter adapter = recyclerView.getAdapter();
    if(adapter == null)
        return;

    if(resource == null || resource.data == null)
        return;

    if(adapter instanceof BaseAdapter){
        ((BaseAdapter)adapter).setData((List) resource.data);
    }
}
 
Example 27
Project: data-binding-validator   File: RegexBindings.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"validateRegex", "validateRegexMessage", "validateRegexAutoDismiss"}, requireAll = false)
public static void bindingRegex(TextView view, String pattern, String errorMessage, boolean autoDismiss) {
    if (autoDismiss) {
        EditTextHandler.disableErrorOnChanged(view);
    }

    String handledErrorMessage = ErrorMessageHelper.getStringOrDefault(view,
            errorMessage, R.string.error_message_regex_validation);
    ViewTagHelper.appendValue(R.id.validator_rule, view, new RegexRule(view, pattern, handledErrorMessage));
}
 
Example 28
Project: data-binding-validator   File: PasswordBindings.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"validatePassword", "validatePasswordMessage", "validatePasswordAutoDismiss"}, requireAll = false)
public static void bindingPassword(TextView view, TextView comparableView, String errorMessage, boolean autoDismiss) {
    if (autoDismiss) {
        EditTextHandler.disableErrorOnChanged(view);
    }

    String handledErrorMessage = ErrorMessageHelper.getStringOrDefault(view,
            errorMessage, R.string.error_message_not_equal_password);
    ViewTagHelper.appendValue(R.id.validator_rule, view,
            new ConfirmPasswordRule(view, comparableView, handledErrorMessage));
}
 
Example 29
Project: DataBindingDemos   File: DatabindingUtils.java   Source Code and License 5 votes vote down vote up
@BindingAdapter({"app:imageUrl", "app:placeholder"})
public static void loadImage(final ImageView view, final String url, final Drawable placeholder) {

    Picasso.with(view.getContext())
            .load(url)
            .placeholder(placeholder)
            .into(view);

}
 
Example 30
Project: bikedeboa-android   File: BindingAdapters.java   Source Code and License 5 votes vote down vote up
@BindingAdapter({"imageAddress"})
public static void loadImage(final ImageView imageView, final String imageAddress) {

	if (imageAddress != null && imageAddress.startsWith("https://s3.amazonaws.com/bikedeboa/")) {

		Context context = imageView.getContext();
		// Hopefully the thumbnail is already disk cached and no requests are made
		DrawableRequestBuilder<String> thumbnailRequest = Glide
				.with(context)
				.load(imageAddress.replace("images/", "images/thumbs/"))
				.diskCacheStrategy(DiskCacheStrategy.ALL)
				.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
				.transform(new BlurTransformation(context));

		Glide.with(context)
				.load(imageAddress)
				.thumbnail(thumbnailRequest)
				.crossFade()
				.diskCacheStrategy(DiskCacheStrategy.SOURCE)
				.priority(Priority.HIGH)
				.into(imageView);
	}
}
 
Example 31
Project: Mvvm   File: BindingAdapters.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("android:src")
public static void setSrc(ImageView view, Bitmap bitmap) {
    view.setImageBitmap(bitmap);
}
 
Example 32
Project: OpenYOLO-Android   File: DataBindingAdapters.java   Source Code and License 5 votes vote down vote up
/**
 * Facilitates loading images into an ImageView using Glide, by binding a string URI.
 */
@BindingAdapter("android:src")
public static void setImageUri(ImageView view, String imageUri) {
    GlideApp.with(view)
            .load(imageUri)
            .fitCenter()
            .into(view);
}
 
Example 33
Project: MVVM-JueJin   File: FragmentAdapter.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"fragments", "curIndex"}, requireAll = false)
public static void bind(ViewPager container, final List<? extends Fragment> fragments, int curIndex) {
    if(!(container.getContext() instanceof FragmentActivity))
        throw new IllegalArgumentException(TAG + "context must instanceof FragmentActivity");
    FragmentManager fm = ((FragmentActivity) container.getContext()).getSupportFragmentManager();

    if (fragments != null && !fragments.isEmpty()) {
        PagerAdapter adapter = container.getAdapter();
        if(adapter == null) {
            // initialize, fragments are only added once !!!
            container.setAdapter(adapter = new FragmentPagerAdapter(fm) {
                @Override
                public Fragment getItem(int position) {
                    return fragments.get(position);
                }

                @Override
                public int getCount() {
                    return fragments.size();
                }
            });
        }

        adapter.notifyDataSetChanged();

        if(curIndex >= 0 && curIndex < fragments.size())
            container.setCurrentItem(curIndex);
    }
}
 
Example 34
Project: MVVM-JueJin   File: RecyclerViewAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * (伪)双向 databinding: 自动调用 {@link TwoWayListVM#getLoadTask()},
 *      并自动触发 {@link TwoWayListVM#setData(ObservableArrayList)}
 *      然后自动更新 RecyclerView
 *
 * @param container
 * @param vm
 * @param datas
 * @param <T>
 */
@BindingAdapter({"vm", "data"})
public static <T> void setDataTwoWay(final RecyclerView container, final ListVM<T> vm, List<T> datas){
    if(vm == null){
        return ;
    }
    setData(container, vm, datas);

    if(vm instanceof TwoWayListVM) {
        boolean isInited = container.getTag(R.id.db_inited) != null;
        if (!isInited) {
            container.setTag(R.id.db_inited, true);

            final TwoWayListVM<T> _vm = ((TwoWayListVM<T>) vm);

            loadData(container, _vm, null, null);
            // 若 parent 可下拉刷新,设置回调
            ViewParent parent = container.getParent();
            if (parent != null && parent instanceof TwoWayListVM.Refreshable) {
                final TwoWayListVM.Refreshable refreshable = (TwoWayListVM.Refreshable) parent;
                ((TwoWayListVM.Refreshable) parent).setOnRefresh(new TwoWayListVM.Refreshable.CallBack() {
                    @Override
                    public void onRefresh() {
                        loadData(container, _vm, null, refreshable);
                    }

                    @Override
                    public void onLoadMore() {
                        List<T> data = _vm.getData();
                        if (data.size() - 1 >= 0) {
                            loadData(container, _vm, data.get(data.size() - 1), refreshable);
                        }
                    }
                });
            }
        }
    }
}
 
Example 35
Project: data-binding-validator   File: TypeBindings.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"validateType", "validateTypeMessage", "validateTypeAutoDismiss"}, requireAll = false)
public static void bindingTypeValidation(TextView view, String fieldTypeText, String errorMessage, boolean autoDismiss) {
    if (autoDismiss) {
        EditTextHandler.disableErrorOnChanged(view);
    }
    TypeRule.FieldType fieldType = getFieldTypeByText(fieldTypeText);
    try {
        String handledErrorMessage = ErrorMessageHelper.getStringOrDefault(view,
                errorMessage, fieldType.errorMessageId);
        ViewTagHelper.appendValue(R.id.validator_rule, view, fieldType.instantiate(view, handledErrorMessage));
    } catch (Exception ignored) {}
}
 
Example 36
Project: PhotoExample   File: ImageBindingAdapter.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = "url")
public static void loadImageUrl(ImageView view, String url) {
    if (url != null && !url.equals(""))
        Picasso.with(view.getContext())
                .load(url)
                .into(view);
}
 
Example 37
Project: okuki   File: RecyclerViewBindings.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"itemBinding", "items", "adapter", "itemIds", "viewHolder", "onItemBound"}, requireAll = false)
public static <T> void setAdapter(RecyclerView recyclerView, OnItemBind<T> onItemBind, List<T> items,
                                  BindingRecyclerViewAdapter<T> adapter, BindingRecyclerViewAdapter.ItemIds<? super T> itemIds,
                                  BindingRecyclerViewAdapter.ViewHolderFactory viewHolderFactory, OnItemBoundHandler<T> onItemBoundHandler) {
    ItemBinding<T> itemBinding = ((onItemBind != null) && (onItemBoundHandler != null))
            ? ItemBinding.of(new OnItemBindWrapper<>(onItemBind, onItemBoundHandler))
            : ItemBinding.of(onItemBind);
    BindingRecyclerViewAdapters.setAdapter(recyclerView, itemBinding, items, adapter, itemIds, viewHolderFactory);

}
 
Example 38
Project: Fairy   File: EditBindingAdapter.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("judgehint")
public static void setHint(EditText view, CharSequence hint) {
    switch (view.getId()) {
        case R.id.edit_options_logcat:
            String options = "[options]";
            if (!hint.equals("")) {
                options = hint.toString();
            }
            view.setHint(options);
            break;
        case R.id.edit_filter_logcat:
            String filter = "[filterspecs]";
            if (!hint.equals("")) {
                filter = hint.toString();
            }
            view.setHint(filter);
            break;
        case R.id.edit_grep_logcat:
            String grep = "[grep]";
            if (!hint.equals("")) {
                grep = hint.toString();
            }
            view.setHint(grep);
            break;
        default:
            ZLog.e("no match");
            break;
    }
}
 
Example 39
Project: data-binding-validator   File: DateBindings.java   Source Code and License 5 votes vote down vote up
@BindingAdapter(value = {"validateDate", "validateDateMessage", "validateDateAutoDismiss"}, requireAll = false)
public static void bindingDate(TextView view, String pattern, String errorMessage, boolean autoDismiss) {
    if (autoDismiss) {
        EditTextHandler.disableErrorOnChanged(view);
    }

    String handledErrorMessage = ErrorMessageHelper.getStringOrDefault(view,
            errorMessage, R.string.error_message_date_validation);
    ViewTagHelper.appendValue(R.id.validator_rule, view, new DateRule(view, pattern, handledErrorMessage));
}
 
Example 40
Project: ActivityBuilder   File: BookListActivity.java   Source Code and License 5 votes vote down vote up
@BindingAdapter("content")
public static <T> void setContent(RecyclerView recyclerView, List<T> content) {
  RecyclerView.Adapter adapter = recyclerView.getAdapter();
  if (adapter == null) {
    return;
  }
  if (adapter instanceof BookListAdapter) {
    ((BookListAdapter) adapter).replace((List<Book>) content);
  }
}
 
Example 41
Project: android-mvvm-architecture   File: BindingUtils.java   Source Code and License 5 votes vote down vote up
@BindingAdapter({"adapter"})
public static void addBlogItems(RecyclerView recyclerView,
                              ArrayList<BlogResponse.Blog> blogs) {
    BlogAdapter adapter = (BlogAdapter) recyclerView.getAdapter();
    if(adapter != null) {
        adapter.clearItems();
        adapter.addItems(blogs);
    }
}
 
Example 42
Project: spline   File: FileBindingAdapters.java   Source Code and License 5 votes vote down vote up
/**
 * Simple binding adapter to convert long timestamp to a human-readable date.
 * @param view
 * @param date
 */
@BindingAdapter("android:text")
public static void setText(TextView view, long date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    String formatted = format.format(date);
    view.setText(formatted);
}
 
Example 43
Project: FireBaseTest   File: ViewBindingAdapters.java   Source Code and License 5 votes vote down vote up
@BindingAdapter({"glideSrc"})
public static void setImageViewResource(ImageView imageView, String publicImageUrl) {

    if (publicImageUrl == null) {
        return;
    }

    GlideApp.with(imageView.getContext())
            .load(publicImageUrl)
            .transition(withCrossFade())
            .into(imageView);
}
 
Example 44
Project: android-architecture-components   File: FragmentBindingAdapters.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("imageUrl")
public void bindImage(ImageView imageView, String url) {
    Glide.with(fragment).load(url).into(imageView);
}
 
Example 45
Project: ForgetAdapters   File: BindingAdapters.java   Source Code and License 4 votes vote down vote up
@BindingAdapter(value = {"items", "viewProvider"}, requireAll = true)
public static <TModel extends IIdProvider, TView extends View & IDataViewModelProvider<TModel>> void setItems(ListView listView, IObservableCollection<TModel> items, ListViewProvider<TModel, TView> viewProvider) {

    ListViewCollectionAdapter<TModel, TView> adapter = new ListViewCollectionAdapter<TModel, TView>(items, viewProvider, false);
    listView.setAdapter(adapter);
}
 
Example 46
Project: ui-atoms-android   File: AtomListView.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("viewModel")
public static void adapterSetViewModel(AtomListView view,Object viewModel){
    if(view.getViewModel() == viewModel)
        return;
    view.setViewModel(viewModel);
}
 
Example 47
Project: OCast-Java   File: ViewModel.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("selectedItemPosition")
public void setSelectedItemPosition(AppCompatSpinner spinner,int position)
{
    if(spinner.getSelectedItemPosition()!=position)
        spinner.setSelection(position);
}
 
Example 48
Project: GitHub   File: ImgLoadUtil.java   Source Code and License 4 votes vote down vote up
/**
 * 电影详情页显示高斯背景图
 */
@BindingAdapter("android:showImgBg")
public static void showImgBg(ImageView imageView, String url) {
    displayGaussian(imageView.getContext(), url, imageView);
}
 
Example 49
Project: MVVMArms   File: BindingAdapters.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("sLeftBottomTextString")
public static void setLeftBottomTextString(SuperTextView view, String leftBottom) {
    view.setLeftBottomString(leftBottom);
}
 
Example 50
Project: GitHub   File: BindingUtils.java   Source Code and License 4 votes vote down vote up
@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));
}
 
Example 51
Project: ui-atoms-android   File: AtomListView.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("allowMultipleSelection")
public static void adapterSetViewModel(AtomListView view,boolean allowMultipleSelection){
    view.setAllowMultipleSelection(allowMultipleSelection);
}
 
Example 52
Project: GitHub   File: BGARefreshLayoutAdapter.java   Source Code and License 4 votes vote down vote up
@BindingAdapter({"bga_refresh_delegate"})
public static void setDelegate(BGARefreshLayout refreshLayout, BGARefreshLayout.BGARefreshLayoutDelegate delegate) {
    refreshLayout.setDelegate(delegate);
}
 
Example 53
Project: ui-atoms-android   File: AtomView.java   Source Code and License 4 votes vote down vote up
@BindingAdapter( value = {"layout","model","viewModel"}, requireAll =  false)
public static void setLayout(AtomView view, Object layout, Object model, Object viewModel) {
    view.setLayout(layout, model, viewModel);
}
 
Example 54
Project: firestore-android-arch-components   File: BindingAdapters.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("hideView")
public static void hideView(View view, boolean hide) {
    showView(view, ! hide);
}
 
Example 55
Project: firestore-android-arch-components   File: BindingAdapters.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("showView")
public static void showView(View view, boolean show) {
    view.setVisibility(show ? View.VISIBLE : View.GONE);
}
 
Example 56
Project: meuboleto   File: HomeActivity.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("bind:pagamentos")
public static void bindListPagamentos(final RecyclerView view, ObservableArrayList<CodigoDeBarra> list) {
    LinearLayoutManager layoutManager = new LinearLayoutManager(view.getContext());
    view.setLayoutManager(layoutManager);
    view.setAdapter(new CodigoDeBarraAdapter(list));
}
 
Example 57
Project: meuboleto   File: DigitarCodigoBarrasActivity.java   Source Code and License 4 votes vote down vote up
@BindingAdapter({"bind:mask"})
public static void setMask(EditText editText, String mask){
    if (mask.equals("decimal")) editText.addTextChangedListener(new NumberTextWatcher(editText));
    else editText.addTextChangedListener(Mask.insert(mask, editText));
}
 
Example 58
Project: SampleAppArch   File: ImageBindingUtil.java   Source Code and License 4 votes vote down vote up
@BindingAdapter({"imageUrl"})
public static void loadImage(ImageView view, String url) {
  Picasso.with(view.getContext()).load(url).into(view);
}
 
Example 59
Project: SampleAppArch   File: ImageBindingUtil.java   Source Code and License 4 votes vote down vote up
@BindingAdapter({"imageUrl"})
public static void loadCircleImage(CircleImageView view, String url) {
  Picasso.with(view.getContext()).load(url).into(view);
}
 
Example 60
Project: LiteReader   File: RichTextView.java   Source Code and License 4 votes vote down vote up
@BindingAdapter("richText")
public static void richText(RichTextView tv, String html) {
    tv.setRichText(html);
}