Skip to content

Commit

Permalink
fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
daimajia committed Aug 27, 2014
1 parent ef9579f commit f932049
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public void onClick(View v) {
});
mSampleLayout.setHoverView(hover);
mSampleLayout.setBlurDuration(550);
mSampleLayout.addChildAppearAnimator(hover, R.id.heart, Techniques.FlipInX);
mSampleLayout.addChildAppearAnimator(hover, R.id.share, Techniques.FlipInX);
mSampleLayout.addChildAppearAnimator(hover, R.id.more, Techniques.FlipInX);
mSampleLayout.addChildAppearAnimator(hover, R.id.heart, Techniques.FlipInX, 550, 0);
mSampleLayout.addChildAppearAnimator(hover, R.id.share, Techniques.FlipInX, 550, 250);
mSampleLayout.addChildAppearAnimator(hover, R.id.more, Techniques.FlipInX, 550, 500);

mSampleLayout.addChildDisappearAnimator(hover, R.id.heart, Techniques.FlipOutX);
mSampleLayout.addChildDisappearAnimator(hover, R.id.share, Techniques.FlipOutX);
mSampleLayout.addChildDisappearAnimator(hover, R.id.more, Techniques.FlipOutX);
mSampleLayout.addChildDisappearAnimator(hover, R.id.heart, Techniques.FlipOutX, 550, 500);
mSampleLayout.addChildDisappearAnimator(hover, R.id.share, Techniques.FlipOutX, 550, 250);
mSampleLayout.addChildDisappearAnimator(hover, R.id.more, Techniques.FlipOutX, 550, 0);

