Search in sources :

Example 96 with TargetApi

use of android.annotation.TargetApi in project storio by pushtorefresh.

the class RxChangesObserverTest method shouldEmitChangesOnSdkVersionLowerThan16.

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Test
public void shouldEmitChangesOnSdkVersionLowerThan16() {
    for (int sdkVersion = MIN_SDK_VERSION; sdkVersion < 16; sdkVersion++) {
        ContentResolver contentResolver = mock(ContentResolver.class);
        final Map<Uri, ContentObserver> contentObservers = new HashMap<Uri, ContentObserver>(3);
        doAnswer(new Answer() {

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                contentObservers.put((Uri) invocation.getArguments()[0], (ContentObserver) invocation.getArguments()[2]);
                return null;
            }
        }).when(contentResolver).registerContentObserver(any(Uri.class), eq(true), any(ContentObserver.class));
        TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
        Uri uri1 = mock(Uri.class);
        Uri uri2 = mock(Uri.class);
        Set<Uri> uris = new HashSet<Uri>(2);
        uris.add(uri1);
        uris.add(uri2);
        RxChangesObserver.observeChanges(contentResolver, uris, mock(Handler.class), sdkVersion).subscribe(testSubscriber);
        testSubscriber.assertNoTerminalEvent();
        testSubscriber.assertNoValues();
        // Emulate change of Uris, Observable should react and emit Changes objects
        contentObservers.get(uri1).onChange(false);
        contentObservers.get(uri2).onChange(false);
        testSubscriber.assertValues(Changes.newInstance(uri1), Changes.newInstance(uri2));
        testSubscriber.unsubscribe();
        testSubscriber.assertNoErrors();
    }
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) HashMap(java.util.HashMap) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TestSubscriber(rx.observers.TestSubscriber) ContentObserver(android.database.ContentObserver) HashSet(java.util.HashSet) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 97 with TargetApi

use of android.annotation.TargetApi in project storio by pushtorefresh.

the class RxChangesObserverTest method shouldEmitChangesOnSdkVersionGreaterThan15.

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Test
public void shouldEmitChangesOnSdkVersionGreaterThan15() {
    for (int sdkVersion = 16; sdkVersion < MAX_SDK_VERSION; sdkVersion++) {
        ContentResolver contentResolver = mock(ContentResolver.class);
        final AtomicReference<ContentObserver> contentObserver = new AtomicReference<ContentObserver>();
        doAnswer(new Answer() {

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                // Save reference to ContentObserver only once to assert that it was created once
                if (contentObserver.get() == null) {
                    contentObserver.set((ContentObserver) invocation.getArguments()[2]);
                } else if (contentObserver.get() != invocation.getArguments()[2]) {
                    throw new AssertionError("More than one ContentObserver was created");
                }
                return null;
            }
        }).when(contentResolver).registerContentObserver(any(Uri.class), eq(true), any(ContentObserver.class));
        TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
        Uri uri1 = mock(Uri.class);
        Uri uri2 = mock(Uri.class);
        Set<Uri> uris = new HashSet<Uri>(2);
        uris.add(uri1);
        uris.add(uri2);
        RxChangesObserver.observeChanges(contentResolver, uris, mock(Handler.class), sdkVersion).subscribe(testSubscriber);
        testSubscriber.assertNoTerminalEvent();
        testSubscriber.assertNoValues();
        // RxChangesObserver should ignore call to onChange() without Uri on sdkVersion >= 16
        contentObserver.get().onChange(false);
        testSubscriber.assertNoValues();
        // Emulate change of Uris, Observable should react and emit Changes objects
        contentObserver.get().onChange(false, uri1);
        contentObserver.get().onChange(false, uri2);
        testSubscriber.assertValues(Changes.newInstance(uri1), Changes.newInstance(uri2));
        testSubscriber.unsubscribe();
        testSubscriber.assertNoErrors();
    }
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) AtomicReference(java.util.concurrent.atomic.AtomicReference) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TestSubscriber(rx.observers.TestSubscriber) ContentObserver(android.database.ContentObserver) HashSet(java.util.HashSet) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 98 with TargetApi

use of android.annotation.TargetApi in project platform_frameworks_base by android.

the class RenderTarget method forSurfaceTexture.

