From e9cb75c636234e44c94b38a877f3c60091d907dc Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Mon, 2 Jun 2014 15:56:38 -0700 Subject: [PATCH] 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 --- res/drawable/switchbar_background.xml | 23 +++++++++++++++++++ res/layout/settings_main.xml | 2 +- res/values/colors.xml | 2 +- .../android/settings/widget/SwitchBar.java | 20 +++++++++++++--- 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 res/drawable/switchbar_background.xml diff --git a/res/drawable/switchbar_background.xml b/res/drawable/switchbar_background.xml new file mode 100644 index 00000000000..d329b6b4842 --- /dev/null +++ b/res/drawable/switchbar_background.xml @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/res/layout/settings_main.xml b/res/layout/settings_main.xml index 740932df4a4..46ead18fb21 100644 --- a/res/layout/settings_main.xml +++ b/res/layout/settings_main.xml @@ -31,7 +31,7 @@ #ff263238 #ffe1e1e0 - #ff384248 + #ff384248 #ff7fcac3 diff --git a/src/com/android/settings/widget/SwitchBar.java b/src/com/android/settings/widget/SwitchBar.java index 40c848103fd..bc06d8755a4 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");