mSampleLayout.addChildAppearAnimator(hover, R.id.description, Techniques.FadeInUp);
mSampleLayout.addChildDisappearAnimator(hover, R.id.description, Techniques.FadeOutDown);
Expand Down
1 change: 0 additions & 1 deletion library/gradle-mvn-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,5 @@ afterEvaluate { project ->
archives androidSourcesJar
archives androidJavadocsJar
archives apklib
archives jar
}
}
147 changes: 63 additions & 84 deletions library/src/main/java/com/daimajia/androidviewhover/BlurLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.daimajia.androidviewhover.proxy.AnimationProxy;
import com.daimajia.androidviewhover.tools.Blur;
import com.daimajia.androidviewhover.tools.Util;
import com.nineoldandroids.animation.Animator;
Expand Down Expand Up @@ -55,10 +56,8 @@ public class BlurLayout extends RelativeLayout {
private Animator mHoverDisappearAnimator;
private YoYo.AnimationComposer mHoverDisappearAnimationComposer;

private HashMap<View, ArrayList<YoYo.AnimationComposer>> mChildAppearAnimationComposers = new HashMap<View, ArrayList<YoYo.AnimationComposer>>();
private HashMap<View, ArrayList<YoYo.AnimationComposer>> mChildDisappearAnimationComposers = new HashMap<View, ArrayList<YoYo.AnimationComposer>>();
private HashMap<View, ArrayList<Animator>> mChildAppearAnimators = new HashMap<View, ArrayList<Animator>>();
private HashMap<View, ArrayList<Animator>> mChildDisappearAnimators = new HashMap<View, ArrayList<Animator>>();
private HashMap<View, ArrayList<AnimationProxy>> mChildAppearAnimators = new HashMap<View, ArrayList<AnimationProxy>>();
private HashMap<View, ArrayList<AnimationProxy>> mChildDisappearAnimators = new HashMap<View, ArrayList<AnimationProxy>>();

private long mBlurDuration = DURATION;

Expand Down Expand Up @@ -130,12 +129,12 @@ private boolean hover(){
@Override
public void onGlobalLayout() {

startChildrenAppearAnimations();

startBlurImageAppearAnimator();

startHoverAppearAnimator();

startChildrenAppearAnimations();

if(Build.VERSION.SDK_INT >= 16)
mHoverView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
else
Expand Down Expand Up @@ -311,31 +310,19 @@ private void startHoverDisappearAnimator(){
}

private void startChildrenAppearAnimations(){
for(Map.Entry<View, ArrayList<YoYo.AnimationComposer>> entry : mChildAppearAnimationComposers.entrySet()){
Util.reset(entry.getKey());
for(YoYo.AnimationComposer composer : entry.getValue()){
composer.playOn(entry.getKey());
}
}
for(Map.Entry<View, ArrayList<Animator>> entry : mChildAppearAnimators.entrySet()){
Util.reset(entry.getKey());
for(Animator animator : entry.getValue()){
for(Map.Entry<View, ArrayList<AnimationProxy>> entry : mChildAppearAnimators.entrySet()){
for(AnimationProxy animator : entry.getValue()){
animator.start();
}
}
}

private void startChildrenDisappearAnimations(){
for(View view : mChildDisappearAnimators.keySet()){
for(Animator animator : mChildDisappearAnimators.get(view)){
for(AnimationProxy animator : mChildDisappearAnimators.get(view)){
animator.start();
}
}
for(Map.Entry<View, ArrayList<YoYo.AnimationComposer>> entry : mChildDisappearAnimationComposers.entrySet()){
for(YoYo.AnimationComposer composer : entry.getValue()){
composer.playOn(entry.getKey());
}
}
}

public interface AppearListener {
Expand Down Expand Up @@ -529,97 +516,89 @@ public void addChildAppearAnimator(View hoverView, int resId, Techniques techniq
}

public void addChildAppearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay){
addChildAppearAnimator(hoverView, resId, technique, duration, delay, null);
addChildAppearAnimator(hoverView, resId, technique, duration, delay, true, null);
}

public void addChildAppearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, Interpolator interpolator){
addChildAppearAnimator(hoverView, resId, technique, duration, delay, interpolator, new Animator.AnimatorListener[]{});
public void addChildAppearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, boolean hiddenWhenDelaying){
addChildAppearAnimator(hoverView, resId, technique, duration, delay, hiddenWhenDelaying, null);
}

public void addChildAppearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, Interpolator interpolator, Animator.AnimatorListener... listeners){
if(hoverView == null)
throw new IllegalStateException("Hover view is null");
if(hoverView.findViewById(resId) == null)
throw new IllegalStateException("Can not find the child view");
View child = hoverView.findViewById(resId);
public void addChildAppearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, boolean hiddenWhenDelaying, Interpolator interpolator){
addChildAppearAnimator(hoverView, resId, technique, duration, delay, hiddenWhenDelaying, interpolator, new Animator.AnimatorListener[]{});
}

YoYo.AnimationComposer composer = YoYo.with(technique).duration(duration).delay(delay).interpolate(interpolator);
for(Animator.AnimatorListener l : listeners)
composer.withListener(l);
public void addChildAppearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, boolean hiddenWhenDelaying, Interpolator interpolator, Animator.AnimatorListener... listeners){
AnimationProxy executor = AnimationProxy.build(hoverView, resId, technique, duration, delay, hiddenWhenDelaying, interpolator, listeners);

if(mChildAppearAnimationComposers.get(child) == null){
mChildAppearAnimationComposers.put(child, new ArrayList<YoYo.AnimationComposer>());
}
composer.withListener(mGlobalListener);
composer.withListener(mGlobalAppearingAnimators);
mChildAppearAnimationComposers.get(child).add(composer);
}
View child = executor.getTarget();

public void addChildAppearAnimator(View child, Animator animator){
if(animator == null)
throw new IllegalStateException("animator can not be null");
if(child == null)
throw new IllegalStateException("child view can not be null");
if(mChildAppearAnimators.get(child) == null)
mChildAppearAnimators.put(child, new ArrayList<AnimationProxy>());

animator.setTarget(child);
if(mChildAppearAnimators.containsKey(child) == false){
mChildAppearAnimators.put(child, new ArrayList<Animator>());
}
animator.addListener(mGlobalListener);
animator.addListener(mGlobalAppearingAnimators);
mChildAppearAnimators.get(child).add(animator);
executor.withListener(mGlobalListener);
executor.withListener(mGlobalAppearingAnimators);
child.setVisibility(INVISIBLE);

mChildAppearAnimators.get(child).add(executor);
}

public void addChildAppearAnimator(View hoverView, int childId, Animator animator){
AnimationProxy executor = AnimationProxy.build(hoverView, childId, animator);

View child = executor.getTarget();

if(mChildAppearAnimators.get(child) == null)
mChildAppearAnimators.put(child, new ArrayList<AnimationProxy>());

executor.withListener(mGlobalListener);
executor.withListener(mGlobalAppearingAnimators);
mChildAppearAnimators.get(child).add(executor);
}

public void addChildDisappearAnimator(View hoverView, int resId, Techniques technique){
addChildDisappearAnimator(hoverView, resId, technique, DURATION);
}

public void addChildDisappearAnimator(View hoverView, int resId, Techniques technique, long duration){
addChildDisappearAnimator(hoverView, resId, technique, duration, 0);
addChildDisappearAnimator(hoverView, resId, technique, duration, 0, false);
}

public void addChildDisappearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay){
addChildDisappearAnimator(hoverView, resId, technique, duration, delay, null);
addChildDisappearAnimator(hoverView, resId, technique, duration, delay, false, null);
}

public void addChildDisappearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, Interpolator interpolator){
addChildDisappearAnimator(hoverView, resId, technique, duration, delay, interpolator, new Animator.AnimatorListener[]{});
public void addChildDisappearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, boolean invisibleWhenDelaying){
addChildDisappearAnimator(hoverView, resId, technique, duration, delay,invisibleWhenDelaying, null);
}

public void addChildDisappearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, Interpolator interpolator, Animator.AnimatorListener... listeners){
if(hoverView == null)
throw new IllegalStateException("Hover view is null");
if(hoverView.findViewById(resId) == null)
throw new IllegalStateException("Can not find the child view");
public void addChildDisappearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, boolean invisibleWhenDelaying, Interpolator interpolator){
addChildDisappearAnimator(hoverView, resId, technique, duration, delay, invisibleWhenDelaying, interpolator, new Animator.AnimatorListener[]{});
}

