use of android.annotation.TargetApi in project muzei by romannurik.
the class GallerySettingsActivity method getImagesFromTreeUri.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private List<Uri> getImagesFromTreeUri(final Uri treeUri, final int maxImages) {
List<Uri> images = new ArrayList<>();
Queue<String> directories = new LinkedList<>();
directories.add(DocumentsContract.getTreeDocumentId(treeUri));
while (images.size() < maxImages && !directories.isEmpty()) {
String parentDocumentId = directories.poll();
final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(treeUri, parentDocumentId);
Cursor children;
try {
children = getContentResolver().query(childrenUri, new String[] { DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_MIME_TYPE }, null, null, null);
} catch (SecurityException e) {
// No longer can read this URI, which means no images from this URI
// This a temporary state as the next onLoadFinished() will remove this item entirely
children = null;
}
if (children == null) {
continue;
}
while (children.moveToNext()) {
String documentId = children.getString(children.getColumnIndex(DocumentsContract.Document.COLUMN_DOCUMENT_ID));
String mimeType = children.getString(children.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE));
if (DocumentsContract.Document.MIME_TYPE_DIR.equals(mimeType)) {
directories.add(documentId);
} else if (mimeType != null && mimeType.startsWith("image/")) {
// Add images to the list
images.add(DocumentsContract.buildDocumentUriUsingTree(treeUri, documentId));
}
if (images.size() == maxImages) {
break;
}
}
children.close();
}
return images;
}
use of android.annotation.TargetApi in project muzei by romannurik.
the class GallerySettingsActivity method getDisplayNameForTreeUri.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private String getDisplayNameForTreeUri(Uri treeUri) {
Uri documentUri = DocumentsContract.buildDocumentUriUsingTree(treeUri, DocumentsContract.getTreeDocumentId(treeUri));
Cursor data = getContentResolver().query(documentUri, new String[] { DocumentsContract.Document.COLUMN_DISPLAY_NAME }, null, null, null);
String displayName = null;
if (data != null && data.moveToNext()) {
displayName = data.getString(data.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME));
}
if (data != null) {
data.close();
}
return displayName;
}
use of android.annotation.TargetApi in project realm-java by realm.
the class NullTypesRealmProxy method createUsingJsonStream.
@SuppressWarnings("cast")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static some.test.NullTypes createUsingJsonStream(Realm realm, JsonReader reader) throws IOException {
some.test.NullTypes obj = new some.test.NullTypes();
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (false) {
} else if (name.equals("fieldStringNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldStringNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldStringNotNull((String) reader.nextString());
}
} else if (name.equals("fieldStringNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldStringNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldStringNull((String) reader.nextString());
}
} else if (name.equals("fieldBooleanNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldBooleanNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldBooleanNotNull((boolean) reader.nextBoolean());
}
} else if (name.equals("fieldBooleanNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldBooleanNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldBooleanNull((boolean) reader.nextBoolean());
}
} else if (name.equals("fieldBytesNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldBytesNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldBytesNotNull(JsonUtils.stringToBytes(reader.nextString()));
}
} else if (name.equals("fieldBytesNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldBytesNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldBytesNull(JsonUtils.stringToBytes(reader.nextString()));
}
} else if (name.equals("fieldByteNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldByteNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldByteNotNull((byte) reader.nextInt());
}
} else if (name.equals("fieldByteNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldByteNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldByteNull((byte) reader.nextInt());
}
} else if (name.equals("fieldShortNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldShortNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldShortNotNull((short) reader.nextInt());
}
} else if (name.equals("fieldShortNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldShortNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldShortNull((short) reader.nextInt());
}
} else if (name.equals("fieldIntegerNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldIntegerNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldIntegerNotNull((int) reader.nextInt());
}
} else if (name.equals("fieldIntegerNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldIntegerNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldIntegerNull((int) reader.nextInt());
}
} else if (name.equals("fieldLongNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldLongNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldLongNotNull((long) reader.nextLong());
}
} else if (name.equals("fieldLongNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldLongNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldLongNull((long) reader.nextLong());
}
} else if (name.equals("fieldFloatNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldFloatNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldFloatNotNull((float) reader.nextDouble());
}
} else if (name.equals("fieldFloatNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldFloatNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldFloatNull((float) reader.nextDouble());
}
} else if (name.equals("fieldDoubleNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldDoubleNotNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldDoubleNotNull((double) reader.nextDouble());
}
} else if (name.equals("fieldDoubleNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldDoubleNull(null);
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldDoubleNull((double) reader.nextDouble());
}
} else if (name.equals("fieldDateNotNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldDateNotNull(null);
} else if (reader.peek() == JsonToken.NUMBER) {
long timestamp = reader.nextLong();
if (timestamp > -1) {
((NullTypesRealmProxyInterface) obj).realmSet$fieldDateNotNull(new Date(timestamp));
}
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldDateNotNull(JsonUtils.stringToDate(reader.nextString()));
}
} else if (name.equals("fieldDateNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldDateNull(null);
} else if (reader.peek() == JsonToken.NUMBER) {
long timestamp = reader.nextLong();
if (timestamp > -1) {
((NullTypesRealmProxyInterface) obj).realmSet$fieldDateNull(new Date(timestamp));
}
} else {
((NullTypesRealmProxyInterface) obj).realmSet$fieldDateNull(JsonUtils.stringToDate(reader.nextString()));
}
} else if (name.equals("fieldObjectNull")) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
((NullTypesRealmProxyInterface) obj).realmSet$fieldObjectNull(null);
} else {
some.test.NullTypes fieldObjectNullObj = NullTypesRealmProxy.createUsingJsonStream(realm, reader);
((NullTypesRealmProxyInterface) obj).realmSet$fieldObjectNull(fieldObjectNullObj);
}
} else {
reader.skipValue();
}
}
reader.endObject();
obj = realm.copyToRealm(obj);
return obj;
}
use of android.annotation.TargetApi in project glide by bumptech.
the class RequestManagerRetrieverTest method testDoesNotThrowIfAskedToGetManagerForFragmentPreHoneyCombMr2.
@Test
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void testDoesNotThrowIfAskedToGetManagerForFragmentPreHoneyCombMr2() {
Util.setSdkVersionInt(Build.VERSION_CODES.HONEYCOMB_MR1);
Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
android.app.Fragment fragment = new android.app.Fragment();
activity.getFragmentManager().beginTransaction().add(fragment, "test").commit();
android.app.Fragment spyFragment = Mockito.spy(fragment);
when(spyFragment.isDetached()).thenThrow(new NoSuchMethodError());
assertNotNull(retriever.get(spyFragment));
}
use of android.annotation.TargetApi in project android_wear_for_ios by shiitakeo.
the class MusicControlActivity method create_scan_filter.
@TargetApi(21)
private List<ScanFilter> create_scan_filter() {
// ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(service_ancs)).build();
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(service_ams)).build();
List<ScanFilter> list = new ArrayList<ScanFilter>(1);
list.add(filter);
return list;
}
Aggregations