Search in sources :

Example 1 with Query

use of com.orgzly.android.query.Query in project orgzly-android by orgzly.

the class DisplayManager method displayQuery.

public static void displayQuery(FragmentManager fragmentManager, @NonNull String queryString) {
    // If the same query is already displayed, don't do anything.
    String displayedQuery = getDisplayedQuery(fragmentManager);
    if (displayedQuery != null && displayedQuery.equals(queryString)) {
        return;
    }
    // Parse query
    QueryParser queryParser = new InternalQueryParser();
    Query query = queryParser.parse(queryString);
    Fragment fragment;
    String tag;
    // Display agenda or query fragment
    if (query.getOptions().getAgendaDays() > 0) {
        fragment = AgendaFragment.getInstance(queryString);
        tag = AgendaFragment.FRAGMENT_TAG;
    } else {
        fragment = SearchFragment.getInstance(queryString);
        tag = SearchFragment.FRAGMENT_TAG;
    }
    // Add fragment.
    fragmentManager.beginTransaction().setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit, R.anim.fragment_enter, R.anim.fragment_exit).addToBackStack(null).replace(R.id.single_pane_container, fragment, tag).commit();
}
Also used : InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) QueryParser(com.orgzly.android.query.QueryParser) InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) Query(com.orgzly.android.query.Query) SearchFragment(com.orgzly.android.ui.fragments.SearchFragment) FilterFragment(com.orgzly.android.ui.fragments.FilterFragment) Fragment(android.support.v4.app.Fragment) AgendaFragment(com.orgzly.android.ui.fragments.AgendaFragment) NoteFragment(com.orgzly.android.ui.fragments.NoteFragment) BookFragment(com.orgzly.android.ui.fragments.BookFragment) BookPrefaceFragment(com.orgzly.android.ui.fragments.BookPrefaceFragment) BooksFragment(com.orgzly.android.ui.fragments.BooksFragment) FiltersFragment(com.orgzly.android.ui.fragments.FiltersFragment)

Example 2 with Query

use of com.orgzly.android.query.Query in project orgzly-android by orgzly.

the class ListWidgetViewsFactory method onDataSetChanged.

