Back to project page SpunkyCharts.
The source code is released under:
GNU General Public License
If you think the Android project SpunkyCharts listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jogden.spunkycharts.animations; /* /*ww w . j a va 2s . c o m*/ Copyright (C) 2014 Jonathon Ogden < jeog.dev@gmail.com > This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses. */ import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.os.Handler; import android.view.View; /** This is the base class for chart selection animations i.e * what a chart frag does when you touch/ select it. These * animations work for all chart fragments. * </p> * You can create a custom Animation and add it to * chart_manifest.xml. Use the other derived classes in this * package as templates. */ public abstract class BaseSelectAnimationA extends BaseAnimationA { public interface AbortSignalCallback{ public boolean check(); } public static final int INT_ANCHOR = 10; protected AbortSignalCallback abortSignalCallback; protected final Handler thisThread; protected final AnimatorSet animSet; @SuppressWarnings("serial") static public class SelectAnimationException extends RuntimeException { public SelectAnimationException(String msg) { super(msg); } } abstract public <T> void setup( int frequency, float severity, int timeout ); @Override public <T> void start(T... args) { if(!animSet.isRunning()) animSet.start(); } public BaseSelectAnimationA( View animatedView, AbortSignalCallback callback ){ super(animatedView); this.thisThread = new Handler(); this.animSet = new AnimatorSet(); if( callback == null) callback = new AbortSignalCallback(){ public boolean check() { return false ; } }; else abortSignalCallback = callback; } protected <T> void setup( String propertyName, int frequency, int timeout, T posA, T posB, T posEnd ) { final ObjectAnimator animStart; final ObjectAnimator animEnd; if(!posA.getClass().equals(posB.getClass())) throw new SelectAnimationException( "posA and posB must be same type(float or int)" ); if(posA.getClass().equals( Float.class )){ animStart = ObjectAnimator.ofFloat( animatedView, propertyName, (Float)posA, (Float)posB ); animEnd = ObjectAnimator.ofFloat( animatedView, propertyName, (Float)posEnd ); } else if(posA.getClass().equals(Integer.class) ){ animStart = ObjectAnimator.ofFloat( animatedView, propertyName, (Integer)posA, (Integer)posB ); animEnd = ObjectAnimator.ofFloat( animatedView, propertyName, (Float)posEnd ); } else throw new SelectAnimationException( "posA and posB can only be float or int" ); int duration = 1000/frequency; animStart.setDuration(duration); animStart.setRepeatMode(ObjectAnimator.REVERSE); animStart.setRepeatCount(timeout / duration); animSet.play(animStart).before(animEnd); animSet.play(animEnd); animStart.addListener( new Animator.AnimatorListener(){ @Override public void onAnimationRepeat(final Animator animation){ if( abortSignalCallback.check() ) thisThread.post( new Runnable(){ public void run(){ animation.end(); } } ); } @Override public void onAnimationEnd(Animator animation){} @Override public void onAnimationStart(Animator animation){ } @Override public void onAnimationCancel(Animator animation){ } } ); } }