Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
37ee819f
Commit
37ee819f
authored
Dec 21, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add AnimationHelper.kt
parent
74ff3de7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
AnimationHelper.kt
...c/main/java/chat/rocket/android/helper/AnimationHelper.kt
+52
-0
No files found.
app/src/main/java/chat/rocket/android/helper/AnimationHelper.kt
0 → 100644
View file @
37ee819f
package
chat.rocket.android.helper
import
android.animation.Animator
import
android.animation.AnimatorListenerAdapter
import
android.animation.AnimatorSet
import
android.animation.ObjectAnimator
import
android.content.Context
import
android.os.Build
import
android.os.VibrationEffect
import
android.os.Vibrator
import
android.view.View
object
AnimationHelper
{
/**
* Shakes a view.
*/
fun
shakeView
(
viewToShake
:
View
,
x
:
Float
=
2F
,
num
:
Int
=
0
)
{
if
(
num
==
6
)
{
viewToShake
.
translationX
=
0
.
toFloat
()
return
}
val
animatorSet
=
AnimatorSet
()
animatorSet
.
playTogether
(
ObjectAnimator
.
ofFloat
(
viewToShake
,
"translationX"
,
dp
(
viewToShake
.
context
,
x
)))
animatorSet
.
duration
=
50
animatorSet
.
addListener
(
object
:
AnimatorListenerAdapter
()
{
override
fun
onAnimationEnd
(
animation
:
Animator
)
{
shakeView
(
viewToShake
,
if
(
num
==
5
)
0
.
toFloat
()
else
-
x
,
num
+
1
)
}
})
animatorSet
.
start
()
}
/**
* Vibrates the smart phone.
*/
fun
vibrate
(
context
:
Context
)
{
val
vibrator
=
context
.
getSystemService
(
Context
.
VIBRATOR_SERVICE
)
as
Vibrator
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
{
vibrator
.
vibrate
(
VibrationEffect
.
createOneShot
(
200
,
VibrationEffect
.
DEFAULT_AMPLITUDE
))
}
else
{
vibrator
.
vibrate
(
200
)
}
}
private
fun
dp
(
context
:
Context
,
value
:
Float
):
Float
{
val
density
=
context
.
resources
.
displayMetrics
.
density
val
result
=
Math
.
ceil
(
density
.
times
(
value
.
toDouble
()))
return
result
.
toFloat
()
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment