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();
}
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);
}
}
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);
}
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;
}
});
}
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;
}
Aggregations