com.evernote.android.state.StateSaver Java Examples

The following examples show how to use com.evernote.android.state.StateSaver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testTypesReflection() {
    TestTypesReflection object = createSavedInstance(TestTypesReflection.class);
    object.setIntegerObj(5);

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.getIntegerObj()).isNull();

    object.setInt(5);
    object.setIntegerObj(6);
    object.setParcelableArrayList(new ArrayList<TestTypes.ParcelableImpl>() {{
        add(new TestTypes.ParcelableImpl(7));
    }});

    StateSaver.saveInstanceState(object, mBundle);
    object.setInt(0);
    object.setIntegerObj(null);
    object.setParcelableArrayList(null);

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.getInt()).isEqualTo(5);
    assertThat(object.getIntegerObj()).isNotNull().isEqualTo(6);
    assertThat(object.getParcelableArrayList()).isNotNull().isNotEmpty().containsExactly(new TestTypes.ParcelableImpl(7));
}
 
Example #2
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testInheritanceGeneric() {
    TestInheritanceGeneric.InheritanceLevelGeneric2 level2 = createSavedInstance(TestInheritanceGeneric.InheritanceLevelGeneric2.class);
    level2.mValue1 = 4;
    level2.mValue2 = 5;

    StateSaver.restoreInstanceState(level2, mBundle);
    assertThat(level2.mValue1).isEqualTo(0);
    assertThat(level2.mValue2).isEqualTo(0);

    level2.mValue1 = 4;
    level2.mValue2 = 5;

    StateSaver.saveInstanceState(level2, mBundle);
    level2.mValue1 = 0;
    level2.mValue2 = 0;

    StateSaver.restoreInstanceState(level2, mBundle);
    assertThat(level2.mValue1).isEqualTo(4);
    assertThat(level2.mValue2).isEqualTo(5);
}
 
Example #3
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testTypes() {
    TestTypes object = createSavedInstance(TestTypes.class);
    object.mBooleanObj = Boolean.FALSE;

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.mBooleanObj).isNull();

    object.mInt = 5;
    object.mIntegerObj = 6;
    object.mParcelableArrayList = new ArrayList<TestTypes.ParcelableImpl>() {{
        add(new TestTypes.ParcelableImpl(7));
    }};

    StateSaver.saveInstanceState(object, mBundle);
    object.mInt = 0;
    object.mIntegerObj = null;
    object.mParcelableArrayList = null;

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.mInt).isEqualTo(5);
    assertThat(object.mIntegerObj).isNotNull().isEqualTo(6);
    assertThat(object.mParcelableArrayList).isNotNull().isNotEmpty().containsExactly(new TestTypes.ParcelableImpl(7));
}
 
Example #4
Source File: ProguardTest.java    From android-state with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testBundler() {
    TestProguardBundler data = new TestProguardBundler();
    data.verifyValue(0);

    data.setValue(1);

    Bundle bundle = new Bundle();
    StateSaver.saveInstanceState(data, bundle);

    data.setValue(0);
    data.verifyValue(0);

    StateSaver.restoreInstanceState(data, bundle);
    data.verifyValue(1);
}
 
Example #5
Source File: Java8BundlingTest.java    From android-state with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testTypes() {
    TestTypes object = createSavedInstance(TestTypes.class);
    object.mBooleanObj = Boolean.FALSE;

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.mBooleanObj).isNull();

    object.mInt = 5;
    object.mIntegerObj = 6;
    object.mParcelableArrayList = new ArrayList<TestTypes.ParcelableImpl>() {{
        add(new TestTypes.ParcelableImpl(7));
    }};

    StateSaver.saveInstanceState(object, mBundle);
    object.mInt = 0;
    object.mIntegerObj = null;
    object.mParcelableArrayList = null;

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.mInt).isEqualTo(5);
    assertThat(object.mIntegerObj).isNotNull().isEqualTo(6);
    assertThat(object.mParcelableArrayList).isNotNull().isNotEmpty().containsExactly(new TestTypes.ParcelableImpl(7));
}
 
