Override performClick method to eliminate redundant click
Bug: 132226328 Test: make RunSettingsRoboTests ROBOTEST_FILTER=SwitchBar Change-Id: I22987a7695dfc84e50d6419604a9512f98cf4d13
This commit is contained in:
@@ -21,7 +21,6 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -112,8 +111,6 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
// Set the whole SwitchBar focusable and clickable.
|
// Set the whole SwitchBar focusable and clickable.
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
setClickable(true);
|
setClickable(true);
|
||||||
// Set a onClickListener to handle the functionality of ToggleSwitch.
|
|
||||||
setOnClickListener((View v) -> getDelegatingView().performClick());
|
|
||||||
|
|
||||||
final TypedArray a = context.obtainStyledAttributes(attrs, XML_ATTRIBUTES);
|
final TypedArray a = context.obtainStyledAttributes(attrs, XML_ATTRIBUTES);
|
||||||
final int switchBarMarginStart = (int) a.getDimension(0, 0);
|
final int switchBarMarginStart = (int) a.getDimension(0, 0);
|
||||||
@@ -170,6 +167,12 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override the performClick method to eliminate redundant click.
|
||||||
|
@Override
|
||||||
|
public boolean performClick() {
|
||||||
|
return getDelegatingView().performClick();
|
||||||
|
}
|
||||||
|
|
||||||
public void setMetricsTag(String tag) {
|
public void setMetricsTag(String tag) {
|
||||||
mMetricsTag = tag;
|
mMetricsTag = tag;
|
||||||
}
|
}
|
||||||
|
@@ -95,4 +95,11 @@ public class SwitchBarTest {
|
|||||||
mBar.setDisabledByAdmin(null);
|
mBar.setDisabledByAdmin(null);
|
||||||
assertThat(mBar.getDelegatingView().getId()).isEqualTo(R.id.switch_widget);
|
assertThat(mBar.getDelegatingView().getId()).isEqualTo(R.id.switch_widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void performClick_shouldIsCheckedValueChange() {
|
||||||
|
boolean isChecked = mBar.isChecked();
|
||||||
|
mBar.performClick();
|
||||||
|
assertThat(mBar.isChecked()).isEqualTo(!isChecked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user