Extends the touch area for the switch in Master Switch preference.

- set view click listener on the entire widget view instead of only
listening to the switch button event.
- move the preference layout end padding into the widget frame, so that
clicking on the empty space at the end will send the click event to the
widget frame instead of the preference view.

Change-Id: I98025f723465f3941cebbbd03b812209c0240590
Fix: 35872094
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2017-03-13 10:29:34 -07:00
parent 5e2545c3e6
commit 6467d2027e
4 changed files with 41 additions and 25 deletions

View File

@@ -20,7 +20,8 @@ import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.widget.CompoundButton;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Switch;
import android.widget.TextView;
@@ -61,21 +62,24 @@ public class MasterSwitchPreference extends Preference {
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
mSwitch = (Switch) holder.itemView.findViewById(R.id.switchWidget);
if (mSwitch != null) {
mSwitch.setChecked(mChecked);
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
final View widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
if (widgetView != null) {
widgetView.setOnClickListener(new OnClickListener() {
@Override
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
if (!callChangeListener(isChecked)) {
button.setChecked(!isChecked);
public void onClick(View v) {
setChecked(!mChecked);
if (!callChangeListener(mChecked)) {
setChecked(!mChecked);
} else {
persistBoolean(isChecked);
mChecked = isChecked;
persistBoolean(mChecked);
}
}
});
}
mSwitch = (Switch) holder.itemView.findViewById(R.id.switchWidget);
if (mSwitch != null) {
mSwitch.setChecked(mChecked);
}
if (mMultiLine) {
TextView textView = (TextView)holder.findViewById(android.R.id.title);
if (textView != null) {