Created
December 30, 2016 21:59
Star
You must be signed in to star a gist
Flashy android animations
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
package org.toilelibre.libe.athg2sms.androidstuff.interactions; | |
import android.animation.ArgbEvaluator; | |
import android.animation.ValueAnimator; | |
import android.content.Context; | |
import android.content.res.ColorStateList; | |
import android.graphics.Color; | |
import android.os.Build; | |
import android.support.v4.content.ContextCompat; | |
import android.view.View; | |
public class FromColorToColor { | |
public static void animate(final Context context, final View view, final int startColorId, final int EndColorId) { | |
final int nbSteps = 100; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), 0, nbSteps); | |
colorAnimation.setDuration(3000); | |
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | |
@Override | |
public void onAnimationUpdate(ValueAnimator animator) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
final int value = (Integer)animator.getAnimatedValue(); | |
final int oldColor = ContextCompat.getColor(context, startColorId); | |
final int targetColor = ContextCompat.getColor(context, EndColorId); | |
final int decreasing = nbSteps - value; | |
final int currentColor = Color.argb(255, Color.red(oldColor) * decreasing / nbSteps + Color.red(targetColor) * value / nbSteps, | |
Color.green(oldColor) * decreasing / nbSteps + Color.green(targetColor) * value / nbSteps, | |
Color.blue(oldColor) * decreasing / nbSteps + Color.blue(targetColor) * value / nbSteps); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
view.setBackgroundTintList(ColorStateList.valueOf(currentColor)); | |
}else { | |
view.setBackgroundColor(currentColor); | |
} | |
} | |
} | |
}); | |
colorAnimation.start(); | |
} | |
} | |
} |
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
package org.toilelibre.libe.athg2sms.androidstuff.materialdesign; | |
import android.os.Build; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.v4.view.ViewCompat; | |
import android.support.v4.view.ViewPager; | |
import android.support.v4.view.animation.FastOutSlowInInterpolator; | |
import android.view.ViewGroup; | |
import org.toilelibre.libe.athg2sms.R; | |
public class OnPageListener implements ViewPager.OnPageChangeListener { | |
private final ViewPager viewPager; | |
private final ViewGroup viewGroup; | |
private int screen = 0; | |
public OnPageListener(ViewPager viewPager, ViewGroup viewGroup) { | |
this.viewPager = viewPager; | |
this.viewGroup = viewGroup; | |
} | |
@Override | |
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | |
if (screen == 0) { | |
FloatingActionButton startButton = (FloatingActionButton) viewGroup.findViewById(R.id.start); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
startButton.setX(viewPager.getWidth() + viewPager.getScrollX() - 140); | |
} | |
} | |
if (screen == 1) { | |
FloatingActionButton exportButton = (FloatingActionButton) viewGroup.findViewById(R.id.exportfile); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
exportButton.setX(viewPager.getWidth() / 4 + viewPager.getScrollX() / 3 - 140); | |
} | |
} | |
if (screen == 2) { | |
FloatingActionButton addOneButton = (FloatingActionButton) viewGroup.findViewById(R.id.addone); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
addOneButton.setY((int) (viewPager.getHeight() - ((viewPager.getScrollX() - viewPager.getWidth()) * 1.0 / viewPager.getWidth() * 400 - 260))); | |
} | |
} | |
} | |
@Override | |
public void onPageSelected(int position) { | |
screen = position; | |
FloatingActionButton startButton = (FloatingActionButton) viewPager.findViewById(R.id.start); | |
if (screen == 0) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
startButton.setScaleX(0); | |
startButton.setScaleY(0); | |
} | |
ViewCompat.animate(startButton).scaleX(1).scaleY(1).alpha(1.0F) | |
.setInterpolator(new FastOutSlowInInterpolator()).withLayer().setStartDelay(100).start(); | |
} else { | |
if (startButton != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | |
startButton.setScaleX(0); | |
startButton.setScaleY(0); | |
} | |
} | |
} | |
@Override | |
public void onPageScrollStateChanged(int state) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment