Loading packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java +27 −2 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.ColorInt; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.android.settingslib.widget.mainswitch.R; Loading @@ -42,7 +43,7 @@ import java.util.List; /** * MainSwitchBar is a View with a customized Switch. * This component is used as the main switch of the page * to enable or disable the prefereces on the page. * to enable or disable the preferences on the page. */ public class MainSwitchBar extends LinearLayout implements OnCheckedChangeListener { Loading @@ -58,6 +59,8 @@ public class MainSwitchBar extends LinearLayout implements OnCheckedChangeListen protected CompoundButton mSwitch; private final View mFrameView; private @Nullable PreChangeListener mPreChangeListener; public MainSwitchBar(Context context) { this(context, null); } Loading Loading @@ -138,10 +141,20 @@ public class MainSwitchBar extends LinearLayout implements OnCheckedChangeListen @Override public boolean performClick() { if (callPreChangeListener()) { mSwitch.performClick(); } return super.performClick(); } protected boolean callPreChangeListener() { return mPreChangeListener == null || mPreChangeListener.preChange(!mSwitch.isChecked()); } public void setPreChangeListener(@Nullable PreChangeListener preChangeListener) { mPreChangeListener = preChangeListener; } /** * Update the switch status */ Loading Loading @@ -341,4 +354,16 @@ public class MainSwitchBar extends LinearLayout implements OnCheckedChangeListen requestLayout(); } /** * Listener callback before switch is toggled. */ public interface PreChangeListener { /** * Returns if the new value can be set. * * When false is return, the switch toggle is not triggered at all. */ boolean preChange(boolean isCheck); } } Loading
packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java +27 −2 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.ColorInt; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.android.settingslib.widget.mainswitch.R; Loading @@ -42,7 +43,7 @@ import java.util.List; /** * MainSwitchBar is a View with a customized Switch. * This component is used as the main switch of the page * to enable or disable the prefereces on the page. * to enable or disable the preferences on the page. */ public class MainSwitchBar extends LinearLayout implements OnCheckedChangeListener { Loading @@ -58,6 +59,8 @@ public class MainSwitchBar extends LinearLayout implements OnCheckedChangeListen protected CompoundButton mSwitch; private final View mFrameView; private @Nullable PreChangeListener mPreChangeListener; public MainSwitchBar(Context context) { this(context, null); } Loading Loading @@ -138,10 +141,20 @@ public class MainSwitchBar extends LinearLayout implements OnCheckedChangeListen @Override public boolean performClick() { if (callPreChangeListener()) { mSwitch.performClick(); } return super.performClick(); } protected boolean callPreChangeListener() { return mPreChangeListener == null || mPreChangeListener.preChange(!mSwitch.isChecked()); } public void setPreChangeListener(@Nullable PreChangeListener preChangeListener) { mPreChangeListener = preChangeListener; } /** * Update the switch status */ Loading Loading @@ -341,4 +354,16 @@ public class MainSwitchBar extends LinearLayout implements OnCheckedChangeListen requestLayout(); } /** * Listener callback before switch is toggled. */ public interface PreChangeListener { /** * Returns if the new value can be set. * * When false is return, the switch toggle is not triggered at all. */ boolean preChange(boolean isCheck); } }