View child = hoverView.findViewById(resId);
public void addChildDisappearAnimator(View hoverView, int resId, Techniques technique, long duration, long delay, boolean invisibleWhenDelaying, Interpolator interpolator, Animator.AnimatorListener... listeners){

YoYo.AnimationComposer composer = YoYo.with(technique).duration(duration).delay(delay).interpolate(interpolator);
for(Animator.AnimatorListener l : listeners){
composer.withListener(l);
}
if(mChildDisappearAnimationComposers.containsKey(child) == false){
mChildDisappearAnimationComposers.put(child, new ArrayList<YoYo.AnimationComposer>());
}
composer.withListener(mGlobalListener);
composer.withListener(mGlobalDisappearAnimators);
mChildDisappearAnimationComposers.get(child).add(composer);
AnimationProxy executor = AnimationProxy.build(hoverView, resId, technique, duration, delay, invisibleWhenDelaying, interpolator, listeners);

View child = executor.getTarget();
if(mChildDisappearAnimators.containsKey(child) == false)
mChildDisappearAnimators.put(child, new ArrayList<AnimationProxy>());

executor.withListener(mGlobalListener);
executor.withListener(mGlobalDisappearAnimators);
mChildDisappearAnimators.get(child).add(executor);
}

public void addChildDisappearAnimator(View child, Animator animator){
if(animator == null)
throw new IllegalStateException("animator can not be null");
if(child == null)
throw new IllegalStateException("child view can not be null");
public void addChildDisappearAnimator(View hoverView, int childId, Animator animator){
AnimationProxy executor = AnimationProxy.build(hoverView, childId, animator);

animator.setTarget(child);
animator.addListener(mGlobalListener);
animator.addListener(mGlobalDisappearAnimators);
if(mChildDisappearAnimators.containsKey(child) == false){
mChildDisappearAnimators.put(child, new ArrayList<Animator>());
}
mChildDisappearAnimators.get(child).add(animator);
View child = executor.getTarget();

if(mChildDisappearAnimators.get(child) == null)
mChildDisappearAnimators.put(child, new ArrayList<AnimationProxy>());

executor.withListener(mGlobalListener);
executor.withListener(mGlobalDisappearAnimators);
mChildDisappearAnimators.get(child).add(executor);
}

public LayoutParams getFullParentSizeLayoutParams(){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.daimajia.androidviewhover.proxy;

import android.view.View;
import android.view.animation.Interpolator;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.nineoldandroids.animation.Animator;

public class AnimationProxy implements Runnable {

private YoYo.AnimationComposer composer = null;
private Animator animator = null;

private long delay;
private long duration;
private boolean invisibleWhenDelaying;
private View targetView;
private Interpolator interpolator;

private long startTime = -1;

private AnimationProxy(View hoverView, int resId, Techniques technique, long duration, long delay, boolean invisibleWhenDelaying, Interpolator interpolator, Animator.AnimatorListener... listeners){
if(hoverView == null)
throw new IllegalStateException("Hover view is null");

View child = hoverView.findViewById(resId);

if(child == null)
throw new IllegalStateException("Can not find the child view");

if(duration < 0)
throw new IllegalArgumentException("Duration can not be less than 0");

if(delay < 0)
throw new IllegalArgumentException("Delay can not be less than 0");

this.composer = YoYo.with(technique).duration(duration).delay(delay).interpolate(interpolator);

this.targetView = child;
this.interpolator = interpolator;
this.delay = delay;
this.duration = duration;
this.invisibleWhenDelaying = invisibleWhenDelaying;

for(Animator.AnimatorListener l : listeners)
this.composer.withListener(l);
}

public static AnimationProxy build(View hoverView, int resId, Techniques technique, long duration, long delay, boolean invisibleWhenDelaying, Interpolator interpolator, Animator.AnimatorListener... listeners){
return new AnimationProxy(hoverView, resId, technique, duration, delay, invisibleWhenDelaying, interpolator, listeners);
}

public static AnimationProxy build(View hoverView, int childId, Animator animator){
return new AnimationProxy(hoverView, childId, animator);
}

private AnimationProxy(View hoverView, int childId, Animator animator){
if(animator == null)
throw new IllegalArgumentException("Animator can not be null");

if(hoverView == null)
throw new IllegalArgumentException("hoverView can not be null");

View child = hoverView.findViewById(childId);
if(child == null)
throw new IllegalArgumentException("Can not find child");

this.targetView = child;
this.duration = animator.getDuration();
this.delay = animator.getStartDelay();
this.interpolator = null;
this.animator = animator;
}

public void start(){
startTime = System.currentTimeMillis();
targetView.post(this);
}

public boolean isDelaying(){
long current = System.currentTimeMillis();
if(current - startTime <= delay)
return true;
else
return false;
}

@Override
public void run() {
if(startTime == -1)
throw new IllegalStateException("You can not call run directly, you should call start!");

if(!isDelaying()){
if(targetView.getVisibility() != View.VISIBLE)
targetView.setVisibility(View.VISIBLE);

if(composer!=null){
composer.delay(0);
composer.playOn(targetView);
}
if(animator != null){
animator.setStartDelay(0);
animator.start();
}
}else{
if(invisibleWhenDelaying && targetView.getVisibility() != View.INVISIBLE){
targetView.setVisibility(View.INVISIBLE);
}
targetView.post(this);
}
}

public View getTarget(){
return this.targetView;
}

public void withListener(Animator.AnimatorListener l){
if(composer != null)
composer.withListener(l);
if(animator != null)
animator.addListener(l);
}
}

0 comments on commit f932049

Please sign in to comment.