com.jakewharton.rxbinding2.widget.RxTextView Java Examples

The following examples show how to use com.jakewharton.rxbinding2.widget.RxTextView. 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: FormValidationCombineLatestFragment.java    From RxJava-Android-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(
    LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  View layout = inflater.inflate(R.layout.fragment_form_validation_comb_latest, container, false);
  unbinder = ButterKnife.bind(this, layout);

  _emailChangeObservable =
      RxTextView.textChanges(_email).skip(1).toFlowable(BackpressureStrategy.LATEST);
  _passwordChangeObservable =
      RxTextView.textChanges(_password).skip(1).toFlowable(BackpressureStrategy.LATEST);
  _numberChangeObservable =
      RxTextView.textChanges(_number).skip(1).toFlowable(BackpressureStrategy.LATEST);

  _combineLatestEvents();

  return layout;
}
 
Example #2
Source File: JudgeSelectionActivity.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
private void setupSearch() {
  //Add text change watcher
  compositeDisposable.add(
    RxTextView.textChangeEvents(judgeSearchBar)
      .skipInitialValue()
      .debounce(300, TimeUnit.MILLISECONDS)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(getSearchInputObserver()));

  compositeDisposable.add(publishSubject
    .debounce(300, TimeUnit.MILLISECONDS)
    .distinctUntilChanged()
    .switchMapSingle(new Function<String, SingleSource<LookupAccount>>() {
      @Override
      public SingleSource<LookupAccount> apply(String username) {
        return RetrofitServiceGenerator
          .getService()
          .getUsernames(URLS.STEEMIT_API_URL, SteemRequestBody.lookupAccounts(username))
          .subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread());
      }
    }).subscribeWith(usernamesResponseObserver()));

  hideSearchingProgress();
}
 
Example #3
Source File: DialogHolder.java    From filter-dialog-activity with Apache License 2.0 6 votes vote down vote up
@SuppressLint("CheckResult")
public DialogHolder(View itemView) {
    super(itemView);

    initUi(itemView);

    LinearLayoutManager layoutManager = new LinearLayoutManager(itemView.getContext());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    layoutManager.scrollToPosition(0);

    filterRecycler.setLayoutManager(layoutManager);
    filterRecycler.setHasFixedSize(true);
    filterRecycler.setItemAnimator(new DefaultItemAnimator());

    RxTextView.textChanges(searchEdt)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(charSequence -> {
                getAdapter().filter(charSequence.toString());
            });
}
 
Example #4
Source File: RepoSearchFragment.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    RxTextView.textChanges(binding.edtSearch)
            .debounce(100, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .filter(charSequence -> charSequence.length() > 0)
            .map(charSequence -> "*" + charSequence + "*") // realm search
            .subscribe(s -> viewModel.searchLocal(s));

    RxTextView.textChanges(binding.edtSearch)
            .debounce(500, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .filter(charSequence -> charSequence.length() > 0)
            .map(CharSequence::toString)
            .subscribe(s -> viewModel.searchRemote(s));

    setNoDataText("No result");
}
 
Example #5
Source File: TextLabelDetailsFragment.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(
    LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
  setHasOptionsMenu(true);
  noteTextLayout =
      (TextInputLayout) inflater.inflate(R.layout.text_label_details_fragment, container, false);
  noteText = noteTextLayout.findViewById(R.id.note_text);
  noteText.setText(originalLabel.getTextLabelValue().getText());
  noteText.post(() -> noteText.setSelection(noteText.getText().toString().length()));

  RxTextView.afterTextChangeEvents(noteText)
      .subscribe(
          events -> {
            verifyInput(noteText.getText().toString());
          });

  // TODO: Transition

  return noteTextLayout;
}
 
Example #6
Source File: DebounceSearchEmitterFragment.java    From RxJava-Android-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {

  super.onActivityCreated(savedInstanceState);
  _setupLogger();

  _disposable =
      RxTextView.textChangeEvents(_inputSearchText)
          .debounce(400, TimeUnit.MILLISECONDS) // default Scheduler is Computation
          .filter(changes -> isNotNullOrEmpty(changes.text().toString()))
          .observeOn(AndroidSchedulers.mainThread())
          .subscribeWith(_getSearchObserver());
}
 
Example #7
Source File: MainActivity.java    From RxAndroid-Examples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    unbinder = ButterKnife.bind(this);

    firstNameChangeObservable = RxTextView.textChanges(etFirstName).skip(1).toFlowable(BackpressureStrategy.LATEST);
    lastNameChangeObservable = RxTextView.textChanges(etLastName).skip(1).toFlowable(BackpressureStrategy.LATEST);
    emailChangeObservable = RxTextView.textChanges(etEmail).skip(1).toFlowable(BackpressureStrategy.LATEST);

    combineLatestEvents();
}
 
