Last active
August 20, 2020 22:52
-
-
Save yuriyskulskiy/8b2af62e8cd5bca7da29bb7270d9f6ff to your computer and use it in GitHub Desktop.
AnimatedLayout part 3: add additional const and fields
This file contains 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
private float MIN_FLING_START_VELOCITY_DP = 500; | |
private float mCurrentMinFlingVelocityPx; | |
private VelocityTracker mVelocityTracker; | |
private boolean isTouching = false; | |
private FlingAnimation mFling = new FlingAnimation(this, | |
new FloatPropertyCompat<AnimatedLayout>("offset") { | |
@Override | |
public float getValue(AnimatedLayout object) { | |
return object.getOffset(); | |
} | |
@Override | |
public void setValue(AnimatedLayout object, float value) { | |
object.updateOffset(value); | |
object.invalidate(); | |
} | |
}); | |
private float getOffset() { | |
return mOffsetValue; | |
} | |
protected void onSizeChanged(int w, int h, int oldw, int oldh) { | |
... | |
mCurrentMinFlingVelocityPx = convertDpToPixel(MIN_FLING_START_VELOCITY_DP, getContext()); | |
... | |
private static float convertDpToPixel(float valueDp, Context context) { | |
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); | |
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, valueDp, | |
displayMetrics); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment