diff --git a/app/src/main/java/kale/selectorinjection/ImageFragment.java b/app/src/main/java/kale/selectorinjection/ImageFragment.java index b79715f..8d53ddf 100644 --- a/app/src/main/java/kale/selectorinjection/ImageFragment.java +++ b/app/src/main/java/kale/selectorinjection/ImageFragment.java @@ -11,6 +11,7 @@ import kale.injection.SelectorInjection; import kale.ui.view.ISelectorView; +import kale.ui.view.SelectorImageView; /** * @author Kale @@ -48,6 +49,22 @@ public void onClick(View v) { findCbAndSetListener(root, R.id.pressed_stroke_cb); findCbAndSetListener(root, R.id.isSmart_cb); findCbAndSetListener(root, R.id.show_ripple_cb); + + final SelectorImageView imageView = root.findViewById(R.id.check_iv); + + imageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + imageView.toggle(); + } + }); + + imageView.setOnCheckedChangeListener(new SelectorImageView.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(SelectorImageView view, boolean isChecked) { + Toast.makeText(getActivity(), "" + isChecked, Toast.LENGTH_SHORT).show(); + } + }); } @Override diff --git a/app/src/main/res/layout/image_layout.xml b/app/src/main/res/layout/image_layout.xml index 802a1c6..f106026 100644 --- a/app/src/main/res/layout/image_layout.xml +++ b/app/src/main/res/layout/image_layout.xml @@ -6,7 +6,7 @@ android:layout_height="match_parent" android:padding="@dimen/activity_horizontal_margin" > - + - - + + + + + + + - - + diff --git a/lib/src/main/java/kale/ui/view/SelectorImageView.java b/lib/src/main/java/kale/ui/view/SelectorImageView.java index d66a774..cc2c80f 100644 --- a/lib/src/main/java/kale/ui/view/SelectorImageView.java +++ b/lib/src/main/java/kale/ui/view/SelectorImageView.java @@ -1,6 +1,7 @@ package kale.ui.view; import android.content.Context; +import android.support.annotation.Nullable; import android.support.v7.widget.AppCompatImageButton; import android.util.AttributeSet; @@ -11,6 +12,8 @@ public class SelectorImageView extends AppCompatImageButton implements ISelector private SelectorInjection injection; + private OnCheckedChangeListener mOnCheckedChangeListener; + public SelectorImageView(Context context) { this(context, null); } @@ -48,23 +51,36 @@ public int[] onCreateDrawableState(int extraSpace) { return drawableState; } - private boolean mIsChecked = false; + private boolean mChecked = false; @Override public void setChecked(boolean checked) { - if (mIsChecked != checked) { - mIsChecked = checked; - refreshDrawableState(); + if (mChecked != checked) { + mChecked = checked; + + if (mOnCheckedChangeListener != null) { + mOnCheckedChangeListener.onCheckedChanged(this, mChecked); + } +// refreshDrawableState(); } } @Override public boolean isChecked() { - return mIsChecked; + return mChecked; } @Override public void toggle() { - setChecked(!mIsChecked); + setChecked(!mChecked); + } + + public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener) { + mOnCheckedChangeListener = listener; + } + + public interface OnCheckedChangeListener { + + void onCheckedChanged(SelectorImageView view, boolean isChecked); } } \ No newline at end of file