當前位置: 首頁>>代碼示例>>Java>>正文


Java ObservableField類代碼示例

本文整理匯總了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);
        }
    });

}
 
開發者ID:Mindjet,項目名稱:LiteReader,代碼行數:17,代碼來源:OneReviewContentViewModel.java

示例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);
    }
}
 
開發者ID:Appolica,項目名稱:Flubber,代碼行數:24,代碼來源:BindingAdapters.java

示例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));
}
 
開發者ID:tresorit,項目名稱:ZeroKit-Android-SDK,代碼行數:18,代碼來源:EncryptViewModel.java

示例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();
}
 
開發者ID:oldergod,項目名稱:RxDataBinding,代碼行數:22,代碼來源:RxObservableFieldTest.java

示例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();
}
 
開發者ID:oldergod,項目名稱:RxDataBinding,代碼行數:23,代碼來源:RxObservableFieldTest.java

示例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));
        });
    }
 
開發者ID:wongcain,項目名稱:okuki,代碼行數:18,代碼來源:RxObservableField.java

示例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<>();
}
 
開發者ID:0nko,項目名稱:Architecture-Demo,代碼行數:17,代碼來源:EditPostComponentViewModel.java

示例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);
}
 
開發者ID:kobakei,項目名稱:Anago,代碼行數:23,代碼來源:SignInActivityViewModel.java

示例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);
}
 
開發者ID:TangoAgency,項目名稱:android-data-binding-rxjava,代碼行數:19,代碼來源:RxUtils.java

示例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);
}
 
開發者ID:akiraspeirs,項目名稱:Cinder,代碼行數:17,代碼來源:CinderUnitTest.java

示例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);
}
 
開發者ID:akiraspeirs,項目名稱:Cinder,代碼行數:23,代碼來源:CinderUnitTest.java

示例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);
}
 
開發者ID:akiraspeirs,項目名稱:Cinder,代碼行數:25,代碼來源:CinderUnitTest.java

示例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());
}
 
開發者ID:akiraspeirs,項目名稱:Cinder,代碼行數:20,代碼來源:CinderComputableUnitTest.java

示例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());
}
 
開發者ID:akiraspeirs,項目名稱:Cinder,代碼行數:18,代碼來源:CinderComputableUnitTest.java

示例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());
}
 
開發者ID:akiraspeirs,項目名稱:Cinder,代碼行數:22,代碼來源:CinderComputableUnitTest.java


注:本文中的android.databinding.ObservableField類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。