Skip to content

Commit dafe1a7

Browse files
committed
animation for just for the text view
1 parent d6daf0e commit dafe1a7

File tree

11 files changed

+177
-74
lines changed

11 files changed

+177
-74
lines changed

app/build.gradle

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
compileSdkVersion 28
99
defaultConfig {
1010
applicationId "it.sephiroth.android.library.tooltip_demo"
11-
minSdkVersion 18
11+
minSdkVersion 21
1212
targetSdkVersion 28
1313
versionCode 1
1414
versionName "1.0"
@@ -34,18 +34,23 @@ android {
3434
dependencies {
3535
implementation fileTree(dir: 'libs', include: ['*.jar'])
3636
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
37-
implementation 'androidx.appcompat:appcompat:1.0.1'
38-
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
39-
implementation 'com.google.android.material:material:1.1.0-alpha01'
37+
implementation 'androidx.appcompat:appcompat:1.0.2'
38+
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
39+
implementation 'com.google.android.material:material:1.1.0-alpha02'
4040
implementation 'com.jakewharton.timber:timber:4.7.1'
4141
implementation 'androidx.core:core-ktx:1.0.1'
4242

43+
implementation('com.github.sephiroth74:NumberSlidingPicker:v1.0.0') {
44+
exclude module: 'android-target-tooltip'
45+
}
46+
47+
4348
implementation project(':xtooltip')
4449

4550
testImplementation 'junit:junit:4.12'
4651

47-
androidTestImplementation 'androidx.test:runner:1.1.0'
48-
androidTestImplementation 'androidx.test:rules:1.1.0'
49-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
52+
androidTestImplementation 'androidx.test:runner:1.1.1'
53+
androidTestImplementation 'androidx.test:rules:1.1.1'
54+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
5055
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
5156
}

app/src/main/java/it/sephiroth/android/library/tooltip_demo/MainActivity.kt

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package it.sephiroth.android.library.tooltip_demo
22

33
import android.os.Bundle
4-
import android.widget.SeekBar
54
import androidx.appcompat.app.AppCompatActivity
65
import androidx.core.text.toSpannable
7-
import androidx.core.view.doOnNextLayout
6+
import it.sephiroth.android.library.numberpicker.doOnProgressChanged
87
import it.sephiroth.android.library.xtooltip.ClosePolicy
98
import it.sephiroth.android.library.xtooltip.Tooltip
109
import it.sephiroth.android.library.xtooltip.Typefaces
@@ -37,60 +36,39 @@ class MainActivity : AppCompatActivity() {
3736
Timber.v("gravity: $gravity")
3837
Timber.v("closePolicy: $closePolicy")
3938

40-
// tooltip?.dismiss()
41-
42-
tooltip?.let {
43-
it.update("123")
44-
45-
val w = it.contentView!!.measuredWidth
46-
47-
it.contentView?.doOnNextLayout {
48-
val diff = it.measuredWidth - w
49-
50-
tooltip?.offsetBy((-diff / 2).toFloat(), 0f)
51-
}
52-
return@setOnClickListener
53-
}
39+
tooltip?.dismiss()
5440

5541
tooltip = Tooltip.Builder(this)
56-
.anchor(button, 0, 0, false)
57-
.text(text)
58-
.styleId(style)
59-
.typeface(typeface)
60-
.maxWidth(metrics.widthPixels / 2)
61-
.arrow(arrow)
62-
.floatingAnimation(animation)
63-
.closePolicy(closePolicy)
64-
.showDuration(showDuration)
65-
.overlay(overlay)
66-
.create()
42+
.anchor(button, 0, 0, false)
43+
.text(text)
44+
.styleId(style)
45+
.typeface(typeface)
46+
.maxWidth(metrics.widthPixels / 2)
47+
.arrow(arrow)
48+
.floatingAnimation(animation)
49+
.closePolicy(closePolicy)
50+
.showDuration(showDuration)
51+
.overlay(overlay)
52+
.create()
6753

6854
tooltip
69-
?.doOnHidden {
70-
tooltip = null
71-
}
72-
?.doOnFailure { }
73-
?.doOnShown {}
74-
?.show(button, gravity, true)
55+
?.doOnHidden {
56+
tooltip = null
57+
}
58+
?.doOnFailure { }
59+
?.doOnShown {}
60+
?.show(button, gravity, true)
7561
}
7662

7763
button2.setOnClickListener {
7864
val fragment = TestDialogFragment.newInstance()
7965
fragment.showNow(supportFragmentManager, "test_dialog_fragment")
8066
}
8167

82-
seekbar_duration.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
83-
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
84-
text_duration.text = "Duration:\n${progress}ms"
85-
}
86-
87-
override fun onStartTrackingTouch(seekBar: SeekBar?) {
88-
}
89-
90-
override fun onStopTrackingTouch(seekBar: SeekBar?) {
91-
}
68+
seekbar_duration.doOnProgressChanged { numberPicker, progress, formUser ->
69+
text_duration.text = "Duration: ${progress}ms"
70+
}
9271

93-
})
9472
}
9573

