List of usage examples for android.database MatrixCursor addRow
public void addRow(Iterable<?> columnValues)
From source file:bf.io.openshop.ux.MainActivity.java
/** * Show user search whisperer with generated suggestions. * * @param query actual search query * @param searchView corresponding search action view. *///from www . j a v a 2s. c o m private void showSearchSuggestions(String query, SearchView searchView) { if (searchSuggestionsAdapter != null && searchSuggestionsList != null) { Timber.d("Populate search adapter - mySuggestions.size(): %d", searchSuggestionsList.size()); final MatrixCursor c = new MatrixCursor(new String[] { BaseColumns._ID, "categories" }); for (int i = 0; i < searchSuggestionsList.size(); i++) { if (searchSuggestionsList.get(i) != null && searchSuggestionsList.get(i).toLowerCase().startsWith(query.toLowerCase())) c.addRow(new Object[] { i, searchSuggestionsList.get(i) }); } searchView.setSuggestionsAdapter(searchSuggestionsAdapter); searchSuggestionsAdapter.changeCursor(c); } else { Timber.e("Search adapter is null or search data suggestions missing"); } }
From source file:com.csipsimple.db.DBProvider.java
/** * Build a {@link Cursor} with a single row that contains all values * provided through the given {@link ContentValues}. *///from www .j a v a 2 s . com private Cursor getCursor(ContentValues[] contentValues) { if (contentValues.length > 0) { final Set<Entry<String, Object>> valueSet = contentValues[0].valueSet(); int colSize = valueSet.size(); final String[] keys = new String[colSize]; int i = 0; for (Entry<String, Object> entry : valueSet) { keys[i] = entry.getKey(); i++; } final MatrixCursor cursor = new MatrixCursor(keys); for (ContentValues cv : contentValues) { final Object[] values = new Object[colSize]; i = 0; for (Entry<String, Object> entry : cv.valueSet()) { values[i] = entry.getValue(); i++; } cursor.addRow(values); } return cursor; } return null; }
From source file:ch.blinkenlights.android.vanilla.MediaUtils.java
/** * Returns a (possibly empty) Cursor for given file path * @param path The path to the file to be queried * @return A new Cursor object//from www. j a v a2 s. c o m * */ public static Cursor getCursorForFileQuery(String path) { MatrixCursor matrixCursor = new MatrixCursor(Song.FILLED_PROJECTION); MediaMetadataExtractor tags = new MediaMetadataExtractor(path); String title = tags.getFirst(MediaMetadataExtractor.TITLE); String album = tags.getFirst(MediaMetadataExtractor.ALBUM); String artist = tags.getFirst(MediaMetadataExtractor.ARTIST); String duration = tags.getFirst(MediaMetadataExtractor.DURATION); if (duration != null) { // looks like we will be able to play this file // Vanilla requires each file to be identified by its unique id in the media database. // However: This file is not in the database, so we are going to roll our own // using the negative crc32 sum of the path value. While this is not perfect // (the same file may be accessed using various paths) it's the fastest method // and far good enough. long songId = MediaLibrary.hash63(path) * -1; if (songId > -2) songId = -2; // must be less than -1 (-1 defines an empty song object) // Build minimal fake-database entry for this file Object[] objData = new Object[] { songId, path, "", "", "", 0, 0, 0, 0, 0 }; if (title != null) objData[2] = title; if (album != null) objData[3] = album; if (artist != null) objData[4] = artist; if (duration != null) objData[7] = Long.parseLong(duration, 10); matrixCursor.addRow(objData); } return matrixCursor; }
From source file:com.facebook.samples.booleanog.LogicActivity.java
private void updateCursor(Iterable<ActionRow> publishedItems) { MatrixCursor cursor = createEmptyCursor(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); int id = 0;/*from w w w . j a v a2 s .co m*/ for (ActionRow item : publishedItems) { Object[] row = new Object[3]; row[0] = id++; row[1] = dateFormat.format(item.publishDate); row[2] = item.actionText; cursor.addRow(row); } friendActivityAdapter.changeCursor(cursor); friendActivityAdapter.notifyDataSetChanged(); }
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
private Cursor getNotificationsCursor() { final MatrixCursor c = new MatrixCursor(TwidereDataStore.Notifications.MATRIX_COLUMNS); c.addRow(new Integer[] { NOTIFICATION_ID_HOME_TIMELINE, mUnreadStatuses.size() }); c.addRow(new Integer[] { NOTIFICATION_ID_MENTIONS_TIMELINE, mNewMentions.size() }); c.addRow(new Integer[] { NOTIFICATION_ID_DIRECT_MESSAGES, mNewMessages.size() }); return c;/*from w w w . j a v a 2 s . c o m*/ }
From source file:com.rappsantiago.weighttracker.profile.WeightProgressCursorLoader.java
@Override protected Cursor onLoadInBackground() { MatrixCursor matrixCursor = new MatrixCursor(COLS_WEIGHT_PROGRESS); double initialWeight = Util.getInitialWeight(getContext()); double currentWeight = Util.getCurrentWeight(getContext()); double targetWeight = Util.getTargetWeight(getContext()); double percentComplete = Util.computePercentComplete(initialWeight, currentWeight, targetWeight); double remainingWeight = Util.computeRemainingValue(currentWeight, targetWeight); double weightLost = Util.computeValueLost(initialWeight, currentWeight); double initialBodyFatIndex = Util.getInitialBodyFatIndex(getContext()); double currentBodyFatIndex = Util.getCurrentBodyFatIndex(getContext()); double targetBodyFatIndex = Util.getTargetBodyFatIndex(getContext()); double remainingBodyFatIndex = Util.computeRemainingValue(currentBodyFatIndex, targetBodyFatIndex); double currentFatMass = (currentBodyFatIndex / 100) * currentWeight; double currentMuscleMass = ((100 - currentBodyFatIndex) / 100) * currentWeight; matrixCursor.addRow(new Object[] { 1, initialWeight, currentWeight, percentComplete, remainingWeight, weightLost, initialBodyFatIndex, currentBodyFatIndex, remainingBodyFatIndex, currentFatMass, currentMuscleMass });//from w w w . j av a 2 s .com return matrixCursor; }
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
private Cursor getNotificationsCursor(final int id) { final MatrixCursor c = new MatrixCursor(TwidereDataStore.Notifications.MATRIX_COLUMNS); if (id == NOTIFICATION_ID_HOME_TIMELINE) { c.addRow(new Integer[] { id, mNewStatuses.size() }); } else if (id == NOTIFICATION_ID_MENTIONS_TIMELINE) { c.addRow(new Integer[] { id, mNewMentions.size() }); } else if (id == NOTIFICATION_ID_DIRECT_MESSAGES) { c.addRow(new Integer[] { id, mNewMessages.size() }); }// ww w . j a va 2 s.com return c; }
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
private Cursor getCachedImageCursor(final String url) { if (Utils.isDebugBuild()) { Log.d(LOGTAG, String.format("getCachedImageCursor(%s)", url)); }//ww w . ja v a 2s . co m final MatrixCursor c = new MatrixCursor(TwidereDataStore.CachedImages.MATRIX_COLUMNS); final File file = mImagePreloader.getCachedImageFile(url); if (url != null && file != null) { c.addRow(new String[] { url, file.getPath() }); } return c; }
From source file:com.vishwa.pinit.LocationSuggestionProvider.java
private MatrixCursor getLocationSuggestionsUsingAPI(String query, MatrixCursor cursor) { String transformedQuery = query.replace(" ", "+"); String queryUrl = mGoogleGeocodingEndpoint + transformedQuery + "&sensor=false"; try {/* w ww .j a v a2 s. co m*/ JSONObject apiResponse = new JSONObject( mAndroidHttpClient.execute(new HttpGet(queryUrl), new BasicResponseHandler())); JSONArray results = (JSONArray) apiResponse.get("results"); for (int i = 0; i < results.length(); i++) { String formattedAddress; JSONObject result = results.getJSONObject(i); if (result.has("formatted_address")) { formattedAddress = result.getString("formatted_address"); if (result.has("geometry")) { JSONObject geometry = result.getJSONObject("geometry"); if (geometry.has("location")) { JSONObject location = geometry.getJSONObject("location"); double latitude = location.getDouble("lat"); double longitude = location.getDouble("lng"); cursor.addRow(new String[] { Integer.toString(i), formattedAddress, "", latitude + "," + longitude }); } } } } return cursor; } catch (ClientProtocolException e) { cursor.addRow(new String[] { "0", "Search is not available currently", "Try again later.", "" }); return cursor; } catch (JSONException e) { cursor.addRow(new String[] { "0", "Search is not available currently", "Try again later.", "" }); return cursor; } catch (IOException e) { cursor.addRow(new String[] { "0", "Search is not available currently", "Try again later.", "" }); return cursor; } }
From source file:com.andrew.apolloMod.helpers.AddIdCursorLoader.java
@Override public Cursor loadInBackground() { Cursor mediaCursor = getContext().getContentResolver().query(mUri, mProjection, mSelection, mSelectionArgs, mSortOrder);/*from w ww.j a v a 2 s. c o m*/ //Get cursor filled with Audio Id's String[] projection = new String[] { BaseColumns._ID, AlbumColumns.ALBUM }; Uri uri = Audio.Albums.EXTERNAL_CONTENT_URI; String sortOrder = Audio.Albums.DEFAULT_SORT_ORDER; Cursor albumCursor = getContext().getContentResolver().query(uri, projection, null, null, sortOrder); //Matrix cursor to hold final data to be returned to calling context MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ARTIST, AudioColumns.ALBUM, AudioColumns.ALBUM_ID }); //Map data from Audio Id cursor to the ALbumName Colum ContentQueryMap mQueryMap = new ContentQueryMap(albumCursor, AlbumColumns.ALBUM, false, null); Map<String, ContentValues> data = mQueryMap.getRows(); if (mediaCursor != null) { while (mediaCursor.moveToNext()) { String id = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(BaseColumns._ID)); String title = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(MediaColumns.TITLE)); String artist = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(AudioColumns.ARTIST)); String album = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(AudioColumns.ALBUM)); ContentValues tData = data.get(album); String albumid = (String) tData.get(BaseColumns._ID); cursor.addRow(new String[] { id, title, artist, album, albumid }); } mediaCursor.close(); } if (cursor != null) { // Ensure the cursor window is filled registerContentObserver(cursor, mObserver); } return cursor; }