Search in sources :

Example 6 with OnSaveInstanceStateEvent

use of proton.inject.observer.event.OnSaveInstanceStateEvent in project AndroidTraining by mixi-inc.

the class ProtonPreferenceActivity method onSaveInstanceState.

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mObserverManager.fire(new OnSaveInstanceStateEvent(outState));
}
Also used : OnSaveInstanceStateEvent(proton.inject.observer.event.OnSaveInstanceStateEvent)

Example 7 with OnSaveInstanceStateEvent

use of proton.inject.observer.event.OnSaveInstanceStateEvent 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

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