Example #6
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
private <T> T createSavedInstance(Class<T> clazz) {
    try {
        T instance = clazz.newInstance();
        StateSaver.saveInstanceState(instance, mBundle);
        return instance;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testInheritance() {
    TestInheritance.InheritanceLevel2 level2 = createSavedInstance(TestInheritance.InheritanceLevel2.class);
    level2.mValue1 = 4;
    level2.mValue2 = 5;

    StateSaver.restoreInstanceState(level2, mBundle);
    assertThat(level2.mValue1).isEqualTo(0);
    assertThat(level2.mValue2).isEqualTo(0);

    level2.mValue1 = 4;
    level2.mValue2 = 5;

    StateSaver.saveInstanceState(level2, mBundle);
    level2.mValue1 = 0;
    level2.mValue2 = 0;

    StateSaver.restoreInstanceState(level2, mBundle);
    assertThat(level2.mValue1).isEqualTo(4);
    assertThat(level2.mValue2).isEqualTo(5);

    TestInheritance.InheritanceLevel1 level1 = createSavedInstance(TestInheritance.InheritanceLevel1.class);
    level1.mValue1 = 4;

    StateSaver.restoreInstanceState(level1, mBundle);
    assertThat(level1.mValue1).isEqualTo(0);
    level1.mValue1 = 4;

    StateSaver.saveInstanceState(level1, mBundle);
    level1.mValue1 = 0;

    StateSaver.restoreInstanceState(level1, mBundle);
    assertThat(level1.mValue1).isEqualTo(4);
}
 
Example #8
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testSimple() {
    TestSimple object = createSavedInstance(TestSimple.class);
    object.field = 5;

    StateSaver.restoreInstanceState(object, mBundle);

    assertThat(object.field).isEqualTo(0);
}
 
Example #9
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testProperty() {
    TestProperty object = createSavedInstance(TestProperty.class);
    object.setTest(5);

    StateSaver.restoreInstanceState(object, mBundle);

    assertThat(object.getTest()).isEqualTo(0);
}
 
Example #10
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNested() {
    TestNested.Inner1.InnerInner1 object1 = createSavedInstance(TestNested.Inner1.InnerInner1.class);
    TestNested.Inner2.InnerInner1 object2 = createSavedInstance(TestNested.Inner2.InnerInner1.class);

    object1.test = 5;
    object2.test = 5;

    StateSaver.restoreInstanceState(object1, mBundle);
    StateSaver.restoreInstanceState(object2, mBundle);

    assertThat(object1.test).isEqualTo(0);
    assertThat(object2.test).isEqualTo(0);
}
 
Example #11
Source File: Java8BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
private <T> T createSavedInstance(Class<T> clazz) {
    try {
        T instance = clazz.newInstance();
        StateSaver.saveInstanceState(instance, mBundle);
        return instance;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #12
Source File: Java8BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNested() {
    TestNested.Inner1.InnerInner1 object1 = createSavedInstance(TestNested.Inner1.InnerInner1.class);
    TestNested.Inner2.InnerInner1 object2 = createSavedInstance(TestNested.Inner2.InnerInner1.class);

    object1.test = 5;
    object2.test = 5;

    StateSaver.restoreInstanceState(object1, mBundle);
    StateSaver.restoreInstanceState(object2, mBundle);

    assertThat(object1.test).isEqualTo(0);
    assertThat(object2.test).isEqualTo(0);
}
 
Example #13
Source File: Java8BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTypesProperty() {
    TestTypesProperty object = createSavedInstance(TestTypesProperty.class);
    object.setBooleanObj(Boolean.FALSE);

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.getBooleanObj()).isNull();

    object.setInt(5);
    object.setIntegerObj(6);
    object.setParcelableImplExtension(new TestTypesProperty.ParcelableImplExtension(7, 8));
    object.setParcelableArrayList(new ArrayList<TestTypes.ParcelableImpl>() {{
        add(new TestTypes.ParcelableImpl(9));
    }});

    StateSaver.saveInstanceState(object, mBundle);
    object.setInt(0);
    object.setIntegerObj(0);
    object.setParcelableImplExtension(null);
    object.setParcelableArrayList(null);

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.getInt()).isEqualTo(5);
    assertThat(object.getIntegerObj()).isNotNull().isEqualTo(6);
    assertThat(object.getParcelableImplExtension()).isNotNull().isEqualTo(new TestTypesProperty.ParcelableImplExtension(7, 8));
    assertThat(object.getParcelableArrayList()).isNotNull().isNotEmpty().containsExactly(new TestTypes.ParcelableImpl(9));
}
 
Example #14
Source File: ProguardTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testProguardRules() {
    TestProguard data = new TestProguard();
    TestProguardHelper.verifyValue(data, 0);
    TestProguardHelper.setValue(data, 1);

    Bundle bundle = new Bundle();
    StateSaver.saveInstanceState(data, bundle);

    TestProguardHelper.setValue(data, 0);
    TestProguardHelper.verifyValue(data, 0);

    StateSaver.restoreInstanceState(data, bundle);
    TestProguardHelper.verifyValue(data, 1);
}
 
Example #15
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testBundler() {
    TestBundler object = createSavedInstance(TestBundler.class);
    object.setData2(new TestBundler.Data());
    object.setDataRefl(new TestBundler.Data());

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.getData2()).isNull();
    assertThat(object.getDataRefl()).isNull();

    TestBundler.Data data = new TestBundler.Data();
    data.int1 = 1;
    data.int2 = 2;
    object.setData2(data);
    data = new TestBundler.Data();
    data.int1 = 3;
    data.int2 = 4;
    object.setDataRefl(data);

    StateSaver.saveInstanceState(object, mBundle);

    object.setData2(null);
    object.setDataRefl(null);
    assertThat(object.getData2()).isNull();
    assertThat(object.getDataRefl()).isNull();

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.getData2()).isNotNull();
    assertThat(object.getData2().int1).isEqualTo(1);
    assertThat(object.getData2().int2).isEqualTo(2);
    assertThat(object.getDataRefl()).isNotNull();
    assertThat(object.getDataRefl().int1).isEqualTo(3);
    assertThat(object.getDataRefl().int2).isEqualTo(4);
}
 
