当前位置: 首页>>代码示例>>Java>>正文


Java BindingAdapter类代码示例

本文整理汇总了Java中android.databinding.BindingAdapter的典型用法代码示例。如果您正苦于以下问题:Java BindingAdapter类的具体用法?Java BindingAdapter怎么用?Java BindingAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BindingAdapter类属于android.databinding包,在下文中一共展示了BindingAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setChecked

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:Appolica,项目名称:Flubber,代码行数:24,代码来源:BindingAdapters.java

示例2: bindToModel

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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()));
            }));
}
 
开发者ID:Appolica,项目名称:Flubber,代码行数:26,代码来源:BindingAdapters.java

示例3: elevationBoolean

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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.");
    }
}
 
开发者ID:Mindjet,项目名称:LiteReader,代码行数:9,代码来源:BaseBindingAdapter.java

示例4: setVisibility

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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;
    }
}
 
开发者ID:Mindjet,项目名称:LiteReader,代码行数:18,代码来源:BaseBindingAdapter.java

示例5: populateDiagram

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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();
}
 
开发者ID:krokers,项目名称:exchange-rates-mvvm,代码行数:20,代码来源:LineChartExtensions.java

示例6: loadImage

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:EduardoVernier,项目名称:bikedeboa-android,代码行数:24,代码来源:BindingAdapters.java

示例7: setDataTwoWay

import android.databinding.BindingAdapter; //导入依赖的package包/类
/**
 * (伪)双向 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);
        }
    }
}
 
开发者ID:fashare2015,项目名称:MVVM-JueJin,代码行数:24,代码来源:ViewGroupAdapter.java

示例8: setOnEditorActionListener

import android.databinding.BindingAdapter; //导入依赖的package包/类
/**
 * Facilitates binding editor action listeners on EditText fields.
 */
@BindingAdapter("onEditorAction")
public static void setOnEditorActionListener(
        EditText layout,
        TextView.OnEditorActionListener listener) {
    layout.setOnEditorActionListener(listener);
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:10,代码来源:DataBindingAdapters.java

示例9: setImage

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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);
}
 
开发者ID:monkeywiiu,项目名称:Discover,代码行数:9,代码来源:DatabindingUtil.java

示例10: setCircleImage

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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);
                }
            });*/
}
 
开发者ID:monkeywiiu,项目名称:Discover,代码行数:23,代码来源:DatabindingUtil.java

示例11: setImage

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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);
}
 
开发者ID:chenzj-king,项目名称:RetrofitSample,代码行数:17,代码来源:DataBindingAdapter.java

示例12: showImg

import android.databinding.BindingAdapter; //导入依赖的package包/类
/**
 * 电影详情页显示电影图片(等待被替换)(测试的还在,已可以弃用)
 * 没有加载中的图
 */
@BindingAdapter("android:showImg")
public static void showImg(ImageView imageView, String url) {
    Glide.with(imageView.getContext())
            .load(url)
            .crossFade(500)
            .error(getDefaultPic(0))
            .into(imageView);
}
 
开发者ID:joelan,项目名称:ClouldReader,代码行数:13,代码来源:ImgLoadUtil.java

示例13: showBookImg

import android.databinding.BindingAdapter; //导入依赖的package包/类
/**
 * 书籍列表图片
 */
@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);
}
 
开发者ID:joelan,项目名称:ClouldReader,代码行数:14,代码来源:ImgLoadUtil.java

示例14: setImageSrc

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:SpryRocks,项目名称:AndroidModules-Samples,代码行数:9,代码来源:BindingAdapters.java

示例15: bindingMinLength

import android.databinding.BindingAdapter; //导入依赖的package包/类
@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));
}
 
开发者ID:Ilhasoft,项目名称:data-binding-validator,代码行数:11,代码来源:LengthBindings.java


注:本文中的android.databinding.BindingAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。