Search in sources :

Example 41 with ContextWrapper

use of android.content.ContextWrapper in project Presentation by StanKocken.

the class BasePresenterTest method testGetActivity_wrappedIntoContextWrapper.

@Test
public void testGetActivity_wrappedIntoContextWrapper() {
    final ContextWrapper contextWrapper = Mockito.mock(ContextWrapper.class);
    Activity activity = Mockito.mock(Activity.class);
    doReturn(activity).when(contextWrapper).getBaseContext();
    TestPresenter presenter = new TestPresenter() {

        @Override
        public Context getContext() {
            return contextWrapper;
        }
    };
    assertEquals(activity, presenter.getActivity());
    verify(contextWrapper, times(1)).getBaseContext();
}
Also used : Activity(android.app.Activity) ContextWrapper(android.content.ContextWrapper) Test(org.junit.Test)

Example 42 with ContextWrapper

use of android.content.ContextWrapper in project Presentation by StanKocken.

the class BasePresenterTest method testGetActivity_infiniteLoopReturnNull.

@Test
public void testGetActivity_infiniteLoopReturnNull() {
    final ContextWrapper contextWrapper = Mockito.mock(ContextWrapper.class);
    doReturn(contextWrapper).when(contextWrapper).getBaseContext();
    TestPresenter presenter = new TestPresenter() {

        @Override
        public Context getContext() {
            return contextWrapper;
        }
    };
    assertEquals(null, presenter.getActivity());
    verify(contextWrapper, times(1)).getBaseContext();
}
Also used : ContextWrapper(android.content.ContextWrapper) Test(org.junit.Test)

Example 43 with ContextWrapper

use of android.content.ContextWrapper in project nucleus by konmik.

the class NucleusLayoutTest method getActivityFromWrappedContext.

@Test
public void getActivityFromWrappedContext() throws Exception {
    Activity activity = mock(Activity.class);
    ContextWrapper wrapper = mock(ContextWrapper.class);
    when(wrapper.getBaseContext()).thenReturn(activity);
    ContextWrapper wrapper2 = mock(ContextWrapper.class);
    when(wrapper2.getBaseContext()).thenReturn(wrapper);
    stub(method(BASE_VIEW_CLASS, "getContext")).toReturn(wrapper2);
    assertEquals(activity, tested.getActivity());
}
Also used : Activity(android.app.Activity) ContextWrapper(android.content.ContextWrapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with ContextWrapper

use of android.content.ContextWrapper in project VirtualApp by asLody.

the class NotificationCompatCompatV14 method getAppContext.

Context getAppContext(final String packageName) {
    final Resources resources = getResources(packageName);
    Context context = null;
    try {
        context = getHostContext().createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
    } catch (PackageManager.NameNotFoundException e) {
        context = getHostContext();
    // ignore
    }
    return new ContextWrapper(context) {

        @Override
        public Resources getResources() {
            return resources;
        }

        @Override
        public String getPackageName() {
            return packageName;
        }
    };
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) Resources(android.content.res.Resources) ContextWrapper(android.content.ContextWrapper)

Example 45 with ContextWrapper

use of android.content.ContextWrapper in project CameraKit-Android by flurgle.

the class CameraView method requestCameraPermission.

private void requestCameraPermission() {
    Activity activity = null;
    Context context = getContext();
    while (context instanceof ContextWrapper) {
        if (context instanceof Activity) {
            activity = (Activity) context;
        }
        context = ((ContextWrapper) context).getBaseContext();
    }
    if (activity != null) {
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO }, CameraKit.Constants.PERMISSION_REQUEST_CAMERA);
    }
}
Also used : Context(android.content.Context) Activity(android.app.Activity) ContextWrapper(android.content.ContextWrapper)

Aggregations

ContextWrapper (android.content.ContextWrapper)108 Context (android.content.Context)37 Activity (android.app.Activity)25 File (java.io.File)16 Test (org.junit.Test)13 Intent (android.content.Intent)11 MockContentResolver (android.test.mock.MockContentResolver)11 PackageManager (android.content.pm.PackageManager)10 Resources (android.content.res.Resources)9 View (android.view.View)9 IOException (java.io.IOException)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)6 UserManager (android.os.UserManager)6 ThemePreferenceController (com.android.settings.display.ThemePreferenceController)6 OverlayManager (com.android.settings.display.ThemePreferenceController.OverlayManager)6 ArrayList (java.util.ArrayList)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)5 LayoutInflater (android.view.LayoutInflater)5 JsonParser (com.google.gson.JsonParser)5