Example #8
Source File: RxTextViews.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
public static Observable<CharSequence> textChanges(TextView... views) {
    List<Observable<CharSequence>> observables = new ArrayList<>();
    for (TextView view : views) {
        observables.add(RxTextView.textChanges(view));
    }

    return Observable.merge(observables)
            .subscribeOn(AndroidSchedulers.mainThread());
}
 
Example #9
Source File: ReceiveFragment.java    From iroha-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_receive, container, false);
    SampleApplication.instance.getApplicationComponent().inject(this);

    presenter.setFragment(this);
    presenter.generateQR(binding.amount.getText().toString());
    RxTextView.textChangeEvents(binding.amount)
            .subscribe(text -> presenter.generateQR(text.text().toString()),
                    this::didError);
    return binding.getRoot();
}
 
Example #10
Source File: SearchActivity.java    From Capstone-Project with MIT License 5 votes vote down vote up
private void initSearching() {
    RxTextView.textChanges(editTextSearch)
            .subscribeOn(Schedulers.computation())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new DisposableObserver<CharSequence>() {
                @Override
                public void onNext(CharSequence charSequence) {
                    if (!isNetworkAvailable(true)) {
                        networkUnavailable();
                    } else if (TextUtils.isEmpty(charSequence) ||
                            TextUtils.isEmpty(charSequence.toString().trim())) {
                        editTextSearch.post(new Runnable() {
                            @Override
                            public void run() {
                                searchInit();
                                mSearchPresenter.cancelOngoingRequest();
                            }
                        });
                    } else {
                        mSearchPresenter.search(charSequence.toString());
                        searchingStarted();
                    }
                }

                @Override
                public void onError(Throwable e) {
                    Logger.e(TAG, e.getMessage(), e);
                }

                @Override
                public void onComplete() {
                    // Done.
                }
            });
}
 
