SwitchBar.java revision 006b2cca1311e61472a8b66fb0c50854fc36d2e7
141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio/*
241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * Copyright (C) 2014 The Android Open Source Project
341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio *
441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * Licensed under the Apache License, Version 2.0 (the "License");
541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * you may not use this file except in compliance with the License.
641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * You may obtain a copy of the License at
741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio *
841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio *      http://www.apache.org/licenses/LICENSE-2.0
941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio *
1041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * Unless required by applicable law or agreed to in writing, software
1141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * distributed under the License is distributed on an "AS IS" BASIS,
1241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * See the License for the specific language governing permissions and
1441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio * limitations under the License.
1541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio */
1641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
1741937766981423c9252e12e3319b2e7532739627Fabrice Di Megliopackage com.android.settings.widget;
1841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
1941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport android.content.Context;
20138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglioimport android.os.Parcel;
21138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglioimport android.os.Parcelable;
2241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport android.util.AttributeSet;
2341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport android.view.LayoutInflater;
2441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport android.view.View;
2541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport android.widget.CompoundButton;
2641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport android.widget.LinearLayout;
2741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
2841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport android.widget.Switch;
2941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport android.widget.TextView;
3041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.R;
3141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
3241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport java.util.ArrayList;
3341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
34e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Megliopublic class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener,
35e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio        View.OnClickListener {
3641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
376220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio    private ToggleSwitch mSwitch;
3841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private TextView mTextView;
3941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
4041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
4141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio            new ArrayList<OnSwitchChangeListener>();
4241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
4341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public static interface OnSwitchChangeListener {
4441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        /**
4541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio         * Called when the checked state of the Switch has changed.
4641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio         *
4741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio         * @param switchView The Switch view whose state has changed.
4841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio         * @param isChecked  The new checked state of switchView.
4941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio         */
5041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        void onSwitchChanged(Switch switchView, boolean isChecked);
5141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
5241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
5341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar(Context context) {
5441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        this(context, null);
5541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
5641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
5741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar(Context context, AttributeSet attrs) {
5841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        this(context, attrs, 0);
5941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
6041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
6141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr) {
6241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        this(context, attrs, defStyleAttr, 0);
6341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
6441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
6541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
6641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        super(context, attrs, defStyleAttr, defStyleRes);
6741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
6841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        LayoutInflater.from(context).inflate(R.layout.switch_bar, this);
6941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
7041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mTextView = (TextView) findViewById(R.id.switch_text);
7141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mTextView.setText(R.string.switch_off_text);
7241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
736220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio        mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget);
74d2b1e441b7314640b2c51ca367c6cc3925147a81Fabrice Di Meglio        // Prevent onSaveInstanceState() to be called as we are managing the state of the Switch
75d2b1e441b7314640b2c51ca367c6cc3925147a81Fabrice Di Meglio        // on our own
76d2b1e441b7314640b2c51ca367c6cc3925147a81Fabrice Di Meglio        mSwitch.setSaveEnabled(false);
7741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
7841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        addOnSwitchChangeListener(new OnSwitchChangeListener() {
7941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio            @Override
8041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio            public void onSwitchChanged(Switch switchView, boolean isChecked) {
81138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio                setTextViewLabel(isChecked);
8241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio            }
8341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        });
8441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
8541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitch.setTrackResource(R.drawable.switch_track);
8641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitch.setThumbResource(R.drawable.switch_inner);
8741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
88e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio        setOnClickListener(this);
89e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio
9041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        // Default is hide
9141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        setVisibility(View.GONE);
9241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
9341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
94138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    public void setTextViewLabel(boolean isChecked) {
95138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        mTextView.setText(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
96138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    }
97138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
98138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    public void setChecked(boolean checked) {
99138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        setTextViewLabel(checked);
100138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        mSwitch.setChecked(checked);
101138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    }
102138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
103006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio    public void setCheckedInternal(boolean checked) {
104006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio        setTextViewLabel(checked);
105006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio        mSwitch.setCheckedInternal(checked);
106006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio    }
107006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio
108138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    public boolean isChecked() {
109138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        return mSwitch.isChecked();
110138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    }
111138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
112138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    public void setEnabled(boolean enabled) {
113138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        super.setEnabled(enabled);
114138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        mTextView.setEnabled(enabled);
115138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        mSwitch.setEnabled(false);
116138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    }
117138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
118138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    public final ToggleSwitch getSwitch() {
11941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        return mSwitch;
12041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
12141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
12241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public void show() {
123138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        if (!isShowing()) {
124138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            setVisibility(View.VISIBLE);
125138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            mSwitch.setOnCheckedChangeListener(this);
126138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        }
12741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
12841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
12941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public void hide() {
130138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        if (isShowing()) {
131138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            setVisibility(View.GONE);
132138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            mSwitch.setOnCheckedChangeListener(null);
133138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        }
13441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
13541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
13641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public boolean isShowing() {
13741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        return (getVisibility() == View.VISIBLE);
13841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
13941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
14041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    @Override
141e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio    public void onClick(View v) {
142e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio        final boolean isChecked = !mSwitch.isChecked();
143d2b1e441b7314640b2c51ca367c6cc3925147a81Fabrice Di Meglio        setChecked(isChecked);
144e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio    }
145e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio
146e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio    public void propagateChecked(boolean isChecked) {
14741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        final int count = mSwitchChangeListeners.size();
14841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        for (int n = 0; n < count; n++) {
149e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio            mSwitchChangeListeners.get(n).onSwitchChanged(mSwitch, isChecked);
15041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        }
15141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
15241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
153e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio    @Override
154e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
155e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio        propagateChecked(isChecked);
156e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio    }
157e9cb75c636234e44c94b38a877f3c60091d907dcFabrice Di Meglio
15841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public void addOnSwitchChangeListener(OnSwitchChangeListener listener) {
15941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        if (mSwitchChangeListeners.contains(listener)) {
16041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio            throw new IllegalStateException("Cannot add twice the same OnSwitchChangeListener");
16141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        }
16241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitchChangeListeners.add(listener);
16341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
16441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio
16541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    public void removeOnSwitchChangeListener(OnSwitchChangeListener listener) {
16641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        if (!mSwitchChangeListeners.contains(listener)) {
16741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio            throw new IllegalStateException("Cannot remove OnSwitchChangeListener");
16841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        }
16941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio        mSwitchChangeListeners.remove(listener);
17041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio    }
171138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
172138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    static class SavedState extends BaseSavedState {
173138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        boolean checked;
174138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        boolean visible;
175138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
176138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        SavedState(Parcelable superState) {
177138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            super(superState);
178138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        }
179138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
180138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        /**
181138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio         * Constructor called from {@link #CREATOR}
182138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio         */
183138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        private SavedState(Parcel in) {
184138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            super(in);
185138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            checked = (Boolean)in.readValue(null);
186138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            visible = (Boolean)in.readValue(null);
187138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        }
188138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
189138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        @Override
190138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        public void writeToParcel(Parcel out, int flags) {
191138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            super.writeToParcel(out, flags);
192138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            out.writeValue(checked);
193138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            out.writeValue(visible);
194138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        }
195138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
196138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        @Override
197138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        public String toString() {
198138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            return "SwitchBar.SavedState{"
199138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio                    + Integer.toHexString(System.identityHashCode(this))
200138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio                    + " checked=" + checked
201138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio                    + " visible=" + visible + "}";
202138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        }
203138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
204138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        public static final Parcelable.Creator<SavedState> CREATOR
205138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio                = new Parcelable.Creator<SavedState>() {
206138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            public SavedState createFromParcel(Parcel in) {
207138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio                return new SavedState(in);
208138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            }
209138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
210138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            public SavedState[] newArray(int size) {
211138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio                return new SavedState[size];
212138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio            }
213138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        };
214138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    }
215138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
216138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    @Override
217138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    public Parcelable onSaveInstanceState() {
218138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        Parcelable superState = super.onSaveInstanceState();
219138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
220138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        SavedState ss = new SavedState(superState);
221138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        ss.checked = mSwitch.isChecked();
222138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        ss.visible = isShowing();
223138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        return ss;
224138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    }
225138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
226138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    @Override
227138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    public void onRestoreInstanceState(Parcelable state) {
228138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        SavedState ss = (SavedState) state;
229138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio
230138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        super.onRestoreInstanceState(ss.getSuperState());
231d2b1e441b7314640b2c51ca367c6cc3925147a81Fabrice Di Meglio
232d2b1e441b7314640b2c51ca367c6cc3925147a81Fabrice Di Meglio        mSwitch.setCheckedInternal(ss.checked);
233138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        setTextViewLabel(ss.checked);
234138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        setVisibility(ss.visible ? View.VISIBLE : View.GONE);
235d2b1e441b7314640b2c51ca367c6cc3925147a81Fabrice Di Meglio        mSwitch.setOnCheckedChangeListener(ss.visible ? this : null);
236d2b1e441b7314640b2c51ca367c6cc3925147a81Fabrice Di Meglio
237138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio        requestLayout();
238138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio    }
23941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio}
240