This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In Fragment | |
@Override | |
public void onCreate( @Nullable Bundle savedInstanceState ){ | |
super.onCreate( savedInstanceState ); | |
... | |
if( savedInstanceState != null ){ | |
onRestoreInstanceState( savedInstanceState ); // Restore Instance State here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract public class BaseViewGroup extends FrameLayout{ | |
... | |
@Override | |
protected void dispatchSaveInstanceState( SparseArray<Parcelable> container ){ | |
dispatchFreezeSelfOnly( container ); | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract public class BaseViewGroup extends FrameLayout{ | |
... | |
@Override | |
protected void onRestoreInstanceState(Parcelable state) { | |
if (!(state instanceof ChildSavedState)) { | |
super.onRestoreInstanceState(state); | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract public class BaseViewGroup extends FrameLayout{ | |
... | |
public static abstract class ChildSavedState extends BaseSavedState{ | |
SparseArray childrenStates; | |
public ChildSavedState( Parcelable superState ){ | |
super( superState ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SwitchViewGroup extends BaseViewGroup{ | |
... | |
@Override | |
public Parcelable onSaveInstanceState(){ | |
Parcelable superState = super.onSaveInstanceState(); | |
// Must call | |
SavedState ss = (SavedState) onSaveInstanceChildState( new SavedState( superState ) ); | |
//save data here | |
return ss; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SwitchViewGroup extends BaseViewGroup{ | |
... | |
private static class SavedState extends ChildSavedState{ | |
SavedState( Parcelable superState ){ | |
super( superState ); | |
} | |
private SavedState( Parcel in, ClassLoader classLoader ){ | |
super( in, classLoader ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity extends Activity{ | |
public void calculateSomeValue(int value){ | |
int result = getPresenter().calculate(value); | |
if(result > 0){ | |
// some logic 1 | |
}else if(result < 0){ | |
// some logic 2 | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) | |
@LargeTest | |
class MainActivityUnitTest{ | |
@Before | |
public void setup(){ | |
... | |
} | |
@Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainPresenter{ | |
public int calculate(int value){ | |
// some logic | |
... | |
} | |
public void clickGotoSecondActivity(){ | |
// some logic | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(JUnit4.class) | |
class MainPresenterUnitTest{ | |
@Before | |
public void setup(){ | |
... | |
} | |
@Test | |
public void calculate(){ |