本文整理匯總了Java中android.databinding.Observable.OnPropertyChangedCallback方法的典型用法代碼示例。如果您正苦於以下問題:Java Observable.OnPropertyChangedCallback方法的具體用法?Java Observable.OnPropertyChangedCallback怎麽用?Java Observable.OnPropertyChangedCallback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.databinding.Observable
的用法示例。
在下文中一共展示了Observable.OnPropertyChangedCallback方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}));
}
}
示例2: 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());
});
}
};
}
示例3: setAdapter
import android.databinding.Observable; //導入方法依賴的package包/類
@BindingAdapter(value = {"clickCommand", "commandParameter"}, requireAll = false)
public static void setAdapter(View button, AtomCommand command, Object parameter){
Observable.OnPropertyChangedCallback pc;
AtomCommand oldCommand = (AtomCommand)button.getTag(R.id.atomCommand);
if(oldCommand != command) {
if(button instanceof Button) {
if(oldCommand!=null) {
pc = (Observable.OnPropertyChangedCallback)
button.getTag(R.id.atomCommandEnabled);
if (pc != null) {
oldCommand.enabled.removeOnPropertyChangedCallback(pc);
}
}
pc = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable sender, int propertyId) {
((Button)button).setEnabled(command.enabled.get());
}
};
command.enabled.addOnPropertyChangedCallback(pc);
}
button.setTag(R.id.atomCommand, command);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
command.execute(parameter);
}
});
}
command.parameter.set(parameter);
}
示例4: bindViewModel
import android.databinding.Observable; //導入方法依賴的package包/類
@Override
public void bindViewModel(AddEditTaskViewModel viewModel) {
checkNotNull(viewModel);
this.viewModel = viewModel;
snackbarCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
SnackbarUtils.showSnackbar(getView(), viewModel.getSnackbarText());
}
};
viewModel.snackbarText.addOnPropertyChangedCallback(snackbarCallback);
}
示例5: setupSnackbar
import android.databinding.Observable; //導入方法依賴的package包/類
private void setupSnackbar() {
snackbarCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
SnackbarUtils.showSnackbar(getView(), viewModel.getSnackbarText());
}
};
viewModel.snackbarText.addOnPropertyChangedCallback(snackbarCallback);
}
示例6: bindVisible
import android.databinding.Observable; //導入方法依賴的package包/類
public void bindVisible(final ObservableField<Boolean> visibleChangeField) {
if (visibleChangeField.get() != null) setVisible(visibleChangeField.get());
visibleChangeCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable sender, int propertyId) {
setVisible(visibleChangeField.get());
}
};
visibleChangeField.addOnPropertyChangedCallback(visibleChangeCallback);
this.visibleChangeField = visibleChangeField;
}
示例7: testOnPropertyChangedCallbacksAddedToViewModel
import android.databinding.Observable; //導入方法依賴的package包/類
@Test
public void testOnPropertyChangedCallbacksAddedToViewModel() {
final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
activityController.create();
activity.setViewModel(activity.createViewModel());
activity.addOnPropertyChangedCallback(firstCallback);
activity.addOnPropertyChangedCallback(secondCallback);
verify(activity.getViewModel()).addOnPropertyChangedCallback(firstCallback);
verify(activity.getViewModel()).addOnPropertyChangedCallback(secondCallback);
}
示例8: testRemoveOnPropertyChangedCallbacksOnActivityDestroy
import android.databinding.Observable; //導入方法依賴的package包/類
@Test
public void testRemoveOnPropertyChangedCallbacksOnActivityDestroy() {
final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
activityController.create();
activity.setViewModel(activity.createViewModel());
activity.addOnPropertyChangedCallback(firstCallback);
activity.addOnPropertyChangedCallback(secondCallback);
activity.onDestroy();
verify(activity.getViewModel()).removeOnPropertyChangedCallback(firstCallback);
verify(activity.getViewModel()).removeOnPropertyChangedCallback(secondCallback);
}
示例9: testOnPropertyChangedCallbacksAddedToViewModel
import android.databinding.Observable; //導入方法依賴的package包/類
@Test
public void testOnPropertyChangedCallbacksAddedToViewModel() {
final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
fragment.setViewModel(fragment.createViewModel());
fragment.addOnPropertyChangedCallback(firstCallback);
fragment.addOnPropertyChangedCallback(secondCallback);
verify(fragment.getViewModel()).addOnPropertyChangedCallback(firstCallback);
verify(fragment.getViewModel()).addOnPropertyChangedCallback(secondCallback);
}
示例10: testRemoveOnPropertyChangedCallbacksOnActivityDestroy
import android.databinding.Observable; //導入方法依賴的package包/類
@Test
public void testRemoveOnPropertyChangedCallbacksOnActivityDestroy() {
final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
fragment.setViewModel(fragment.createViewModel());
fragment.addOnPropertyChangedCallback(firstCallback);
fragment.addOnPropertyChangedCallback(secondCallback);
SupportFragmentTestUtil.startFragment(fragment);
fragment.onDestroy();
verify(fragment.getViewModel()).removeOnPropertyChangedCallback(firstCallback);
verify(fragment.getViewModel()).removeOnPropertyChangedCallback(secondCallback);
}
示例11: addCallback
import android.databinding.Observable; //導入方法依賴的package包/類
public static void addCallback(BaseActivity activity, Observable observable, Observable.OnPropertyChangedCallback callback) {
ArrayMap<Observable, Observable.OnPropertyChangedCallback> localMap = mGlobalMap.get(activity);
if (localMap == null) {
localMap = new ArrayMap<>();
mGlobalMap.put(activity, localMap);
}
observable.addOnPropertyChangedCallback(callback);
localMap.put(observable, callback);
}
示例12: removeCallbacks
import android.databinding.Observable; //導入方法依賴的package包/類
public static void removeCallbacks(BaseActivity activity) {
ArrayMap<Observable, Observable.OnPropertyChangedCallback> localMap = mGlobalMap.get(activity);
if (localMap != null) {
for (Observable observable : localMap.keySet()) {
observable.removeOnPropertyChangedCallback(localMap.get(observable));
}
}
}
示例13: setOnClick
import android.databinding.Observable; //導入方法依賴的package包/類
@BindingAdapter("rxCommandOnClick")
public static void setOnClick(final View view, final RxCommand<NoParameter> command) {
// Set initial state.
view.setEnabled(command.canExecute());
// Observe click events.
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (command.canExecute()) {
command.execute(NoParameter.INSTANCE);
}
}
});
// Observe enabled changed events.
final Observable.OnPropertyChangedCallback callback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
view.setEnabled(command.canExecute());
}
};
command.getEnabled().addOnPropertyChangedCallback(callback);
command.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
command.getEnabled().removeOnPropertyChangedCallback(callback);
}
});
}
示例14: shouldNotifyPropertyChangeWhenSetRepository
import android.databinding.Observable; //導入方法依賴的package包/類
@Test
public void shouldNotifyPropertyChangeWhenSetRepository() {
Repository repository = new Repository();
ItemRepoViewModel itemRepoViewModel = new ItemRepoViewModel(application, repository);
Observable.OnPropertyChangedCallback mockCallback =
mock(Observable.OnPropertyChangedCallback.class);
itemRepoViewModel.addOnPropertyChangedCallback(mockCallback);
itemRepoViewModel.setRepository(repository);
verify(mockCallback).onPropertyChanged(any(Observable.class), anyInt());
}
示例15: init
import android.databinding.Observable; //導入方法依賴的package包/類
public void init(Context context) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
mDensity = metrics.density;
ViewConfiguration vc = ViewConfiguration.get(context);
mTouchSlop = vc.getScaledTouchSlop();
mLongPressTimeout = vc.getLongPressTimeout();
mScroller = new OverScroller(context);
mTouchRadius = TOUCH_RADIUS_DP * mDensity;
mEditCtrlStrokeWidth = EDIT_CTRL_STROKE_DP * mDensity;
mEditColor = getResources().getColor(R.color.colorAccent, context.getTheme());
mOnListChangedCallback = new ObservableList
.OnListChangedCallback<ObservableList<Layer>>() {
@Override
public void onChanged(ObservableList<Layer> layers) {
invalidate();
}
@Override
public void onItemRangeChanged(ObservableList<Layer> layers, int i, int i1) {
invalidate();
}
@Override
public void onItemRangeInserted(ObservableList<Layer> layers, int start, int count) {
invalidate();
addPropertyChangedCallbacks(layers, start, start + count);
}
@Override
public void onItemRangeMoved(ObservableList<Layer> layers, int i, int i1, int i2) {
invalidate();
}
@Override
public void onItemRangeRemoved(ObservableList<Layer> layers, int i, int i1) {
invalidate();
}
};
mOnPropertyChangedCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
invalidate();
}
};
}