Search in sources :

Example 21 with Context

use of android.content.Context in project AndroidTraining by mixi-inc.

the class Proton method initialize.

public static void initialize(Application app, Module... modules) {
    synchronized (Proton.class) {
        checkState(sInjectors == null, "Already initialized Proton");
        sInjectors = new WeakHashMap<Context, InjectorImpl>();
        sBindings = new Bindings();
        sProviderListeners = new ProviderListeners();
        sFieldListeners = new FieldListeners();
        for (Module module : modules) module.configure(sBindings, sProviderListeners, sFieldListeners);
        InjectorImpl injector = new InjectorImpl(app, sBindings, sProviderListeners, sFieldListeners, null);
        sInjectors.put(app, injector);
    }
}
Also used : Context(android.content.Context) InjectorImpl(proton.inject.internal.InjectorImpl) FieldListeners(proton.inject.listener.FieldListeners) ProviderListeners(proton.inject.listener.ProviderListeners) Bindings(proton.inject.binding.Bindings)

Example 22 with Context

use of android.content.Context in project AndroidTraining by mixi-inc.

the class ContextScopedInjectionTest method testInject.

public void testInject() {
    Context context1 = new MockContext(mMockApplication);
    Client obj1 = Proton.getInjector(context1).inject(new Client());
    assertNotNull(obj1.contextScopedClass1);
    assertEquals(obj1.contextScopedClass1, obj1.contextScopedClass2);
    assertNotNull(obj1.contextScopedClassProvider1);
    assertEquals(obj1.contextScopedClassProvider1, obj1.contextScopedClassProvider2);
    Client obj2 = Proton.getInjector(context1).inject(new Client());
    assertEquals(obj1.contextScopedClass1, obj2.contextScopedClass2);
    assertEquals(obj1.contextScopedClassProvider1, obj2.contextScopedClassProvider2);
    Client obj3 = Proton.getInjector(new MockContext(mMockApplication)).inject(new Client());
    assertNotSame(obj1.contextScopedClass1, obj3.contextScopedClass1);
    assertNotSame(obj1.contextScopedClassProvider1, obj3.contextScopedClassProvider1);
}
Also used : Context(android.content.Context)

Example 23 with Context

use of android.content.Context in project AndroidTraining by mixi-inc.

the class ApplicationScopedInjectionTest method testGetInstanceWithIllegalApplicationScoped.

public void testGetInstanceWithIllegalApplicationScoped() {
    try {
        Context context = new MockContext(mMockApplication);
        Proton.getInjector(context).getInstance(IllegalApplicationScopedClass.class);
        fail();
    } catch (ProvisionException exp) {
    }
}
Also used : Context(android.content.Context)

Example 24 with Context

use of android.content.Context in project AndroidTraining by mixi-inc.

the class ApplicationScopedInjectionTest method testGetInstanceWithApplicationScoped.

public void testGetInstanceWithApplicationScoped() {
    Context context1 = new MockContext(mMockApplication);
    Client c = Proton.getInjector(context1).getInstance(Client.class);
    assertNotNull(c.applicationScopedClass);
    assertEquals(c.applicationScopedClass, Proton.getInjector(context1).getInstance(ApplicationScopedClass.class));
    assertEquals(c.applicationScopedClass, Proton.getInjector(new MockContext(mMockApplication)).getInstance(ApplicationScopedClass.class));
}
Also used : Context(android.content.Context)

Example 25 with Context

use of android.content.Context in project AndroidTraining by mixi-inc.

the class ContextInjectionTest method testGetProvider.

public void testGetProvider() {
    Context context = new MockContext(mMockApplication);
    Provider<Context> provider1 = Proton.getInjector(context).getProvider(Context.class);
    Provider<Context> provider2 = Proton.getInjector(context).getProvider(Context.class);
    assertEquals(context, provider1.get());
    assertEquals(provider1, provider2);
}
Also used : Context(android.content.Context)

Aggregations

Context (android.content.Context)7516 Test (org.junit.Test)1645 Intent (android.content.Intent)1356 View (android.view.View)797 TextView (android.widget.TextView)549 BroadcastReceiver (android.content.BroadcastReceiver)497 IntentFilter (android.content.IntentFilter)485 PackageManager (android.content.pm.PackageManager)383 Resources (android.content.res.Resources)369 ArrayList (java.util.ArrayList)358 Bundle (android.os.Bundle)292 PendingIntent (android.app.PendingIntent)281 File (java.io.File)280 LayoutInflater (android.view.LayoutInflater)279 ImageView (android.widget.ImageView)263 Drawable (android.graphics.drawable.Drawable)256 IOException (java.io.IOException)248 Uri (android.net.Uri)247 RecyclerView (android.support.v7.widget.RecyclerView)200 Activity (android.app.Activity)198