• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RxSearchView类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.jakewharton.rxbinding.support.v7.widget.RxSearchView的典型用法代码示例。如果您正苦于以下问题:Java RxSearchView类的具体用法?Java RxSearchView怎么用?Java RxSearchView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RxSearchView类属于com.jakewharton.rxbinding.support.v7.widget包,在下文中一共展示了RxSearchView类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createSearchViewChangeSub

import com.jakewharton.rxbinding.support.v7.widget.RxSearchView; //导入依赖的package包/类
/**
 * Create a subscriber which observes changes to the SearchView's text and updates filters {@link #books}
 * accordingly.
 * @param searchView SearchView to observe changes of.
 */
private void createSearchViewChangeSub(SearchView searchView) {
    // Unsubscribe from an existing subscriber (if it exists) first.
    if (searchViewChangeSub != null && !searchViewChangeSub.isUnsubscribed()) searchViewChangeSub.unsubscribe();
    // Create new subscriber.
    searchViewChangeSub = RxSearchView.queryTextChanges(searchView)
                                      .skip(1)
                                      .debounce(500, TimeUnit.MILLISECONDS)
                                      .observeOn(AndroidSchedulers.mainThread())
                                      .subscribe(cs -> {
                                          // Apply filter to items and then update adapter's copy of items.
                                          getBooksList(cs.toString());
                                          //noinspection unchecked
                                          adapter.updateRealmResults(books);
                                      }, t -> {
                                          // Shouldn't happen, but we'll log it if it does.
                                          Timber.e(t, "Some error occurred due to the SearchView observer!");
                                      });
}
 
开发者ID:bkromhout,项目名称:Minerva,代码行数:24,代码来源:LibraryFragment.java


示例2: onCreateOptionsMenu

import com.jakewharton.rxbinding.support.v7.widget.RxSearchView; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_icons, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setQueryHint(getString(R.string.icon_search_hint));
    // reset max width to device width to make search view full width
    searchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels);

    RxSearchView.queryTextChanges(searchView)
            .debounce(200, TimeUnit.MILLISECONDS)
            .skip(1)    // skip initial unnecessary change
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<CharSequence>() {
                @Override
                public void call(CharSequence query) {
                    mIconsPresenter.loadIcons(query);
                }
            });
}
 
开发者ID:eo,项目名称:mdx,代码行数:22,代码来源:IconsFragment.java


示例3: theRxBeginner

import com.jakewharton.rxbinding.support.v7.widget.RxSearchView; //导入依赖的package包/类
/**
 * working solution until an error occurs. Does not handle backpressure well
 * @param searchView
 */
private void theRxBeginner(final SearchView searchView) {
    RxSearchView.queryTextChanges(searchView)
            .filter(charSequence -> !TextUtils.isEmpty(charSequence))
            .flatMap(charSequence -> {
                return mGitApiService.searchRepositoriesObservable(charSequence.toString())
                        .subscribeOn(Schedulers.io());
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(response -> {
                showRepositories(response.getItems());
            }, throwable -> {
                throwable.printStackTrace();
                showEmptyErrorView(throwable.getMessage());
                Toast.makeText(RepoListActivity.this,
                        "Completed Observable 'RxSearchView.queryTextChanges(searchView)' "
                                + "with error! Should never happen",
                        Toast.LENGTH_SHORT).show();
            });
}
 
开发者ID:passsy,项目名称:android-GetReactive,代码行数:24,代码来源:RepoListActivity.java


示例4: onOptionsItemSelected

import com.jakewharton.rxbinding.support.v7.widget.RxSearchView; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_search) {
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
        RxSearchView.queryTextChanges(searchView)
                .map(charSequence -> charSequence == null ? null : charSequence.toString().trim())
                .throttleLast(100, TimeUnit.MILLISECONDS)
                .debounce(100, TimeUnit.MILLISECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(searchText -> selectCityFragment.cityListAdapter.getFilter().filter(searchText));
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:SelectCityActivity.java


示例5: onCreateOptionsMenu

import com.jakewharton.rxbinding.support.v7.widget.RxSearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_action_search));
    compositeSubscription.add(mainViewModel.searchCity(RxSearchView.queryTextChanges(searchView)));
    return true;
}
 
开发者ID:AleksanderMielczarek,项目名称:RealmRepository,代码行数:8,代码来源:MainActivity.java


示例6: theRxExpert

import com.jakewharton.rxbinding.support.v7.widget.RxSearchView; //导入依赖的package包/类
/**
 * with backpressure and error handling
 * @param searchView
 */
private void theRxExpert(final SearchView searchView) {
    RxSearchView.queryTextChanges(searchView)
            .skip(1)
            .doOnNext(charSequence -> Log.v(TAG, "searching: " + charSequence))
            .throttleLast(100, TimeUnit.MILLISECONDS)
            .debounce(200, TimeUnit.MILLISECONDS)
            .onBackpressureLatest()
            .observeOn(AndroidSchedulers.mainThread())
            .filter(charSequence -> {
                final boolean empty = TextUtils.isEmpty(charSequence);
                if (empty) {
                    Log.v(TAG, "empty view");
                    mAdapter.clear();
                }
                return !empty;
            })
            .concatMap(query -> {
                Log.v(TAG, "requesting " + query);
                // with rx.Observable
                //return searchRepositories(query)

                // with rx.Single (proof of concept)
                return searchRepositoriesSingle(query);
            })
            .doOnNext(charSequence -> Log.v(TAG, "got data"))
            .subscribe(response -> {
                showRepositories(response.getItems());
            }, throwable -> {
                throwable.printStackTrace();
                showEmptyErrorView(throwable.getMessage());
            });
}
 