Example #11
Source File: TextNoteFragment.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Override
public final View onCreateView(
    LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
  // The send button coloring depends on whether or not were recording so we have to set the theme
  // here. The theme will be updated by the activity if we're currently recording.
  View rootView = inflater.inflate(R.layout.text_note_fragment, null);

  textView = rootView.findViewById(R.id.text);
  textSize.onNext((int) textView.getTextSize());

  RxTextView.afterTextChangeEvents(textView)
      .subscribe(event -> whenText.onNext(event.view().getText()));

  if (savedInstanceState != null) {
    textView.setText(savedInstanceState.getString(KEY_TEXT));
  }

  textView.setOnFocusChangeListener(
      (v, hasFocus) -> {
        InputMethodManager imm =
            (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (hasFocus) {
          imm.showSoftInputFromInputMethod(v.getWindowToken(), 0);
        } else {
          imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
      });
  textView.requestFocus();

  FloatingActionButton addButton = rootView.findViewById(R.id.btn_add_inline);
  setupAddButton(addButton);
  actionController.attachAddButton(addButton);
  actionController.attachProgressBar(rootView.findViewById(R.id.recording_progress_bar));
  setUpTitleBar(rootView, false, R.string.action_bar_text_note, R.drawable.ic_text);
  return rootView;
}
 
Example #12
Source File: SearchActivity.java    From Rey-MusicPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    mApp = (Common) getApplicationContext();
    mContext = getApplicationContext();
    mSearchResults = new ArrayList<>();

    mImageButtonClear = findViewById(R.id.image_button_cross);
    mBackImageButton = findViewById(R.id.image_back_button);
    mBackImageButton.setOnClickListener(v -> finish());
    mFragments = new ArrayList<>();
    mMainParent = findViewById(R.id.main_parent);
    mRelativeLayout = findViewById(R.id.best_matches);


    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mRelativeLayout.getLayoutParams();
    params.topMargin = Common.getStatusBarHeight(this);
    mRelativeLayout.setLayoutParams(params);

    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    mSearchEditText = findViewById(R.id.edit_text_search);
    mSearchEditText.setTypeface(TypefaceHelper.getTypeface(getApplicationContext().getApplicationContext(), TypefaceHelper.FUTURA_BOOK));

    mImageButtonClear.setOnClickListener(v -> mSearchEditText.setText(""));

    mRecyclerView = findViewById(R.id.recyclerview);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, Common.getNumberOfColms());
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            if (mAdapter.getItemViewType(position) == 0 || mAdapter.getItemViewType(position) == 2) {
                return Common.getNumberOfColms();
            } else {
                return 1;
            }

        }
    });

    mRecyclerView.setLayoutManager(gridLayoutManager);


    mAdapter = new SearchAdapter(this);
    mRecyclerView.setAdapter(mAdapter);

    RxTextView.textChangeEvents(mSearchEditText)
            .debounce(175, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(getSearchObserver());
    String recentlySearchedKey = PreferencesHelper.getInstance().getString(PreferencesHelper.Key.RECENT_SEARCH, "");
    mSearchEditText.setText(recentlySearchedKey);
    mSearchEditText.setSelection(recentlySearchedKey.length());
}
 
Example #13
Source File: NameExperimentDialog.java    From science-journal with Apache License 2.0 4 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  String previousTitle = getResources().getString(R.string.default_experiment_name);
  if (savedInstanceState != null) {
    previousTitle = savedInstanceState.getString(KEY_SAVED_TITLE);
  }

  appAccount = WhistlePunkApplication.getAccount(getContext(), getArguments(), KEY_ACCOUNT_KEY);

  experimentId = getArguments().getString(KEY_EXPERIMENT_ID);

  final AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
  ViewGroup rootView =
      (ViewGroup)
          LayoutInflater.from(getActivity()).inflate(R.layout.name_experiment_dialog, null);
  input = (TextInputEditText) rootView.findViewById(R.id.title);
  inputLayout = (TextInputLayout) rootView.findViewById(R.id.title_input_layout);
  input.setText(previousTitle);
  if (savedInstanceState == null) {
    input.selectAll();
  }
  // TODO: Max char count?
  // TODO: Pop up the keyboard immediately.

  alertDialog.setView(rootView);

  alertDialog.setTitle(R.string.name_experiment_dialog_title);
  alertDialog.setCancelable(true);
  alertDialog.setPositiveButton(
      android.R.string.ok, (dialogInterface, i) -> saveNewTitle(alertDialog.getContext()));
  AlertDialog result = alertDialog.create();
  RxTextView.afterTextChangeEvents(input)
      .subscribe(
          event -> {
            Button button = result.getButton(DialogInterface.BUTTON_POSITIVE);
            if (input.getText().toString().length() == 0) {
              if (getActivity() != null) {
                inputLayout.setError(
                    getActivity()
                        .getResources()
                        .getString(R.string.empty_experiment_title_error));
              }
              if (button != null) {
                button.setEnabled(false);
              }
            } else if (button != null) {
              inputLayout.setErrorEnabled(false);
              button.setEnabled(true);
            }
          });

  return result;
}
 
