Search in sources :

Example 6 with Injector

use of proton.inject.Injector in project AndroidTraining by mixi-inc.

the class ProtonService method onCreate.

@Override
public void onCreate() {
    Injector injector = Proton.getInjector(this);
    mObserverManager = injector.getInstance(ObserverManager.class);
    injector.inject(this);
    super.onCreate();
    mObserverManager.fire(new OnCreateEvent(null));
}
Also used : Injector(proton.inject.Injector) OnCreateEvent(proton.inject.observer.event.OnCreateEvent) ObserverManager(proton.inject.observer.ObserverManager)

Example 7 with Injector

use of proton.inject.Injector in project AndroidTraining by mixi-inc.

the class ProtonListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Injector injector = Proton.getInjector(this);
    mObserverManager = injector.getInstance(ObserverManager.class);
    mStateEventObserver = injector.getInstance(StateEventObserver.class);
    injector.inject(this);
    super.onCreate(savedInstanceState);
    mObserverManager.fire(new OnCreateEvent(savedInstanceState));
}
Also used : Injector(proton.inject.Injector) StateEventObserver(proton.inject.state.StateEventObserver) OnCreateEvent(proton.inject.observer.event.OnCreateEvent) ObserverManager(proton.inject.observer.ObserverManager)

Example 8 with Injector

use of proton.inject.Injector in project AndroidTraining by mixi-inc.

the class ProtonLauncherActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Injector injector = Proton.getInjector(this);
    mObserverManager = injector.getInstance(ObserverManager.class);
    mStateEventObserver = injector.getInstance(StateEventObserver.class);
    injector.inject(this);
    super.onCreate(savedInstanceState);
    mObserverManager.fire(new OnCreateEvent(savedInstanceState));
}
Also used : Injector(proton.inject.Injector) StateEventObserver(proton.inject.state.StateEventObserver) OnCreateEvent(proton.inject.observer.event.OnCreateEvent) ObserverManager(proton.inject.observer.ObserverManager)

Example 9 with Injector

use of proton.inject.Injector in project AndroidTraining by mixi-inc.

the class StateRecoveryTest method testRecovery.

public void testRecovery() {
    mObserverManager.fire(new OnCreateEvent(null));
    Aaa a1 = mInjector.getInstance(Aaa.class);
    a1.intState = 1;
    a1.integerState = Integer.valueOf(1);
    a1.intArrayState[0] = 1;
    ArrayList<Integer> integerList = new ArrayList<Integer>();
    integerList.add(1);
    a1.integerListState = integerList;
    a1.stringState = "a";
    a1.stringArrayState = new String[] { "aa" };
    ParcelableClass parcelable = new ParcelableClass("a");
    a1.parcelableState = parcelable;
    ParcelableClass[] parcelableArray = new ParcelableClass[1];
    parcelableArray[0] = new ParcelableClass("a");
    a1.parcelableArrayState = parcelableArray;
    Bundle outState = new Bundle();
    mObserverManager.fire(new OnSaveInstanceStateEvent(outState));
    mObserverManager.fire(new OnDestroyEvent());
    Injector injector = Proton.getInjector(new MockContext(mMockApplication));
    injector.getInstance(StateEventObserver.class);
    injector.getInstance(ObserverManager.class).fire(new OnCreateEvent(outState));
    Aaa a2 = injector.getInstance(Aaa.class);
    assertNotSame(a1, a2);
    assertEquals(1, a2.intState);
    assertEquals(Integer.valueOf(1), a2.integerState);
    assertEquals(1, a2.intArrayState[0]);
    assertEquals("a", a2.stringState);
    assertEquals("aa", a2.stringArrayState[0]);
    assertEquals(integerList, a2.integerListState);
    assertEquals("a", a2.parcelableState.string);
    assertEquals("a", a2.parcelableArrayState[0].string);
    injector.getInstance(ObserverManager.class).fire(new OnDestroyEvent());
}
Also used : MockContext(proton.inject.MockContext) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) OnCreateEvent(proton.inject.observer.event.OnCreateEvent) OnSaveInstanceStateEvent(proton.inject.observer.event.OnSaveInstanceStateEvent) Injector(proton.inject.Injector) OnDestroyEvent(proton.inject.observer.event.OnDestroyEvent) ObserverManager(proton.inject.observer.ObserverManager)

Aggregations

Injector (proton.inject.Injector)9 ObserverManager (proton.inject.observer.ObserverManager)9 OnCreateEvent (proton.inject.observer.event.OnCreateEvent)9 StateEventObserver (proton.inject.state.StateEventObserver)6 Bundle (android.os.Bundle)1 ArrayList (java.util.ArrayList)1 MockContext (proton.inject.MockContext)1 OnDestroyEvent (proton.inject.observer.event.OnDestroyEvent)1 OnSaveInstanceStateEvent (proton.inject.observer.event.OnSaveInstanceStateEvent)1