本文整理匯總了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);
}
}
示例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()));
}));
}
示例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.");
}
}
示例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;
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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);
}
});*/
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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));
}