Search in sources :

Example 41 with Application

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;
}
Also used : Context(android.content.Context) EmptyActivityLifecycleCallbacks(com.jakewharton.u2020.util.EmptyActivityLifecycleCallbacks) Activity(android.app.Activity) BindView(butterknife.BindView) View(android.view.View) BugReportLens(com.jakewharton.u2020.ui.bugreport.BugReportLens) ContextThemeWrapper(android.view.ContextThemeWrapper) CompositeSubscription(rx.subscriptions.CompositeSubscription) Application(android.app.Application)

Example 42 with Application

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());
}
Also used : Application(android.app.Application)

Example 43 with Application

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);
    }
}
Also used : Context(android.content.Context) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException) Application(android.app.Application)

Example 44 with Application

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);
    }
}
Also used : Context(android.content.Context) AndroidRuntimeException(android.util.AndroidRuntimeException) Application(android.app.Application)

Example 45 with Application

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;
}
Also used : Field(java.lang.reflect.Field) Application(android.app.Application) MultiDexApplication(android.support.multidex.MultiDexApplication)

Aggregations

Application (android.app.Application)125 Test (org.junit.Test)27 Context (android.content.Context)24 Activity (android.app.Activity)23 ApplicationInfo (android.content.pm.ApplicationInfo)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 File (java.io.File)10 MvpPresenter (com.hannesdorfmann.mosby3.mvp.MvpPresenter)8 Before (org.junit.Before)8 ShadowApplication (org.robolectric.shadows.ShadowApplication)8 MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 PrintWriter (java.io.PrintWriter)6 Date (java.util.Date)6 SuppressLint (android.annotation.SuppressLint)5 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 AndroidRuntimeException (android.util.AndroidRuntimeException)5