Skip to content

Commit

Permalink
支持了用svg做背景
Browse files Browse the repository at this point in the history
  • Loading branch information
Kale committed Apr 28, 2018
1 parent 04b7bf1 commit 79b7576
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 24 deletions.
Binary file added app/src/main/res/drawable-xhdpi/kale_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion app/src/main/res/layout/image_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
app:src="@drawable/icon_facebook_svg"
/>


<kale.ui.view.SelectorImageView
android:layout_width="100dp"
android:layout_height="100dp"
Expand Down
58 changes: 52 additions & 6 deletions app/src/main/res/layout/svg_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,25 @@
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"

android:gravity="center_vertical"

android:tint="@color/blue"

app:srcCompat="@drawable/icon_facebook_svg"
/>

<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:contentDescription="控件小于SVG的大小"
android:gravity="center_vertical"

android:gravity="center_vertical"
android:tint="@color/orange"
app:srcCompat="@drawable/icon_facebook_svg"
/>
Expand All @@ -161,10 +163,11 @@
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:scaleType="center"

android:scaleType="center"
android:tint="@color/green"
app:srcCompat="@drawable/icon_facebook_svg"
/>
Expand All @@ -179,18 +182,61 @@
android:contentDescription="上下左右icon分别着色"
android:gravity="center_vertical"
android:padding="@dimen/activity_horizontal_margin"

app:drawableBottom="@drawable/icon_facebook_svg"
app:drawableBottomTint="@color/green"

app:drawableLeft="@drawable/icon_facebook_svg"
app:drawableLeftTint="@color/red"

app:drawableRight="@drawable/icon_facebook_svg"
app:drawableRightTint="@color/green"

app:drawableTop="@drawable/icon_vimeo_svg"
app:drawableTopTint="@color/blue"
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:background="@color/white"
android:padding="@dimen/activity_horizontal_margin"
>

<kale.ui.view.SelectorButton
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"

app:background="@drawable/icon_renren_svg"
app:backgroundTint="@color/blue"
/>

<kale.ui.view.SelectorButton
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"

app:background="@drawable/icon_robot"
app:backgroundTint="@color/orange"
/>

<kale.ui.view.SelectorButton
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"

app:background="@drawable/kale_mask"
app:backgroundTint="@color/green"
/>

</LinearLayout>

</LinearLayout>
3 changes: 0 additions & 3 deletions app/src/main/res/layout/text_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
app:normalDrawable="@drawable/shape_rectangle_with_shadow"
/>


<kale.ui.view.SelectorTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -93,7 +92,6 @@
app:normalDrawable="@drawable/shape_rectangle"
/>


<kale.ui.view.SelectorTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -120,5 +118,4 @@
app:normalDrawable="@drawable/shape_rectangle"
/>


</LinearLayout>
23 changes: 15 additions & 8 deletions lib/src/main/java/kale/injection/SelectorInjection.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {

TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SelectorInjection, defStyleAttr, 0);

smartColor = a.getBoolean(R.styleable.SelectorInjection_smartColor, true);
inSrc = a.getBoolean(R.styleable.SelectorInjection_inSrc, false);
showRipple = a.getBoolean(R.styleable.SelectorInjection_ripple, false);

Drawable src = a.getDrawable(R.styleable.SelectorInjection_src);

normal = SelectorBean.create(a,
R.styleable.SelectorInjection_normalDrawable,
R.styleable.SelectorInjection_normalColor,
Expand All @@ -93,11 +87,24 @@ public void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
R.styleable.SelectorInjection_disableStrokeWidth
);

a.recycle();
inSrc = a.getBoolean(R.styleable.SelectorInjection_inSrc, false);
smartColor = a.getBoolean(R.styleable.SelectorInjection_smartColor, true);
showRipple = a.getBoolean(R.styleable.SelectorInjection_ripple, false);

Drawable src = a.getDrawable(R.styleable.SelectorInjection_src);
if (src != null && view instanceof ImageView) {
((ImageView) view).setImageDrawable(src);
}

Drawable background = a.getDrawable(R.styleable.SelectorInjection_background);
int backgroundTint = a.getColor(R.styleable.SelectorInjection_backgroundTint, DEFAULT_COLOR);

if (backgroundTint != DEFAULT_COLOR && background != null) {
SelectorUtils.tintDrawable(background, backgroundTint);
view.setBackground(background);
}

a.recycle();
}

public void injection() {
Expand Down Expand Up @@ -202,7 +209,7 @@ private void setSelectorDrawableToView() {
return;
}

view.setBackgroundDrawable(selector);
view.setBackground(selector);
}

public void configButtonDrawable() {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/kale/utils/SelectorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static SelectorInjection injectionToSelectorView(View view, AttributeSet
SvgInjection svgInjection = new SvgInjection(view);
svgInjection.loadFromAttributes(attrs, defStyle);
svgInjection.injection();

SelectorInjection injection = ((ISelectorView) view).createSelectorInjection(view.getContext(), attrs);
injection.loadFromAttributes(attrs, defStyle);
injection.injection();
Expand Down
13 changes: 8 additions & 5 deletions lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@
<attr name="android:drawableTop" />
<attr name="android:drawableBottom" />
<attr name="src" format="reference" />
<attr name="button" format="reference"/>
<attr name="background" format="reference" />

<!-- svg & tint support -->
<!-- tint support -->

<attr name="button" format="reference"/>
<attr name="buttonTint" format="color" />

<attr name="drawableLeftTint" format="color" />
<attr name="drawableTopTint" format="color" />
<attr name="drawableRightTint" format="color" />
Expand All @@ -61,7 +59,10 @@
<attr name="drawableBottom" format="reference" />
<attr name="drawableLeft" format="reference" />
<attr name="drawableRight" format="reference" />


<attr name="buttonTint" format="color" />
<attr name="backgroundTint" format="color" />

<!-- 事件控制 -->
<attr name="isClicked" format="boolean" />
<attr name="android:contentDescription" />
Expand Down Expand Up @@ -100,6 +101,7 @@
<attr name="drawableLeft"/>
<attr name="drawableRight"/>
<attr name="background"/>
<attr name="backgroundTint"/>
</declare-styleable>

<declare-styleable name="SelectorImageView">
Expand All @@ -124,6 +126,7 @@
<attr name="ripple"/>
<attr name="src"/>
<attr name="background"/>
<attr name="backgroundTint"/>
</declare-styleable>


Expand Down

0 comments on commit 79b7576

Please sign in to comment.