Search in sources :

Example 41 with ContentProviderClient

use of android.content.ContentProviderClient in project robolectric by robolectric.

the class ContentProviderControllerTest method shouldRegisterWithContentResolver.

@Test
public void shouldRegisterWithContentResolver() throws Exception {
    controller.create().get();
    ContentProviderClient client = contentResolver.acquireContentProviderClient("org.robolectric.authority1");
    client.query(Uri.parse("something"), new String[] { "title" }, "*", new String[] {}, "created");
    assertThat(controller.get().transcript).containsExactly("onCreate", "query for something");
    close(client);
}
Also used : ContentProviderClient(android.content.ContentProviderClient) Test(org.junit.Test)

Example 42 with ContentProviderClient

use of android.content.ContentProviderClient in project robolectric by robolectric.

the class ContentProviderControllerTest method contentProviderShouldBeCreatedBeforeBeingRegistered.

@Test
public void contentProviderShouldBeCreatedBeforeBeingRegistered() throws Exception {
    XContentProvider xContentProvider = Robolectric.setupContentProvider(XContentProvider.class, "x-authority");
    assertThat(xContentProvider.transcript).containsExactly("x-authority not registered yet");
    ContentProviderClient contentProviderClient = contentResolver.acquireContentProviderClient("x-authority");
    assertThat(contentProviderClient.getLocalContentProvider()).isSameInstanceAs(xContentProvider);
    close(contentProviderClient);
}
Also used : ContentProviderClient(android.content.ContentProviderClient) Test(org.junit.Test)

Example 43 with ContentProviderClient

use of android.content.ContentProviderClient in project robolectric by robolectric.

the class ShadowContentProviderClientTest method release_shouldRelease.

@Test
public void release_shouldRelease() {
    ContentProviderClient client = contentResolver.acquireContentProviderClient(AUTHORITY);
    ShadowContentProviderClient shadow = shadowOf(client);
    assertThat(shadow.isReleased()).isFalse();
    client.release();
    assertThat(shadow.isReleased()).isTrue();
}
Also used : ContentProviderClient(android.content.ContentProviderClient) Test(org.junit.Test)

Example 44 with ContentProviderClient

use of android.content.ContentProviderClient in project robolectric by robolectric.

the class ShadowContentProviderClientTest method release_shouldFailWhenCalledTwice.

@Test
@Config(maxSdk = M)
public void release_shouldFailWhenCalledTwice() {
    ContentProviderClient client = contentResolver.acquireContentProviderClient(AUTHORITY);
    client.release();
    assertThrows(IllegalStateException.class, () -> client.release());
}
Also used : ContentProviderClient(android.content.ContentProviderClient) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 45 with ContentProviderClient

use of android.content.ContentProviderClient in project ImageViewZoom by sephiroth74.

the class ExifUtils method getExifOrientation.

/**
 * Try to get the exif orientation of the passed image uri
 *
 * @param context
 * @param uri
 * @return
 */
public static int getExifOrientation(Context context, Uri uri) {
    final String scheme = uri.getScheme();
    ContentProviderClient provider = null;
    if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) {
        return getExifOrientation(uri.getPath());
    } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
        try {
            provider = context.getContentResolver().acquireContentProviderClient(uri);
        } catch (SecurityException e) {
            return 0;
        }
        if (provider != null) {
            Cursor result;
            try {
                result = provider.query(uri, new String[] { Images.ImageColumns.ORIENTATION, Images.ImageColumns.DATA }, null, null, null);
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }
            if (result == null) {
                return 0;
            }
            int orientationColumnIndex = result.getColumnIndex(Images.ImageColumns.ORIENTATION);
            int dataColumnIndex = result.getColumnIndex(Images.ImageColumns.DATA);
            try {
                if (result.getCount() > 0) {
                    result.moveToFirst();
                    int rotation = 0;
                    if (orientationColumnIndex > -1) {
                        rotation = result.getInt(orientationColumnIndex);
                    }
                    if (dataColumnIndex > -1) {
                        String path = result.getString(dataColumnIndex);
                        rotation |= getExifOrientation(path);
                    }
                    return rotation;
                }
            } finally {
                result.close();
            }
        }
    }
    return 0;
}
Also used : Cursor(android.database.Cursor) ContentProviderClient(android.content.ContentProviderClient) IOException(java.io.IOException)

Aggregations

ContentProviderClient (android.content.ContentProviderClient)93 RemoteException (android.os.RemoteException)30 Cursor (android.database.Cursor)28 Uri (android.net.Uri)24 ContentResolver (android.content.ContentResolver)18 Bundle (android.os.Bundle)18 FileNotFoundException (java.io.FileNotFoundException)15 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)9 Test (org.junit.Test)9 OperationCanceledException (android.os.OperationCanceledException)8 CancellationSignal (android.os.CancellationSignal)7 IContentProvider (android.content.IContentProvider)6 ActivityManager (android.app.ActivityManager)5 AlertDialog (android.app.AlertDialog)5 ClipData (android.content.ClipData)5 ComponentName (android.content.ComponentName)5 Intent (android.content.Intent)5 ServiceConnection (android.content.ServiceConnection)5 UriPermission (android.content.UriPermission)5