List of usage examples for android.database MatrixCursor MatrixCursor
public MatrixCursor(String[] columnNames)
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
private static Cursor getPreferencesCursor(final SharedPreferencesWrapper preferences, final String key) { final MatrixCursor c = new MatrixCursor(TwidereDataStore.Preferences.MATRIX_COLUMNS); final Map<String, Object> map = new HashMap<>(); final Map<String, ?> all = preferences.getAll(); if (key == null) { map.putAll(all);//from w ww . ja va2s.c o m } 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.adityarathi.muo.services.AudioPlaybackService.java
/** * This method combines the current cursor with the specified playlist cursor. * @param newCursor//from ww w. java2s . 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: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);/*from w w w . j av a 2s. com*/ } 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.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 www. j a v a2 s .com 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: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 ww w .j a v a 2 s . c om*/ 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:com.av.remusic.service.MediaService.java
private void updateCursorForDownloadedFile(Context context, Uri uri) { synchronized (this) { closeCursor();//from w ww . j a v 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:org.totschnig.myexpenses.activity.ExpenseEdit.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data == null) { return;//from ww w .j av a 2 s .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); } } } } }