Skip to content

Commit c813048

Browse files
committed
Merge branch 'release/1.0.5'
2 parents 6c0eabc + 40c16b3 commit c813048

19 files changed

Lines changed: 258 additions & 92 deletions

File tree

README.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# FSAnimatedTextView
22

33
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/danielceinos/FSAnimatedTextView/blob/master/LICENSE.md)
4-
[![Version](https://img.shields.io/badge/jitpack-1.0.4-green.svg)](https://jitpack.io/#danielceinos/FSAnimatedTextView/1.0.4)
4+
[![Version](https://img.shields.io/badge/jitpack-1.0.5-green.svg)](https://jitpack.io/#danielceinos/FSAnimatedTextView/1.0.5)
55

66
<p align="center">
7-
<img src="https://github.com/danielceinos/FSAnimatedTextView/blob/develop/example1.gif" />
7+
<img src="https://github.com/danielceinos/FSAnimatedTextView/blob/develop/example2.gif" />
88
</p>
99

1010
# Requirements
@@ -24,19 +24,40 @@
2424
```
2525
```
2626
dependencies {
27-
compile 'com.github.danielceinos:FSAnimatedTextView:1.0.4'
27+
compile 'com.github.danielceinos:FSAnimatedTextView:1.0.5'
2828
}
2929
```
3030
# Use
3131

32+
## Options
33+
34+
<attr name="textSize" format="dimension"/>
35+
<attr name="textColor" format="color"/>
36+
<attr name="duration" format="integer"/>
37+
<attr name="leftDrawable" format="reference"/>
38+
<attr name="leftDrawableHeight" format="dimension"/>
39+
<attr name="leftDrawableWidth" format="dimension"/>
40+
<attr name="leftDrawableSize" format="dimension"/>
41+
<attr name="leftDrawableTint" format="color"/>
42+
<attr name="colorFeedback" format="boolean"/>
43+
44+
## Example
45+
3246
```xml
33-
<com.fireshield.animatedtextview.FSAnimatedTV
34-
android:id="@+id/tv_number"
35-
android:layout_width="wrap_content"
36-
android:layout_height="wrap_content"
37-
app:textSize="50sp"
38-
app:textColor="@color/colorPrimary"
39-
/>
47+
<com.fireshield.animatedtextview.FSAnimatedTV
48+
android:id="@+id/tv_retweet"
49+
android:layout_width="wrap_content"
50+
android:layout_height="wrap_content"
51+
android:layout_marginLeft="6dp"
52+
android:layout_weight="1"
53+
app:colorFeedback="true"
54+
app:duration="200"
55+
app:leftDrawable="@drawable/ic_cached"
56+
app:leftDrawableSize="20dp"
57+
app:leftDrawableTint="#FFF"
58+
app:textColor="#FFF"
59+
app:textSize="16sp"
60+
/>
4061
```
4162

4263
```kotlin
@@ -46,3 +67,11 @@
4667
```kotlin
4768
findViewById<FSAnimatedTV>(R.id.tv_number).setText("hey!")
4869
```
70+
71+
```kotlin
72+
findViewById<FSAnimatedTV>(R.id.tv_like).increment(1)
73+
```
74+
75+
```kotlin
76+
findViewById<FSAnimatedTV>(R.id.tv_like).decrement(6)
77+
```

animatedtextview/animatedtextview.iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@
144144
<orderEntry type="library" name="android.arch.lifecycle:runtime-1.0.0" level="project" />
145145
<orderEntry type="library" name="com.android.support:appcompat-v7-26.1.0" level="project" />
146146
<orderEntry type="library" name="com.android.support:support-annotations:26.1.0@jar" level="project" />
147+
<orderEntry type="library" name="com.android.support.constraint:constraint-layout-solver:1.0.2@jar" level="project" />
147148
<orderEntry type="library" name="com.android.support:support-core-utils-26.1.0" level="project" />
149+
<orderEntry type="library" name="com.android.support.constraint:constraint-layout-1.0.2" level="project" />
148150
<orderEntry type="library" name="com.android.support:support-core-ui-26.1.0" level="project" />
149151
<orderEntry type="library" scope="TEST" name="com.android.support.test:runner-1.0.1" level="project" />
150152
<orderEntry type="library" scope="TEST" name="com.android.support.test:rules-1.0.1" level="project" />

animatedtextview/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ android {
2323
minSdkVersion 16
2424
targetSdkVersion 26
2525
versionCode 1
26-
versionName "1.0.4"
26+
versionName "1.0.5"
2727

2828
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2929
}
@@ -43,6 +43,7 @@ dependencies {
4343
testImplementation 'junit:junit:4.12'
4444
androidTestImplementation 'com.android.support.test:runner:1.0.1'
4545
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
46+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
4647
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4748
}
4849
repositories {

animatedtextview/src/main/java/com/fireshield/animatedtextview/FSAnimatedTV.kt

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import android.animation.ValueAnimator
55
import android.animation.ValueAnimator.REVERSE
66
import android.content.Context
77
import android.graphics.Color
8+
import android.graphics.drawable.BitmapDrawable
89
import android.util.AttributeSet
10+
import android.view.View
911
import android.view.animation.AccelerateDecelerateInterpolator
1012
import android.view.animation.Animation
1113
import android.view.animation.AnimationUtils
1214
import android.view.animation.Interpolator
1315
import android.widget.FrameLayout
16+
import android.widget.ImageView
1417
import android.widget.TextView
18+
import android.view.ViewGroup
19+
20+
1521

1622

1723
/**
@@ -24,11 +30,11 @@ class FSAnimatedTV(context: Context?, attrs: AttributeSet?) : FrameLayout(contex
2430
private var value: Int = 0
2531
private var outAnim: Animation
2632
private var inAnim: Animation
27-
val color: Int
28-
val duration: Long
29-
val outInterpolator: Interpolator = AccelerateDecelerateInterpolator()
30-
val inInterpolator: Interpolator = AccelerateDecelerateInterpolator()
31-
val colorFeedback: Boolean
33+
var color: Int
34+
var duration: Long
35+
var outInterpolator: Interpolator = AccelerateDecelerateInterpolator()
36+
var inInterpolator: Interpolator = AccelerateDecelerateInterpolator()
37+
var colorFeedback: Boolean
3238

3339
private fun initialize(context: Context) {
3440
inflate(context, R.layout.animated_tv, this)
@@ -40,18 +46,42 @@ class FSAnimatedTV(context: Context?, attrs: AttributeSet?) : FrameLayout(contex
4046
inAnim = AnimationUtils.loadAnimation(this.context, R.anim.trans_in_up)
4147

4248
val ta = context.obtainStyledAttributes(attrs, R.styleable.FSAnimatedTV, 0, 0)
43-
val dimension = ta.getDimension(R.styleable.FSAnimatedTV_textSize, 40F)
49+
val dimension = ta.getDimension(R.styleable.FSAnimatedTV_textSize, 0F)
50+
val leftDrawableSize = ta.getDimension(R.styleable.FSAnimatedTV_leftDrawableSize, dimension)
51+
val leftDrawableHeight = ta.getDimension(R.styleable.FSAnimatedTV_leftDrawableHeight, leftDrawableSize)
52+
val leftDrawableWidth = ta.getDimension(R.styleable.FSAnimatedTV_leftDrawableWidth, leftDrawableSize)
53+
val leftDrawable = ta.getDrawable(R.styleable.FSAnimatedTV_leftDrawable)
54+
val leftDrawableTintColor = ta.getColor(R.styleable.FSAnimatedTV_leftDrawableTint, Color.BLACK)
4455
color = ta.getColor(R.styleable.FSAnimatedTV_textColor, Color.BLACK)
4556
duration = ta.getInt(R.styleable.FSAnimatedTV_duration, 300).toLong()
4657
colorFeedback = ta.getBoolean(R.styleable.FSAnimatedTV_colorFeedback, false)
4758

4859
val text = findViewById<TextView>(R.id.fs_number)
49-
text.textSize = dimension
60+
text.textSize = dimension / 2F
5061
text.setTextColor(color)
5162

63+
if (leftDrawable != null) {
64+
val leftIv = findViewById<ImageView>(R.id.iv_left_drawable)
65+
val params = leftIv.layoutParams
66+
params.height = leftDrawableHeight.toInt()
67+
params.width = leftDrawableWidth.toInt()
68+
leftIv.requestLayout()
69+
leftIv.setImageDrawable(leftDrawable)
70+
leftIv.visibility = View.VISIBLE
71+
leftIv.setColorFilter(leftDrawableTintColor)
72+
}
73+
5274
ta.recycle()
5375
}
5476

77+
fun increment(by: Int) {
78+
setNum(value + by)
79+
}
80+
81+
fun decrement(by: Int) {
82+
setNum(value - by)
83+
}
84+
5585
fun setNum(num: Int) {
5686
if (num > value) {
5787
animate(num.toString(), DIRECTION.UPWARDS)
@@ -104,10 +134,16 @@ class FSAnimatedTV(context: Context?, attrs: AttributeSet?) : FrameLayout(contex
104134
FSAnimatedTV.DIRECTION.DOWNWARDS -> Color.RED
105135
}
106136
val text = findViewById<TextView>(R.id.fs_number)
137+
val leftIv = findViewById<ImageView>(R.id.iv_left_drawable)
107138
val colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), color, colorTo)
108139
colorAnimation.duration = duration * 2
109140
colorAnimation.interpolator = AccelerateDecelerateInterpolator()
110-
colorAnimation.addUpdateListener { animator -> text.setTextColor(animator.animatedValue as Int) }
141+
colorAnimation.addUpdateListener { animator ->
142+
run {
143+
text.setTextColor(animator.animatedValue as Int)
144+
leftIv.setColorFilter(animator.animatedValue as Int)
145+
}
146+
}
111147
colorAnimation.repeatMode = REVERSE
112148
colorAnimation.repeatCount = 1
113149
colorAnimation.start()

animatedtextview/src/main/res/anim/trans_in_down.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<set xmlns:android="http://schemas.android.com/apk/res/android"
33
android:duration="300">
44
<translate
5-
android:fromYDelta="-50%"
5+
android:fromYDelta="-35%"
66
android:toYDelta="0"/>
77

88
<alpha

animatedtextview/src/main/res/anim/trans_in_up.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<set xmlns:android="http://schemas.android.com/apk/res/android"
33
android:duration="300">
44
<translate
5-
android:fromYDelta="50%"
5+
android:fromYDelta="35%"
66
android:toYDelta="0"/>
77

88
<alpha

animatedtextview/src/main/res/anim/trans_out_down.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<translate
66
android:fromYDelta="0"
7-
android:toYDelta="50%" />
7+
android:toYDelta="35%" />
88

99
<alpha
1010
android:fromAlpha="1"

animatedtextview/src/main/res/anim/trans_out_up.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<translate
66
android:fromYDelta="0"
7-
android:toYDelta="-50%" />
7+
android:toYDelta="-35%" />
88

99
<alpha
1010
android:fromAlpha="1"
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:layout_width="wrap_content"
45
android:layout_height="wrap_content"
6+
android:orientation="horizontal"
57
>
68

9+
<ImageView
10+
android:id="@+id/iv_left_drawable"
11+
android:layout_width="20dp"
12+
android:layout_height="20dp"
13+
android:scaleType="fitCenter"
14+
android:visibility="gone"
15+
tools:src="@drawable/avatar"
16+
android:layout_gravity="center_vertical"
17+
/>
18+
719
<TextView
820
android:id="@+id/fs_number"
921
android:layout_width="wrap_content"
1022
android:layout_height="wrap_content"
23+
android:layout_marginLeft="2dp"
24+
android:maxLines="1"
1125
android:text="0"
1226
android:textColor="#000"
13-
android:textSize="26sp"
27+
android:textSize="16sp"
1428
/>
1529

16-
</RelativeLayout>
30+
</LinearLayout>

animatedtextview/src/main/res/values/attrs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<attr name="textSize" format="dimension"/>
55
<attr name="textColor" format="color"/>
66
<attr name="duration" format="integer"/>
7+
<attr name="leftDrawable" format="reference"/>
8+
<attr name="leftDrawableHeight" format="dimension"/>
9+
<attr name="leftDrawableWidth" format="dimension"/>
10+
<attr name="leftDrawableSize" format="dimension"/>
11+
<attr name="leftDrawableTint" format="color"/>
712
<attr name="colorFeedback" format="boolean"/>
813
</declare-styleable>
914
</resources>

0 commit comments

Comments
 (0)