Example #14
Source File: LoginActivity.java    From landlord_client with Apache License 2.0 4 votes vote down vote up
@Override
protected void init() {
    gson = new Gson();
    etUsername.setText(SharedPreferencesUtil.getUsername());
    etPassword.setText("");
    addDisposable(
            //用户名点击
            RxView.focusChanges(etUsername)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(hasFocus -> {
                        if(hasFocus) {
                            if(etUsername.getText().length() > 0) visible(deleteUsername);
                            else gone(deleteUsername);
                        } else {
                            gone(deleteUsername);
                        }
                    }),
            //用户名输入
            RxTextView.textChangeEvents(etUsername)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(textViewTextChangeEvent -> {
                        etPassword.setText("");
                        if(textViewTextChangeEvent.count() > 0) visible(deleteUsername);
                        else gone(deleteUsername);
                    }),
            //登录
            RxView.clicks(btnLogin)
                    .throttleFirst(5, TimeUnit.SECONDS)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(o -> {
                        if(!NetworkUtil.isConnected(App.getApp())) ToastUtil.showCenterSingleToast("当前网络不可用");
                        else login();
                    }),
            //清空用户名和密码
            RxView.clicks(deleteUsername)
                    .throttleFirst(5, TimeUnit.SECONDS)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(o -> {
                        etUsername.setText("");
                        gone(deleteUsername);
                        etUsername.setFocusable(true);
                        etUsername.setFocusableInTouchMode(true);
                        etUsername.requestFocus();
                    })
    );
}
 
Example #15
Source File: LoginActivity.java    From RxCommand with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);
    viewModel = ViewModelProviders.of(this, new ViewModelFactory()).get(LoginViewModel.class);

    // bind view model
    RxTextView
            .textChanges(phoneNumberEditText)
            .compose(Live.bindLifecycle(this))
            .subscribe(viewModel.phoneNumber::setValue);

    RxTextView
            .textChanges(captchaEditText)
            .compose(Live.bindLifecycle(this))
            .subscribe(viewModel.captcha::setValue);

    RxCommandBinder
            .bind(captchaButton, viewModel.captchaCommand(), Live.bindLifecycle(this));
    RxCommandBinder
            .bind(loginButton, viewModel.loginCommand(), Live.bindLifecycle(this));

    // captcha
    viewModel.captchaCommand()
            .executing()
            .compose(Live.bindLifecycle(this))
            .subscribe(executing -> {
                if (executing) {
                    captchaButton.setText("Fetch...");
                } else {
                    captchaButton.setText("Fetch Captcha");
                }
            });

    viewModel.captchaCommand()
            .switchToLatest()
            .observeOn(AndroidSchedulers.mainThread())
            .compose(Live.bindLifecycle(this))
            .subscribe(result -> Toast.makeText(LoginActivity.this, result, Toast.LENGTH_LONG).show());

    // countdown
    viewModel.countdownCommand()
            .executing()
            .compose(Live.bindLifecycle(this))
            .subscribe(executing -> {
                if (!executing) {
                    captchaButton.setText("Fetch Captcha");
                    tipTextView.setVisibility(View.GONE);
                } else {
                    tipTextView.setVisibility(View.VISIBLE);
                }
            });

    viewModel.countdownCommand()
            .switchToLatest()
            .observeOn(AndroidSchedulers.mainThread())
            .compose(Live.bindLifecycle(this))
            .subscribe(s -> captchaButton.setText(s));


    // login
    viewModel.loginCommand()
            .executing()
            .compose(Live.bindLifecycle(this))
            .subscribe(executing -> {
                if (executing) {
                    loginButton.setText("Login...");
                } else {
                    loginButton.setText("Login");
                }
            });

    viewModel.loginCommand()
            .switchToLatest()
            .observeOn(AndroidSchedulers.mainThread())
            .compose(Live.bindLifecycle(this))
            .subscribe(success -> {
                if (success) {
                    Toast.makeText(LoginActivity.this, "Login success!! Now goto the MainActivity.", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(LoginActivity.this, "Login fail!!", Toast.LENGTH_LONG).show();
                }
            });

    // errors
    Observable.merge(
            viewModel.captchaCommand().errors(),
            viewModel.loginCommand().errors())
            .compose(Live.bindLifecycle(this))
            .subscribe(throwable ->
                    Toast.makeText(LoginActivity.this, throwable.getLocalizedMessage(), Toast.LENGTH_LONG).show()
            );
}
 
