Java Code Examples for android.app.Activity#isChild()

The following examples show how to use android.app.Activity#isChild() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void onActivityCreate(final Activity activity) {
	if (!activity.isChild()) {
		if (activity.getClass().getClassLoader() instanceof RealPluginClassLoader) {
			String pluginPackageName = ((PluginContextTheme)activity.getApplication().getBaseContext()).getPluginDescriptor().getPackageName();
			BroadcastReceiver br = new BroadcastReceiver() {
				@Override
				public void onReceive(Context context, Intent intent) {
					LogUtil.w("onReceive", intent.getAction(), "activity.finish()");
					activity.finish();
				}
			};
			receivers.put(activity, br);

			LogUtil.v("registerReceiver", pluginPackageName + ACTION_STOP_PLUGIN);
			activity.registerReceiver(br, new IntentFilter(pluginPackageName + ACTION_STOP_PLUGIN));
		}
	}
}
 
Example 2
Source Project: sa-sdk-android   File: AppStateManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
    setForegroundActivity(activity);
    if (!activity.isChild()) {
        mCurrentRootWindowsHashCode = -1;
    }
}
 
Example 3
Source Project: sa-sdk-android   File: AppStateManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResumed(Activity activity) {
    setForegroundActivity(activity);
    if (!activity.isChild()) {
        mCurrentRootWindowsHashCode = activity.getWindow().getDecorView().hashCode();
    }
}
 
Example 4
public void onActivityDestory(Activity activity) {
	if (!activity.isChild()) {
		if (activity.getClass().getClassLoader() instanceof RealPluginClassLoader) {
			BroadcastReceiver br = receivers.remove(activity);
			LogUtil.v("unregisterReceiver", br.getClass().getName());
			activity.unregisterReceiver(br);
		}
	}
}
 
Example 5
Source Project: sa-sdk-android   File: AppStateManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityPaused(Activity activity) {
    if (!activity.isChild()) {
        mCurrentRootWindowsHashCode = -1;
    }
}
 
Example 6
public void onActivityResume(Activity activity) {
	if (!activity.isChild()) {

	}
}
 
Example 7
public void onActivityPause(Activity activity) {
	if (!activity.isChild()) {

	}
}
 
Example 8
static void resetWindowConfig(final Context pluginContext, final PluginDescriptor pd,
							  final Activity activity,
							  final ActivityInfo activityInfo,
							  final PluginActivityInfo pluginActivityInfo) {

	if (pluginActivityInfo != null) {

		//如果PluginContextTheme的getPackageName返回了插件包名,需要在这里对attribute修正
		activity.getWindow().getAttributes().packageName = FairyGlobal.getHostApplication().getPackageName();

		if (null != pluginActivityInfo.getWindowSoftInputMode()) {
			activity.getWindow().setSoftInputMode((int)Long.parseLong(pluginActivityInfo.getWindowSoftInputMode().replace("0x", ""), 16));
		}
		if (Build.VERSION.SDK_INT >= 14) {
			if (null != pluginActivityInfo.getUiOptions()) {
				activity.getWindow().setUiOptions((int)Long.parseLong(pluginActivityInfo.getUiOptions().replace("0x", ""), 16));
			}
		}
		if (null != pluginActivityInfo.getScreenOrientation()) {
			int orientation = (int)Long.parseLong(pluginActivityInfo.getScreenOrientation());
			//noinspection ResourceType
			if (orientation != activityInfo.screenOrientation && !activity.isChild()) {
				//noinspection ResourceType
                   //框架中只内置了unspec和landscape两种screenOrientation
                   //如果是其他类型,这里通过代码实现切换
                   LogUtil.v("修改screenOrientation");
				activity.setRequestedOrientation(orientation);
			}
		}
		if (Build.VERSION.SDK_INT >= 18 && !activity.isChild()) {
			Boolean isImmersive = ResourceUtil.getBoolean(pluginActivityInfo.getImmersive(), pluginContext);
			if (isImmersive != null) {
				activity.setImmersive(isImmersive);
			}
		}

		String activityClassName = activity.getClass().getName();
		LogUtil.v(activityClassName, "immersive", pluginActivityInfo.getImmersive());
		LogUtil.v(activityClassName, "screenOrientation", pluginActivityInfo.getScreenOrientation());
		LogUtil.v(activityClassName, "launchMode", pluginActivityInfo.getLaunchMode());
		LogUtil.v(activityClassName, "windowSoftInputMode", pluginActivityInfo.getWindowSoftInputMode());
		LogUtil.v(activityClassName, "uiOptions", pluginActivityInfo.getUiOptions());
	}

	//如果是独立插件,由于没有合并资源,这里还需要替换掉 mActivityInfo,
	//避免activity试图通过ActivityInfo中的资源id来读取资源时失败
	activityInfo.icon = pd.getApplicationIcon();
	activityInfo.logo = pd.getApplicationLogo();
	if (Build.VERSION.SDK_INT >= 19) {
		activity.getWindow().setIcon(activityInfo.icon);
		activity.getWindow().setLogo(activityInfo.logo);
	}
}
 
Example 9
@Override
public void callActivityOnCreate(Activity activity, Bundle icicle) {
	if (icicle != null && icicle.getParcelable("android:support:fragments") != null) {
		if (ProcessUtil.isPluginProcess()) {
			if (AnnotationProcessor.getPluginContainer(activity.getClass()) != null) {
				// 加了注解的Activity正在自动恢复且页面包含了Fragment。直接清除fragment,
				// 防止如果被恢复的fragment来自插件时,在某些情况下会使用宿主的classloader加载插件fragment
				// 导致classnotfound问题
				icicle.clear();
				icicle = null;
			}
		}
	}

	PluginInjector.injectInstrumetionFor360Safe(activity, this);

	PluginInjector.injectActivityContext(activity);

	Intent intent = activity.getIntent();

	if (intent != null) {
		intent.setExtrasClassLoader(activity.getClassLoader());
	}

	if (icicle != null) {
		icicle.setClassLoader(activity.getClassLoader());
	}

	if (ProcessUtil.isPluginProcess()) {

		installPluginViewFactory(activity);

		if (activity instanceof WaitForLoadingPluginActivity) {
			//NOTHING
		} else {
			AndroidWebkitWebViewFactoryProvider.switchWebViewContext(activity);
		}

		if (activity.isChild()) {
			//修正TabActivity中的Activity的ContextImpl的packageName
			Context base = activity.getBaseContext();
			while(base instanceof ContextWrapper) {
				base = ((ContextWrapper)base).getBaseContext();
			}
			if (HackContextImpl.instanceOf(base)) {
				HackContextImpl impl = new HackContextImpl(base);
				String packageName = FairyGlobal.getHostApplication().getPackageName();
				String packageName1 = activity.getPackageName();
				impl.setBasePackageName(packageName);
				impl.setOpPackageName(packageName);
			}
		}
	}

	try {
		real.callActivityOnCreate(activity, icicle);
	} catch (RuntimeException e) {
		throw new RuntimeException(
				" activity : " + activity.getClassLoader() +
				" pluginContainer : " + AnnotationProcessor.getPluginContainer(activity.getClass()) +
				", process : " + ProcessUtil.isPluginProcess(), e);
	}

	monitor.onActivityCreate(activity);

}