List of usage examples for android.database MatrixCursor MatrixCursor
public MatrixCursor(String[] columnNames)
From source file:org.linphone.compatibility.ApiFivePlus.java
public static Cursor getGeneralContactCursor(ContentResolver cr, String select, boolean shouldGroupBy) { String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME }; String query;/*from w ww .j a v a 2 s . com*/ query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")"; Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, " lower(" + Data.DISPLAY_NAME + ") COLLATE UNICODE ASC"); if (!shouldGroupBy || cursor == null) { return cursor; } MatrixCursor result = new MatrixCursor(cursor.getColumnNames()); Set<String> groupBy = new HashSet<String>(); while (cursor.moveToNext()) { String name = cursor.getString(getCursorDisplayNameColumnIndex(cursor)); if (!groupBy.contains(name)) { groupBy.add(name); Object[] newRow = new Object[cursor.getColumnCount()]; int contactID = cursor.getColumnIndex(Data.CONTACT_ID); int displayName = cursor.getColumnIndex(Data.DISPLAY_NAME); newRow[contactID] = cursor.getString(contactID); newRow[displayName] = cursor.getString(displayName); result.addRow(newRow); } } cursor.close(); return result; }
From source file:org.sufficientlysecure.privacybox.VaultProvider.java
@Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection)); final RowBuilder row = result.newRow(); row.add(Root.COLUMN_ROOT_ID, DEFAULT_ROOT_ID); row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_LOCAL_ONLY); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_label)); row.add(Root.COLUMN_DOCUMENT_ID, DEFAULT_DOCUMENT_ID); row.add(Root.COLUMN_ICON, R.drawable.ic_launcher); row.add(Root.COLUMN_SUMMARY, "todo: display user id?"); return result; }
From source file:org.sufficientlysecure.keychain.ui.ImportKeysSearchFragment.java
private void updateAdapter(String query) { mCurrentSuggestions.clear();/*from w w w . j a v a 2 s . c o m*/ MatrixCursor c = new MatrixCursor(new String[] { BaseColumns._ID, CURSOR_SUGGESTION }); for (int i = 0; i < mNamesAndEmails.size(); i++) { String s = mNamesAndEmails.get(i); if (s.toLowerCase().startsWith(query.toLowerCase())) { mCurrentSuggestions.add(s); c.addRow(new Object[] { i, s }); } } mSearchAdapter.changeCursor(c); }
From source file:de.janrenz.app.mediathek.ArdMediathekProvider.java
private Cursor processResultForList(String result, Boolean doReverse) { MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "title", "subtitle", "image", "extId", "startTime", "startTimeAsTimestamp", "isLive" }); try {/*from ww w. j a v a2 s. c om*/ JSONArray jsonArray = new JSONArray(result); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json_data; if (doReverse == true) { json_data = jsonArray.getJSONObject(jsonArray.length() - (i + 1)); } else { json_data = jsonArray.getJSONObject(i); } // build the Headline String t2 = android.text.Html.fromHtml(json_data.getString("Title3")).toString(); String t3 = android.text.Html.fromHtml(json_data.getString("Title2")).toString(); // Handle grouped views Boolean IsGrouped = false; try { IsGrouped = json_data.getBoolean("IsGrouped"); } catch (Exception e) { //this value might not exists } if (IsGrouped) { String mtime = json_data.getString("BTime").toString(); String cliplisturl = "http://m-service.daserste.de/appservice/1.4.2/video/clip/list/" + mtime + "/" + URLEncoder.encode(t3) + "?func=getVideoClipList&clipTimestamp=" + mtime + "&clipTitle=" + URLEncoder.encode(t3); String result2 = ""; result2 = readJSONFeed(cliplisturl); JSONArray jsonArray2 = new JSONArray(result2); for (int j = 0; j < jsonArray2.length(); j++) { JSONObject json_data2 = jsonArray2.getJSONObject(j); t2 = android.text.Html.fromHtml(json_data2.getString("Title3")).toString(); t3 = android.text.Html.fromHtml(json_data2.getString("Title2")).toString(); // only add movie if it has a video if (android.text.Html.fromHtml(json_data2.getString("VId")).toString() != "") { cursor.addRow(new Object[] { 1000 + j, t2, t3, json_data2.getString("ImageUrl").toString(), json_data2.getString("VId"), json_data2.getString("BTimeF").toString(), json_data2.getString("BTime").toString(), json_data2.getString("IsLive") }); } } } Boolean hideLive = false; try { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); hideLive = sharedPref.getBoolean(SettingsActivity.HIDE_LIVE, false); } catch (Exception e) { } Boolean IsGrouped2 = false; try { IsGrouped2 = json_data.getBoolean("IsGrouped"); } catch (Exception e) { //this value might not exists } if (!IsGrouped2) { if (!json_data.getString("VId").equalsIgnoreCase("")) { if (json_data.getString("IsLive").toString().equalsIgnoreCase("false") || (json_data.getString("IsLive").toString().equalsIgnoreCase("true") && hideLive == false)) cursor.addRow(new Object[] { i, t2, t3, json_data.getString("ImageUrl").toString(), json_data.getString("VId"), json_data.getString("BTimeF").toString(), json_data.getString("BTime").toString(), json_data.getString("IsLive") }); } } } } catch (JSONException e) { e.printStackTrace(); return (Cursor) cursor; } return (Cursor) cursor; }
From source file:com.csipsimple.ui.favorites.FavLoader.java
/** * Creates a cursor that contains contacts group corresponding to an sip * account./*from w w w . j a va 2 s .c o m*/ */ private Cursor createContentCursorFor(SipProfile account) { Cursor c = null; if (!TextUtils.isEmpty(account.android_group)) { c = ContactsWrapper.getInstance().getContactsByGroup(getContext(), account.android_group); } if (c != null) { return c; } MatrixCursor mc = new MatrixCursor(new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE }); mc.addRow(new Object[] { account.id, ContactsWrapper.TYPE_CONFIGURE }); return mc; }
From source file:com.roamprocess1.roaming4world.ui.favorites.FavLoader.java
/** * Creates a cursor that contains contacts group corresponding to an sip * account./* w ww .j av a 2s. com*/ */ private Cursor createContentCursorFor(SipProfile account) { Cursor c = null; if (!TextUtils.isEmpty(account.android_group)) { c = ContactsWrapper.getInstance().getContactsByGroup(getContext(), account.android_group); } if (c != null) { return c; } MatrixCursor mc = new MatrixCursor(new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE }); mc.addRow(new Object[] { account.id, ContactsWrapper.TYPE_CONFIGURE }); return mc; }
From source file:com.esri.arcgisruntime.sample.findaddress.MainActivity.java
/** * Sets up the address SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. *///www .ja v a2 s. c o m private void setupAddressSearchView() { mAddressGeocodeParameters = new GeocodeParameters(); // get place name and address attributes mAddressGeocodeParameters.getResultAttributeNames().add("PlaceName"); mAddressGeocodeParameters.getResultAttributeNames().add("StAddr"); // return only the closest result mAddressGeocodeParameters.setMaxResults(1); mAddressSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { // geocode typed address geoCodeTypedAddress(address); // clear focus from search views mAddressSearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the results of the async operation List<SuggestResult> suggestResults = suggestionsFuture.get(); MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each address suggestion to a new row for (SuggestResult result : suggestResults) { suggestionsCursor.addRow(new Object[] { key++, result.getLabel() }); } // define SimpleCursorAdapter String[] cols = new String[] { COLUMN_NAME_ADDRESS }; int[] to = new int[] { R.id.suggestion_address }; final SimpleCursorAdapter suggestionAdapter = new SimpleCursorAdapter( MainActivity.this, R.layout.suggestion, suggestionsCursor, cols, to, 0); mAddressSearchView.setSuggestionsAdapter(suggestionAdapter); // handle an address suggestion being chosen mAddressSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // get the selected row MatrixCursor selectedRow = (MatrixCursor) suggestionAdapter .getItem(position); // get the row's index int selectedCursorIndex = selectedRow.getColumnIndex(COLUMN_NAME_ADDRESS); // get the string from the row at index String address = selectedRow.getString(selectedCursorIndex); // use clicked suggestion as query mAddressSearchView.setQuery(address, true); return true; } }); } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); } return true; } }); }
From source file:com.wecandoit.jinju_0_0_4.jActivity_YoutubeSearchList.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Used to put dark icons on light action bar boolean isLight = SampleList.THEME == R.style.Theme_Sherlock_Light; // Create the search view mSearchView = new SearchView(getSupportActionBar().getThemedContext()); // mSearchView.setIconifiedByDefault(false);// jTODO ??. // mSearchView.setIconified(false); // mSearchView.onActionViewExpanded(); mSearchView.setQueryHint("Search for Internet"); mSearchView.setOnQueryTextListener(this); mSearchView.setSubmitButtonEnabled(true); //mSearchView.setOnSuggestionListener(this); if (mSuggestionsAdapter == null) { MatrixCursor cursor = new MatrixCursor(COLUMNS); cursor.addRow(new String[] { "1", "Let It Go" }); cursor.addRow(new String[] { "2", "steve jobs" }); cursor.addRow(new String[] { "3", "TED" }); mSuggestionsAdapter = new SuggestionsAdapter(getSupportActionBar().getThemedContext(), cursor); }/*from w w w . j a v a2 s . c o m*/ mSearchView.setSuggestionsAdapter(mSuggestionsAdapter); mSearchView.setIconified(false); mSearchView.setIconifiedByDefault(false); //mSearchView.getActionView().expandActionView(); mSearchView.requestFocus(); MenuItem searchMenuItem = menu.add("Search"); searchMenuItem.setIcon(isLight ? R.drawable.ic_search_inverse : R.drawable.abs__ic_search) .setActionView(mSearchView) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); searchMenuItem.expandActionView(); return true; }
From source file:org.andstatus.app.msg.TimelineFragment.java
private Cursor getEmptyCursor() { return new MatrixCursor(TimelineSql.getTimelineProjection()); }
From source file:net.sf.fdshare.BaseProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final String filePath = uri.getPath(); if (TextUtils.isEmpty(filePath)) throw new IllegalArgumentException("Empty path!"); if (projection == null) { projection = new String[] { MediaStore.MediaColumns.MIME_TYPE, OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };/*w w w . j a v a 2 s. c o m*/ } final MatrixCursor result = new MatrixCursor(projection); final TimestampedMime info = guessTypeInternal(filePath); final Object[] row = new Object[projection.length]; for (int i = 0; i < projection.length; i++) { String projColumn = projection[i]; if (TextUtils.isEmpty(projColumn)) continue; switch (projColumn.toLowerCase()) { case OpenableColumns.DISPLAY_NAME: row[i] = uri.getLastPathSegment(); break; case OpenableColumns.SIZE: row[i] = info.size >= 0 ? info.size : null; break; case MediaStore.MediaColumns.MIME_TYPE: final String forcedType = uri.getQueryParameter("type"); if (!TextUtils.isEmpty(forcedType)) row[i] = "null".equals(forcedType) ? null : forcedType; else row[i] = info.mime[0]; break; case MediaStore.MediaColumns.DATA: Log.w("BaseProvider", "Relying on MediaColumns.DATA is unreliable and must be avoided!"); row[i] = uri.getPath(); break; } } result.addRow(row); return result; }