List of usage examples for android.database MatrixCursor addRow
public void addRow(Iterable<?> columnValues)
From source file:org.linphone.ContactsManager.java
public Cursor getFriendListCursor(List<Contact> contacts, boolean shouldGroupBy) { String[] columns = new String[] { ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME }; if (!shouldGroupBy) { return null; }//from w w w . j ava 2 s. co m MatrixCursor result = new MatrixCursor(columns); Set<String> groupBy = new HashSet<String>(); for (Contact contact : contacts) { String name = contact.getName(); if (!groupBy.contains(name)) { groupBy.add(name); Object[] newRow = new Object[2]; newRow[0] = contact.getID(); newRow[1] = contact.getName(); result.addRow(newRow); } } return result; }
From source file:fr.matthiasbosc.translucentmap.PlaceProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor c = null;//w w w .ja v a 2s. co m PlaceJSONParser parser = new PlaceJSONParser(); PlaceDetailsJSONParser detailsParser = new PlaceDetailsJSONParser(); String jsonString = ""; String jsonPlaceDetails = ""; List<HashMap<String, String>> list = null; List<HashMap<String, String>> detailsList = null; MatrixCursor mCursor = null; switch (mUriMatcher.match(uri)) { case SEARCH: // Defining a cursor object with columns description, lat and lng mCursor = new MatrixCursor(new String[] { "description", "lat", "lng" }); // Create a parser object to parse places in JSON format parser = new PlaceJSONParser(); // Create a parser object to parse place details in JSON format detailsParser = new PlaceDetailsJSONParser(); // Get Places from Google Places API jsonString = getPlaces(selectionArgs); try { // Parse the places ( JSON => List ) list = parser.parse(new JSONObject(jsonString)); // Finding latitude and longitude for each places using Google Places Details API for (int i = 0; i < list.size(); i++) { HashMap<String, String> hMap = (HashMap<String, String>) list.get(i); detailsParser = new PlaceDetailsJSONParser(); // Get Place details jsonPlaceDetails = getPlaceDetails(hMap.get("reference")); // Parse the details ( JSON => List ) detailsList = detailsParser.parse(new JSONObject(jsonPlaceDetails)); // Creating cursor object with places for (int j = 0; j < detailsList.size(); j++) { HashMap<String, String> hMapDetails = detailsList.get(j); // Adding place details to cursor mCursor.addRow(new String[] { hMap.get("description"), hMapDetails.get("lat"), hMapDetails.get("lng") }); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } c = mCursor; break; case SUGGESTIONS: // Defining a cursor object with columns id, SUGGEST_COLUMN_TEXT_1, SUGGEST_COLUMN_INTENT_EXTRA_DATA mCursor = new MatrixCursor(new String[] { "_id", SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA }); // Creating a parser object to parse places in JSON format parser = new PlaceJSONParser(); // Get Places from Google Places API jsonString = getPlaces(selectionArgs); try { // Parse the places ( JSON => List ) list = parser.parse(new JSONObject(jsonString)); // Creating cursor object with places for (int i = 0; i < list.size(); i++) { HashMap<String, String> hMap = (HashMap<String, String>) list.get(i); // Adding place details to cursor mCursor.addRow( new String[] { Integer.toString(i), hMap.get("description"), hMap.get("reference") }); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } c = mCursor; break; case DETAILS: // Defining a cursor object with columns description, lat and lng mCursor = new MatrixCursor(new String[] { "description", "lat", "lng" }); detailsParser = new PlaceDetailsJSONParser(); jsonPlaceDetails = getPlaceDetails(selectionArgs[0]); try { detailsList = detailsParser.parse(new JSONObject(jsonPlaceDetails)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (int j = 0; j < detailsList.size(); j++) { HashMap<String, String> hMapDetails = detailsList.get(j); mCursor.addRow(new String[] { hMapDetails.get("formatted_address"), hMapDetails.get("lat"), hMapDetails.get("lng") }); } c = mCursor; break; } return c; }
From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data == null) { return;//from w w w . j a v a 2s . c om } int id = loader.getId(); switch (id) { case METHODS_CURSOR: mMethodsCursor = data; View methodContainer = findViewById(R.id.MethodRow); if (mMethodsAdapter == null || !data.moveToFirst()) { methodContainer.setVisibility(View.GONE); } else { methodContainer.setVisibility(View.VISIBLE); MatrixCursor extras = new MatrixCursor(new String[] { KEY_ROWID, KEY_LABEL, KEY_IS_NUMBERED }); extras.addRow(new String[] { "0", "- - - -", "0" }); mMethodsAdapter.swapCursor(new MergeCursor(new Cursor[] { extras, data })); if (mSavedInstance) { mTransaction.methodId = mMethodId; } if (mTransaction.methodId != null) { while (data.isAfterLast() == false) { if (data.getLong(data.getColumnIndex(KEY_ROWID)) == mTransaction.methodId) { mMethodSpinner.setSelection(data.getPosition() + 1); break; } data.moveToNext(); } } else { mMethodSpinner.setSelection(0); } } break; case ACCOUNTS_CURSOR: mAccountsAdapter.swapCursor(data); mAccounts = new Account[data.getCount()]; if (mSavedInstance) { mTransaction.accountId = mAccountId; mTransaction.transfer_account = mTransferAccountId; } data.moveToFirst(); boolean selectionSet = false; String currencyExtra = getIntent().getStringExtra(KEY_CURRENCY); while (data.isAfterLast() == false) { int position = data.getPosition(); Account a = Account.fromCacheOrFromCursor(data); mAccounts[position] = a; if (!selectionSet && (a.currency.getCurrencyCode().equals(currencyExtra) || (currencyExtra == null && a.getId().equals(mTransaction.accountId)))) { mAccountSpinner.setSelection(position); setAccountLabel(a); selectionSet = true; } data.moveToNext(); } //if the accountId we have been passed does not exist, we select the first entry if (mAccountSpinner.getSelectedItemPosition() == android.widget.AdapterView.INVALID_POSITION) { mAccountSpinner.setSelection(0); mTransaction.accountId = mAccounts[0].getId(); setAccountLabel(mAccounts[0]); } if (mOperationType == MyExpenses.TYPE_TRANSFER) { mTransferAccountCursor = new FilterCursorWrapper(data); int selectedPosition = setTransferAccountFilterMap(); mTransferAccountsAdapter.swapCursor(mTransferAccountCursor); mTransferAccountSpinner.setSelection(selectedPosition); mTransaction.transfer_account = mTransferAccountSpinner.getSelectedItemId(); configureTransferInput(); if (!mNewInstance && !(mTransaction instanceof Template)) { isProcessingLinkedAmountInputs = true; mTransferAmountText.setAmount(mTransaction.getTransferAmount().getAmountMajor().abs()); updateExchangeRates(); isProcessingLinkedAmountInputs = false; } } else { //the methods cursor is based on the current account, //hence it is loaded only after the accounts cursor is loaded if (!(mTransaction instanceof SplitPartCategory)) { mManager.initLoader(METHODS_CURSOR, null, this); } } mTypeButton.setEnabled(true); configureType(); configureStatusSpinner(); if (mIsResumed) setupListeners(); break; case LAST_EXCHANGE_CURSOR: if (data.moveToFirst()) { final Currency currency1 = getCurrentAccount().currency; final Currency currency2 = Account .getInstanceFromDb(mTransferAccountSpinner.getSelectedItemId()).currency; if (currency1.getCurrencyCode().equals(data.getString(0)) && currency2.getCurrencyCode().equals(data.getString(1))) { BigDecimal amount = new Money(currency1, data.getLong(2)).getAmountMajor(); BigDecimal transferAmount = new Money(currency2, data.getLong(3)).getAmountMajor(); BigDecimal exchangeRate = amount.compareTo(nullValue) != 0 ? transferAmount.divide(amount, EXCHANGE_RATE_FRACTION_DIGITS, RoundingMode.DOWN) : nullValue; if (exchangeRate.compareTo(nullValue) != 0) { mExchangeRate1Text.setAmount(exchangeRate); } } } } }
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 w ww .j a v a2s.co m*/ 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:de.vanita5.twittnuker.provider.TwidereDataProvider.java
private Cursor getUnreadCountsCursor(final int position) { final MatrixCursor c = new MatrixCursor(TwidereDataStore.UnreadCounts.MATRIX_COLUMNS); final Context context = getContext(); final SupportTabSpec tab = CustomTabUtils.getAddedTabAt(context, position); if (tab == null) return c; final int count; if (TAB_TYPE_HOME_TIMELINE.equals(tab.type) || TAB_TYPE_STAGGERED_HOME_TIMELINE.equals(tab.type)) { final long account_id = tab.args != null ? tab.args.getLong(EXTRA_ACCOUNT_ID, -1) : -1; final long[] account_ids = account_id > 0 ? new long[] { account_id } : getActivatedAccountIds(context); count = getUnreadCount(mUnreadStatuses, account_ids); } else if (TAB_TYPE_MENTIONS_TIMELINE.equals(tab.type)) { final long account_id = tab.args != null ? tab.args.getLong(EXTRA_ACCOUNT_ID, -1) : -1; final long[] account_ids = account_id > 0 ? new long[] { account_id } : getActivatedAccountIds(context); count = getUnreadCount(mUnreadMentions, account_ids); } else if (TAB_TYPE_DIRECT_MESSAGES.equals(tab.type)) { final long account_id = tab.args != null ? tab.args.getLong(EXTRA_ACCOUNT_ID, -1) : -1; final long[] account_ids = account_id > 0 ? new long[] { account_id } : getActivatedAccountIds(context); count = getUnreadCount(mUnreadMessages, account_ids); } else {//from w ww.j av a2s. c om count = 0; } if (tab.type != null) { c.addRow(new Object[] { position, tab.type, count }); } return c; }
From source file:com.av.remusic.service.MediaService.java
private void updateCursor(final long trackId) { MusicInfo info = mPlaylistInfo.get(trackId); if (mPlaylistInfo.get(trackId) != null) { MatrixCursor cursor = new MatrixCursor(PROJECTION); cursor.addRow(new Object[] { info.songId, info.artist, info.albumName, info.musicName, info.data, info.albumData, info.albumId, info.artistId }); cursor.moveToFirst();/*w w w .ja v a2 s. c o m*/ mCursor = cursor; cursor.close(); } }
From source file:com.av.remusic.service.MediaService.java
private void updateCursorForDownloadedFile(Context context, Uri uri) { synchronized (this) { closeCursor();// w w w . j av a 2 s.c o m MatrixCursor cursor = new MatrixCursor(PROJECTION_MATRIX); String title = getValueForDownloadedFile(this, uri, "title"); cursor.addRow(new Object[] { null, null, null, title, null, null, null, null }); mCursor = cursor; mCursor.moveToFirst(); } }
From source file:com.cyanogenmod.eleven.MusicPlaybackService.java
/** * Creates a pseudo cursor for downloaded audio files with minimal info * * @param context needed to query the download uri * @param uri the uri of the downloaded file *//*from w ww.jav a 2 s . c o m*/ private void updateCursorForDownloadedFile(Context context, Uri uri) { synchronized (this) { closeCursor(); // clear mCursor MatrixCursor cursor = new MatrixCursor(PROJECTION_MATRIX); // get title of the downloaded file ; Downloads.Impl.COLUMN_TITLE String title = getValueForDownloadedFile(this, uri, "title"); // populating the cursor with bare minimum info cursor.addRow(new Object[] { null, null, null, title, null, null, null, null }); mCursor = cursor; mCursor.moveToFirst(); } }
From source file:com.adityarathi.muo.services.AudioPlaybackService.java
/** * This method combines the current cursor with the specified playlist cursor. * @param newCursor/*from www . jav a 2 s. c o m*/ */ public void enqueuePlaylistCursor(Cursor newCursor) { String[] matrixCursorColumns = { DBAccessHelper.SONG_ARTIST, DBAccessHelper.SONG_ALBUM, DBAccessHelper.SONG_TITLE, DBAccessHelper.SONG_FILE_PATH, DBAccessHelper.SONG_DURATION, DBAccessHelper.SONG_GENRE, DBAccessHelper.SONG_ID, DBAccessHelper.SONG_ALBUM_ART_PATH, DBAccessHelper.SONG_SOURCE }; //Create an empty matrix getCursor() with the specified columns. MatrixCursor mMatrixCursor = new MatrixCursor(matrixCursorColumns); //Make a copy of the old getCursor() and copy it's contents over to the matrix getCursor(). Cursor tempCursor = getCursor(); tempCursor.moveToFirst(); MediaMetadataRetriever mMMDR = new MediaMetadataRetriever(); for (int i = 0; i < tempCursor.getCount(); i++) { tempCursor.moveToPosition(i); //Check which type of getCursor() the service currently has. if (getCursor().getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) { //We'll have to manually extract the info from the audio file. /* String songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.PLAYLIST_SONG_FILE_PATH)); try { mMMDR.setDataSource(songFilePath); } catch (Exception e) { //Skip the song if there's a problem with reading it. continue; }*/ String songArtist = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); String songAlbum = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); String songTitle = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); String songDuration = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); String songGenre = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE); mMatrixCursor .addRow(new Object[] { songArtist, songAlbum, songTitle, "", songDuration, songGenre }); } else { mMatrixCursor.addRow( new Object[] { tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)), tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ALBUM)), tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_TITLE)), tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)), tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_DURATION)), tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_GENRE)), tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ID)), tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH)), tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_SOURCE)) }); } } tempCursor.close(); //Copy the contents of the new getCursor() over to the MatrixCursor. if (newCursor.getCount() > 0) { String songArtist = ""; String songAlbum = ""; String songTitle = ""; String filePath = ""; String songDuration = ""; for (int j = 0; j < newCursor.getCount(); j++) { /* newCursor.moveToPosition(j); filePath = newCursor.getString(newCursor.getColumnIndex(DBAccessHelper.PLAYLIST_SONG_FILE_PATH)); try { mMMDR.setDataSource(filePath); } catch (Exception e) { continue; }*/ //Get the metadata from the song file. songArtist = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); songAlbum = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); songTitle = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); songDuration = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); String songGenre = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE); mMatrixCursor.addRow( new Object[] { songArtist, songAlbum, songTitle, filePath, songDuration, songGenre }); } } mEnqueuePerformed = true; newCursor.close(); mCursor = (Cursor) mMatrixCursor; mMatrixCursor.close(); }
From source file:com.google.android.dialer.provider.DialerProvider.java
private Cursor buildResultCursor(String[] array, JSONArray jsonArray, int n) throws JSONException { int indexDisplayName = -1; int indexData3 = -1; int indexHasPhoneNumber = -1; int indexId = -1; int indexContactId = -1; int indexData1 = -1; int indexData2 = -1; int indexPhotoUri = -1; int indexPhotoThumbUri = -1; int indexLookup = -1; for (int i = 0; i < array.length; ++i) { String s = array[i];//from w w w. j av a 2 s . co m if ("display_name".equals(s)) { indexDisplayName = i; } else if ("data3".equals(s)) { indexData3 = i; } else if ("has_phone_number".equals(s)) { indexHasPhoneNumber = i; } else if ("_id".equals(s)) { indexId = i; } else if ("contact_id".equals(s)) { indexContactId = i; } else if ("data1".equals(s)) { indexData1 = i; } else if ("data2".equals(s)) { indexData2 = i; } else if ("photo_uri".equals(s)) { indexPhotoUri = i; } else if ("photo_thumb_uri".equals(s)) { indexPhotoThumbUri = i; } else if ("lookup".equals(s)) { indexLookup = i; } } ContentResolver resolver = getContext().getContentResolver(); boolean showNearbyDistance = Gservices.getBoolean(resolver, "dialer_debug_display_nearby_place_distance", false); int n12; if (Gservices.getBoolean(resolver, "dialer_enable_nearby_places_export", true)) { n12 = 2; } else { n12 = 0; } MatrixCursor matrixCursor = new MatrixCursor(array); JSONArray jsonArray2 = jsonArray.getJSONArray(1); int n13 = 1; int position = 0; while (position < jsonArray2.length()) { try { JSONArray jsonArray3 = jsonArray2.getJSONArray(position); String displayName = decodeHtml(jsonArray3.getString(0)); JSONObject jsonObject = jsonArray3.getJSONObject(3); String data1 = decodeHtml(jsonObject.getString("b")); String data3 = decodeHtml(jsonObject.getString("g")); String optString = jsonObject.optString("f", null); String photoUri = jsonObject.optString("d", null); if (showNearbyDistance) { String miles = jsonObject.optString("c", null); if (miles != null) { displayName = displayName + " [" + miles + " miles]"; } } if (!data1.isEmpty()) { Object[] array2 = new Object[array.length]; if (indexDisplayName >= 0) { array2[indexDisplayName] = displayName; } if (indexData3 >= 0) { array2[indexData3] = data3; } if (indexHasPhoneNumber >= 0) { array2[indexHasPhoneNumber] = true; } if (indexContactId != -1) { array2[indexContactId] = n13; } if (indexData1 >= 0) { array2[indexData1] = data1; } if (indexData2 >= 0) { array2[indexData2] = 12; } String photoThumbUri; if (photoUri == null) { photoUri = new Uri.Builder().scheme("android.resource") .authority("com.google.android.dialer") .appendPath(String.valueOf(R.drawable.ic_places_picture_180_holo_light)).toString(); photoThumbUri = new Uri.Builder().scheme("android.resource") .authority("com.google.android.dialer") .appendPath(String.valueOf(R.drawable.ic_places_picture_holo_light)).toString(); } else { photoThumbUri = photoUri; } if (indexPhotoUri >= 0) { array2[indexPhotoUri] = photoUri; } if (indexPhotoThumbUri >= 0) { array2[indexPhotoThumbUri] = photoThumbUri; } if (indexLookup >= 0) { JSONObject put = new JSONObject() .put("vnd.android.cursor.item/name", new JSONObject().put("data1", displayName)) .put("vnd.android.cursor.item/phone_v2", JsonUtil.newJsonArray( new JSONObject().put("data1", data1).put("data2", 12))) .put("vnd.android.cursor.item/postal-address_v2", JsonUtil.newJsonArray( new JSONObject().put("data1", displayName + ", " + data3).put("data2", 2))); if (optString != null) { put.put("vnd.android.cursor.item/website", JsonUtil .newJsonArray(new JSONObject().put("data1", optString).put("data2", 3))); } array2[indexLookup] = new JSONObject().put("display_name", displayName) .put("display_name_source", 30).put("exportSupport", n12).put("photo_uri", photoUri) .put("vnd.android.cursor.item/contact", put).toString(); } if (indexId != -1) { array2[indexId] = n13; } matrixCursor.addRow(array2); if (n != -1 && matrixCursor.getCount() >= n) { break; } n13++; } } catch (JSONException e) { Log.e("DialerProvider", "Skipped the suggestions at position " + position, e); } position++; } return matrixCursor; }