@Override
public void onDataSetChanged() {
    if (mCursor != null) {
        mCursor.close();
    }
    // Parse query
    QueryParser queryParser = new InternalQueryParser();
    Query query = queryParser.parse(queryString);
    isPartitioned = query.getOptions().getAgendaDays() > 0;
    // from http://stackoverflow.com/a/20645908
    final long token = Binder.clearCallingIdentity();
    try {
        if (isPartitioned) {
            Cursor cursor = NotesClient.getCursorForQuery(mContext, queryString);
            AgendaCursor.AgendaMergedCursor agendaCursor = AgendaCursor.INSTANCE.create(mContext, cursor, queryString);
            mCursor = agendaCursor.getCursor();
            originalNoteIDs = agendaCursor.getOriginalNoteIDs();
        } else {
            mCursor = NotesClient.getCursorForQuery(mContext, queryString);
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) QueryParser(com.orgzly.android.query.QueryParser) InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) Query(com.orgzly.android.query.Query) AgendaCursor(com.orgzly.android.provider.AgendaCursor) Cursor(android.database.Cursor) AgendaCursor(com.orgzly.android.provider.AgendaCursor)

Example 3 with Query

use of com.orgzly.android.query.Query in project orgzly-android by orgzly.

the class NotesClient method getCursorForBook.

public static Cursor getCursorForBook(Context context, String bookName) throws SQLException {
    /* Create a query with a book name condition. */
    InternalQueryBuilder builder = new InternalQueryBuilder();
    String query = builder.build(new Query(new Condition.InBook(bookName)));
    return context.getContentResolver().query(ProviderContract.Notes.ContentUri.notesSearchQueried(query), null, null, null, // For book view, force ordering by position only
    DbNoteView.LFT);
}
Also used : InternalQueryBuilder(com.orgzly.android.query.user.InternalQueryBuilder) Query(com.orgzly.android.query.Query)

Example 4 with Query

use of com.orgzly.android.query.Query 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 5 with Query

use of com.orgzly.android.query.Query in project orgzly-android by orgzly.

the class ShareActivity method getDataFromIntent.

public Data getDataFromIntent(Intent intent) {
    Data data = new Data();
    mError = null;
    String action = intent.getAction();
    String type = intent.getType();
    if (action == null) {
    // mError = getString(R.string.share_action_not_set);
    } else if (type == null) {
    // mError = getString(R.string.share_type_not_set);
    } else if (action.equals(Intent.ACTION_SEND)) {
        if (type.startsWith("text/")) {
            if (intent.hasExtra(Intent.EXTRA_TEXT)) {
                data.title = intent.getStringExtra(Intent.EXTRA_TEXT);
            } else if (intent.hasExtra(Intent.EXTRA_STREAM)) {
                Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                data.title = uri.getLastPathSegment();
                /*
                     * Store file's content as note content.
                     */
                try {
                    File file = new File(uri.getPath());
                    /* Don't read large files. */
                    if (file.length() > MAX_TEXT_FILE_LENGTH_FOR_CONTENT) {
                        mError = "File has " + file.length() + " bytes (refusing to read files larger then " + MAX_TEXT_FILE_LENGTH_FOR_CONTENT + " bytes)";
                    } else {
                        data.content = MiscUtils.readStringFromFile(file);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    mError = "Failed reading the content of " + uri.toString() + ": " + e.toString();
                }
            }
            if (data.title != null && data.content == null && intent.hasExtra(Intent.EXTRA_SUBJECT)) {
                data.content = data.title;
                data.title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
            }
            if (intent.hasExtra(AppIntent.EXTRA_FILTER)) {
                Query query = new DottedQueryParser().parse(intent.getStringExtra(AppIntent.EXTRA_FILTER));
                String bookName = QueryUtils.INSTANCE.extractFirstBookNameFromQuery(query.getCondition());
                if (bookName != null) {
                    Book book = new Shelf(this).getBook(bookName);
                    if (book != null) {
                        data.bookId = book.getId();
                    }
                }
            }
        } else {
            mError = getString(R.string.share_type_not_supported, type);
        }
    } else if (action.equals("com.google.android.gm.action.AUTO_SEND")) {
        if (type.startsWith("text/") && intent.hasExtra(Intent.EXTRA_TEXT)) {
            data.title = intent.getStringExtra(Intent.EXTRA_TEXT);
        }
    } else {
        mError = getString(R.string.share_action_not_supported, action);
    }
    /* Make sure that title is never empty. */
    if (data.title == null) {
        data.title = "";
    }
    return data;
}
Also used : Query(com.orgzly.android.query.Query) Book(com.orgzly.android.Book) DottedQueryParser(com.orgzly.android.query.user.DottedQueryParser) Shelf(com.orgzly.android.Shelf) IOException(java.io.IOException) Uri(android.net.Uri) File(java.io.File)

Aggregations

Query (com.orgzly.android.query.Query)6 QueryParser (com.orgzly.android.query.QueryParser)3 InternalQueryParser (com.orgzly.android.query.user.InternalQueryParser)3 Book (com.orgzly.android.Book)2 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 NavigationView (android.support.design.widget.NavigationView)1 Fragment (android.support.v4.app.Fragment)1 SearchView (android.support.v7.widget.SearchView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 Shelf (com.orgzly.android.Shelf)1 AgendaCursor (com.orgzly.android.provider.AgendaCursor)1 Condition (com.orgzly.android.query.Condition)1 SqlQuery (com.orgzly.android.query.sql.SqlQuery)1 SqliteQueryBuilder (com.orgzly.android.query.sql.SqliteQueryBuilder)1 DottedQueryBuilder (com.orgzly.android.query.user.DottedQueryBuilder)1 DottedQueryParser (com.orgzly.android.query.user.DottedQueryParser)1 InternalQueryBuilder (com.orgzly.android.query.user.InternalQueryBuilder)1