android.databinding.BindingConversion Java Examples
The following examples show how to use
android.databinding.BindingConversion.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BindingAdapters.java From android-mvvm with Apache License 2.0 | 6 votes |
@BindingConversion public static View.OnClickListener toOnClickListener(final Action listener) { if (listener != null) { return new View.OnClickListener() { @Override public void onClick(View view) { try { listener.run(); } catch (Exception e) { e.printStackTrace(); } } }; } else { return null; } }
Example #2
Source File: BindingAdapters.java From android-mvvm with Apache License 2.0 | 6 votes |
@BindingConversion public static int toLayout(Calculator.Operation operation) { if (operation == null) { return -1; } switch (operation) { case ADD: return R.id.radio_add; case SUBTRACT: return R.id.radio_subtract; case MULTIPLY: return R.id.radio_multiply; case DIVIDE: return R.id.radio_divide; default: return -1; } }
Example #3
Source File: FontBinding.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@BindingConversion public static Typeface convertStringToFace(String fontName) { try { return FontCache.getTypeface(fontName, Utils.getContext()); } catch (Exception e) { throw e; } }
Example #4
Source File: RxJavaBindingUtils.java From android-mvvm with Apache License 2.0 | 5 votes |
@BindingConversion @Nullable public static <U extends ViewModel> io.reactivex.Observable<List<ViewModel>> toV1GenericList(@Nullable Observable<List<U>> specificList) { return specificList == null ? null : RxJavaInterop.toV2Observable(specificList).map(new Function<List<U>, List<ViewModel>>() { @Override public List<ViewModel> apply(List<U> ts) throws Exception { return new ArrayList<ViewModel>(ts); } }); }
Example #5
Source File: BindingUtils.java From android-mvvm with Apache License 2.0 | 5 votes |
@BindingConversion @NonNull public static ViewProvider getViewProviderForStaticLayout(@LayoutRes final int layoutId) { return new ViewProvider() { @Override public int getView(ViewModel vm) { return layoutId; } }; }
Example #6
Source File: BindingUtils.java From android-mvvm with Apache License 2.0 | 5 votes |
@BindingConversion @Nullable public static <T extends ViewModel> Observable<List<ViewModel>> toGenericList(@Nullable Observable<List<T>> specificList) { return specificList == null ? null : specificList.map(new Function<List<T>, List<ViewModel>>() { @Override public List<ViewModel> apply(List<T> ts) throws Exception { return new ArrayList<ViewModel>(ts); } }); }
Example #7
Source File: BindingAdapters.java From android-mvvm with Apache License 2.0 | 5 votes |
@BindingConversion public static View.OnClickListener toOnClickListener(final Action0 listener) { if (listener != null) { return new View.OnClickListener() { @Override public void onClick(View view) { listener.call(); } }; } else { return null; } }
Example #8
Source File: BindingAdapters.java From android-mvvm with Apache License 2.0 | 5 votes |
@BindingConversion public static Calculator.Operation toOperation(int layoutId) { switch (layoutId) { case R.id.radio_add: return Calculator.Operation.ADD; case R.id.radio_subtract: return Calculator.Operation.SUBTRACT; case R.id.radio_multiply: return Calculator.Operation.MULTIPLY; case R.id.radio_divide: return Calculator.Operation.DIVIDE; default: return null; } }
Example #9
Source File: Quantity.java From moserp with Apache License 2.0 | 5 votes |
@BindingConversion public static String convertQuantityToString(Quantity quantity) { Log.d("Quantity", "convert quantity to string " + quantity); if (quantity == null) { return null; } return quantity.toString(); }
Example #10
Source File: Quantity.java From moserp with Apache License 2.0 | 5 votes |
@BindingConversion public static Quantity convertStringToQuantity(String string) { Log.d("Quantity", "convert string to quantity " + string); if (string == null) { return Quantity.ZERO; } return new Quantity(string); }
Example #11
Source File: Utils.java From android-advanced-light with MIT License | 4 votes |
@BindingConversion public static String convertDate(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(date); }
Example #12
Source File: RecyclerViewAdapter.java From MVVM-JueJin with MIT License | 4 votes |
@BindingConversion public static ItemView resToResHolder(@LayoutRes int layoutRes) { int defaultBindingVariable = BR.item; return ItemView.of(defaultBindingVariable, layoutRes); }
Example #13
Source File: BindingUtils.java From android-mvvm with Apache License 2.0 | 4 votes |
@BindingConversion @Nullable public static <T extends ViewModel> Observable<List<ViewModel>> toListObservable(@Nullable List<T> specificList) { return specificList == null ? null : Observable.just((List<ViewModel>)new ArrayList<ViewModel>(specificList)); }
Example #14
Source File: ConverterActivity.java From AndroidMVVMSample with Apache License 2.0 | 4 votes |
@BindingConversion public static ColorDrawable convertColorToDrawable(int color) { Log.d("BindingConversion", "convertColorToDrawable:" + color); return new ColorDrawable(color); }