use of android.app.Application in project u2020 by JakeWharton.
the class DebugViewContainer method forActivity.
@Override
public ViewGroup forActivity(final Activity activity) {
activity.setContentView(R.layout.debug_activity_frame);
final ViewHolder viewHolder = new ViewHolder();
ButterKnife.bind(viewHolder, activity);
final Context drawerContext = new ContextThemeWrapper(activity, R.style.Theme_U2020_Debug);
final DebugView debugView = new DebugView(drawerContext);
viewHolder.debugDrawer.addView(debugView);
// Set up the contextual actions to watch views coming in and out of the content area.
ContextualDebugActions contextualActions = debugView.getContextualDebugActions();
contextualActions.setActionClickListener(v -> viewHolder.drawerLayout.closeDrawers());
viewHolder.content.setOnHierarchyChangeListener(HierarchyTreeChangeListener.wrap(contextualActions));
viewHolder.drawerLayout.setDrawerShadow(R.drawable.debug_drawer_shadow, GravityCompat.END);
viewHolder.drawerLayout.setDrawerListener(new DebugDrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
debugView.onDrawerOpened();
}
});
// Clean up any old screenshots.
TelescopeLayout.cleanUp(activity);
viewHolder.telescopeLayout.setLens(new BugReportLens(activity, lumberYard));
// If you have not seen the debug drawer before, show it with a message
if (!seenDebugDrawer.get()) {
viewHolder.drawerLayout.postDelayed(() -> {
viewHolder.drawerLayout.openDrawer(GravityCompat.END);
Toast.makeText(drawerContext, R.string.debug_drawer_welcome, Toast.LENGTH_LONG).show();
}, 1000);
seenDebugDrawer.set(true);
}
final CompositeSubscription subscriptions = new CompositeSubscription();
setupMadge(viewHolder, subscriptions);
setupScalpel(viewHolder, subscriptions);
final Application app = activity.getApplication();
app.registerActivityLifecycleCallbacks(new EmptyActivityLifecycleCallbacks() {
@Override
public void onActivityDestroyed(Activity lifecycleActivity) {
if (lifecycleActivity == activity) {
subscriptions.unsubscribe();
app.unregisterActivityLifecycleCallbacks(this);
}
}
});
riseAndShine(activity);
return viewHolder.content;
}
use of android.app.Application in project react-native-push-notification by zo0r.
the class RNPushNotificationPublisher method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
int id = intent.getIntExtra(NOTIFICATION_ID, 0);
long currentTime = System.currentTimeMillis();
Log.i(LOG_TAG, "NotificationPublisher: Prepare To Publish: " + id + ", Now Time: " + currentTime);
Application applicationContext = (Application) context.getApplicationContext();
new RNPushNotificationHelper(applicationContext).sendToNotificationCentre(intent.getExtras());
}
use of android.app.Application in project android_frameworks_base by DirtyUnicorns.
the class WebViewFactory method getWebViewContextAndSetProvider.
private static Context getWebViewContextAndSetProvider() {
Application initialApplication = AppGlobals.getInitialApplication();
try {
WebViewProviderResponse response = null;
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewUpdateService.waitForAndGetProvider()");
try {
response = getUpdateService().waitForAndGetProvider();
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
if (response.status != LIBLOAD_SUCCESS && response.status != LIBLOAD_FAILED_WAITING_FOR_RELRO) {
throw new MissingWebViewPackageException("Failed to load WebView provider: " + getWebViewPreparationErrorReason(response.status));
}
// Register to be killed before fetching package info - so that we will be
// killed if the package info goes out-of-date.
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "ActivityManager.addPackageDependency()");
try {
ActivityManagerNative.getDefault().addPackageDependency(response.packageInfo.packageName);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
// Fetch package info and verify it against the chosen package
PackageInfo newPackageInfo = null;
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "PackageManager.getPackageInfo()");
try {
newPackageInfo = initialApplication.getPackageManager().getPackageInfo(response.packageInfo.packageName, PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.MATCH_DEBUG_TRIAGED_MISSING | // installed for the current user
PackageManager.MATCH_UNINSTALLED_PACKAGES | // Fetch signatures for verification
PackageManager.GET_SIGNATURES | // Get meta-data for meta data flag verification
PackageManager.GET_META_DATA);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
// Validate the newly fetched package info, throws MissingWebViewPackageException on
// failure
verifyPackageInfo(response.packageInfo, newPackageInfo);
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "initialApplication.createApplicationContext");
try {
// Construct an app context to load the Java code into the current app.
Context webViewContext = initialApplication.createApplicationContext(newPackageInfo.applicationInfo, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
sPackageInfo = newPackageInfo;
return webViewContext;
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
} catch (RemoteException | PackageManager.NameNotFoundException e) {
throw new MissingWebViewPackageException("Failed to load WebView provider: " + e);
}
}
use of android.app.Application in project android_frameworks_base by DirtyUnicorns.
the class WebViewFactory method getProviderClass.
private static Class<WebViewFactoryProvider> getProviderClass() {
Context webViewContext = null;
Application initialApplication = AppGlobals.getInitialApplication();
try {
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getWebViewContextAndSetProvider()");
try {
webViewContext = getWebViewContextAndSetProvider();
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
Log.i(LOGTAG, "Loading " + sPackageInfo.packageName + " version " + sPackageInfo.versionName + " (code " + sPackageInfo.versionCode + ")");
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getChromiumProviderClass()");
try {
initialApplication.getAssets().addAssetPathAsSharedLibrary(webViewContext.getApplicationInfo().sourceDir);
ClassLoader clazzLoader = webViewContext.getClassLoader();
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()");
loadNativeLibrary(clazzLoader);
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
try {
return (Class<WebViewFactoryProvider>) Class.forName(CHROMIUM_WEBVIEW_FACTORY, true, clazzLoader);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
} catch (ClassNotFoundException e) {
Log.e(LOGTAG, "error loading provider", e);
throw new AndroidRuntimeException(e);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
} catch (MissingWebViewPackageException e) {
// original exception.
try {
return (Class<WebViewFactoryProvider>) Class.forName(NULL_WEBVIEW_FACTORY);
} catch (ClassNotFoundException e2) {
// Ignore.
}
Log.e(LOGTAG, "Chromium WebView package does not exist", e);
throw new AndroidRuntimeException(e);
}
}
use of android.app.Application in project YourAppIdea by Michenux.
the class MCXApplication method getRealApplication.
public static MCXApplication getRealApplication(Context applicationContext) {
MCXApplication application = null;
if (applicationContext instanceof MCXApplication) {
application = (MCXApplication) applicationContext;
} else {
Application realApplication = null;
Field magicField = null;
try {
magicField = applicationContext.getClass().getDeclaredField("realApplication");
magicField.setAccessible(true);
realApplication = (Application) magicField.get(applicationContext);
} catch (NoSuchFieldException e) {
Log.e(LOG_TAG, e.getMessage(), e);
} catch (IllegalAccessException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}
application = (MCXApplication) realApplication;
}
return application;
}
Aggregations