Search in sources :

Example 61 with Application

use of android.app.Application in project Android-Boilerplate by hitherejoe.

the class UnlockDeviceAndroidJUnitRunner method onStart.

@SuppressLint("MissingPermission")
@Override
public void onStart() {
    Application application = (Application) getTargetContext().getApplicationContext();
    String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    ((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE)).newKeyguardLock(simpleName).disableKeyguard();
    // Wake up the screen.
    PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
    mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, simpleName);
    mWakeLock.acquire();
    super.onStart();
}
Also used : PowerManager(android.os.PowerManager) Application(android.app.Application) SuppressLint(android.annotation.SuppressLint)

Example 62 with Application

use of android.app.Application in project k-9 by k9mail.

the class DeviceNotificationsTest method createFakeNotificationController.

private NotificationController createFakeNotificationController(final Builder builder) {
    Application context = RuntimeEnvironment.application;
    NotificationController controller = mock(NotificationController.class);
    when(controller.getContext()).thenReturn(context);
    when(controller.getAccountName(any(Account.class))).thenReturn(ACCOUNT_NAME);
    when(controller.createNotificationBuilder()).thenAnswer(new Answer<Builder>() {

        private int invocationCount = 0;

        @Override
        public Builder answer(InvocationOnMock invocation) throws Throwable {
            invocationCount++;
            switch(invocationCount) {
                case 1:
                    {
                        return builder;
                    }
                case 2:
                    {
                        return builder2;
                    }
            }
            throw new AssertionError("createNotificationBuilder() invoked more than twice");
        }
    });
    return controller;
}
Also used : Account(com.fsck.k9.Account) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockHelper.mockBuilder(com.fsck.k9.MockHelper.mockBuilder) Builder(android.support.v4.app.NotificationCompat.Builder) Application(android.app.Application)

Example 63 with Application

use of android.app.Application in project Genius-Android by qiujuer.

the class KitActivity method init.

private void init() {
    //Application kitApp = Kit.getApplication();
    Application application = getApplication();
    //showLog(TAG, "Kit.getApplication() eq getApplication() is:" + (kitApp == application));
    Cmd.init(application);
}
Also used : Application(android.app.Application)

Example 64 with Application

use of android.app.Application in project roboguice by roboguice.

the class DefaultRoboModule method configure.

