android.databinding.Observable Java Examples
The following examples show how to use
android.databinding.Observable.
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: MvvmDialogFragmentTest.java From android-mvvm with Apache License 2.0 | 7 votes |
@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); }
Example #2
Source File: MovieViewModel.java From android-mvvm-sample with MIT License | 6 votes |
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)); } } }); }
Example #3
Source File: Layer.java From spline with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: MusicService.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
@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"); }
Example #5
Source File: BaseMusicFragment.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
@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()); }); } }; }
Example #6
Source File: LayerRowViewModel.java From spline with Apache License 2.0 | 6 votes |
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); }
Example #7
Source File: SettingsRVAdapter.java From Flubber with Apache License 2.0 | 6 votes |
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(); }
Example #8
Source File: PostActionVM.java From chaoli-forum-for-android-2 with GNU General Public License v3.0 | 6 votes |
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) { } }); }
Example #9
Source File: MvvmDialogFragmentTest.java From android-mvvm with Apache License 2.0 | 6 votes |
@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); }
Example #10
Source File: DataBindingUtils.java From chaoli-forum-for-android-2 with GNU General Public License v3.0 | 5 votes |
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); }
Example #11
Source File: MvvmActivityTest.java From android-mvvm with Apache License 2.0 | 5 votes |
@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); }
Example #12
Source File: MvvmActivityTest.java From android-mvvm with Apache License 2.0 | 5 votes |
@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); }
Example #13
Source File: MvvmFragmentTest.java From android-mvvm with Apache License 2.0 | 5 votes |
@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); }
Example #14
Source File: MvvmFragmentTest.java From android-mvvm with Apache License 2.0 | 5 votes |
@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); }
Example #15
Source File: HtmlWebViewActivity.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Override public void initViewObservable() { viewModel.uc.backObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable sender, int propertyId) { if (binding.htmlWebView.canGoBack()) { binding.htmlWebView.goBack(); return; } finish(); } }); }
Example #16
Source File: DataBindingUtils.java From chaoli-forum-for-android-2 with GNU General Public License v3.0 | 5 votes |
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)); } } }
Example #17
Source File: TextWatcherAdapter.java From Learning-Resources with MIT License | 5 votes |
public TextWatcherAdapter(ObservableField<String> f) { this.field = f; field.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback(){ @Override public void onPropertyChanged(Observable sender, int propertyId) { if (isInEditMode){ return; } value.set(field.get()); } }); }
Example #18
Source File: SetupWizardFragment.java From island with Apache License 2.0 | 5 votes |
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final SetupViewModel vm; if (savedInstanceState == null) { final Bundle args = getArguments(); vm = args != null ? args.getParcelable(null) : null; } else vm = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL); if (vm == null) { mViewModel = new SetupViewModel(); // Initial view - "Welcome" mViewModel.button_next.set(R.string.setup_accept); // "Accept" button for device-admin privilege consent, required by Google Play developer policy. } else mViewModel = vm; mContainerViewId = container.getId(); final SetupWizardBinding binding = SetupWizardBinding.inflate(inflater, container, false); binding.setSetup(mViewModel); final View view = binding.getRoot(); final SetupWizardLayout layout = view.findViewById(R.id.setup_wizard_layout); layout.requireScrollToBottom(); final NavigationBar nav_bar = layout.getNavigationBar(); nav_bar.setNavigationBarListener(this); setButtonText(nav_bar.getBackButton(), mViewModel.button_back); setButtonText(nav_bar.getNextButton(), mViewModel.button_next.get()); // mViewModel.button_back.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(final Observable observable, final int i) { // setButtonText(button_back, mViewModel.button_back); // }}); mViewModel.button_next.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(final Observable observable, final int i) { setButtonText(nav_bar.getNextButton(), mViewModel.button_next.get()); }}); return view; }
Example #19
Source File: TwoWayActivity.java From DataBindingSample with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mBinding = DataBindingUtil.setContentView(this, R.layout.activity_two_way); FormModel model = new FormModel("markzhai", "123456"); model.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable observable, int i) { Toast.makeText(TwoWayActivity.this, String.valueOf(i), Toast.LENGTH_SHORT).show(); } }); mBinding.setModel(model); }
Example #20
Source File: HomeActivity.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@Override public void onPropertyChanged(@NonNull final Observable sender, final int propertyId) { //noinspection unchecked final ObservableField<NavigationItem> o = (ObservableField<NavigationItem>) sender; final NavigationItem value = o.get(); if (value != null) { navigateTo(value); } }
Example #21
Source File: ViewModelTest.java From AndroidMvvm with Apache License 2.0 | 5 votes |
@Override public void setup() { super.setup(); savedInstanceState = null; onPropertyChangedCallback = mock(Observable.OnPropertyChangedCallback.class); viewModel = createViewModel(null); viewModel.addOnPropertyChangedCallback(onPropertyChangedCallback); }
Example #22
Source File: ViewModelTest.java From AndroidMvvm with Apache License 2.0 | 5 votes |
protected final void rotateCreate() { onPropertyChangedCallback = mock(Observable.OnPropertyChangedCallback.class); viewModel = createViewModel(savedInstanceState); viewModel.addOnPropertyChangedCallback(onPropertyChangedCallback); viewModel.onStart(); savedInstanceState = null; }
Example #23
Source File: ItemRepoViewModelTest.java From archi with Apache License 2.0 | 5 votes |
@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()); }
Example #24
Source File: AssetFragment.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Override public void initViewObservable() { viewModel.uc.accountItemObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable sender, int propertyId) { dialog = new BottomSheetDialog(activity,R.style.BottomSheetDialog); DialogSwitchAccountBinding binding = DataBindingUtil.inflate(LayoutInflater.from(Utils.getContext()), R.layout.dialog_switch_account, null, false); dialog.setContentView(binding.getRoot()); binding.setViewModel(new SwitchAccountViewModel((Application) Utils.getContext())); dialog.setCanceledOnTouchOutside(true); dialog.show(); } }); }
Example #25
Source File: AssetOverviewActivity.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Override public void initViewObservable() { viewModel.uc.pSwitchObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable observable, int i) { if (!viewModel.uc.pSwitchObservable.get()) { binding.ivAssetVisible.setImageResource(R.drawable.asset_overview_visible_icon); viewModel.totalAsset.set(SPUtils.getString(Utils.getContext(), SPKeyGlobal.TOTAL_ASSET_VALUE, "0.00")); } else { binding.ivAssetVisible.setImageResource(R.drawable.asset_overview_invisible_icon); viewModel.totalAsset.set("****"); } } }); }
Example #26
Source File: ShapeLayer.java From spline with Apache License 2.0 | 5 votes |
/** * Exists as public method to allow Json deserializing to add color change listener after * deserializing */ public void addOnColorChangeListener() { this.color.addOnPropertyChangedCallback(new OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable sender, int propertyId) { ShapeLayer.this.notifyPropertyChanged(BR.color); } }); }
Example #27
Source File: ContactActivity.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Override public void initViewObservable() { viewModel.uc.addContactObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable observable, int i) { onClickPopIcon(binding.addContact); } }); }
Example #28
Source File: RadioRVAdapter.java From Flubber with Apache License 2.0 | 5 votes |
public RadioRVAdapter(Context context) { this.context = context; checked.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable observable, int i) { if (selectedListener != null) { final ObservableField observableField = (ObservableField) observable; selectedListener.onElementSelected((RadioElementModel) observableField.get()); } } }); }
Example #29
Source File: AccountManagerListActivity.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Override public void initViewObservable() { super.initViewObservable(); viewModel.uc.loginViewObservable.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable sender, int propertyId) { ARouter.getInstance().build(RouterActivityPath.ACTIVITY_PASSWORD_LOGIN).navigation(); finish(); } }); }
Example #30
Source File: MainActivity.java From android-ponewheel with MIT License | 5 votes |
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()); } }); }