Ignore drag action on the switch button of MasterSwitchPreference
MasterSwitchPreference provides a toggle switch and it only
acts for clicking events. This fix consumes move events to
ignore drag actions.
Bug: 148770615
Test: make RunSettingsRoboTests ROBOTEST_FILTER=MasterSwitchPreferenceTest
Manually drag the switch button of MasterSwitchPreference and
observe the switch state is not changed.
Change-Id: I0d8b947b32d35b85403fc65605c18c09a4053135
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.settings.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Switch;
|
||||
@@ -81,6 +82,11 @@ public class MasterSwitchPreference extends RestrictedPreference {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Consumes move events to ignore drag actions.
|
||||
switchWidget.setOnTouchListener((v, event) -> {
|
||||
return event.getActionMasked() == MotionEvent.ACTION_MOVE;
|
||||
});
|
||||
}
|
||||
|
||||
mSwitch = (Switch) holder.findViewById(R.id.switchWidget);
|
||||
|
||||
Reference in New Issue
Block a user