Skip to content

Commit

Permalink
added animation cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Kwiecień committed May 19, 2015
1 parent 009708b commit afbce2e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public static void fadeIn(final View view, int animDuration) {
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.VISIBLE);
}

@Override
public void onAnimationCancel(Animator animation) {
view.setVisibility(View.VISIBLE);
}
});
}

Expand All @@ -38,6 +43,11 @@ public static void fadeOut(final View view, int animDuration) {
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.INVISIBLE);
}

@Override
public void onAnimationCancel(Animator animation) {
view.setVisibility(View.INVISIBLE);
}
});
}
}
24 changes: 18 additions & 6 deletions switcher-library/src/main/java/pl/aprilapps/switcher/Switcher.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package pl.aprilapps.switcher;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -98,16 +100,26 @@ private void setupViews() {
}

private static View getCurrentlyVisibleView(View viewToShow) {
try {
FrameLayout parent = (FrameLayout) viewToShow.getParent();

ViewParent parentView = viewToShow.getParent();

if (parentView instanceof FrameLayout) {

FrameLayout parent = (FrameLayout) parentView;
View visibleView = null;

for (int i = 0; i < parent.getChildCount(); i++) {
View child = parent.getChildAt(i);
if (child.getVisibility() == View.VISIBLE) return child;
}
} catch (ClassCastException e) {
child.animate().cancel();

if (child.getVisibility() == View.VISIBLE) visibleView = child;
}
if (visibleView != null) return visibleView;
else throw new Resources.NotFoundException("Visible view not found");
} else {
throw new ClassCastException("All state views (content|error|progress|blur) should have the same FrameLayout parent");
}
throw new ClassCastException("All state views (content|error|progress) should have the same FrameLayout parent");

}

public void showContentView() {
Expand Down

0 comments on commit afbce2e

Please sign in to comment.