@TargetApi(11)
public RenderTarget forSurfaceTexture(SurfaceTexture surfaceTexture) {
    EGLConfig eglConfig = chooseEglConfig(mEgl, mDisplay);
    EGLSurface eglSurf = null;
    synchronized (mSurfaceSources) {
        eglSurf = mSurfaceSources.get(surfaceTexture);
        if (eglSurf == null) {
            eglSurf = mEgl.eglCreateWindowSurface(mDisplay, eglConfig, surfaceTexture, null);
            mSurfaceSources.put(surfaceTexture, eglSurf);
        }
    }
    checkEglError(mEgl, "eglCreateWindowSurface");
    checkSurface(mEgl, eglSurf);
    RenderTarget result = new RenderTarget(mDisplay, mContext, eglSurf, 0, false, true);
    result.setSurfaceSource(surfaceTexture);
    result.addReferenceTo(eglSurf);
    return result;
}
Also used : EGLSurface(javax.microedition.khronos.egl.EGLSurface) EGLConfig(javax.microedition.khronos.egl.EGLConfig) TargetApi(android.annotation.TargetApi)

Example 99 with TargetApi

use of android.annotation.TargetApi in project grpc-java by grpc.

the class TesterOkHttpChannelBuilder method getSslCertificateSocketFactory.

@TargetApi(14)
private static SSLCertificateSocketFactory getSslCertificateSocketFactory(@Nullable InputStream testCa, String androidSocketFatoryTls) throws Exception {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) /* API level 14 */
    {
        throw new RuntimeException("android_socket_factory_tls doesn't work with API level less than 14.");
    }
    SSLCertificateSocketFactory factory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(5000);
    // Use HTTP/2.0
    byte[] h2 = "h2".getBytes();
    byte[][] protocols = new byte[][] { h2 };
    if (androidSocketFatoryTls.equals("alpn")) {
        Method setAlpnProtocols = factory.getClass().getDeclaredMethod("setAlpnProtocols", byte[][].class);
        setAlpnProtocols.invoke(factory, new Object[] { protocols });
    } else if (androidSocketFatoryTls.equals("npn")) {
        Method setNpnProtocols = factory.getClass().getDeclaredMethod("setNpnProtocols", byte[][].class);
        setNpnProtocols.invoke(factory, new Object[] { protocols });
    } else {
        throw new RuntimeException("Unknown protocol: " + androidSocketFatoryTls);
    }
    if (testCa != null) {
        factory.setTrustManagers(getTrustManagers(testCa));
    }
    return factory;
}
Also used : SSLCertificateSocketFactory(android.net.SSLCertificateSocketFactory) Method(java.lang.reflect.Method) TargetApi(android.annotation.TargetApi)

Example 100 with TargetApi

use of android.annotation.TargetApi in project AndroidPicker by gzu-liyujiang.

the class ConvertUtils method toPath.

/**
     * 从第三方文件选择器获取路径。
     * 参见:http://blog.csdn.net/zbjdsbj/article/details/42387551
     */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String toPath(Context context, Uri uri) {
    if (uri == null) {
        LogUtils.verbose("uri is null");
        return "";
    }
    LogUtils.verbose("uri: " + uri.toString());
    String path = uri.getPath();
    String scheme = uri.getScheme();
    String authority = uri.getAuthority();
    //是否是4.4及以上版本
    boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        String docId = DocumentsContract.getDocumentId(uri);
        String[] split = docId.split(":");
        String type = split[0];
        Uri contentUri = null;
        switch(authority) {
            // ExternalStorageProvider
            case "com.android.externalstorage.documents":
                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }
                break;
            // DownloadsProvider
            case "com.android.providers.downloads.documents":
                contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
                return _queryPathFromMediaStore(context, contentUri, null, null);
            // MediaProvider
            case "com.android.providers.media.documents":
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }
                String selection = "_id=?";
                String[] selectionArgs = new String[] { split[1] };
                return _queryPathFromMediaStore(context, contentUri, selection, selectionArgs);
        }
    } else // MediaStore (and general)
    {
        if ("content".equalsIgnoreCase(scheme)) {
            // Return the remote address
            if (authority.equals("com.google.android.apps.photos.content")) {
                return uri.getLastPathSegment();
            }
            return _queryPathFromMediaStore(context, uri, null, null);
        } else // File
        if ("file".equalsIgnoreCase(scheme)) {
            return uri.getPath();
        }
    }
    LogUtils.verbose("uri to path: " + path);
    return path;
}
Also used : Uri(android.net.Uri) 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