Android Open Source - Bluetooth-Proximity-Lock Better Compound Button

From Project

Back to project page Bluetooth-Proximity-Lock.


The source code is released under:

Apache License

If you think the Android project Bluetooth-Proximity-Lock listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.javadog.bluetoothproximitylock.helpers;
/*from w  ww .  j  ava 2  s.  co m*/
import android.content.Context;
import android.util.AttributeSet;
import android.widget.CompoundButton;

 * Implementation of Android's CompoundButton (like Switch, Checkbox) which can differentiate between user and
 * programmatic changes to checked state.
public class BetterCompoundButton<T extends CompoundButton> extends CompoundButton {
  private OnCheckedChangeListener listener = null;
  private T mCompoundButton;

  @SuppressWarnings("unused") //Used by android tools and IDE complains about it being removed...
  public BetterCompoundButton(Context context, AttributeSet attrs) {
    super(context, attrs);

  public BetterCompoundButton(Context context, T arg) {
    mCompoundButton = arg;

  public void setOnCheckedChangeListener(OnCheckedChangeListener listenerArg) {
    if(listener == null || (!listener.equals(listenerArg) && listenerArg != null)) {
      listener = listenerArg;

   * Sets the checked state of this Switch without notifying the onCheckedChangedListener.
   * @param checked Checked?
  public void silentlySetChecked(boolean checked) {

   * Enables/disables the onCheckedChangedListener.
   * @param on On?
  private void toggleListener(boolean on) {
    setOnCheckedChangeListener(on ? listener : null);

Java Source Code List