Skip to content

Instantly share code, notes, and snippets.

springForce = SpringForce(0f)
relative_layout.pivotX = 0f
relative_layout.pivotY = 0f
val springAnim = SpringAnimation(relative_layout, DynamicAnimation.ROTATION).apply {
springForce.dampingRatio = SpringForce.DAMPING_RATIO_HIGH_BOUNCY
springForce.stiffness = SpringForce.STIFFNESS_VERY_LOW
}
springAnim.spring = springForce
springAnim.setStartValue(80f)
@amanjeetsingh150
amanjeetsingh150 / SpringEndAnimation.kt
Created January 4, 2018 20:37
A gist to describe the end listener of the spring animation.
springAnim.addEndListener(object : DynamicAnimation.OnAnimationEndListener {
override fun onAnimationEnd(animation: DynamicAnimation<out DynamicAnimation<*>>?,
canceled: Boolean, value: Float, velocity: Float) {
//Translation code will be here
})
@amanjeetsingh150
amanjeetsingh150 / SpringOnAnimationEnd.kt
Created January 4, 2018 20:48
OnAnimationEnd of SpringAnimation
override fun onAnimationEnd(animation: DynamicAnimation<out DynamicAnimation<*>>?, canceled: Boolean, value: Float, velocity: Float) {
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
val height = displayMetrics.heightPixels.toFloat()
val width = displayMetrics.widthPixels
relative_layout.animate()
.setStartDelay(1)
.translationXBy(width.toFloat() / 2)
.translationYBy(height)
.setListener(object : Animator.AnimatorListener {
private fun setupApollo(): ApolloClient {
val okHttp = OkHttpClient
.Builder()
.addInterceptor({ chain ->
val original = chain.request()
val builder = original.newBuilder().method(original.method(),
original.body())
builder.addHeader("Authorization"
, "Bearer " + BuildConfig.AUTH_TOKEN)
chain.proceed(builder.build())
client=setupApollo()
client.query(FindQuery //From the auto generated class
.builder()
.name(repo_name_edittext.text.toString()) //Passing required arguments
.owner(owner_name_edittext.text.toString()) //Passing required arguments
.build())
.enqueue(object : ApolloCall.Callback<FindQuery.Data>() {
override fun onFailure(e: ApolloException) {
Log.info(e.message.toString())
}
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (index < polyLineList.size() - 1) {
index++;
next = index + 1;
}
if (index < polyLineList.size() - 1) {
startPosition = polyLineList.get(index);
endPosition = polyLineList.get(next);
v = valueAnimator.getAnimatedFraction();
lng = v * endPosition.longitude + (1 - v)* startPosition.longitude;
lat = v * endPosition.latitude + (1 - v)* startPosition.latitude;
LatLng newPos = new LatLng(lat, lng);
marker.setPosition(newPos);
marker.setAnchor(0.5f, 0.5f);
marker.setRotation(getBearing(startPosition, newPos));
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(new CameraPosition.Builder().target(newPos).zoom(15.5f).build()));
public void setOnJourneyBegin(Object journeyEvent) {
subject.onNext(journeyEvent);
}
public Observable<Object> getOnJourneyEvent() {
return subject;
}
public void setOnJourneyEnd(Object journeyEvent) {
subject.onNext(journeyEvent);
/**
Begin of the journey when index of LatLng in list will be 0.
**/
if (index == 0) {
BeginJourneyEvent beginJourneyEvent = new BeginJourneyEvent();
beginJourneyEvent.setBeginLatLng(startPosition);
JourneyEventBus.getInstance().setOnJourneyBegin(beginJourneyEvent);
}
/**
End of the journey when index of LatLng in list will be last that is size()-1.