Example #16
Source File: BaseFragment.java    From timecat with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
        StateSaver.restoreInstanceState(this, savedInstanceState);
        getPresenter().onRestoreInstanceState(savedInstanceState);
    }
    getPresenter().setEnterprise(isEnterprise());
}
 
Example #17
Source File: BundlingTest.java    From android-state with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTypesProperty() {
    TestTypesProperty object = createSavedInstance(TestTypesProperty.class);
    object.setBooleanObj(Boolean.FALSE);

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.getBooleanObj()).isNull();

    object.setInt(5);
    object.setIntegerObj(6);
    object.setParcelableImplExtension(new TestTypesProperty.ParcelableImplExtension(7, 8));
    object.setParcelableArrayList(new ArrayList<TestTypes.ParcelableImpl>() {{
        add(new TestTypes.ParcelableImpl(9));
    }});

    StateSaver.saveInstanceState(object, mBundle);
    object.setInt(0);
    object.setIntegerObj(0);
    object.setParcelableImplExtension(null);
    object.setParcelableArrayList(null);

    StateSaver.restoreInstanceState(object, mBundle);
    assertThat(object.getInt()).isEqualTo(5);
    assertThat(object.getIntegerObj()).isNotNull().isEqualTo(6);
    assertThat(object.getParcelableImplExtension()).isNotNull().isEqualTo(new TestTypesProperty.ParcelableImplExtension(7, 8));
    assertThat(object.getParcelableArrayList()).isNotNull().isNotEmpty().containsExactly(new TestTypes.ParcelableImpl(9));
}
 
Example #18
Source File: BaseActivity.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
private void restoreState(@Nullable Bundle savedInstanceState) {
    if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
        StateSaver.restoreInstanceState(this, savedInstanceState);
    }
}
 
Example #19
Source File: BaseBottomSheetDialog.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    StateSaver.saveInstanceState(this, outState);
}
 
Example #20
Source File: BaseBottomSheetDialog.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
        StateSaver.restoreInstanceState(this, savedInstanceState);
    }
}
 
Example #21
Source File: BaseActivity.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    StateSaver.saveInstanceState(this, outState);
}
 
Example #22
Source File: TestView.java    From android-state with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
    super.onRestoreInstanceState(StateSaver.restoreInstanceState(this, state));
}
 
Example #23
Source File: FontTextView.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override public Parcelable onSaveInstanceState() {
    return StateSaver.saveInstanceState(this, super.onSaveInstanceState());
}
 
Example #24
Source File: FontTextView.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override public void onRestoreInstanceState(Parcelable state) {
    super.onRestoreInstanceState(StateSaver.restoreInstanceState(this, state));
    tintDrawables(tintColor);
    setSelected(selected);
}
 
Example #25
Source File: StateLayout.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override public Parcelable onSaveInstanceState() {
    return StateSaver.saveInstanceState(this, super.onSaveInstanceState());
}
 
Example #26
Source File: StateLayout.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Override public void onRestoreInstanceState(Parcelable state) {
    super.onRestoreInstanceState(StateSaver.restoreInstanceState(this, state));
    onHandleLayoutState();
}
 
Example #27
Source File: BaseActivity.java    From andela-crypto-app with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    StateSaver.restoreInstanceState(this, savedInstanceState);
}
 
Example #28
Source File: BaseActivity.java    From andela-crypto-app with Apache License 2.0 4 votes vote down vote up
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    StateSaver.saveInstanceState(this, outState);
}
 
Example #29
Source File: BasePresenter.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
public void onSaveInstanceState(Bundle outState) {
    StateSaver.saveInstanceState(this, outState);
}
 
Example #30
Source File: TestView.java    From android-state with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Parcelable onSaveInstanceState() {
    return StateSaver.saveInstanceState(this, super.onSaveInstanceState());
}