diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2014-06-02 23:30:29 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-06-02 23:30:30 +0000 |
commit | 6ba7075ae8afb1edc5cb7864bc71121c9992903f (patch) | |
tree | d996e259c67a3a7b4e3968303e3718e9295e1f7c /src | |
parent | 4e2104b1191e5c3a049ebc159150fbb9a7bc2d03 (diff) | |
parent | e9cb75c636234e44c94b38a877f3c60091d907dc (diff) | |
download | packages_apps_Settings-6ba7075ae8afb1edc5cb7864bc71121c9992903f.tar.gz packages_apps_Settings-6ba7075ae8afb1edc5cb7864bc71121c9992903f.tar.bz2 packages_apps_Settings-6ba7075ae8afb1edc5cb7864bc71121c9992903f.zip |
Merge "Entire Switch bar should be a touch state" into lmp-preview-dev
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/widget/SwitchBar.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/com/android/settings/widget/SwitchBar.java b/src/com/android/settings/widget/SwitchBar.java index 40c848103..bc06d8755 100644 --- a/src/com/android/settings/widget/SwitchBar.java +++ b/src/com/android/settings/widget/SwitchBar.java @@ -20,6 +20,7 @@ import android.content.Context; import android.transition.TransitionManager; import android.util.AttributeSet; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; @@ -31,7 +32,8 @@ import com.android.settings.R; import java.util.ArrayList; -public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener { +public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedChangeListener, + View.OnClickListener { private ToggleSwitch mSwitch; private TextView mTextView; @@ -82,6 +84,8 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC mSwitch.setTrackResource(R.drawable.switch_track); mSwitch.setThumbResource(R.drawable.switch_inner); + setOnClickListener(this); + // Default is hide setVisibility(View.GONE); } @@ -105,13 +109,23 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC } @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + public void onClick(View v) { + final boolean isChecked = !mSwitch.isChecked(); + mSwitch.setChecked(isChecked); + } + + public void propagateChecked(boolean isChecked) { final int count = mSwitchChangeListeners.size(); for (int n = 0; n < count; n++) { - mSwitchChangeListeners.get(n).onSwitchChanged(mSwitch,isChecked); + mSwitchChangeListeners.get(n).onSwitchChanged(mSwitch, isChecked); } } + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + propagateChecked(isChecked); + } + public void addOnSwitchChangeListener(OnSwitchChangeListener listener) { if (mSwitchChangeListeners.contains(listener)) { throw new IllegalStateException("Cannot add twice the same OnSwitchChangeListener"); |