9674
private fun getClosePolicy(): ClosePolicy {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<set xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:duration="@android:integer/config_shortAnimTime"
5+
android:interpolator="@android:interpolator/decelerate_quint"
6+
android:shareInterpolator="true">
7+
8+
<scale
9+
android:fromXScale="0.7"
10+
android:fromYScale="0.7"
11+
android:pivotX="50%"
12+
android:pivotY="50%"
13+
android:toXScale="1"
14+
android:toYScale="1" />
15+
16+
<alpha
17+
android:fromAlpha="0.0"
18+
android:toAlpha="1.0" />
19+
</set>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<set xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:duration="@android:integer/config_shortAnimTime"
5+
android:interpolator="@android:interpolator/decelerate_quint"
6+
android:shareInterpolator="true">
7+
8+
<scale
9+
android:fromXScale="1"
10+
android:fromYScale="1"
11+
android:pivotX="50%"
12+
android:pivotY="50%"
13+
android:toXScale="0.7"
14+
android:toYScale="0.7" />
15+
16+
<alpha
17+
android:fromAlpha="1.0"
18+
android:toAlpha="0.0" />
19+
</set>

app/src/main/res/layout/content_main.xml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,28 @@
115115
android:orientation="horizontal">
116116

117117
<androidx.appcompat.widget.AppCompatTextView
118+
android:id="@+id/text_duration"
118119
android:layout_width="wrap_content"
119120
android:layout_height="wrap_content"
120121
android:lines="2"
121-
android:id="@+id/text_duration"
122-
android:text="Duration:\n3000ms" />
122+
android:text="Duration: 3000ms" />
123123

124-
<androidx.appcompat.widget.AppCompatSeekBar
124+
<Space
125+
android:layout_width="0dp"
126+
android:layout_height="wrap_content"
127+
android:layout_weight="1" />
128+
129+
<it.sephiroth.android.library.numberpicker.NumberPicker
125130
android:id="@+id/seekbar_duration"
126-
android:layout_width="match_parent"
131+
style="@style/NumberPicker.Filled"
132+
android:layout_width="wrap_content"
127133
android:layout_height="wrap_content"
128-
android:max="5000"
129-
android:min="0"
130-
android:progress="3000" />
134+
android:progress="3000"
135+
app:picker_max="5000"
136+
app:picker_min="0"
137+
app:picker_orientation="vertical"
138+
app:picker_stepSize="50"
139+
app:picker_tracker="exponential" />
131140

132141
</LinearLayout>
133142

@@ -155,7 +164,7 @@
155164
android:layout_width="match_parent"
156165
android:layout_height="wrap_content"
157166
android:layout_columnSpan="2"
158-
android:hint="10"
167+
android:hint="Tooltip Text"
159168
android:maxLines="2" />
160169

161170
</GridLayout>

app/src/main/res/values/styles.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424
<item name="ttlm_cornerRadius">6dp</item>
2525
<item name="ttlm_arrowRatio">1.2</item>
2626
<item name="ttlm_overlayStyle">@style/ToolTipOverlayAltStyle</item>
27-
<item name="ttlm_animationStyle">@android:style/Animation.Dialog</item>
27+
<item name="ttlm_animationStyle">@style/ToolTipAltAnimation</item>
2828
</style>
2929

3030
<style name="ToolTipOverlayAltStyle" parent="ToolTipOverlayDefaultStyle">
3131
<item name="android:color">#FF333333</item>
3232
<item name="android:alpha">0.3</item>
3333
</style>
3434

35+
<style name="ToolTipAltAnimation">
36+
<item name="android:windowExitAnimation">@anim/custom_anim_exit</item>
37+
<item name="android:windowEnterAnimation">@anim/custom_anim_enter</item>
38+
</style>
39+
3540
</resources>

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.11'
4+
ext.kotlin_version = '1.3.20'
55
repositories {
66
google()
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.4.0-beta01'
10+
classpath 'com.android.tools.build:gradle:3.4.0-beta02'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212

1313
// NOTE: Do not place your application dependencies here; they belong
@@ -19,6 +19,7 @@ allprojects {
1919
repositories {
2020
google()
2121
jcenter()
22+
maven { url 'https://jitpack.io' }
2223
}
2324
}
2425

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
VERSION_NAME=2.0.3
2-
VERSION_CODE=104
1+
VERSION_NAME=2.0.4
2+
VERSION_CODE=105
33
GROUP=it.sephiroth.android.library.targettooltip
44

55
POM_DESCRIPTION=Custom tooltips for android
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Jan 16 15:11:44 EST 2019
1+
#Fri Jan 25 16:35:02 EST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-milestone-1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

xtooltip/src/main/java/it/sephiroth/android/library/xtooltip/Tooltip.kt

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import android.view.*
1313
import android.view.ViewGroup
1414
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
1515
import android.view.animation.AccelerateDecelerateInterpolator
16+
import android.view.animation.AnimationUtils
1617
import android.widget.FrameLayout
1718
import android.widget.PopupWindow.INPUT_METHOD_NOT_NEEDED
1819
import android.widget.TextView
@@ -81,6 +82,8 @@ class Tooltip private constructor(private val context: Context, builder: Builder
8182
private var mHasAnchorView = false
8283
private var mFollowAnchor = false
8384
private var mAnimationStyleResId: Int
85+
private var mEnterAnimation: Int
86+
private var mExitAnimation: Int
8487
private var mTextStyleResId: Int
8588

8689
private var mViewOverlay: TooltipOverlay? = null
@@ -153,6 +156,10 @@ class Tooltip private constructor(private val context: Context, builder: Builder
153156
theme.getResourceId(R.styleable.TooltipLayout_ttlm_animationStyle, android.R.style.Animation_Toast)
154157
}
155158

159+
val typedArray = context.theme.obtainStyledAttributes(mAnimationStyleResId, intArrayOf(android.R.attr.windowEnterAnimation, android.R.attr.windowExitAnimation))
160+
mEnterAnimation = typedArray.getResourceId(typedArray.getIndex(0), 0)
161+
mExitAnimation = typedArray.getResourceId(typedArray.getIndex(1), 0)
162+
typedArray.recycle()
156163

157164
val font = theme.getString(R.styleable.TooltipLayout_ttlm_font)
158165

@@ -249,7 +256,7 @@ class Tooltip private constructor(private val context: Context, builder: Builder
249256
p.token = token
250257
p.softInputMode = mSoftInputMode
251258
p.title = "ToolTip:" + Integer.toHexString(hashCode())
252-
p.windowAnimations = mAnimationStyleResId
259+
// p.windowAnimations = mAnimationStyleResId
253260
return p
254261
}
255262

@@ -661,16 +668,37 @@ class Tooltip private constructor(private val context: Context, builder: Builder
661668
private fun fadeIn() {
662669
if (!isShowing || isVisible) return
663670

671+
if (mEnterAnimation != 0) {
672+
mTextView.clearAnimation()
673+
mTextView.startAnimation(AnimationUtils.loadAnimation(context, mEnterAnimation))
674+
}
675+
664676
isVisible = true
665677
mShownFunc?.invoke(this)
666678
}
667679

668680
private fun fadeOut() {
669681
if (!isShowing || !isVisible) return
670682

671-
isVisible = false
672-
removeCallbacks()
673-
dismiss()
683+
if (mExitAnimation != 0) {
684+
val animation = AnimationUtils.loadAnimation(context, mExitAnimation)
685+
animation.setListener {
686+
onAnimationEnd {
687+
isVisible = false
688+
removeCallbacks()
689+
dismiss()
690+
}
691+
}.start()
692+
693+
mTextView.clearAnimation()
694+
mTextView.startAnimation(animation)
695+
696+
} else {
697+
isVisible = false
698+
removeCallbacks()
699+
dismiss()
700+
}
701+
674702
}
675703

676704
inner class TooltipViewContainer(context: Context) : FrameLayout(context) {

0 commit comments

Comments
 (0)