use of android.content.ContextWrapper in project CameraKit-Android by flurgle.
the class CameraKitView method onStart.
public void onStart() {
if (isInEditMode()) {
return;
}
List<String> missingPermissions = getMissingPermissions();
if (Build.VERSION.SDK_INT >= 23 && missingPermissions.size() > 0) {
Activity activity = null;
Context context = getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
activity = (Activity) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
if (activity != null) {
List<String> requestPermissions = new ArrayList<>();
List<String> rationalePermissions = new ArrayList<>();
for (String permission : missingPermissions) {
if (!activity.shouldShowRequestPermissionRationale(permission)) {
requestPermissions.add(permission);
} else {
rationalePermissions.add(permission);
}
}
if (requestPermissions.size() > 0) {
activity.requestPermissions(requestPermissions.toArray(new String[requestPermissions.size()]), PERMISSION_REQUEST_CODE);
}
if (rationalePermissions.size() > 0 && mPermissionsListener != null) {
mPermissionsListener.onPermissionsFailure();
}
}
return;
}
if (mPermissionsListener != null) {
mPermissionsListener.onPermissionsSuccess();
}
setFlash(mFlash);
setImageMegaPixels(mImageMegaPixels);
cameraFacing = getFacing() == CameraKit.FACING_BACK ? CameraFacing.BACK : CameraFacing.FRONT;
mCameraPreview.start(cameraFacing);
}
use of android.content.ContextWrapper in project atlas by alibaba.
the class ActivityTaskMgr method updateBundleActivityResource.
public void updateBundleActivityResource(String bundleName) {
for (int x = 0; x < activityList.size(); x++) {
WeakReference<Activity> ref = activityList.get(x);
if (ref != null && ref.get() != null && !ref.get().isFinishing()) {
Activity activity = ref.get();
try {
if (Build.VERSION.SDK_INT >= 17 && activity.getResources() != RuntimeVariables.delegateResources) {
Field mResourcesField = Activity.class.getSuperclass().getDeclaredField("mResources");
mResourcesField.setAccessible(true);
mResourcesField.set(activity, RuntimeVariables.delegateResources);
}
Field mThemeField = Activity.class.getSuperclass().getDeclaredField("mTheme");
mThemeField.setAccessible(true);
Object mTheme = mThemeField.get(activity);
Field mReferenceResource = mTheme.getClass().getDeclaredField("this$0");
mReferenceResource.setAccessible(true);
if (mReferenceResource.get(mTheme) != RuntimeVariables.delegateResources) {
mThemeField.set(activity, null);
}
Class TintContextWrapper = Class.forName("android.support.v7.widget.TintContextWrapper");
Field tintWrapperField = TintContextWrapper.getDeclaredField("sCache");
tintWrapperField.setAccessible(true);
ArrayList<WeakReference<Object>> sCache = (ArrayList<WeakReference<Object>>) tintWrapperField.get(TintContextWrapper);
if (sCache != null) {
for (int n = 0; n < sCache.size(); n++) {
final WeakReference<Object> wrappRef = sCache.get(n);
final Object wrapper = wrappRef != null ? wrappRef.get() : null;
if (wrapper != null && ((ContextWrapper) wrapper).getBaseContext() == activity) {
Field mTintResourcesField = TintContextWrapper.getDeclaredField("mResources");
mTintResourcesField.setAccessible(true);
mTintResourcesField.set(wrapper, RuntimeVariables.delegateResources);
break;
}
}
}
} catch (Throwable e) {
// e.printStackTrace();
}
}
}
}
use of android.content.ContextWrapper in project robolectric by robolectric.
the class ShadowInstrumentation method assertNoBroadcastListenersOfActionRegistered.
void assertNoBroadcastListenersOfActionRegistered(ContextWrapper context, String action) {
synchronized (registeredReceivers) {
for (Wrapper registeredReceiver : registeredReceivers) {
if (registeredReceiver.context == context.getBaseContext()) {
Iterator<String> actions = registeredReceiver.intentFilter.actionsIterator();
while (actions.hasNext()) {
if (actions.next().equals(action)) {
RuntimeException e = new IllegalStateException("Unexpected BroadcastReceiver on " + context + " with action " + action + " " + registeredReceiver.broadcastReceiver + " that was originally registered here:");
e.setStackTrace(registeredReceiver.exception.getStackTrace());
throw e;
}
}
}
}
}
}
use of android.content.ContextWrapper in project robolectric by robolectric.
the class ShadowAlertDialogTest method shouldCallTheClickListenerOfTheCheckedAdapterInASingleChoiceDialog.
@Test
public void shouldCallTheClickListenerOfTheCheckedAdapterInASingleChoiceDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextWrapper(context));
TestDialogOnClickListener listener = new TestDialogOnClickListener();
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
ArrayAdapter<Integer> arrayAdapter = new ArrayAdapter<>(context, R.layout.main, R.id.title, list);
builder.setSingleChoiceItems(arrayAdapter, 1, listener);
AlertDialog alert = builder.create();
alert.show();
ShadowAlertDialog shadowAlertDialog = shadowOf(alert);
shadowAlertDialog.clickOnItem(0);
assertThat(listener.transcript).containsExactly("clicked on 0");
listener.transcript.clear();
shadowAlertDialog.clickOnItem(1);
assertThat(listener.transcript).containsExactly("clicked on 1");
}
use of android.content.ContextWrapper in project robolectric by robolectric.
the class ShadowAlertDialogTest method testBuilderWithItemArrayViaResourceId.
@Test
public void testBuilderWithItemArrayViaResourceId() {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextWrapper(context));
builder.setTitle("title");
builder.setItems(R.array.alertDialogTestItems, new TestDialogOnClickListener());
AlertDialog alert = builder.create();
alert.show();
assertThat(alert.isShowing()).isTrue();
ShadowAlertDialog shadowAlertDialog = shadowOf(alert);
assertThat(shadowAlertDialog.getTitle().toString()).isEqualTo("title");
assertThat(shadowAlertDialog.getItems().length).isEqualTo(2);
assertThat(shadowAlertDialog.getItems()[0].toString()).isEqualTo("Aloha");
assertThat(shadowOf(ShadowAlertDialog.getLatestAlertDialog())).isSameInstanceAs(shadowAlertDialog);
assertThat(ShadowAlertDialog.getLatestAlertDialog()).isSameInstanceAs(alert);
}
Aggregations