11package fr .free .nrw .commons .nearby ;
22
33import android .content .Context ;
4- import android .os .Parcel ;
5- import android .os .Parcelable ;
64import android .util .AttributeSet ;
75import android .widget .CompoundButton ;
86
1210import java .util .List ;
1311
1412import fr .free .nrw .commons .R ;
15- import fr .free .nrw .commons .nearby .presenter .NearbyParentFragmentPresenter ;
1613
1714/**
1815 * Base on https://stackoverflow.com/a/40939367/3950497 answer.
@@ -25,7 +22,7 @@ public class CheckBoxTriStates extends AppCompatCheckBox {
2522
2623 static public final int CHECKED = 1 ;
2724
28- private int state ;
25+ private int state = UNKNOWN ;
2926
3027 private Callback callback ;
3128
@@ -64,12 +61,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
6461 */
6562 private OnCheckedChangeListener clientListener ;
6663
67- /**
68- * This flag is needed to avoid accidentally changing the current {@link #state} when
69- * {@link #onRestoreInstanceState(Parcelable)} calls {@link #setChecked(boolean)}
70- * evoking our {@link #privateListener} and therefore changing the real state.
71- */
72- private boolean restoring ;
7364
7465 public CheckBoxTriStates (Context context ) {
7566 super (context );
@@ -91,7 +82,7 @@ public int getState() {
9182 }
9283
9384 public void setState (int state ) {
94- if (! this . restoring && this .state != state ) {
85+ if (this .state != state ) {
9586 this .state = state ;
9687
9788 if (this .clientListener != null ) {
@@ -118,27 +109,6 @@ public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listene
118109 super .setOnCheckedChangeListener (privateListener );
119110 }
120111
121- @ Override
122- public Parcelable onSaveInstanceState () {
123- Parcelable superState = super .onSaveInstanceState ();
124-
125- SavedState ss = new SavedState (superState );
126-
127- ss .state = state ;
128-
129- return ss ;
130- }
131-
132- @ Override
133- public void onRestoreInstanceState (Parcelable state ) {
134- this .restoring = true ; // indicates that the ui is restoring its state
135- SavedState ss = (SavedState ) state ;
136- super .onRestoreInstanceState (ss .getSuperState ());
137- setState (ss .state );
138- requestLayout ();
139- this .restoring = false ;
140- }
141-
142112 private void init () {
143113 state = UNKNOWN ;
144114 updateBtn ();
@@ -164,44 +134,4 @@ private void updateBtn() {
164134 setButtonDrawable (btnDrawable );
165135
166136 }
167-
168- static class SavedState extends BaseSavedState {
169- int state ;
170-
171- SavedState (Parcelable superState ) {
172- super (superState );
173- }
174-
175- private SavedState (Parcel in ) {
176- super (in );
177- state = in .readInt ();
178- }
179-
180- @ Override
181- public void writeToParcel (Parcel out , int flags ) {
182- super .writeToParcel (out , flags );
183- out .writeValue (state );
184- }
185-
186- @ Override
187- public String toString () {
188- return "CheckboxTriState.SavedState{"
189- + Integer .toHexString (System .identityHashCode (this ))
190- + " state=" + state + "}" ;
191- }
192-
193- @ SuppressWarnings ("hiding" )
194- public static final Parcelable .Creator <SavedState > CREATOR =
195- new Parcelable .Creator <SavedState >() {
196- @ Override
197- public SavedState createFromParcel (Parcel in ) {
198- return new SavedState (in );
199- }
200-
201- @ Override
202- public SavedState [] newArray (int size ) {
203- return new SavedState [size ];
204- }
205- };
206- }
207137}
0 commit comments