List of usage examples for android.database MatrixCursor addRow
public void addRow(Iterable<?> columnValues)
From source file:edu.purdue.safewalk.MapItems.MapJSONParser.java
/** Parses all the JSON files defined in the schemas and provides cursors to the data in each */ private void parseJSON() throws JSONException { // Create the fileCursorMap fileCursorMap = new HashMap<String, Cursor>(); // Iterate over each JSON file for (String file : jsonFiles) { // Get the resource identifier for the JSON file we're parsing String packageName = context.getPackageName(); int id = context.getResources().getIdentifier(packageName + ":raw/" + file, null, null); Log.d("JSONParsing", packageName + ":raw/" + file); // Create the buffered reader which will read in the json file BufferedReader bfr = new BufferedReader( new InputStreamReader(context.getResources().openRawResource(id))); // Read in the file line-by-line and store it in a JSONArray JSONArray array = null;/*w w w . j av a 2s . c o m*/ try { String line = null; StringBuilder sb = new StringBuilder(); while ((line = bfr.readLine()) != null) { sb.append(line); } array = new JSONArray(sb.toString()); } catch (IOException e) { e.printStackTrace(); } // Create the cursor which will store our data. // Its columns are defined by the Map provided by the schema MatrixCursor c = new MatrixCursor(fileSchemaMap.get(file)); // Populate the rows of the cursor by iterating over the json array for (int i = 0; i < array.length(); i++) { JSONObject entry = array.getJSONObject(i); // And populate the columns by iterating over the known schemas for each row Object[] row = new Object[fileSchemaMap.get(file).length]; for (int col = 0; col < fileSchemaMap.get(file).length; col++) { row[col] = entry.get(fileSchemaMap.get(file)[col]); } c.addRow(row); } // Map the filename string to the cursor we just created fileCursorMap.put(file, c); } }
From source file:be.brunoparmentier.openbikesharing.app.activities.StationsListActivity.java
private void loadData(String query) { ArrayList<Station> queryStations = new ArrayList<>(); String[] columns = new String[] { "_id", "text" }; Object[] temp = new Object[] { 0, "default" }; MatrixCursor cursor = new MatrixCursor(columns); if (stations != null) { for (int i = 0; i < stations.size(); i++) { Station station = stations.get(i); if (station.getName().toLowerCase().contains(query.toLowerCase())) { temp[0] = i;// w w w . j av a 2s . c o m temp[1] = station.getName(); cursor.addRow(temp); queryStations.add(station); } } } searchView.setSuggestionsAdapter(new SearchStationAdapter(this, cursor, queryStations)); }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
private static Cursor getPreferencesCursor(final SharedPreferencesWrapper preferences, final String key) { final MatrixCursor c = new MatrixCursor(FiretweetDataStore.Preferences.MATRIX_COLUMNS); final Map<String, Object> map = new HashMap<>(); final Map<String, ?> all = preferences.getAll(); if (key == null) { map.putAll(all);//w w w .ja v a 2 s . c om } else { map.put(key, all.get(key)); } for (final Map.Entry<String, ?> item : map.entrySet()) { final Object value = item.getValue(); final int type = getPreferenceType(value); c.addRow(new Object[] { item.getKey(), ParseUtils.parseString(value), type }); } return c; }
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 ww . ja v a2 s . c om*/ 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:com.android.music.PlaylistBrowserFragment.java
private Cursor mergedCursor(Cursor c) { if (c == null) { return null; }// ww w. j a v a 2s . co m if (c instanceof MergeCursor) { // this shouldn't happen, but fail gracefully Log.d("PlaylistBrowserActivity", "Already wrapped"); return c; } MatrixCursor autoplaylistscursor = new MatrixCursor(mCols); if (mCreateShortcut) { ArrayList<Object> all = new ArrayList<Object>(2); all.add(ALL_SONGS_PLAYLIST); all.add(getString(R.string.play_all)); autoplaylistscursor.addRow(all); } ArrayList<Object> recent = new ArrayList<Object>(2); recent.add(RECENTLY_ADDED_PLAYLIST); recent.add(getString(R.string.recentlyadded)); autoplaylistscursor.addRow(recent); // check if there are any podcasts Cursor counter = MusicUtils.query(getActivity(), MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { "count(*)" }, "is_podcast=1", null, null); if (counter != null) { counter.moveToFirst(); int numpodcasts = counter.getInt(0); counter.close(); if (numpodcasts > 0) { ArrayList<Object> podcasts = new ArrayList<Object>(2); podcasts.add(PODCASTS_PLAYLIST); podcasts.add(getString(R.string.podcasts_listitem)); autoplaylistscursor.addRow(podcasts); } } Cursor cc = new MergeCursor(new Cursor[] { autoplaylistscursor, c }); return cc; }
From source file:com.android.ex.chips.RecipientAlternatesAdapter.java
/** * @return a new cursor based on the given cursor with all duplicate destinations removed. * It's only intended to use for the alternate list, so... * - This method ignores all other fields and dedupe solely on the destination. Normally, * if a cursor contains multiple contacts and they have the same destination, we'd still want * to show both.//w w w . ja v a 2 s. com * - This method creates a MatrixCursor, so all data will be kept in memory. We wouldn't want * to do this if the original cursor is large, but it's okay here because the alternate list * won't be that big. */ // Visible for testing /* package */static Cursor removeDuplicateDestinations(Cursor original) { final MatrixCursor result = new MatrixCursor(original.getColumnNames(), original.getCount()); final HashSet<String> destinationsSeen = new HashSet<String>(); original.moveToPosition(-1); while (original.moveToNext()) { final String destination = original.getString(Query.DESTINATION); if (destinationsSeen.contains(destination)) { continue; } destinationsSeen.add(destination); Object[] cursorObjects; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { cursorObjects = new Object[] { original.getString(Query.NAME), original.getString(Query.DESTINATION), original.getInt(Query.DESTINATION_TYPE), original.getString(Query.DESTINATION_LABEL), original.getLong(Query.CONTACT_ID), original.getLong(Query.DATA_ID), original.getString(Query.PHOTO_THUMBNAIL_URI), original.getInt(Query.DISPLAY_NAME_SOURCE) }; } else { cursorObjects = new Object[] { original.getString(Query.NAME), original.getString(Query.DESTINATION), original.getInt(Query.DESTINATION_TYPE), original.getString(Query.DESTINATION_LABEL), original.getLong(Query.CONTACT_ID), original.getLong(Query.DATA_ID), original.getString(Query.PHOTO_ID) }; } result.addRow(cursorObjects); } return result; }
From source file:com.mattprecious.telescope.FileProvider.java
/** * Use a content URI returned by//w w w . jav a 2 s . c om * {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file * managed by the FileProvider. * FileProvider reports the column names defined in {@link android.provider.OpenableColumns}: * <ul> * <li>{@link android.provider.OpenableColumns#DISPLAY_NAME}</li> * <li>{@link android.provider.OpenableColumns#SIZE}</li> * </ul> * For more information, see * {@link ContentProvider#query(Uri, String[], String, String[], String) * ContentProvider.query()}. * * @param uri A content URI returned by {@link #getUriForFile}. * @param projection The list of columns to put into the {@link Cursor}. If null all columns are * included. * @param selection Selection criteria to apply. If null then all data that matches the content * URI is returned. * @param selectionArgs An array of {@link java.lang.String}, containing arguments to bind to * the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to * right and iterates through <i>selectionArgs</i>, replacing the current "?" character in * <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The * values are bound to <i>selection</i> as {@link java.lang.String} values. * @param sortOrder A {@link java.lang.String} containing the column name(s) on which to sort * the resulting {@link Cursor}. * @return A {@link Cursor} containing the results of the query. */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // ContentProvider has already checked granted permissions final File file = mStrategy.getFileForUri(uri); if (projection == null) { projection = COLUMNS; } String[] cols = new String[projection.length]; Object[] values = new Object[projection.length]; int i = 0; for (String col : projection) { if (OpenableColumns.DISPLAY_NAME.equals(col)) { cols[i] = OpenableColumns.DISPLAY_NAME; values[i++] = file.getName(); } else if (OpenableColumns.SIZE.equals(col)) { cols[i] = OpenableColumns.SIZE; values[i++] = file.length(); } } cols = copyOf(cols, i); values = copyOf(values, i); final MatrixCursor cursor = new MatrixCursor(cols, 1); cursor.addRow(values); return cursor; }
From source file:com.peaceworld.wikisms.view.newui.BaseActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void loadData(String query) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Load data from list to cursor String[] columns = new String[] { "_id", "text", "cid" }; Object[] temp = new Object[] { 0, "name", -1l }; MatrixCursor cursor = new MatrixCursor(columns); int index = 0; for (int i = 0; i < items.size(); i++) { if (query == null || items.get(i).getName().contains(query.trim())) { temp[0] = index;// www. j av a 2 s . c o m temp[1] = items.get(i).getName(); temp[2] = items.get(i).getId(); cursor.addRow(temp); index++; } } temp[0] = index; temp[1] = " " + " \"" + query + "\" "; temp[2] = query.trim(); cursor.addRow(temp); SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchView search = (SearchView) menu.findItem(R.id.menu_search).getActionView(); search.setSearchableInfo(manager.getSearchableInfo(getComponentName())); ActionBarSearchAdapter adapter = new ActionBarSearchAdapter(this, cursor, this, search); search.setSuggestionsAdapter(adapter); } }
From source file:com.hippo.content.FileProvider.java
/** * Use a content URI returned by//from w w w . jav a 2 s. c o m * {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file * managed by the FileProvider. * FileProvider reports the column names defined in {@link android.provider.MediaStore.MediaColumns}: * <ul> * <li>{@link android.provider.MediaStore.MediaColumns#DISPLAY_NAME}</li> * <li>{@link android.provider.MediaStore.MediaColumns#SIZE}</li> * <li>{@link android.provider.MediaStore.MediaColumns#DATA}</li> * </ul> * For more information, see * {@link ContentProvider#query(Uri, String[], String, String[], String) * ContentProvider.query()}. * * @param uri A content URI returned by {@link #getUriForFile}. * @param projection The list of columns to put into the {@link Cursor}. If null all columns are * included. * @param selection Selection criteria to apply. If null then all data that matches the content * URI is returned. * @param selectionArgs An array of {@link java.lang.String}, containing arguments to bind to * the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to * right and iterates through <i>selectionArgs</i>, replacing the current "?" character in * <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The * values are bound to <i>selection</i> as {@link java.lang.String} values. * @param sortOrder A {@link java.lang.String} containing the column name(s) on which to sort * the resulting {@link Cursor}. * @return A {@link Cursor} containing the results of the query. * */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // ContentProvider has already checked granted permissions final File file = mStrategy.getFileForUri(uri); if (projection == null) { projection = COLUMNS; } String[] cols = new String[projection.length]; Object[] values = new Object[projection.length]; int i = 0; for (String col : projection) { if (MediaStore.MediaColumns.DISPLAY_NAME.equals(col)) { cols[i] = MediaStore.MediaColumns.DISPLAY_NAME; values[i++] = file.getName(); } else if (MediaStore.MediaColumns.SIZE.equals(col)) { cols[i] = MediaStore.MediaColumns.SIZE; values[i++] = file.length(); } else if (MediaStore.MediaColumns.DATA.equals(col)) { cols[i] = MediaStore.MediaColumns.DATA; values[i++] = file.getPath(); } } cols = copyOf(cols, i); values = copyOf(values, i); final MatrixCursor cursor = new MatrixCursor(cols, 1); cursor.addRow(values); return cursor; }
From source file:com.vishwa.pinit.LocationSuggestionProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { switch (uriMatcher.match(uri)) { case SEARCH_SUGGEST: String query = uri.getLastPathSegment(); MatrixCursor cursor = new MatrixCursor(SEARCH_SUGGEST_COLUMNS, 1); if (Geocoder.isPresent()) { try { mGeocoder = new Geocoder(getContext(), Locale.ENGLISH); List<Address> addressList = mGeocoder.getFromLocationName(query, 5); for (int i = 0; i < addressList.size(); i++) { Address address = addressList.get(i); StringBuilder fullAddress = new StringBuilder(); for (int j = 1; j < address.getMaxAddressLineIndex(); j++) { fullAddress.append(address.getAddressLine(j)); }/*w ww.j ava 2s .c om*/ cursor.addRow(new String[] { Integer.toString(i), address.getAddressLine(0).toString(), fullAddress.toString(), address.getLatitude() + "," + address.getLongitude() }); } return cursor; } catch (IllegalArgumentException e) { return getLocationSuggestionsUsingAPI(query, cursor); } catch (IOException e) { return getLocationSuggestionsUsingAPI(query, cursor); } } default: throw new IllegalArgumentException("Unknown Uri: " + uri); } }