Skip to content

Commit

Permalink
animation for just for the text view
Browse files Browse the repository at this point in the history
  • Loading branch information
sephiroth74 committed Jan 25, 2019
1 parent d6daf0e commit dafe1a7
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 74 deletions.
19 changes: 12 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "it.sephiroth.android.library.tooltip_demo"
minSdkVersion 18
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -34,18 +34,23 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'androidx.core:core-ktx:1.0.1'

implementation('com.github.sephiroth74:NumberSlidingPicker:v1.0.0') {
exclude module: 'android-target-tooltip'
}


implementation project(':xtooltip')

testImplementation 'junit:junit:4.12'

androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package it.sephiroth.android.library.tooltip_demo

import android.os.Bundle
import android.widget.SeekBar
import androidx.appcompat.app.AppCompatActivity
import androidx.core.text.toSpannable
import androidx.core.view.doOnNextLayout
import it.sephiroth.android.library.numberpicker.doOnProgressChanged
import it.sephiroth.android.library.xtooltip.ClosePolicy
import it.sephiroth.android.library.xtooltip.Tooltip
import it.sephiroth.android.library.xtooltip.Typefaces
Expand Down Expand Up @@ -37,60 +36,39 @@ class MainActivity : AppCompatActivity() {
Timber.v("gravity: $gravity")
Timber.v("closePolicy: $closePolicy")

// tooltip?.dismiss()

tooltip?.let {
it.update("123")

val w = it.contentView!!.measuredWidth

it.contentView?.doOnNextLayout {
val diff = it.measuredWidth - w

tooltip?.offsetBy((-diff / 2).toFloat(), 0f)
}
return@setOnClickListener
}
tooltip?.dismiss()

tooltip = Tooltip.Builder(this)
.anchor(button, 0, 0, false)
.text(text)
.styleId(style)
.typeface(typeface)
.maxWidth(metrics.widthPixels / 2)
.arrow(arrow)
.floatingAnimation(animation)
.closePolicy(closePolicy)
.showDuration(showDuration)
.overlay(overlay)
.create()
.anchor(button, 0, 0, false)
.text(text)
.styleId(style)
.typeface(typeface)
.maxWidth(metrics.widthPixels / 2)
.arrow(arrow)
.floatingAnimation(animation)
.closePolicy(closePolicy)
.showDuration(showDuration)
.overlay(overlay)
.create()

tooltip
?.doOnHidden {
tooltip = null
}
?.doOnFailure { }
?.doOnShown {}
?.show(button, gravity, true)
?.doOnHidden {
tooltip = null
}
?.doOnFailure { }
?.doOnShown {}
?.show(button, gravity, true)
}

button2.setOnClickListener {
val fragment = TestDialogFragment.newInstance()
fragment.showNow(supportFragmentManager, "test_dialog_fragment")
}

seekbar_duration.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
text_duration.text = "Duration:\n${progress}ms"
}

override fun onStartTrackingTouch(seekBar: SeekBar?) {
}

override fun onStopTrackingTouch(seekBar: SeekBar?) {
}
seekbar_duration.doOnProgressChanged { numberPicker, progress, formUser ->
text_duration.text = "Duration: ${progress}ms"
}

})
}

private fun getClosePolicy(): ClosePolicy {
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/anim/custom_anim_enter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/decelerate_quint"
android:shareInterpolator="true">

<scale
android:fromXScale="0.7"
android:fromYScale="0.7"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" />

<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
19 changes: 19 additions & 0 deletions app/src/main/res/anim/custom_anim_exit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/decelerate_quint"
android:shareInterpolator="true">

<scale
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.7"
android:toYScale="0.7" />

<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>
25 changes: 17 additions & 8 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,28 @@
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/text_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="2"
android:id="@+id/text_duration"
android:text="Duration:\n3000ms" />
android:text="Duration: 3000ms" />

<androidx.appcompat.widget.AppCompatSeekBar
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />

<it.sephiroth.android.library.numberpicker.NumberPicker
android:id="@+id/seekbar_duration"
android:layout_width="match_parent"
style="@style/NumberPicker.Filled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="5000"
android:min="0"
android:progress="3000" />
android:progress="3000"
app:picker_max="5000"
app:picker_min="0"
app:picker_orientation="vertical"
app:picker_stepSize="50"
app:picker_tracker="exponential" />

</LinearLayout>

Expand Down Expand Up @@ -155,7 +164,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:hint="10"
android:hint="Tooltip Text"
android:maxLines="2" />

</GridLayout>
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
<item name="ttlm_cornerRadius">6dp</item>
<item name="ttlm_arrowRatio">1.2</item>
<item name="ttlm_overlayStyle">@style/ToolTipOverlayAltStyle</item>
<item name="ttlm_animationStyle">@android:style/Animation.Dialog</item>
<item name="ttlm_animationStyle">@style/ToolTipAltAnimation</item>
</style>

<style name="ToolTipOverlayAltStyle" parent="ToolTipOverlayDefaultStyle">
<item name="android:color">#FF333333</item>
<item name="android:alpha">0.3</item>
</style>

<style name="ToolTipAltAnimation">
<item name="android:windowExitAnimation">@anim/custom_anim_exit</item>
<item name="android:windowEnterAnimation">@anim/custom_anim_enter</item>
</style>

</resources>
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.11'
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0-beta01'
classpath 'com.android.tools.build:gradle:3.4.0-beta02'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -19,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=2.0.3
VERSION_CODE=104
VERSION_NAME=2.0.4
VERSION_CODE=105
GROUP=it.sephiroth.android.library.targettooltip

POM_DESCRIPTION=Custom tooltips for android
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jan 16 15:11:44 EST 2019
#Fri Jan 25 16:35:02 EST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-milestone-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.view.*
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.AnimationUtils
import android.widget.FrameLayout
import android.widget.PopupWindow.INPUT_METHOD_NOT_NEEDED
import android.widget.TextView
Expand Down Expand Up @@ -81,6 +82,8 @@ class Tooltip private constructor(private val context: Context, builder: Builder
private var mHasAnchorView = false
private var mFollowAnchor = false
private var mAnimationStyleResId: Int
private var mEnterAnimation: Int
private var mExitAnimation: Int
private var mTextStyleResId: Int

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

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

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

Expand Down Expand Up @@ -249,7 +256,7 @@ class Tooltip private constructor(private val context: Context, builder: Builder
p.token = token
p.softInputMode = mSoftInputMode
p.title = "ToolTip:" + Integer.toHexString(hashCode())
p.windowAnimations = mAnimationStyleResId
// p.windowAnimations = mAnimationStyleResId
return p
}

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

if (mEnterAnimation != 0) {
mTextView.clearAnimation()
mTextView.startAnimation(AnimationUtils.loadAnimation(context, mEnterAnimation))
}

isVisible = true
mShownFunc?.invoke(this)
}

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

isVisible = false
removeCallbacks()
dismiss()
if (mExitAnimation != 0) {
val animation = AnimationUtils.loadAnimation(context, mExitAnimation)
animation.setListener {
onAnimationEnd {
isVisible = false
removeCallbacks()
dismiss()
}
}.start()

mTextView.clearAnimation()
mTextView.startAnimation(animation)

} else {
isVisible = false
removeCallbacks()
dismiss()
}

}

inner class TooltipViewContainer(context: Context) : FrameLayout(context) {
Expand Down
Loading

0 comments on commit dafe1a7

Please sign in to comment.