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