Search in sources :

Example 76 with TargetApi

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;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) LinkedList(java.util.LinkedList) TargetApi(android.annotation.TargetApi)

Example 77 with TargetApi

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;
}
Also used : Cursor(android.database.Cursor) Uri(android.net.Uri) TargetApi(android.annotation.TargetApi)

Example 78 with TargetApi

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;
}
Also used : Date(java.util.Date) TargetApi(android.annotation.TargetApi)

Example 79 with TargetApi

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));
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity) Fragment(android.support.v4.app.Fragment) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 80 with TargetApi

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;
}
Also used : ScanFilter(android.bluetooth.le.ScanFilter) ArrayList(java.util.ArrayList) TargetApi(android.annotation.TargetApi)

Aggregations

TargetApi (android.annotation.TargetApi)1365 Intent (android.content.Intent)153 View (android.view.View)147 Test (org.junit.Test)119 SuppressLint (android.annotation.SuppressLint)115 Uri (android.net.Uri)70 ArrayList (java.util.ArrayList)68 Animator (android.animation.Animator)67 Point (android.graphics.Point)64 Window (android.view.Window)56 TextView (android.widget.TextView)56 IOException (java.io.IOException)56 ViewGroup (android.view.ViewGroup)53 Matchers.anyString (org.mockito.Matchers.anyString)53 SharedPreferences (android.content.SharedPreferences)44 File (java.io.File)44 Field (java.lang.reflect.Field)44 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)43 Bitmap (android.graphics.Bitmap)42 ImageView (android.widget.ImageView)40