List of usage examples for android.database MergeCursor MergeCursor
public MergeCursor(Cursor[] cursors)
From source file:com.xbm.android.matisse.internal.loader.AlbumMediaLoader.java
@Override public Cursor loadInBackground() { Cursor result = super.loadInBackground(); if (!mEnableCapture || !MediaStoreCompat.hasCameraFeature(getContext())) { return result; }//from w w w .java 2s . c o m MatrixCursor dummy = new MatrixCursor(PROJECTION); dummy.addRow(new Object[] { Item.ITEM_ID_CAPTURE, Item.ITEM_DISPLAY_NAME_CAPTURE, "", 0, 0 }); return new MergeCursor(new Cursor[] { dummy, result }); }
From source file:ro.expectations.expenses.widget.dialog.CategoryPickerDialogFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { MatrixCursor matrixCursor = new MatrixCursor( new String[] { ExpensesContract.Accounts._ID, ExpensesContract.Accounts.TITLE }); matrixCursor.addRow(new Object[] { "0", getString(R.string.no_category) }); MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, data }); mAdapter.swapCursor(mergeCursor);//from w w w . j a va2s .co m }
From source file:com.csipsimple.ui.account.AccountsLoader.java
@Override public Cursor loadInBackground() { // First register for status updates if (loadStatus) { getContext().getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, loaderObserver);/* w ww.jav a2 s . c o m*/ } ArrayList<FilteredProfile> prefinalAccounts = new ArrayList<FilteredProfile>(); // Get all sip profiles ArrayList<SipProfile> accounts; PreferencesProviderWrapper prefsWrapper = new PreferencesProviderWrapper(getContext()); if (onlyActive && !prefsWrapper.isValidConnectionForOutgoing()) { accounts = new ArrayList<SipProfile>(); } else { accounts = SipProfile.getAllProfiles(getContext(), onlyActive, new String[] { SipProfile.FIELD_ID, SipProfile.FIELD_ACC_ID, SipProfile.FIELD_ACTIVE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD }); } // And all external call handlers Map<String, String> externalHandlers; if (loadCallHandlerPlugins) { externalHandlers = CallHandlerPlugin.getAvailableCallHandlers(getContext()); } else { externalHandlers = new HashMap<String, String>(); } if (TextUtils.isEmpty(numberToCall)) { // In case of empty number to call, just add everything without any other question for (SipProfile acc : accounts) { prefinalAccounts.add(new FilteredProfile(acc, false)); } for (Entry<String, String> extEnt : externalHandlers.entrySet()) { prefinalAccounts.add(new FilteredProfile(extEnt.getKey(), false)); } } else { // If there is a number to call, add only those callable, and flag must call entries // Note that we keep processing all call handlers voluntarily cause we may encounter a sip account that doesn't register // But is in force call mode for (SipProfile acc : accounts) { if (Filter.isCallableNumber(getContext(), acc.id, numberToCall)) { boolean forceCall = Filter.isMustCallNumber(getContext(), acc.id, numberToCall); prefinalAccounts.add(new FilteredProfile(acc, forceCall)); } } for (Entry<String, String> extEnt : externalHandlers.entrySet()) { long accId = CallHandlerPlugin.getAccountIdForCallHandler(getContext(), extEnt.getKey()); if (Filter.isCallableNumber(getContext(), accId, numberToCall)) { boolean forceCall = Filter.isMustCallNumber(getContext(), accId, numberToCall); prefinalAccounts.add(new FilteredProfile(extEnt.getKey(), forceCall)); if (forceCall) { break; } } } } // Build final cursor based on final filtered accounts Cursor[] cursorsToMerge = new Cursor[prefinalAccounts.size()]; int i = 0; for (FilteredProfile acc : prefinalAccounts) { cursorsToMerge[i++] = createCursorForAccount(acc); } if (cursorsToMerge.length > 0) { MergeCursor mg = new MergeCursor(cursorsToMerge); mg.registerContentObserver(loaderObserver); finalAccounts = prefinalAccounts; return mg; } else { finalAccounts = prefinalAccounts; return null; } }
From source file:com.fututel.ui.account.AccountsLoader.java
@Override public Cursor loadInBackground() { // First register for status updates if (loadStatus) { getContext().getContentResolver().registerContentObserver(SipProfile.ACCOUNT_STATUS_URI, true, loaderObserver);//from w w w .ja v a 2 s. co m } ArrayList<FilteredProfile> prefinalAccounts = new ArrayList<FilteredProfile>(); // Get all sip profiles ArrayList<SipProfile> accounts; PreferencesProviderWrapper prefsWrapper = new PreferencesProviderWrapper(getContext()); if (onlyActive && !prefsWrapper.isValidConnectionForOutgoing()) { accounts = new ArrayList<SipProfile>(); } else { accounts = SipProfile.getAllProfiles(getContext(), onlyActive, new String[] { SipProfile.FIELD_ID, SipProfile.FIELD_ACC_ID, SipProfile.FIELD_ACTIVE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD }); } // And all external call handlers Map<String, String> externalHandlers; if (loadCallHandlerPlugins) { externalHandlers = CallHandlerPlugin.getAvailableCallHandlers(getContext()); } else { externalHandlers = new HashMap<String, String>(); } if (TextUtils.isEmpty(numberToCall)) { // In case of empty number to call, just add everything without any other question for (SipProfile acc : accounts) { prefinalAccounts.add(new FilteredProfile(acc, false)); } for (Entry<String, String> extEnt : externalHandlers.entrySet()) { prefinalAccounts.add(new FilteredProfile(extEnt.getKey(), false)); } } else { // If there is a number to call, add only those callable, and flag must call entries // If one must call entry is found per group, just stop looping, and don't add other from the group. // Note that we keep processing external call handlers voluntarily cause we may encounter a sip account that doesn't register // But is in force call mode for (SipProfile acc : accounts) { if (Filter.isCallableNumber(getContext(), acc.id, numberToCall)) { boolean forceCall = Filter.isMustCallNumber(getContext(), acc.id, numberToCall); prefinalAccounts.add(new FilteredProfile(acc, forceCall)); if (forceCall) { break; } } } for (Entry<String, String> extEnt : externalHandlers.entrySet()) { long accId = CallHandlerPlugin.getAccountIdForCallHandler(getContext(), extEnt.getKey()); if (Filter.isCallableNumber(getContext(), accId, numberToCall)) { boolean forceCall = Filter.isMustCallNumber(getContext(), accId, numberToCall); prefinalAccounts.add(new FilteredProfile(extEnt.getKey(), forceCall)); if (forceCall) { break; } } } } // Build final cursor based on final filtered accounts Cursor[] cursorsToMerge = new Cursor[prefinalAccounts.size()]; int i = 0; for (FilteredProfile acc : prefinalAccounts) { cursorsToMerge[i++] = createCursorForAccount(acc); } if (cursorsToMerge.length > 0) { MergeCursor mg = new MergeCursor(cursorsToMerge); mg.registerContentObserver(loaderObserver); finalAccounts = prefinalAccounts; return mg; } else { finalAccounts = prefinalAccounts; return null; } }
From source file:cn.edu.wyu.documentviewer.RecentLoader.java
@Override public DirectoryResult loadInBackground() { if (mFirstPassLatch == null) { // First time through we kick off all the recent tasks, and wait // around to see if everyone finishes quickly. final Collection<RootInfo> roots = mRoots.getMatchingRootsBlocking(mState); for (RootInfo root : roots) { if ((root.flags & Root.FLAG_SUPPORTS_RECENTS) != 0) { final RecentTask task = new RecentTask(root.authority, root.rootId); mTasks.put(root, task);//w ww . j av a 2 s. c om } } mFirstPassLatch = new CountDownLatch(mTasks.size()); for (RecentTask task : mTasks.values()) { ProviderExecutor.forAuthority(task.authority).execute(task); } try { mFirstPassLatch.await(MAX_FIRST_PASS_WAIT_MILLIS, TimeUnit.MILLISECONDS); mFirstPassDone = true; } catch (InterruptedException e) { throw new RuntimeException(e); } } final long rejectBefore = System.currentTimeMillis() - REJECT_OLDER_THAN; // Collect all finished tasks boolean allDone = true; List<Cursor> cursors = Lists.newArrayList(); for (RecentTask task : mTasks.values()) { if (task.isDone()) { try { final Cursor cursor = task.get(); if (cursor == null) continue; final FilteringCursorWrapper filtered = new FilteringCursorWrapper(cursor, mState.acceptMimes, RECENT_REJECT_MIMES, rejectBefore) { @Override public void close() { // Ignored, since we manage cursor lifecycle internally } }; cursors.add(filtered); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { // We already logged on other side } } else { allDone = false; } } if (LOGD) { Log.d(TAG, "Found " + cursors.size() + " of " + mTasks.size() + " recent queries done"); } final DirectoryResult result = new DirectoryResult(); result.sortOrder = SORT_ORDER_LAST_MODIFIED; // Hint to UI if we're still loading final Bundle extras = new Bundle(); if (!allDone) { extras.putBoolean(DocumentsContract.EXTRA_LOADING, true); } final Cursor merged; if (cursors.size() > 0) { merged = new MergeCursor(cursors.toArray(new Cursor[cursors.size()])); } else { // Return something when nobody is ready merged = new MatrixCursor(new String[0]); } final SortingCursorWrapper sorted = new SortingCursorWrapper(merged, result.sortOrder) { @Override public Bundle getExtras() { return extras; } }; result.cursor = sorted; return result; }
From source file:org.thoughtcrime.securesms.PushContactSelectionListFragment.java
@Override public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) { Cursor pushCursor = ContactAccessor.getInstance().getCursorForContactsWithPush(getActivity()); ((CursorAdapter) getListAdapter()).changeCursor(new MergeCursor(new Cursor[] { pushCursor, cursor })); ((TextView) getView().findViewById(android.R.id.empty)) .setText(R.string.contact_selection_group_activity__no_contacts); }
From source file:com.hybris.mobile.app.commerce.fragment.CatalogContentFragmentBase.java
protected void onResponseSearch(String requestId, List<ProductSimple> products, SpellingSuggestion spellingSuggestion, Pagination pagination) { mInitialCall = false;/*from w w w . j a v a 2 s.co m*/ // TODO - offline - when offline work with the local search // We create a cursor based on the results, to use the same adapter as the one used for the product list from a category if (products != null) { List<DataBaseDataSimple> dataList = new ArrayList<>(); for (ProductSimple product : products) { dataList.add(new DataBaseDataSimple(product.getCode(), product.getData(), CatalogContract.SyncStatus.UPTODATE)); } // Merging old with new cursor - in case of pagination Cursor oldCursor = mProductItemsAdapter.getCursor(); Cursor newCursor = CatalogDatabaseHelper.createCursor(dataList); MergeCursor mergeCursor; if (oldCursor != null && oldCursor.getCount() > 0) { mergeCursor = new MergeCursor(new Cursor[] { oldCursor, newCursor }); } else { mergeCursor = new MergeCursor(new Cursor[] { newCursor }); } mProductItemsAdapter.swapCursor(mergeCursor); } updateUI(StringUtils.equals(requestId, mSearchRequestId), spellingSuggestion, pagination != null ? pagination.getTotalResults() : 0); mOnCategorySelectedActivated = true; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static Cursor getVisibleTopNodesCursor() { // XXX android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 final String showHidden = Preferences.getShowHidden() ? "" : " AND " + getHiddenSelection(); final String[] projection = Nodes.getDefaultProjection(); String selection = Nodes.NODE_RESOURCE_PATH + "=?" + showHidden; String[] selectionArgs = new String[] { Preferences.U1_RESOURCE }; final Cursor ubuntuOne = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); selection = Nodes.NODE_RESOURCE_PATH + "=?" + showHidden; selectionArgs = new String[] { Preferences.U1_PURCHASED_MUSIC }; final Cursor purchasedMusic = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null);/* w w w.ja va2 s . co m*/ selection = Nodes.NODE_PARENT_PATH + " IS NULL " + "AND " + Nodes.NODE_RESOURCE_PATH + "!=? " + "AND " + Nodes.NODE_RESOURCE_PATH + "!=? " + showHidden; selectionArgs = new String[] { Preferences.U1_RESOURCE, Preferences.U1_PURCHASED_MUSIC }; final Cursor cloudFolders = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); final MergeCursor cursor = new MergeCursor(new Cursor[] { ubuntuOne, purchasedMusic, cloudFolders }); cursor.setNotificationUri(sResolver, Nodes.CONTENT_URI); return cursor; }
From source file:org.fdroid.enigtext.contacts.ContactAccessor.java
/*** * If the code below looks shitty to you, that's because it was taken * directly from the Android source, where shitty code is all you get. *//*from www . j a v a 2 s . c o m*/ public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) { final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," + Contacts.DISPLAY_NAME + "," + Phone.TYPE; final String[] PROJECTION_PHONE = { Phone._ID, // 0 Phone.CONTACT_ID, // 1 Phone.TYPE, // 2 Phone.NUMBER, // 3 Phone.LABEL, // 4 Phone.DISPLAY_NAME, // 5 }; String phone = ""; String cons = null; if (constraint != null) { cons = constraint.toString(); if (RecipientsAdapter.usefulAsDigits(cons)) { phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons); if (phone.equals(cons)) { phone = ""; } else { phone = phone.trim(); } } } Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons)); String selection = String.format("%s=%s OR %s=%s OR %s=%s", Phone.TYPE, Phone.TYPE_MOBILE, Phone.TYPE, Phone.TYPE_WORK_MOBILE, Phone.TYPE, Phone.TYPE_MMS); Cursor phoneCursor = mContentResolver.query(uri, PROJECTION_PHONE, null, null, SORT_ORDER); if (phone.length() > 0) { ArrayList result = new ArrayList(); result.add(Integer.valueOf(-1)); // ID result.add(Long.valueOf(-1)); // CONTACT_ID result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE result.add(phone); // NUMBER /* * The "\u00A0" keeps Phone.getDisplayLabel() from deciding * to display the default label ("Home") next to the transformation * of the letters into numbers. */ result.add("\u00A0"); // LABEL result.add(cons); // NAME ArrayList<ArrayList> wrap = new ArrayList<ArrayList>(); wrap.add(result); ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap); return new MergeCursor(new Cursor[] { translated, phoneCursor }); } else { return phoneCursor; } }
From source file:monakhv.android.samlib.AuthorListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int sel = item.getItemId(); if (sel == android.R.id.home) { //mCallbacks.onOpenPanel(); if (getSelection() != null) { refresh(null, null);/*from w w w .ja v a 2 s . c o m*/ mCallbacks.onTitleChange(getString(R.string.app_name)); } } if (sel == R.id.menu_refresh) { startRefresh(); } if (sel == R.id.sort_option_item_books) { mCallbacks.selectBookSortOrder(); } if (sel == R.id.sort_option_item) { AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SortOrder so = SortOrder.values()[position]; mCallbacks.onAuthorSelected(0); setSortOrder(so); sortDialog.dismiss(); } }; sortDialog = SingleChoiceSelectDialog.getInstance(SortOrder.getTitles(getActivity()), listener, this.getString(R.string.dialog_title_sort_author), getSortOrder().ordinal()); sortDialog.show(getActivity().getSupportFragmentManager(), "DoSortDialog"); } if (sel == R.id.add_option_item) { View v = getActivity().findViewById(R.id.add_author_panel); v.setVisibility(View.VISIBLE); String txt = null; try { txt = getClipboardText(getActivity()); } catch (Exception ex) { Log.e(DEBUG_TAG, "Clipboard Error!", ex); } if (txt != null) { if (SamLibConfig.getParsedUrl(txt) != null) { EditText editText = (EditText) getActivity().findViewById(R.id.addUrlText); editText.setText(txt); } } } if (sel == R.id.settings_option_item) { Log.d(DEBUG_TAG, "go to Settings"); Intent prefsIntent = new Intent(getActivity().getApplicationContext(), SamlibPreferencesActivity.class); //prefsIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); getActivity().startActivityForResult(prefsIntent, MainActivity.PREFS_ACTIVITY); } if (sel == R.id.archive_option_item) { Log.d(DEBUG_TAG, "go to Archive"); Intent prefsIntent = new Intent(getActivity().getApplicationContext(), ArchiveActivity.class); //prefsIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); //startActivityForResult must be called via getActivity direct call produce wrong requestCode getActivity().startActivityForResult(prefsIntent, MainActivity.ARCHIVE_ACTIVITY); } if (sel == R.id.selected_option_item) { Log.d(DEBUG_TAG, "go to Selected"); cleanSelection(); mCallbacks.onAuthorSelected(SamLibConfig.SELECTED_BOOK_ID); } if (sel == R.id.menu_filter) { Log.d(DEBUG_TAG, "go to Filter"); Cursor tags = getActivity().getContentResolver().query(AuthorProvider.TAG_URI, null, null, null, SQLController.COL_TAG_NAME); MatrixCursor extras = new MatrixCursor( new String[] { SQLController.COL_ID, SQLController.COL_TAG_NAME }); extras.addRow(new String[] { Integer.toString(SamLibConfig.TAG_AUTHOR_ALL), getText(R.string.filter_all).toString() }); extras.addRow(new String[] { Integer.toString(SamLibConfig.TAG_AUTHOR_NEW), getText(R.string.filter_new).toString() }); Cursor[] cursors = { extras, tags }; final Cursor extendedCursor = new MergeCursor(cursors); AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { extendedCursor.moveToPosition(position); int tag_id = extendedCursor.getInt(extendedCursor.getColumnIndex(SQLController.COL_ID)); String tg_name = extendedCursor .getString(extendedCursor.getColumnIndex(SQLController.COL_TAG_NAME)); filterDialog.dismiss(); selection = SQLController.TABLE_TAGS + "." + SQLController.COL_ID + "=" + tag_id; if (tag_id == SamLibConfig.TAG_AUTHOR_ALL) { selection = null; mCallbacks.onTitleChange(getActivity().getText(R.string.app_name).toString()); } else { mCallbacks.onTitleChange(tg_name); } if (tag_id == SamLibConfig.TAG_AUTHOR_NEW) { selection = SQLController.TABLE_AUTHOR + "." + SQLController.COL_isnew + "=1"; } Log.i(DEBUG_TAG, "WHERE " + selection); refresh(selection, null); mCallbacks.onAuthorSelected(0); } }; filterDialog = FilterSelectDialog.getInstance(extendedCursor, listener, getText(R.string.dialog_title_filtr).toString()); filterDialog.show(getActivity().getSupportFragmentManager(), "FilterDialogShow"); } return super.onOptionsItemSelected(item); }