Last active
July 22, 2016 06:38
-
-
Save troZee/7942b98588104a636b97ec174424f2a2 to your computer and use it in GitHub Desktop.
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
//Blinking Animation of Multiply Drawables in ActionBar Toolbar on Android | |
//You can use AnimationDrawable, if you don't want to custom blinking animation | |
private void initAnimationOfCustomPins() { | |
ActionBar actionBar = getActionBar(); | |
if (actionBar == null || !Constant.USE_ANIMATION_OF_CUSTOM_PINS) { | |
return; | |
} | |
customActionBarView.setAlpha(1); | |
if(customActionBarView.getAnimation() != null) { | |
isAnimating = true; | |
customActionBarView.startAnimation(customActionBarView.getAnimation()); | |
return; | |
} | |
final ArrayList<String> textToAnimation = getResources().getStringArray(R.array.services_title); | |
final ArrayList<Integer> imagesToAnimation = new ArrayList<>(); | |
for(int i = 0; i< customPinsForServices.length; i++) { | |
imagesToAnimation.add(getResources().getIdentifier(getResources().getStringArray(R.array.services_drawable), "drawable", getPackageName())); | |
} | |
final Animation fadeOut = new AlphaAnimation(1, 0.0f); | |
fadeOut.setInterpolator(new AccelerateInterpolator()); | |
fadeOut.setDuration(Constant.TITLE_ANIMATION_TIME); | |
fadeOut.setStartOffset(Constant.TITLE_DISPLAY_TIME); | |
final Animation fadeIn = new AlphaAnimation(0.0f, 1); | |
fadeIn.setInterpolator(new DecelerateInterpolator()); | |
fadeIn.setDuration(Constant.TITLE_ANIMATION_TIME); | |
fadeOut.setAnimationListener(new Animation.AnimationListener() { | |
@Override | |
public void onAnimationStart(Animation animation) { | |
} | |
@Override | |
public void onAnimationEnd(Animation animation) { | |
if(isAnimating) { | |
customActionBarView.startAnimation(fadeIn); | |
} | |
} | |
@Override | |
public void onAnimationRepeat(Animation animation) { | |
throw new RuntimeException("Fade-In/Fade-Out animation does not support reapting."); | |
} | |
}); | |
fadeIn.setAnimationListener(new Animation.AnimationListener() { | |
public int position = 0; | |
@Override | |
public void onAnimationStart(Animation animation) { | |
updateTitle(textToAnimation.get(position), imagesToAnimation.get(position)); | |
position = ((position + 1) % imagesToAnimation.size()); | |
} | |
@Override | |
public void onAnimationEnd(Animation animation) { | |
if(isAnimating) { | |
customActionBarView.startAnimation(fadeOut); | |
} | |
} | |
@Override | |
public void onAnimationRepeat(Animation animation) { | |
throw new RuntimeException("Fade-In/Fade-Out animation does not support reapting."); | |
} | |
}); | |
isAnimating = true; | |
customActionBarView.setAnimation(fadeOut); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment