Java Code Examples for android.support.v7.widget.SearchView#requestFocus()

The following examples show how to use android.support.v7.widget.SearchView#requestFocus() . 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: ProductsFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.product_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.product_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 2
Source File: CustomersFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.customer_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.customer_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 3
Source File: OrdersFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.order_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.order_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 4
Source File: ProductsFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.product_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.product_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 5
Source File: CustomersFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.customer_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.customer_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 6
Source File: OrdersFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.order_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.order_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 7
Source File: SearchActivity.java    From ratebeer with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_search);

	searchEdit = (SearchView) findViewById(R.id.search_text);
	TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
	resultsPager = (ViewPager) findViewById(R.id.results_pager);
	loadingProgress = (ProgressBar) findViewById(R.id.loading_progress);
	emptyText = (TextView) findViewById(R.id.empty_text);

	setupDefaultUpButton();

	modeBeerPicker = getIntent().getBooleanExtra("modeBeerPicker", false);

	// Set up tabs
	searchEdit.setQuery(getIntent().getStringExtra("query"), false);
	searchEdit.setInputType(InputType.TYPE_CLASS_TEXT);
	tabTypes = new ArrayList<>(3);
	tabs = new ArrayList<>(3);
	tabsTitles = new ArrayList<>(3);
	addTab(TAB_BEERS, R.string.search_beers);
	if (!modeBeerPicker) {
		addTab(TAB_BREWERIES, R.string.search_breweries);
		addTab(TAB_PLACES, R.string.search_places);
	}
	RxViewPager.pageSelected(resultsPager).subscribe(this::refreshTab);
	resultsPager.setAdapter(new SearchPagerAdapter());
	tabLayout.setupWithViewPager(resultsPager);
	if (tabs.size() == 1)
		tabLayout.setVisibility(View.GONE);
	refreshTab(0);

	// When in picker mode, only search beers and set the activity result as cancelled until we actually picked a beer
	if (modeBeerPicker) {
		setResult(RESULT_CANCELED);
		if (TextUtils.isEmpty(searchEdit.getQuery())) {
			// No query given so focus on search field and do not show loading spinner until an input is given
			loadingProgress.setVisibility(View.INVISIBLE);
			searchEdit.requestFocus();
		}
	}

}
 
Example 8
Source File: AtUserFragment.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showSearchMenu(Menu menu) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setMaxWidth(Utility.dip2px(200));
    // searchView.setQueryHint(getString(R.string.at_other));

    // searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setIconifiedByDefault(false);
    // searchView.setQueryHint(getString(R.string.at_other));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                if (task != null) {
                    task.cancel(true);
                }
                task = new AtUserTask(newText);
                task.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                if (task != null) {
                    task.cancel(true);
                }
                atList.clear();
                result.clear();
                atList = AtUsersDBTask.get(BeeboApplication.getInstance().getCurrentAccountId());
                for (AtUserBean b : atList) {
                    result.add(b.getNickname());
                }
                adapter.notifyDataSetChanged();
            }
            return false;
        }
    });
    searchView.requestFocus();
}
 
Example 9
Source File: AtUserFragment.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
private void showSearchMenu(Menu menu) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setMaxWidth(Utility.dip2px(200));
    // searchView.setQueryHint(getString(R.string.at_other));

    // searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // searchView.setIconifiedByDefault(false);
    // searchView.setQueryHint(getString(R.string.at_other));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                if (task != null) {
                    task.cancel(true);
                }
                task = new AtUserTask(newText);
                task.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                if (task != null) {
                    task.cancel(true);
                }
                atList.clear();
                result.clear();
                atList = AtUsersDBTask.get(BeeboApplication.getInstance().getCurrentAccountId());
                for (AtUserBean b : atList) {
                    result.add(b.getNickname());
                }
                adapter.notifyDataSetChanged();
            }
            return false;
        }
    });
    searchView.requestFocus();
}