Search in sources :

Example 1 with DottedQueryBuilder

use of com.orgzly.android.query.user.DottedQueryBuilder in project orgzly-android by orgzly.

the class MainActivity method setupSearchView.

/**
 * SearchView setup and query text listeners.
 * TODO: http://developer.android.com/training/search/setup.html
 */
private void setupSearchView(Menu menu) {
    final MenuItem searchItem = menu.findItem(R.id.activity_action_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint(getString(R.string.search_hint));
    /* When user starts the search, fill the search box with text depending on current fragment. */
    searchView.setOnSearchClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Make search as wide as possible. */
            ViewGroup.LayoutParams layoutParams = searchView.getLayoutParams();
            layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
            /* For Query fragment, fill the box with full query. */
            String q = DisplayManager.getDisplayedQuery(getSupportFragmentManager());
            if (q != null) {
                searchView.setQuery(q + " ", false);
            } else {
                /* If searching from book, add book name to query. */
                Book book = getActiveFragmentBook();
                if (book != null) {
                    DottedQueryBuilder builder = new DottedQueryBuilder();
                    String query = builder.build(new Query(new Condition.InBook(book.getName())));
                    searchView.setQuery(query + " ", false);
                }
            }
        }
    });
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String str) {
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String str) {
            if (BuildConfig.LOG_DEBUG)
                LogUtils.d(TAG, str);
            /* Close search. */
            searchItem.collapseActionView();
            DisplayManager.displayQuery(getSupportFragmentManager(), str.trim());
            return true;
        }
    });
}
Also used : Condition(com.orgzly.android.query.Condition) Query(com.orgzly.android.query.Query) MenuItem(android.view.MenuItem) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) TextView(android.widget.TextView) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) SearchView(android.support.v7.widget.SearchView) Book(com.orgzly.android.Book)

Example 2 with DottedQueryBuilder

use of com.orgzly.android.query.user.DottedQueryBuilder in project orgzly-android by orgzly.

the class MainActivity method setupSearchView.

/**
 * SearchView setup and query text listeners.
 * TODO: http://developer.android.com/training/search/setup.html
 */
private void setupSearchView(Menu menu) {
    final MenuItem searchItem = menu.findItem(R.id.activity_action_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint(getString(R.string.search_hint));
    /* When user starts the search, fill the search box with text depending on current fragment. */
    searchView.setOnSearchClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Make search as wide as possible. */
            ViewGroup.LayoutParams layoutParams = searchView.getLayoutParams();
            layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
            /* For Query fragment, fill the box with full query. */
            String q = DisplayManager.getDisplayedQuery(getSupportFragmentManager());
            if (q != null) {
                searchView.setQuery(q + " ", false);
            } else {
                /* If searching from book, add book name to query. */
                Book book = getActiveFragmentBook();
                if (book != null) {
                    DottedQueryBuilder builder = new DottedQueryBuilder();
                    String query = builder.build(new Query(new Condition.InBook(book.getName())));
                    searchView.setQuery(query + " ", false);
                }
            }
        }
    });
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String str) {
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String str) {
            if (BuildConfig.LOG_DEBUG)
                LogUtils.d(TAG, str);
            /* Close search. */
            searchItem.collapseActionView();
            DisplayManager.displayQuery(getSupportFragmentManager(), str.trim());
            return true;
        }
    });
}
Also used : Condition(com.orgzly.android.query.Condition) Query(com.orgzly.android.query.Query) MenuItem(android.view.MenuItem) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) NavigationView(com.google.android.material.navigation.NavigationView) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) SearchView(androidx.appcompat.widget.SearchView) Book(com.orgzly.android.db.entity.Book)

Aggregations

MenuItem (android.view.MenuItem)2 View (android.view.View)2 Condition (com.orgzly.android.query.Condition)2 Query (com.orgzly.android.query.Query)2 DottedQueryBuilder (com.orgzly.android.query.user.DottedQueryBuilder)2 DrawerNavigationView (com.orgzly.android.ui.drawer.DrawerNavigationView)2 NavigationView (android.support.design.widget.NavigationView)1 SearchView (android.support.v7.widget.SearchView)1 TextView (android.widget.TextView)1 SearchView (androidx.appcompat.widget.SearchView)1 NavigationView (com.google.android.material.navigation.NavigationView)1 Book (com.orgzly.android.Book)1 Book (com.orgzly.android.db.entity.Book)1