Skip to content

Commit

Permalink
增加了inSrc的demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Kale committed Apr 28, 2018
1 parent efdd1ea commit e3e722c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/kale/selectorinjection/ImageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import kale.injection.SelectorInjection;
import kale.ui.view.ISelectorView;
import kale.ui.view.SelectorImageView;

/**
* @author Kale
Expand Down Expand Up @@ -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
Expand Down
47 changes: 40 additions & 7 deletions app/src/main/res/layout/image_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
android:layout_height="match_parent"
android:padding="@dimen/activity_horizontal_margin"
>

<LinearLayout

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<kale.ui.view.SelectorTextView
<kale.ui.view.SelectorImageView
android:id="@+id/stv"
android:layout_width="200dp"
android:layout_height="200dp"
Expand Down Expand Up @@ -91,16 +91,49 @@
</LinearLayout>

</LinearLayout>

<kale.ui.view.SelectorImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

app:src="@drawable/icon_facebook_svg"
android:layout_marginTop="20dp"

android:tint="@color/orange"
app:src="@drawable/icon_facebook_svg"
/>


<kale.ui.view.SelectorImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:background="@drawable/shape_oval_with_shadow"
android:scaleType="center"
android:clickable="true"

app:inSrc="true"
app:normalDrawable="@drawable/icon_vimeo_svg"
app:normalColor="@color/green"
app:pressedDrawable="@drawable/icon_renren_svg"
app:pressedColor="@color/blue"
/>


<kale.ui.view.SelectorImageView
android:id="@+id/check_iv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"

app:normalDrawable="@drawable/icon_vimeo_svg"
app:normalColor="@color/green"

app:pressedDrawable="@drawable/icon_renren_svg"
app:pressedColor="@color/blue"

app:checkedDrawable="@drawable/icon_facebook_svg"
app:checkedColor="@color/red"
/>


</LinearLayout>

</FrameLayout>
28 changes: 22 additions & 6 deletions lib/src/main/java/kale/ui/view/SelectorImageView.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,6 +12,8 @@ public class SelectorImageView extends AppCompatImageButton implements ISelector

private SelectorInjection injection;

private OnCheckedChangeListener mOnCheckedChangeListener;

public SelectorImageView(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit e3e722c

Please sign in to comment.