From e9cb75c636234e44c94b38a877f3c60091d907dc Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Mon, 2 Jun 2014 15:56:38 -0700 Subject: Entire Switch bar should be a touch state - add click listener for toggling the Switch and its text - add Ripple background to the SwitchBar to make a nice Ripple when there is a click/touch See bug #15385724 Entire Switch bar should be a touch state Change-Id: I26ef77ace596029e9c3e1e17b153b54df4a9110e --- src/com/android/settings/widget/SwitchBar.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src') 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"); -- cgit v1.2.3