开发者ID:passsy,项目名称:android-GetReactive,代码行数:37,代码来源:RepoListActivity.java


示例7: refreshTab

import com.jakewharton.rxbinding.support.v7.widget.RxSearchView; //导入依赖的package包/类
private void refreshTab(int position) {

		int type = tabTypes.get(position);
		RecyclerView view = ((RecyclerView) tabs.get(position));
		Animations.fadeFlipOut(loadingProgress, view, emptyText);

		Observable<CharSequence> debouncedQueries = RxSearchView.queryTextChanges(searchEdit)
				.compose(onUi())
				.debounce(666, TimeUnit.MILLISECONDS)
				.filter(query -> query.length() > 3)
				.compose(toIo());
		if (type == TAB_BEERS) {

			ItemClickSupport.addTo(view)
					.setOnItemClickListener((parent, pos, v) -> handleBeerResult(((BeerSearchResultAdapter) view.getAdapter()).get(pos)));
			debouncedQueries.switchMap(query -> Api.get().searchBeers(query.toString())
					.flatMap(result -> Db.getOfflineRatingForBeer(this, result.beerId)
							.singleOrDefault(null)
							.map(userRating -> result.withRating(userRating)))
					.toList()
					.compose(toUi())
					.doOnError(e -> Snackbar.show(SearchActivity.this, R.string.error_connectionfailure))
					.onErrorResumeNext(Observable.empty()))
					.compose(bindToLifecycle())
					.subscribe(results -> {

						view.setAdapter(new BeerSearchResultAdapter(results));
						if (results.isEmpty())
							Animations.fadeFlipOut(emptyText, view, loadingProgress);
						else
							Animations.fadeFlipOut(view, emptyText, loadingProgress);
					});

		} else if (type == TAB_BREWERIES) {

			ItemClickSupport.addTo(view)
					.setOnItemClickListener((parent, pos, v) -> handleBreweryResult(((BrewerySearchResultAdapter) view.getAdapter()).get(pos)));
			debouncedQueries.switchMap(query -> Api.get().searchBreweries(query.toString())
					.toList()
					.compose(toUi())
					.doOnError(e -> Snackbar.show(SearchActivity.this, R.string.error_connectionfailure))
					.onErrorResumeNext(Observable.empty())).compose(bindToLifecycle())
					.subscribe(results -> {

						view.setAdapter(new BrewerySearchResultAdapter(results));
						if (results.isEmpty())
							Animations.fadeFlipOut(emptyText, view, loadingProgress);
						else
							Animations.fadeFlipOut(view, emptyText, loadingProgress);
					});

		} else if (type == TAB_PLACES) {

			ItemClickSupport.addTo(view)
					.setOnItemClickListener((parent, pos, v) -> handlePlaceResult(((PlaceSearchResultAdapter) view.getAdapter()).get(pos)));
			debouncedQueries.switchMap(query -> Api.get().searchPlaces(query.toString())
					.toList()
					.compose(toUi())
					.doOnError(e -> Snackbar.show(SearchActivity.this, R.string.error_connectionfailure))
					.onErrorResumeNext(Observable.empty())).compose(bindToLifecycle())
					.subscribe(results -> {

						view.setAdapter(new PlaceSearchResultAdapter(results));
						if (results.isEmpty())
							Animations.fadeFlipOut(emptyText, view, loadingProgress);
						else
							Animations.fadeFlipOut(view, emptyText, loadingProgress);
					});

		}

	}
 
开发者ID:erickok,项目名称:ratebeer,代码行数:73,代码来源:SearchActivity.java


示例8: onCreateOptionsMenu

import com.jakewharton.rxbinding.support.v7.widget.RxSearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_movie_list_menu, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    itemSearch = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) itemSearch.getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    // Make the SearchView occupy the entire available width on the Toolbar
    searchView.setMaxWidth(Integer.MAX_VALUE);

    // Restore state of SearchView after configuration changes
    if (!TextUtils.isEmpty(getSearchQuery())) {
        itemSearch.expandActionView();
        searchView.setQuery(getSearchQuery(), false);
    }

    // Perform a search automatically after 1 second of no typing
    RxSearchView.queryTextChanges(searchView)
            .debounce(QUERY_TYPING_RUN_WAIT_MILLIS, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(charSequence -> {
                if (!getSearchQuery().equals(charSequence.toString())) {
                    setSearchQuery(charSequence.toString());
                    presenter.start();
                }
            });

    // Reload default list after the SearchView is closed
    RxMenuItemCompat.actionViewEvents(itemSearch)
            .subscribe(menuItemActionViewEvent -> {
                if (menuItemActionViewEvent.kind() == MenuItemActionViewEvent.Kind.COLLAPSE &&
                        !TextUtils.isEmpty(searchView.getQuery().toString())) {
                    setSearchQuery("");
                    presenter.start();
                }
            });

    return true;
}
 
开发者ID:dakshj,项目名称:TMDb_Sample,代码行数:44,代码来源:MovieListActivity.java



注:本文中的com.jakewharton.rxbinding.support.v7.widget.RxSearchView类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PositionedByteRange类代码示例发布时间:2022-05-22
下一篇:
Java Project类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap