@Test public void testSwapCursor() { SimpleCursorAdapter adapter = new SimpleCursorAdapter(context, 1, null, new String[] {"name"}, new int[] {2}, 0); Cursor cursor = setUpDatabase(); adapter.swapCursor(cursor); assertThat(adapter.getCursor()).isSameAs(cursor); }
@Test public void testChangeCursor() { SimpleCursorAdapter adapter = new SimpleCursorAdapter(context, 1, null, new String[] {"name"}, new int[] {2}, 0); Cursor cursor = setUpDatabase(); adapter.changeCursor(cursor); assertThat(adapter.getCursor()).isSameAs(cursor); }
@Test public void testSwapCursorToNull() { SimpleCursorAdapter adapter = new SimpleCursorAdapter(context, 1, null, new String[] {"name"}, new int[] {2}, 0); Cursor cursor = setUpDatabase(); adapter.swapCursor(cursor); adapter.swapCursor(null); assertThat(adapter.getCursor()).isNull(); }
private void startRingdroidEditor() { Cursor c = mAdapter.getCursor(); int dataIndex = c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA); String filename = c.getString(dataIndex); try { Intent intent = new Intent(Intent.ACTION_EDIT, Uri.parse(filename)); intent.putExtra("was_get_content_intent", mWasGetContentIntent); intent.setClassName( "com.ringdroid", "com.ringdroid.RingdroidEditActivity"); startActivityForResult(intent, REQUEST_CODE_EDIT); } catch (Exception e) { Log.e("Ringdroid", "Couldn't start editor"); } }
private Uri getUri(){ //Get the uri of the item that is in the row Cursor c = mAdapter.getCursor(); int uriIndex = getUriIndex(c); if (uriIndex == -1) { return null; } String itemUri = c.getString(uriIndex) + "/" + c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID)); return (Uri.parse(itemUri)); }
private void setList() { listHosts.setAdapter(hostsAdapter); listHosts.setOnItemClickListener((parent, view, position, id) -> { Cursor cursor = hostsAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { selectedHost = new Host(); selectedHost.initFromCursor(cursor); buttonMigrateToSelected.setEnabled(true); } }); }
private void onDelete() { Cursor c = mAdapter.getCursor(); int dataIndex = c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA); String filename = c.getString(dataIndex); int uriIndex = getUriIndex(c); if (uriIndex == -1) { showFinalAlert(getResources().getText(R.string.delete_failed)); return; } if (!new File(filename).delete()) { showFinalAlert(getResources().getText(R.string.delete_failed)); } String itemUri = c.getString(uriIndex) + "/" + c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media._ID)); getContentResolver().delete(Uri.parse(itemUri), null, null); }
private void assignRingtoneToContact() { Cursor c = mAdapter.getCursor(); int dataIndex = c.getColumnIndexOrThrow(Contacts._ID); String contactId = c.getString(dataIndex); dataIndex = c.getColumnIndexOrThrow(Contacts.DISPLAY_NAME); String displayName = c.getString(dataIndex); Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, contactId); ContentValues values = new ContentValues(); values.put(Contacts.CUSTOM_RINGTONE, mRingtoneUri.toString()); getContentResolver().update(uri, values, null, null); String message = getResources().getText(R.string.success_contact_ringtone) + " " + displayName; Toast.makeText(this, message, Toast.LENGTH_SHORT) .show(); finish(); return; }
private void setAsDefaultRingtoneOrNotification(){ Cursor c = mAdapter.getCursor(); // If the item is a ringtone then set the default ringtone, // otherwise it has to be a notification so set the default notification sound if (0 != c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.IS_RINGTONE))){ RingtoneManager.setActualDefaultRingtoneUri( RingdroidSelectActivity.this, RingtoneManager.TYPE_RINGTONE, getUri()); Toast.makeText( RingdroidSelectActivity.this, R.string.default_ringtone_success_message, Toast.LENGTH_SHORT) .show(); } else { RingtoneManager.setActualDefaultRingtoneUri( RingdroidSelectActivity.this, RingtoneManager.TYPE_NOTIFICATION, getUri()); Toast.makeText( RingdroidSelectActivity.this, R.string.default_notification_success_message, Toast.LENGTH_SHORT) .show(); } }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); Cursor c = mAdapter.getCursor(); String title = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)); menu.setHeaderTitle(title); menu.add(0, CMD_EDIT, 0, R.string.context_menu_edit); menu.add(0, CMD_DELETE, 0, R.string.context_menu_delete); // Add items to the context menu item based on file type if (0 != c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.IS_RINGTONE))) { menu.add(0, CMD_SET_AS_DEFAULT, 0, R.string.context_menu_default_ringtone); menu.add(0, CMD_SET_AS_CONTACT, 0, R.string.context_menu_contact); } else if (0 != c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.Media.IS_NOTIFICATION))) { menu.add(0, CMD_SET_AS_DEFAULT, 0, R.string.context_menu_default_notification); } }
private void confirmDelete() { Cursor c = mAdapter.getCursor(); String artist = c.getString(c.getColumnIndexOrThrow( MediaStore.Audio.Media.ARTIST));
private void showUnsent() { mShowUnsent = true; Cursor c = mShowUnsent ? getUnsentCursor() : getAllCursor(); Cursor old = mInstances.getCursor(); try { mInstances.changeCursor(c); } finally { if (old != null) { old.close(); this.stopManagingCursor(old); } } getListView().invalidate(); }
private void showAll() { mShowUnsent = false; Cursor c = mShowUnsent ? getUnsentCursor() : getAllCursor(); Cursor old = mInstances.getCursor(); try { mInstances.changeCursor(c); } finally { if (old != null) { old.close(); this.stopManagingCursor(old); } } getListView().invalidate(); }