Example #16
Source File: UserSearchActivity.java    From 1Rramp-Android with MIT License 4 votes vote down vote up
private void attachListener() {
  usernameSearchInputField.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      usernameSearchInputField.setCursorVisible(true);
    }
  });

  DisposableObserver<LookupAccount> accountDisposableObserver = usernamesObserver();

  compositeDisposable.add(
    RxTextView
      .textChangeEvents(usernameSearchInputField)
      .skipInitialValue()
      .debounce(300, TimeUnit.MILLISECONDS)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribeWith(searchUsernameTextWatcher()));

  compositeDisposable.add(
    publishSubject
      .debounce(300, TimeUnit.MILLISECONDS)
      .distinctUntilChanged()
      .switchMapSingle(new Function<String, Single<LookupAccount>>() {
        @Override
        public Single<LookupAccount> apply(String username) {
          return RetrofitServiceGenerator
            .getService()
            .getUsernames(URLS.STEEMIT_API_URL, SteemRequestBody.lookupAccounts(username))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread());
        }
      })
      .subscribeWith(accountDisposableObserver));

  compositeDisposable.add(accountDisposableObserver);

  backBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      if (SEARCH_MODE) {
        setBrowseMode();
      } else {
        close();
      }
    }
  });
}
 
Example #17
Source File: OrgUnitCascadeDialog.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

    binding = DataBindingUtil.inflate(inflater, R.layout.dialog_cascade_orgunit, container, false);
    binding.title.setText(title);
    disposable = new CompositeDisposable();

    setListeners();


    disposable.add(RxTextView.textChanges(binding.orgUnitSearchEditText)
            .skipInitialValue()
            .debounce(500, TimeUnit.MILLISECONDS)
            .filter(data -> !isEmpty(data))
            .map(textTofind -> d2.organisationUnitModule().organisationUnits().byDisplayName().like("%" + textTofind.toString() + "%").blockingGet())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                    this::showChips,
                    Timber::e
            ));

    disposable.add(
            Observable.fromCallable(() -> d2.organisationUnitModule().organisationUnits().blockingGet())
                    .map(ouList -> {
                        int maxLevel = -1;
                        for (OrganisationUnit ou : ouList) {
                            if (maxLevel < ou.level())
                                maxLevel = ou.level();
                        }
                        return maxLevel;
                    })
                    .map(maxLevel -> {
                        List<OrgUnitItem> orgUnitItems = new ArrayList<>();
                        for (int i = 1; i <= maxLevel; i++) {
                            OrgUnitItem orgUnitItem = new OrgUnitItem(d2.organisationUnitModule().organisationUnits(), ouSelectionType);
                            orgUnitItem.setMaxLevel(maxLevel);
                            orgUnitItem.setLevel(i);
                            orgUnitItem.setOrganisationUnitLevel(d2.organisationUnitModule().organisationUnitLevels().byLevel().eq(i).one().blockingGet());//TODO: CHECK IF OU ALREADY SELECTED
                            orgUnitItems.add(orgUnitItem);
                        }
                        return orgUnitItems;
                    })
                    .subscribeOn(Schedulers.computation())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(
                            this::setAdapter,
                            Timber::e
                    )
    );
    setRetainInstance(true);
    return binding.getRoot();
}