/**
     * Configure this module to define Android related bindings.
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void configure() {
    final Provider<Context> contextProvider = getProvider(Context.class);
    final EventListenerThreadingDecorator observerThreadingDecorator = new EventListenerThreadingDecorator();
    // Singletons
    bind(ViewListener.class).toInstance(viewListener);
    // ContextSingleton bindings
    bindScope(ContextSingleton.class, contextScope);
    //we need to super bind as we inject the scope by code only, not by annotations
    superbind(ContextScope.class).toInstance(contextScope);
    bind(AssetManager.class).toProvider(AssetManagerProvider.class);
    bind(Context.class).toProvider(NullProvider.<Context>instance()).in(ContextSingleton.class);
    bind(Activity.class).toProvider(NullProvider.<Activity>instance()).in(ContextSingleton.class);
    bind(RoboActivity.class).toProvider(NullProvider.<RoboActivity>instance()).in(ContextSingleton.class);
    bind(Service.class).toProvider(NullProvider.<Service>instance()).in(ContextSingleton.class);
    bind(RoboService.class).toProvider(NullProvider.<RoboService>instance()).in(ContextSingleton.class);
    // Sundry Android Classes
    bind(SharedPreferences.class).toProvider(SharedPreferencesProvider.class);
    bind(Resources.class).toProvider(ResourcesProvider.class);
    bind(ContentResolver.class).toProvider(ContentResolverProvider.class);
    bind(Application.class).toInstance(application);
    bind(EventListenerThreadingDecorator.class).toInstance(observerThreadingDecorator);
    bind(EventManager.class).annotatedWith(Names.named(GLOBAL_EVENT_MANAGER_NAME)).to(EventManager.class).asEagerSingleton();
    bind(Handler.class).toProvider(HandlerProvider.class);
    // System Services
    for (Entry<Class, String> entry : mapSystemSericeClassToName.entrySet()) {
        bindSystemService(entry.getKey(), entry.getValue());
    }
    // System Services that must be scoped to current context
    bind(LayoutInflater.class).toProvider(new ContextScopedSystemServiceProvider<LayoutInflater>(contextProvider, Context.LAYOUT_INFLATER_SERVICE));
    bind(SearchManager.class).toProvider(new ContextScopedSystemServiceProvider<SearchManager>(contextProvider, Context.SEARCH_SERVICE));
    // Android Resources, Views and extras require special handling
    if (hasInjectionPointsForAnnotation(InjectResource.class)) {
        bindListener(Matchers.any(), resourceListener);
    }
    if (hasInjectionPointsForAnnotation(InjectExtra.class)) {
        final ExtrasListener extrasListener = new ExtrasListener(contextProvider);
        bindListener(Matchers.any(), extrasListener);
    }
    //should be bound only if we use InjectView or InjectFragment
    bindListener(Matchers.any(), viewListener);
    final PreferenceListener preferenceListener = new PreferenceListener(contextProvider, application);
    superbind(PreferenceListener.class).toInstance(preferenceListener);
    if (hasInjectionPointsForAnnotation(InjectPreference.class)) {
        bindListener(Matchers.any(), preferenceListener);
    }
    //should always be bound as ContentViewListener relies on event system
    bindListener(Matchers.any(), new ObservesTypeListener(getProvider(EventManager.class), observerThreadingDecorator));
    requestInjection(observerThreadingDecorator);
    if (isInjectable(Ln.class)) {
        bind(LnInterface.class).to(LnImpl.class);
        //should this be placed in if statement ?
        requestStaticInjection(Ln.class);
    }
    bindDynamicBindings();
}
Also used : RoboService(roboguice.service.RoboService) ViewListener(roboguice.inject.ViewListener) RoboActivity(roboguice.activity.RoboActivity) Activity(android.app.Activity) ContentResolver(android.content.ContentResolver) RoboActivity(roboguice.activity.RoboActivity) Context(android.content.Context) ObservesTypeListener(roboguice.event.ObservesTypeListener) AssetManager(android.content.res.AssetManager) EventManager(roboguice.event.EventManager) EventListenerThreadingDecorator(roboguice.event.eventListener.factory.EventListenerThreadingDecorator) SharedPreferences(android.content.SharedPreferences) SearchManager(android.app.SearchManager) ExtrasListener(roboguice.inject.ExtrasListener) ContextScope(roboguice.inject.ContextScope) Service(android.app.Service) RoboService(roboguice.service.RoboService) Handler(android.os.Handler) PreferenceListener(roboguice.inject.PreferenceListener) LnInterface(roboguice.util.LnInterface) LayoutInflater(android.view.LayoutInflater) Resources(android.content.res.Resources) Application(android.app.Application)

Example 65 with Application

use of android.app.Application in project roboguice by roboguice.

the class RoboSplashActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    final long start = System.currentTimeMillis();
    new Thread(new Runnable() {

        public void run() {
            // Set up a new thread since app.getBaseApplicationInjector() takes so long
            // Set the execution context for this thread in case the user
            // want to use the injector
            final Application app = getApplication();
            RoboGuice.getOrCreateBaseApplicationInjector(getApplication());
            doStuffInBackground(app);
            // Make sure we display splash for MIN_DISPLAY_MS
            final long duration = System.currentTimeMillis() - start;
            if (duration < minDisplayMs) {
                try {
                    Thread.sleep(minDisplayMs - duration);
                } catch (InterruptedException e) {
                    Thread.interrupted();
                }
            }
            startNextActivity();
            andFinishThisOne();
        }
    }).start();
}
Also used : Application(android.app.Application)

Aggregations

Application (android.app.Application)123 Test (org.junit.Test)26 Context (android.content.Context)24 Activity (android.app.Activity)22 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 MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)7 ShadowApplication (org.robolectric.shadows.ShadowApplication)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 PrintWriter (java.io.PrintWriter)6 Date (java.util.Date)6 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 BackgroundColorSpan (android.text.style.BackgroundColorSpan)5 CharacterStyle (android.text.style.CharacterStyle)5