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);
}
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);
}
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();
}
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());
}
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;
}
Aggregations