本文整理汇总了Java中android.databinding.ObservableField类的典型用法代码示例。如果您正苦于以下问题:Java ObservableField类的具体用法?Java ObservableField怎么用?Java ObservableField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObservableField类属于android.databinding包,在下文中一共展示了ObservableField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onViewAttached
import android.databinding.ObservableField; //导入依赖的package包/类
@Override
public void onViewAttached(View view) {
this.content = new ObservableField<>(getString(R.string.loading));
RxTask.asyncMap(new Func1<String, String>() {
@Override
public String call(String s) {
return extractContent(review.shareUrl);
}
}, new Action1<String>() {
@Override
public void call(String html) {
content.set(html);
}
});
}
示例2: setChecked
import android.databinding.ObservableField; //导入依赖的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);
}
}
示例3: EncryptViewModel
import android.databinding.ObservableField; //导入依赖的package包/类
public EncryptViewModel(final Context context, FragmentManager fragmentManager) {
pagerAdapter = new EncryptPagerAdapter(context, fragmentManager);
pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
drawableDot1.set(context.getResources().getDrawable(position == 0 ? R.drawable.selecteditem_dot : R.drawable.nonselecteditem_dot));
drawableDot2.set(context.getResources().getDrawable(position == 1 ? R.drawable.selecteditem_dot : R.drawable.nonselecteditem_dot));
drawableDot3.set(context.getResources().getDrawable(position == 2 ? R.drawable.selecteditem_dot : R.drawable.nonselecteditem_dot));
}
};
drawableDot1 = new ObservableField<>(context.getResources().getDrawable(R.drawable.selecteditem_dot));
drawableDot2 = new ObservableField<>(context.getResources().getDrawable(R.drawable.nonselecteditem_dot));
drawableDot3 = new ObservableField<>(context.getResources().getDrawable(R.drawable.nonselecteditem_dot));
}
示例4: propertyChangeEvents_String
import android.databinding.ObservableField; //导入依赖的package包/类
@Test @UiThreadTest public void propertyChangeEvents_String() {
final ObservableField<String> observableField = new ObservableField<>();
String value = "databinding";
RecordingObserver<String> o = new RecordingObserver<>();
RxObservableField.propertyChanges(observableField).subscribe(o);
o.assertNoMoreEvents();
observableField.set(value);
assertEquals(value, o.takeNext());
value += " is cool.";
observableField.set(value);
assertEquals(value, o.takeNext());
o.dispose();
value += " Yeah?";
observableField.set(value);
o.assertNoMoreEvents();
}
示例5: propertyChangeEvents_Object
import android.databinding.ObservableField; //导入依赖的package包/类
@Test @UiThreadTest public void propertyChangeEvents_Object() {
final ObservableField<Object> observableField = new ObservableField<>();
Object value;
RecordingObserver<Object> o = new RecordingObserver<>();
RxObservableField.propertyChanges(observableField).subscribe(o);
o.assertNoMoreEvents();
value = new Object();
observableField.set(value);
assertEquals(value, o.takeNext());
value = new Object();
observableField.set(value);
assertEquals(value, o.takeNext());
o.dispose();
value = new Object();
observableField.set(value);
o.assertNoMoreEvents();
}
示例6: toObservable
import android.databinding.ObservableField; //导入依赖的package包/类
public static <T> Observable<T> toObservable(@NonNull final ObservableField<T> field) {
return Observable.create(e -> {
T initialValue = field.get();
if (initialValue != null) {
e.onNext(initialValue);
}
final OnPropertyChangedCallback callback = new OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(android.databinding.Observable observable, int i) {
e.onNext(field.get());
}
};
field.addOnPropertyChangedCallback(callback);
e.setCancellable(() -> field.removeOnPropertyChangedCallback(callback));
});
}
示例7: EditPostComponentViewModel
import android.databinding.ObservableField; //导入依赖的package包/类
@Inject
public EditPostComponentViewModel(Bus bus,
INavigator navigator,
IRepository repository,
ILocalization localization) {
super(bus);
this.navigator = navigator;
this.repository = repository;
this.localization = localization;
this.saveCommand = new Command(this::savePost);
this.title = new ObservableField<>();
this.summary = new ObservableField<>();
}
示例8: SignInActivityViewModel
import android.databinding.ObservableField; //导入依赖的package包/类
@Inject
public SignInActivityViewModel(BaseActivity activity, SignInUseCase signInUseCase,
CheckSessionUseCase checkSessionUseCase) {
super(activity);
this.signInUseCase = signInUseCase;
this.checkSessionUseCase = checkSessionUseCase;
name = new ObservableField<>();
password = new ObservableField<>();
buttonEnabled = new ObservableBoolean(false);
checkSessionUseCase.run()
.compose(bindToLifecycle().forSingle())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(authToken -> {
Timber.v("Check session: " + authToken.token);
Toast.makeText(getContext(), "Already signed in", Toast.LENGTH_SHORT).show();
goToNext();
}, Timber::e);
}
示例9: toObservable
import android.databinding.ObservableField; //导入依赖的package包/类
public static <T> Observable<T> toObservable(@NonNull final ObservableField<T> observableField) {
return Observable.fromEmitter(asyncEmitter -> {
final OnPropertyChangedCallback callback = new OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(android.databinding.Observable dataBindingObservable, int propertyId) {
if (dataBindingObservable == observableField) {
asyncEmitter.onNext(observableField.get());
}
}
};
observableField.addOnPropertyChangedCallback(callback);
asyncEmitter.setCancellation(() -> observableField.removeOnPropertyChangedCallback(callback));
}, AsyncEmitter.BackpressureMode.LATEST);
}
示例10: computableListElementsAreComputable
import android.databinding.ObservableField; //导入依赖的package包/类
@Test
public void computableListElementsAreComputable() throws Exception {
String string1 = "STRING 1";
String string2 = "STRING 2";
StringClass stringClass = new StringClass(string1);
ObservableList<StringClass> strings = new ObservableArrayList<>();
strings.add(0, stringClass);
ObservableField<String> computedString = Cinder.computeField(()->strings.get(0).element.get(),
Cinder.observable(strings, StringClass.class, "element")).immediate();
assertEquals(computedString.get(), string1);
strings.get(0).element.set(string2);
assertEquals(computedString.get(), string2);
}
示例11: simpleObservesObservableLists
import android.databinding.ObservableField; //导入依赖的package包/类
@Test
public void simpleObservesObservableLists() throws Exception {
String string1 = "STRING 1";
String string2 = "STRING 2";
StringClass stringClass1 = new StringClass(string1);
StringClass stringClass2 = new StringClass(string2);
ObservableArrayList<StringClass> observableList = new ObservableArrayList<>();
ObservableField<String> observingString = new ObservableField<>("");
Cinder.observe(
()->observingString.set(observableList.get(0).element.get()),
observableList);
observableList.add(0, stringClass1);
assertEquals(observingString.get(), string1);
observableList.add(0, stringClass2);
assertEquals(observingString.get(), string2);
observableList.remove(0);
assertEquals(observingString.get(), string1);
}
示例12: simpleObservesObservableMaps
import android.databinding.ObservableField; //导入依赖的package包/类
@Test
public void simpleObservesObservableMaps() throws Exception {
String key1 = "KEY 1";
String string1 = "STRING 1";
String string2 = "STRING 2";
String stringMissing = "MISSING";
StringClass stringClass1 = new StringClass(string1);
StringClass stringClass2 = new StringClass(string2);
ObservableArrayMap<String, StringClass> observableMap = new ObservableArrayMap<>();
ObservableField<String> observingString = new ObservableField<>("");
Cinder.observe(()->
observingString.set((observableMap.get(key1) != null) ?
observableMap.get(key1).element.get() : stringMissing),
observableMap);
observableMap.put(key1, stringClass1);
assertEquals(observingString.get(), string1);
observableMap.put(key1, stringClass2);
assertEquals(observingString.get(), string2);
observableMap.remove(key1);
assertEquals(observingString.get(), stringMissing);
}
示例13: takeTakesCorrectTimes
import android.databinding.ObservableField; //导入依赖的package包/类
@Test
public void takeTakesCorrectTimes() throws Exception {
String string1 = "STRING 1";
String string2 = "STRING 2";
String string3 = "STRING 3";
ObservableArrayList<String> observed = new ObservableArrayList<>();
observed.add(string1);
CinderComputable computing = Cinder.observable(observed).take(2).immediate();
ObservableField<String> observing = Cinder.<String>computeField(()-> {
return observed.get(0);
}, computing).immediate();
assertEquals(string1, observing.get());
observed.add(0, string2);
assertEquals(string2, observing.get());
observed.add(0, string3);
assertEquals(string2, observing.get());
}
示例14: skipSkipsCorrectTimes
import android.databinding.ObservableField; //导入依赖的package包/类
@Test
public void skipSkipsCorrectTimes() throws Exception {
String string1 = "STRING 1";
String string2 = "STRING 2";
ObservableArrayList<String> observed = new ObservableArrayList<>();
observed.add(string1);
CinderComputable computing = Cinder.observable(observed).skip(1);
ObservableField<String> observing = Cinder.<String>computeField(()-> {
return observed.size() > 0 ? observed.get(0) : "";
}, computing);
observed.add(0, string1);
assertEquals(null, observing.get());
observed.add(0, string2);
assertEquals(string2, observing.get());
}
示例15: takeWhileTakesWhileTrue
import android.databinding.ObservableField; //导入依赖的package包/类
@Test
public void takeWhileTakesWhileTrue() throws Exception {
String badString = "BAD STRING";
String goodString = "GOOD STRING";
String gooderString = "GOODER STRING";
ObservableArrayList<String> observed = new ObservableArrayList<>();
observed.add(goodString);
CinderComputable computing = Cinder.observable(observed).takeWhile(()->observed.get(0).startsWith("GOOD"));
ObservableField<String> observing = Cinder.<String>computeField(()-> {
return observed.get(0);
}, computing).immediate();
observed.add(0, goodString);
assertEquals(goodString, observing.get());
observed.add(0, badString);
assertEquals(goodString, observing.get());
observed.add(0, gooderString);
assertEquals(goodString, observing.get());
}