本文整理匯總了Java中android.databinding.Observable類的典型用法代碼示例。如果您正苦於以下問題:Java Observable類的具體用法?Java Observable怎麽用?Java Observable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Observable類屬於android.databinding包,在下文中一共展示了Observable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.databinding.Observable; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_two_way);
FormModel formModel = new FormModel("123", "123");
mBinding.setModel(formModel);
formModel.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int id/* Model 中 BR 屬性的 id 值 */) {
switch (id) {
case BR.name:
Toast.makeText(TwoWayActivity.this, "BR.name: " + id, Toast.LENGTH_SHORT).show();
break;
case BR.password:
Toast.makeText(TwoWayActivity.this, "BR.password: " + id, Toast.LENGTH_SHORT).show();
break;
}
}
});
}
示例2: AtomWatcher
import android.databinding.Observable; //導入依賴的package包/類
public AtomWatcher(BaseObservable... fields){
for(BaseObservable field: fields){
BaseObservable af = field;
Observable.OnPropertyChangedCallback callback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable sender, int propertyId) {
run();
}
};
field.addOnPropertyChangedCallback(callback);
closables.add(new ClosableAction(()->{
af.removeOnPropertyChangedCallback(callback);
}));
}
}
示例3: ItemViewHolder
import android.databinding.Observable; //導入依賴的package包/類
public ItemViewHolder(ViewDataBinding binding) {
super(binding);
itemModel = new ItemModel();
ReflectionHelper.run(binding,"set",itemModel);
itemModel.selected.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable sender, int propertyId) {
if(!updateSelected)
return;
if(selectedItems == null)
return;
if(selectedItems.contains(model)){
if(allowMultipleSelection){
selectedItems.remove(model);
}
}else{
if(!allowMultipleSelection){
selectedItems.clear();
}
selectedItems.add(model);
}
}
});
}
示例4: setAnimationBody
import android.databinding.Observable; //導入依賴的package包/類
public void setAnimationBody(final CustomAnimationBody animationBody) {
this.models = AnimationBodyModelUtil.generateFor(animationBody);
for (SeekBarModel model : models) {
modelsMap.put(model.getValue(), model);
model.getValue().addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
if (modelChangedCallback != null) {
modelChangedCallback.onModelChanged(modelsMap.get(observable));
}
}
});
}
notifyDataSetChanged();
}
示例5: setLayer
import android.databinding.Observable; //導入依賴的package包/類
public void setLayer(Layer layer) {
if (this.layer != null && changedCallback != null) {
this.layer.removeOnPropertyChangedCallback(changedCallback);
}
this.layer = layer;
// Because other parts of the application are updating layer model objects directly, we
// need to listen for changes to the model's properties and notify of those property
// changes on this object (because they share property names we can get away with this).
changedCallback = new OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable sender, int propertyId) {
notifyPropertyChanged(propertyId);
}
};
layer.addOnPropertyChangedCallback(changedCallback);
}
示例6: setParent
import android.databinding.Observable; //導入依賴的package包/類
public void setParent(Observable parent) {
this.parent = parent;
if (this.parent != null) {
this.parent.addOnPropertyChangedCallback(new OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
if (i == BR.visible || i == BR.ancestorsVisible) {
notifyPropertyChanged(BR.ancestorsVisible);
}
}
});
}
notifyPropertyChanged(BR.parent);
notifyPropertyChanged(BR.parentDepth);
}
示例7: MovieViewModel
import android.databinding.Observable; //導入依賴的package包/類
public MovieViewModel(MoviesRepository moviesRepository) {
this.moviesRepository = moviesRepository;
mObservableMovie.addOnPropertyChangedCallback(new OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
Movie movie = mObservableMovie.get();
if (movie != null) {
posterUrl.set(getPosterUrl(movie));
movieTitle.set(getTitle(movie));
backdropUrl.set(getBackdropUrl(movie));
voteAverage.set((float) movie.getVoteAverage());
voteCount.set(movie.getVoteCount());
movieOverview.set(movie.getOverview());
movieTagline.set(movie.getTagline());
movieReleaseDate.set(getReleaseDate(movie));
}
}
});
}
示例8: PostActionVM
import android.databinding.Observable; //導入依賴的package包/類
public PostActionVM() {
sharedPreferences = ChaoliApplication.getAppContext().getSharedPreferences(TAG, MODE_PRIVATE);
editor = sharedPreferences.edit();
title.set(sharedPreferences.getString(DRAFT_TITLE, ""));
content.set(sharedPreferences.getString(DRAFT_CONTENT, ""));
prevContent = content.get();
channelId.set(sharedPreferences.getInt(DRAFT_CHANNEL, Channel.caff.getChannelId()));
curChannel = Channel.getChannel(channelId.get());
content.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
}
});
}
示例9: onCreate
import android.databinding.Observable; //導入依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
currentAudioCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
onCurrentAudioChanged(currentAudio.get());
}
};
currentAlbumArtCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
getActivity().runOnUiThread(() -> {
onCurrentAlbumArtChanged(currentAlbumArt.get());
});
}
};
}
示例10: onPropertyChanged
import android.databinding.Observable; //導入依賴的package包/類
@Override
public void onPropertyChanged(Observable observable, int i) {
Paper.book().write("shuffle", shuffleSetting);
}
};
onRepeatChangedCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
Paper.book().write("repeat", repeatSetting);
}
};
shuffleSetting.addOnPropertyChangedCallback(onShuffleChangedCallback);
repeatSetting.addOnPropertyChangedCallback(onRepeatChangedCallback);
System.out.println("MusicService started");
}
示例11: logOnChange
import android.databinding.Observable; //導入依賴的package包/類
private void logOnChange(OWDevice.DeviceCharacteristic deviceCharacteristic) {
deviceCharacteristic.value.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
Timber.d(deviceCharacteristic.key.get() + " = " + deviceCharacteristic.value.get());
}
});
}
示例12: setupOnPropertyChangedCallback
import android.databinding.Observable; //導入依賴的package包/類
/**
* Core of all validations.
* Called when value changed (from layout or by notifyPropertyChanged)
* 1) notifies bound fields (e.g. when verifying fields)
* 2) checks if value can be empty
* 3) validates all attached blocking validators
* 4) validates attached asynchronous validators
*
* @return property changed callback which should be set as field
*/
private OnPropertyChangedCallback setupOnPropertyChangedCallback() {
return new OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int brId) {
if(brId != com.mlykotom.valifi.BR.value || mIsResetting) return;
// ad 1) notifying bound fields
notifyBoundFieldsValueChanged();
// ad 2) checking if value can be empty
if(mIsEmptyAllowed && (mValue == null || whenThisFieldIsEmpty(mValue))) {
setIsError(false, null);
return;
}
cancelAndSetValidationTask(null);
setInProgress(true);
// ad 3) validating synchronous validators
if(!checkBlockingValidators()) {
setInProgress(false);
cancelAndSetValidationTask(null);
return;
}
// ad 4) validating asynchronous validators
checkAsyncValidatorsIfAny();
}
};
}
示例13: checkDelayedError
import android.databinding.Observable; //導入依賴的package包/類
@Test
public void checkDelayedError() throws InterruptedException {
final long delay_time = 700;
final ValiFieldBase<String> field = new ValiFieldText("invalid_length_12345");
field.setErrorDelay(delay_time);
assertThat(field.mErrorDelay, is(delay_time));
final boolean[] testIsOk = {false};
field.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
if(i != com.mlykotom.valifi.BR.error) return;
testIsOk[0] = true;
}
});
field.addCustomValidator(ValiFiTest.FIELD_ERROR_MSG, new ValiFieldBase.PropertyValidator<String>() {
@Override
public boolean isValid(@Nullable String value) {
return false;
}
});
assertThat(field.isValid(), is(false));
Thread.sleep(delay_time + 100);
assertThat(field.getError(), is(ValiFiTest.FIELD_ERROR_MSG));
assertThat(field.mDueTime, is(-1L));
assertThat(testIsOk[0], is(true));
}
示例14: init
import android.databinding.Observable; //導入依賴的package包/類
private void init() {
for (final ValidatedObservableField field : this.fields) {
field.addOnPropertyChangedCallback(new OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
set(areAllFieldsValid());
}
});
}
set(areAllFieldsValid());
}
示例15: notCallNotifyChangeForSetErrorMessageWithNullValue
import android.databinding.Observable; //導入依賴的package包/類
@Test
public void notCallNotifyChangeForSetErrorMessageWithNullValue() {
field.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
fail("Should not get here");
}
});
field.setErrorMessage(null);
}
開發者ID:mmotak,項目名稱:DroidMVVMValidator,代碼行數:12,代碼來源:ValidatedObservableFieldCreatedByDefaultConstructorShould.java