Created
September 10, 2019 17:25
-
-
Save diefferson/f5ef123705ceb5d2694323f45b3212dd to your computer and use it in GitHub Desktop.
Animations Utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.Context | |
| import android.util.DisplayMetrics | |
| fun linearMap(source: Float, sourceMin: Float, sourceMax: Float, targetMin: Float, targetMax: Float): Float { | |
| return ((source - sourceMin) / (sourceMax - sourceMin)) * (targetMax - targetMin) + targetMin | |
| } | |
| fun clampedLinearPercent(percent: Float, expandAnchor: Float, collapseAnchor: Float) : Float { | |
| return ((Math.max(percent, collapseAnchor) - collapseAnchor) / (expandAnchor - collapseAnchor)) * expandAnchor | |
| } | |
| fun convertDpToPixel(dp: Float, context: Context): Float { | |
| return dp * (context.resources.displayMetrics.densityDpi.toFloat()/ DisplayMetrics.DENSITY_DEFAULT) | |
| } | |
| fun convertPixelsToDp(px: Float, context: Context): Float { | |
| return px / (context.resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment