From afbce2e012a811b808a3be97ecf81c3e00c846f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20Kwiecie=C5=84?= Date: Tue, 19 May 2015 11:57:09 +0200 Subject: [PATCH] added animation cancel --- .../pl/aprilapps/switcher/Animations.java | 10 ++++++++ .../java/pl/aprilapps/switcher/Switcher.java | 24 ++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/switcher-library/src/main/java/pl/aprilapps/switcher/Animations.java b/switcher-library/src/main/java/pl/aprilapps/switcher/Animations.java index cb4d483..7e634f6 100644 --- a/switcher-library/src/main/java/pl/aprilapps/switcher/Animations.java +++ b/switcher-library/src/main/java/pl/aprilapps/switcher/Animations.java @@ -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); + } }); } @@ -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); + } }); } } diff --git a/switcher-library/src/main/java/pl/aprilapps/switcher/Switcher.java b/switcher-library/src/main/java/pl/aprilapps/switcher/Switcher.java index 133bb3b..c74798a 100644 --- a/switcher-library/src/main/java/pl/aprilapps/switcher/Switcher.java +++ b/switcher-library/src/main/java/pl/aprilapps/switcher/Switcher.java @@ -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; @@ -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() {