Search in sources :

Example 1 with CursorLoader

use of android.support.v4.content.CursorLoader in project WordPress-Android by wordpress-mobile.

the class EditPostActivity method getRealPathFromContentURI.

private String getRealPathFromContentURI(Uri contentUri) {
    if (contentUri == null)
        return null;
    String[] proj = { android.provider.MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(this, contentUri, proj, null, null, null);
    Cursor cursor = loader.loadInBackground();
    if (cursor == null)
        return null;
    int column_index = cursor.getColumnIndex(proj[0]);
    if (column_index == -1) {
        cursor.close();
        return null;
    }
    String path;
    if (cursor.moveToFirst()) {
        path = cursor.getString(column_index);
    } else {
        path = null;
    }
    cursor.close();
    return path;
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Cursor(android.database.Cursor)

Example 2 with CursorLoader

use of android.support.v4.content.CursorLoader in project robolectric by robolectric.

the class ShadowCursorLoaderTest method testGetters.

@Test
public void testGetters() {
    Uri uri = Uri.parse("http://robolectric.org");
    String[] projection = new String[] { "_id", "TestColumn" };
    String selection = "_id = ?";
    String[] selectionArgs = new String[] { "5" };
    String sortOrder = "_id";
    CursorLoader cursorLoader = new CursorLoader(RuntimeEnvironment.application, uri, projection, selection, selectionArgs, sortOrder);
    assertThat(cursorLoader.getUri()).isEqualTo(uri);
    assertThat(cursorLoader.getProjection()).isEqualTo(projection);
    assertThat(cursorLoader.getSelection()).isEqualTo(selection);
    assertThat(cursorLoader.getSelectionArgs()).isEqualTo(selectionArgs);
    assertThat(cursorLoader.getSortOrder()).isEqualTo(sortOrder);
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Uri(android.net.Uri) Test(org.junit.Test)

Example 3 with CursorLoader

use of android.support.v4.content.CursorLoader in project AgentWeb by Justson.

the class AgentWebUtils method getRealPathBelowVersion.

private static String getRealPathBelowVersion(Context context, Uri uri) {
    String filePath = null;
    String[] projection = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(context, uri, projection, null, null, null);
    Cursor cursor = loader.loadInBackground();
    if (cursor != null) {
        cursor.moveToFirst();
        filePath = cursor.getString(cursor.getColumnIndex(projection[0]));
        cursor.close();
    }
    return filePath;
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) SpannableString(android.text.SpannableString) Cursor(android.database.Cursor)

Example 4 with CursorLoader

use of android.support.v4.content.CursorLoader in project AmazeFileManager by TeamAmaze.

the class MainActivity method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (cloudSyncTask != null && cloudSyncTask.getStatus() == AsyncTask.Status.RUNNING) {
        cloudSyncTask.cancel(true);
    }
    Uri uri = Uri.withAppendedPath(Uri.parse("content://" + CloudContract.PROVIDER_AUTHORITY), "/keys.db/secret_keys");
    String[] projection = new String[] { CloudContract.COLUMN_ID, CloudContract.COLUMN_CLIENT_ID, CloudContract.COLUMN_CLIENT_SECRET_KEY };
    switch(id) {
        case REQUEST_CODE_CLOUD_LIST_KEY:
            Uri uriAppendedPath = uri;
            switch(OpenMode.getOpenMode(args.getInt(ARGS_KEY_LOADER, 2))) {
                case GDRIVE:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 2);
                    break;
                case DROPBOX:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 3);
                    break;
                case BOX:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 4);
                    break;
                case ONEDRIVE:
                    uriAppendedPath = ContentUris.withAppendedId(uri, 5);
                    break;
            }
            return new CursorLoader(this, uriAppendedPath, projection, null, null, null);
        case REQUEST_CODE_CLOUD_LIST_KEYS:
            try {
                List<CloudEntry> cloudEntries = cloudHandler.getAllEntries();
                // we want keys for services saved in database, and the cloudrail app key which
                // is at index 1
                String[] ids = new String[cloudEntries.size() + 1];
                ids[0] = 1 + "";
                for (int i = 1; i <= cloudEntries.size(); i++) {
                    // we need to get only those cloud details which user wants
                    switch(cloudEntries.get(i - 1).getServiceType()) {
                        case GDRIVE:
                            ids[i] = 2 + "";
                            break;
                        case DROPBOX:
                            ids[i] = 3 + "";
                            break;
                        case BOX:
                            ids[i] = 4 + "";
                            break;
                        case ONEDRIVE:
                            ids[i] = 5 + "";
                            break;
                    }
                }
                return new CursorLoader(this, uri, projection, CloudContract.COLUMN_ID, ids, null);
            } catch (CloudPluginException e) {
                e.printStackTrace();
                Toast.makeText(this, getResources().getString(R.string.cloud_error_plugin), Toast.LENGTH_LONG).show();
            }
        default:
            return null;
    }
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) CloudEntry(com.amaze.filemanager.database.models.CloudEntry) Uri(android.net.Uri)

Example 5 with CursorLoader

use of android.support.v4.content.CursorLoader in project fdroidclient by f-droid.

the class ManageReposActivity method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    Uri uri = RepoProvider.allExceptSwapUri();
    final String[] projection = { RepoTable.Cols._ID, RepoTable.Cols.NAME, RepoTable.Cols.SIGNING_CERT, RepoTable.Cols.FINGERPRINT, RepoTable.Cols.IN_USE };
    return new CursorLoader(this, uri, projection, null, null, null);
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Uri(android.net.Uri)

Aggregations

CursorLoader (android.support.v4.content.CursorLoader)36 Uri (android.net.Uri)18 Cursor (android.database.Cursor)13 Test (org.junit.Test)8 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 SpannableString (android.text.SpannableString)5 TagMetadataTest (com.google.samples.apps.iosched.model.TagMetadataTest)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Context (android.content.Context)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SettingsMockContext (com.google.samples.apps.iosched.testutils.SettingsMockContext)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 Loader (android.support.v4.content.Loader)1 SimpleCursorAdapter (android.support.v4.widget.SimpleCursorAdapter)1 CloudEntry (com.amaze.filemanager.database.models.CloudEntry)1 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)1