Back to project page FisgoDroid.
The source code is released under:
The smiley icons bundled with this application belong to Meneame.NET and are licensed under the Creative Commons by-sa 3.0 license. For more information, please visit http://creativecommons.org/licens...
If you think the Android project FisgoDroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.meneame.fisgodroid; // ww w .j ava 2 s.c o m import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.CheckBox; import android.widget.CompoundButton; public class ThreeStateChecboxHackView extends CheckBox { public enum State { UNCHECKED, CHECKED, THIRD_STATE } private State mState; private Drawable mOriginalBackground; private Drawable mThirdStateDrawable = null; public ThreeStateChecboxHackView(Context context) { super(context); if ( !isInEditMode() ) init(); } public ThreeStateChecboxHackView(Context context, AttributeSet attrs) { super(context, attrs); if ( !isInEditMode() ) init(); } private void init () { if ( isChecked() ) mState = State.CHECKED; else mState = State.UNCHECKED; mOriginalBackground = getBackground(); setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if ( mThirdStateDrawable == null ) { mState = isChecked ? State.CHECKED : State.UNCHECKED; } else if ( !isChecked ) { if ( mState == State.CHECKED ) { mState = State.THIRD_STATE; setBackgroundDrawable(mThirdStateDrawable); setChecked(true); } else if ( mState == State.THIRD_STATE ) { mState = State.UNCHECKED; setBackgroundDrawable(mOriginalBackground); } } else { mState = State.CHECKED; } } }); } public void setThirdStateDrawable ( Drawable drawable ) { mThirdStateDrawable = drawable; } public State getState () { return mState; } public void setState ( State state ) { mState = state; // Set the visual state Drawable drawable = null; boolean checked = false; switch ( mState ) { case UNCHECKED: drawable = mOriginalBackground; checked = false; break; case CHECKED: drawable = mOriginalBackground; checked = true; break; case THIRD_STATE: drawable = mThirdStateDrawable; checked = true; break; } setBackgroundDrawable ( drawable != null ? drawable : mOriginalBackground ); setChecked(checked); } }