StackStateAnimator.java revision b036ca4de8e93d83bcdc093fbf8f096dc18a810d
1572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek/* 2572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * Copyright (C) 2014 The Android Open Source Project 3572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * 4572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 5572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * you may not use this file except in compliance with the License. 6572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * You may obtain a copy of the License at 7572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * 8572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * http://www.apache.org/licenses/LICENSE-2.0 9572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * 10572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * Unless required by applicable law or agreed to in writing, software 11572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 12572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * See the License for the specific language governing permissions and 14572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * limitations under the License 15572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek */ 16572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 17572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinekpackage com.android.systemui.statusbar.stack; 18572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 19eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinekimport android.animation.Animator; 20eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinekimport android.animation.AnimatorListenerAdapter; 21eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinekimport android.animation.ObjectAnimator; 22d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggiimport android.animation.PropertyValuesHolder; 23572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinekimport android.animation.ValueAnimator; 24572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinekimport android.view.View; 25572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinekimport android.view.animation.AnimationUtils; 26572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinekimport android.view.animation.Interpolator; 27eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 28eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinekimport com.android.systemui.R; 29572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinekimport com.android.systemui.statusbar.ExpandableView; 308b73006a36b3000a9847534dcb01a2e7066e9d93Jorim Jaggiimport com.android.systemui.statusbar.SpeedBumpView; 31572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 32572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinekimport java.util.ArrayList; 33eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinekimport java.util.HashSet; 34eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinekimport java.util.Set; 35eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinekimport java.util.Stack; 36572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 37572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek/** 38572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek * An stack state animator which handles animations to new StackScrollStates 39572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek */ 40572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinekpublic class StackStateAnimator { 41572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 425aa045cc6bca84f5c11f1a99999546ba5e5949a5Jorim Jaggi public static final int ANIMATION_DURATION_STANDARD = 360; 4360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi public static final int ANIMATION_DURATION_GO_TO_FULL_SHADE = 448; 448efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek public static final int ANIMATION_DURATION_APPEAR_DISAPPEAR = 464; 455aa045cc6bca84f5c11f1a99999546ba5e5949a5Jorim Jaggi public static final int ANIMATION_DURATION_DIMMED_ACTIVATED = 220; 468efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek public static final int ANIMATION_DELAY_PER_ELEMENT_INTERRUPTING = 80; 478efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek public static final int ANIMATION_DELAY_PER_ELEMENT_MANUAL = 32; 4860d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi public static final int ANIMATION_DELAY_PER_ELEMENT_GO_TO_FULL_SHADE = 48; 494e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi public static final int ANIMATION_DELAY_PER_ELEMENT_DARK = 24; 508efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek private static final int DELAY_EFFECT_MAX_INDEX_DIFFERENCE = 2; 515aa045cc6bca84f5c11f1a99999546ba5e5949a5Jorim Jaggi 52eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_ANIMATOR_TRANSLATION_Y = R.id.translation_y_animator_tag; 53eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_ANIMATOR_TRANSLATION_Z = R.id.translation_z_animator_tag; 54d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi private static final int TAG_ANIMATOR_SCALE = R.id.scale_animator_tag; 55eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_ANIMATOR_ALPHA = R.id.alpha_animator_tag; 56eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_ANIMATOR_HEIGHT = R.id.height_animator_tag; 57eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_ANIMATOR_TOP_INSET = R.id.top_inset_animator_tag; 58eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_END_TRANSLATION_Y = R.id.translation_y_animator_end_value_tag; 59eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_END_TRANSLATION_Z = R.id.translation_z_animator_end_value_tag; 60d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi private static final int TAG_END_SCALE = R.id.scale_animator_end_value_tag; 61eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_END_ALPHA = R.id.alpha_animator_end_value_tag; 62eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_END_HEIGHT = R.id.height_animator_end_value_tag; 63eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private static final int TAG_END_TOP_INSET = R.id.top_inset_animator_end_value_tag; 648df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek private static final int TAG_START_TRANSLATION_Y = R.id.translation_y_animator_start_value_tag; 658df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek private static final int TAG_START_TRANSLATION_Z = R.id.translation_z_animator_start_value_tag; 668df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek private static final int TAG_START_SCALE = R.id.scale_animator_start_value_tag; 678df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek private static final int TAG_START_ALPHA = R.id.alpha_animator_start_value_tag; 688df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek private static final int TAG_START_HEIGHT = R.id.height_animator_start_value_tag; 698df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek private static final int TAG_START_TOP_INSET = R.id.top_inset_animator_start_value_tag; 70572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 71572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek private final Interpolator mFastOutSlowInInterpolator; 7260d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi private final int mGoToFullShadeAppearingTranslation; 73572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek public NotificationStackScrollLayout mHostLayout; 74eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private ArrayList<NotificationStackScrollLayout.AnimationEvent> mNewEvents = 75eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek new ArrayList<>(); 768efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek private ArrayList<View> mNewAddChildren = new ArrayList<>(); 7760d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi private Set<Animator> mAnimatorSet = new HashSet<>(); 7860d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi private Stack<AnimatorListenerAdapter> mAnimationListenerPool = new Stack<>(); 79d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi private AnimationFilter mAnimationFilter = new AnimationFilter(); 805aa045cc6bca84f5c11f1a99999546ba5e5949a5Jorim Jaggi private long mCurrentLength; 81dbc3dce886cb7abba23a9f18e60d0f5af5c93226Jorim Jaggi private long mCurrentAdditionalDelay; 82572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 8360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi /** The current index for the last child which was not added in this event set. */ 8460d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi private int mCurrentLastNotAddedIndex; 8560d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi 868d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek private ValueAnimator mTopOverScrollAnimator; 878d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek private ValueAnimator mBottomOverScrollAnimator; 888d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek 89572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek public StackStateAnimator(NotificationStackScrollLayout hostLayout) { 90572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek mHostLayout = hostLayout; 91572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(hostLayout.getContext(), 92eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek android.R.interpolator.fast_out_slow_in); 9360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi mGoToFullShadeAppearingTranslation = 9460d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi hostLayout.getContext().getResources().getDimensionPixelSize( 9560d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi R.dimen.go_to_full_shade_appearing_translation); 96572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 97572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 98572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek public boolean isRunning() { 99eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek return !mAnimatorSet.isEmpty(); 100572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 101572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 102572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek public void startAnimationForEvents( 1030dd6881ea481c855976214807c17595b34a2920aJorim Jaggi ArrayList<NotificationStackScrollLayout.AnimationEvent> mAnimationEvents, 104dbc3dce886cb7abba23a9f18e60d0f5af5c93226Jorim Jaggi StackScrollState finalState, long additionalDelay) { 105eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 106eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek processAnimationEvents(mAnimationEvents, finalState); 107eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 108572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek int childCount = mHostLayout.getChildCount(); 109d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi mAnimationFilter.applyCombination(mNewEvents); 110dbc3dce886cb7abba23a9f18e60d0f5af5c93226Jorim Jaggi mCurrentAdditionalDelay = additionalDelay; 1115aa045cc6bca84f5c11f1a99999546ba5e5949a5Jorim Jaggi mCurrentLength = NotificationStackScrollLayout.AnimationEvent.combineLength(mNewEvents); 11260d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi mCurrentLastNotAddedIndex = findLastNotAddedIndex(finalState); 113572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek for (int i = 0; i < childCount; i++) { 114572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek final ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i); 1158efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 116b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek StackViewState viewState = finalState.getViewStateForView(child); 1178efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (viewState == null || child.getVisibility() == View.GONE) { 118572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek continue; 119572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 120572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 121572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek child.setClipBounds(null); 122b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek startStackAnimations(child, viewState, finalState, i, -1 /* fixedDelay */); 123572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 124eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek if (!isRunning()) { 125eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek // no child has preformed any animation, lets finish 126eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek onAnimationFinished(); 127eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 1288efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek mNewEvents.clear(); 1298efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek mNewAddChildren.clear(); 130572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 131572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 13260d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi private int findLastNotAddedIndex(StackScrollState finalState) { 13360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi int childCount = mHostLayout.getChildCount(); 13460d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi for (int i = childCount - 1; i >= 0; i--) { 13560d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi final ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i); 13660d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi 137b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek StackViewState viewState = finalState.getViewStateForView(child); 13860d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi if (viewState == null || child.getVisibility() == View.GONE) { 13960d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi continue; 14060d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi } 14160d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi if (!mNewAddChildren.contains(child)) { 14260d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi return viewState.notGoneIndex; 14360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi } 14460d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi } 14560d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi return -1; 14660d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi } 14760d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi 148b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek 149eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek /** 150b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * Start an animation to the given {@link StackViewState}. 151b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * 152b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param child the child to start the animation on 153b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param viewState the {@link StackViewState} of the view to animate to 154b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param finalState the final state after the animation 155b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param i the index of the view; only relevant if the view is the speed bump and is 156b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * ignored otherwise 157b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param fixedDelay a fixed delay if desired or -1 if the delay should be calculated 158eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek */ 159b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek public void startStackAnimations(final ExpandableView child, StackViewState viewState, 160b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek StackScrollState finalState, int i, long fixedDelay) { 161eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek final float alpha = viewState.alpha; 162b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek boolean wasAdded = mNewAddChildren.contains(child); 163b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek long duration = mCurrentLength; 164b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek if (wasAdded && mAnimationFilter.hasGoToFullShadeEvent) { 165b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek child.setTranslationY(child.getTranslationY() + mGoToFullShadeAppearingTranslation); 166b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek float longerDurationFactor = viewState.notGoneIndex - mCurrentLastNotAddedIndex; 167b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek longerDurationFactor = (float) Math.pow(longerDurationFactor, 0.7f); 168b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek duration = ANIMATION_DURATION_APPEAR_DISAPPEAR + 50 + 169b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek (long) (100 * longerDurationFactor); 170eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 1718efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek boolean yTranslationChanging = child.getTranslationY() != viewState.yTranslation; 1728efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek boolean zTranslationChanging = child.getTranslationZ() != viewState.zTranslation; 1738efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek boolean scaleChanging = child.getScaleX() != viewState.scale; 1748efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek boolean alphaChanging = alpha != child.getAlpha(); 1758efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek boolean heightChanging = viewState.height != child.getActualHeight(); 1764e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi boolean darkChanging = viewState.dark != child.isDark(); 177708a6c120da6750d281195ef15a240a5627efed4Selim Cinek boolean topInsetChanging = viewState.clipTopAmount != child.getClipTopAmount(); 1788efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek boolean hasDelays = mAnimationFilter.hasDelays; 1798efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek boolean isDelayRelevant = yTranslationChanging || zTranslationChanging || scaleChanging || 1804e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi alphaChanging || heightChanging || topInsetChanging || darkChanging; 1818efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek long delay = 0; 182b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek if (fixedDelay != -1) { 183b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek delay = fixedDelay; 184b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek } else if (hasDelays && isDelayRelevant || wasAdded) { 185dbc3dce886cb7abba23a9f18e60d0f5af5c93226Jorim Jaggi delay = mCurrentAdditionalDelay + calculateChildAnimationDelay(viewState, finalState); 1868efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 1878efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 188b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek startViewAnimations(child, viewState, delay, duration); 1898efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 190eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek // start height animation 191d2319fbe6a53ac4c38ca02e4d8e32da86ed0994bSelim Cinek if (heightChanging && child.getActualHeight() != 0) { 192b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek startHeightAnimation(child, viewState, duration, delay); 19359b5a356b828fe60ea2874b0680a1bf7c84809a1Jorim Jaggi } 1948efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 195708a6c120da6750d281195ef15a240a5627efed4Selim Cinek // start top inset animation 196708a6c120da6750d281195ef15a240a5627efed4Selim Cinek if (topInsetChanging) { 197b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek startInsetAnimation(child, viewState, duration, delay); 198708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } 199708a6c120da6750d281195ef15a240a5627efed4Selim Cinek 200d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi // start dimmed animation 201b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek child.setDimmed(viewState.dimmed, mAnimationFilter.animateDimmed); 2028efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 203bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock // start dark animation 204b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek child.setDark(viewState.dark, mAnimationFilter.animateDark, delay); 205bf370992508c55d1f2493923bdc1834a0710e4baJohn Spurlock 2063d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek // apply speed bump state 2073d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek child.setBelowSpeedBump(viewState.belowSpeedBump); 2083d2b94bf8e32640e57573ebb17911b1db9440231Selim Cinek 209ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi // start hiding sensitive animation 210b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek child.setHideSensitive(viewState.hideSensitive, mAnimationFilter.animateHideSensitive, 211b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek delay, duration); 212ae44128776410abd11bd06ae700db9cc4606a773Jorim Jaggi 2138efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (wasAdded) { 21460d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi child.performAddAnimation(delay, mCurrentLength); 2158efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 2168b73006a36b3000a9847534dcb01a2e7066e9d93Jorim Jaggi if (child instanceof SpeedBumpView) { 2178b73006a36b3000a9847534dcb01a2e7066e9d93Jorim Jaggi finalState.performSpeedBumpAnimation(i, (SpeedBumpView) child, viewState, 2188b73006a36b3000a9847534dcb01a2e7066e9d93Jorim Jaggi delay + duration); 2198b73006a36b3000a9847534dcb01a2e7066e9d93Jorim Jaggi } 2208efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 2218efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 222b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek /** 223b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * Start an animation to a new {@link ViewState}. 224b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * 225b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param child the child to start the animation on 226b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param viewState the {@link StackViewState} of the view to animate to 227b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param delay a fixed delay 228b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek * @param duration the duration of the animation 229b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek */ 230b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek public void startViewAnimations(View child, ViewState viewState, long delay, long duration) { 231b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek boolean wasVisible = child.getVisibility() == View.VISIBLE; 232b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek final float alpha = viewState.alpha; 233b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek if (!wasVisible && alpha != 0 && !viewState.gone) { 234b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek child.setVisibility(View.VISIBLE); 235b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek } 236b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek boolean yTranslationChanging = child.getTranslationY() != viewState.yTranslation; 237b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek boolean zTranslationChanging = child.getTranslationZ() != viewState.zTranslation; 238b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek boolean scaleChanging = child.getScaleX() != viewState.scale; 239b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek float childAlpha = child.getVisibility() == View.INVISIBLE ? 0.0f : child.getAlpha(); 240b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek boolean alphaChanging = viewState.alpha != childAlpha; 241b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek 242b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek // start translationY animation 243b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek if (yTranslationChanging) { 244b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek startYTranslationAnimation(child, viewState, duration, delay); 245b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek } 246b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek 247b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek // start translationZ animation 248b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek if (zTranslationChanging) { 249b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek startZTranslationAnimation(child, viewState, duration, delay); 250b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek } 251b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek 252b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek // start scale animation 253b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek if (scaleChanging) { 254b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek startScaleAnimation(child, viewState, duration); 255b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek } 256b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek 257b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek // start alpha animation 258b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek if (alphaChanging && child.getTranslationX() == 0) { 259b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek startAlphaAnimation(child, viewState, duration, delay); 260b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek } 261b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek } 262b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek 263b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek private long calculateChildAnimationDelay(StackViewState viewState, 2648efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek StackScrollState finalState) { 2654e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi if (mAnimationFilter.hasDarkEvent) { 2664e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi return calculateDelayDark(viewState); 2674e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi } 26860d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi if (mAnimationFilter.hasGoToFullShadeEvent) { 26960d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi return calculateDelayGoToFullShade(viewState); 27060d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi } 2718efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek long minDelay = 0; 2728efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek for (NotificationStackScrollLayout.AnimationEvent event : mNewEvents) { 2738efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek long delayPerElement = ANIMATION_DELAY_PER_ELEMENT_INTERRUPTING; 2748efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek switch (event.animationType) { 2758efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek case NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_ADD: { 2768efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek int ownIndex = viewState.notGoneIndex; 2778efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek int changingIndex = finalState 2788efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek .getViewStateForView(event.changingView).notGoneIndex; 2798efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek int difference = Math.abs(ownIndex - changingIndex); 2808efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek difference = Math.max(0, Math.min(DELAY_EFFECT_MAX_INDEX_DIFFERENCE, 2818efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek difference - 1)); 2828efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek long delay = (DELAY_EFFECT_MAX_INDEX_DIFFERENCE - difference) * delayPerElement; 2838efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek minDelay = Math.max(delay, minDelay); 2848efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek break; 2858efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 2868efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek case NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT: 2878efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek delayPerElement = ANIMATION_DELAY_PER_ELEMENT_MANUAL; 2888efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek case NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_REMOVE: { 2898efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek int ownIndex = viewState.notGoneIndex; 2908efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek boolean noNextView = event.viewAfterChangingView == null; 2918efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek View viewAfterChangingView = noNextView 2928efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek ? mHostLayout.getLastChildNotGone() 2938efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek : event.viewAfterChangingView; 2948efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 2958efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek int nextIndex = finalState 2968efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek .getViewStateForView(viewAfterChangingView).notGoneIndex; 2978efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (ownIndex >= nextIndex) { 2988efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // we only have the view afterwards 2998efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek ownIndex++; 3008efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 3018efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek int difference = Math.abs(ownIndex - nextIndex); 3028efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek difference = Math.max(0, Math.min(DELAY_EFFECT_MAX_INDEX_DIFFERENCE, 3038efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek difference - 1)); 3048efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek long delay = difference * delayPerElement; 3058efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek minDelay = Math.max(delay, minDelay); 3068efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek break; 3078efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 3088efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek default: 3098efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek break; 3108efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 3118efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 3128efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek return minDelay; 313572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 314572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 315b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek private long calculateDelayDark(StackViewState viewState) { 3162a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi int referenceIndex; 3172a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi if (mAnimationFilter.darkAnimationOriginIndex == 3182a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi NotificationStackScrollLayout.AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE) { 3192a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi referenceIndex = 0; 3202a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi } else if (mAnimationFilter.darkAnimationOriginIndex == 3212a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi NotificationStackScrollLayout.AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW) { 3222a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi referenceIndex = mHostLayout.getNotGoneChildCount() - 1; 3232a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi } else { 3242a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi referenceIndex = mAnimationFilter.darkAnimationOriginIndex; 3252a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi } 3262a5e452f4f70d2dd717946dd50486cc66ea4cc43Jorim Jaggi return Math.abs(referenceIndex - viewState.notGoneIndex) * ANIMATION_DELAY_PER_ELEMENT_DARK; 3274e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi } 3284e857f4ef0357e05806819d0488a73a12208fe8fJorim Jaggi 329b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek private long calculateDelayGoToFullShade(StackViewState viewState) { 33060d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi float index = viewState.notGoneIndex; 33160d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi index = (float) Math.pow(index, 0.7f); 33260d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi return (long) (index * ANIMATION_DELAY_PER_ELEMENT_GO_TO_FULL_SHADE); 33360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi } 33460d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi 335eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private void startHeightAnimation(final ExpandableView child, 336b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek StackViewState viewState, long duration, long delay) { 3378df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek Integer previousStartValue = getChildTag(child, TAG_START_HEIGHT); 338d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi Integer previousEndValue = getChildTag(child, TAG_END_HEIGHT); 3398df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek int newEndValue = viewState.height; 3408df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousEndValue != null && previousEndValue == newEndValue) { 341eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek return; 342eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 343eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek ValueAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_HEIGHT); 3448df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (!mAnimationFilter.animateHeight) { 3458df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // just a local update was performed 3468df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousAnimator != null) { 3478df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // we need to increase all animation keyframes of the previous animator by the 3488df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // relative change to the end value 3498df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek PropertyValuesHolder[] values = previousAnimator.getValues(); 3508df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek int relativeDiff = newEndValue - previousEndValue; 3518df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek int newStartValue = previousStartValue + relativeDiff; 3528df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek values[0].setIntValues(newStartValue, newEndValue); 3538df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_HEIGHT, newStartValue); 3548df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_HEIGHT, newEndValue); 3558df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); 3568df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek return; 3578df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek } else { 3588df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // no new animation needed, let's just apply the value 3598df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setActualHeight(newEndValue, false); 3608df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek return; 361eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 362eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 363eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 3648df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek ValueAnimator animator = ValueAnimator.ofInt(child.getActualHeight(), newEndValue); 365eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 366572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek @Override 367572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek public void onAnimationUpdate(ValueAnimator animation) { 368d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi child.setActualHeight((int) animation.getAnimatedValue(), 369d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi false /* notifyListeners */); 370572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 371572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek }); 372eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.setInterpolator(mFastOutSlowInInterpolator); 37360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator); 374eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.setDuration(newDuration); 3758efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (delay > 0 && (previousAnimator == null || !previousAnimator.isRunning())) { 3768efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek animator.setStartDelay(delay); 3778efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 378eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addListener(getGlobalAnimationFinishedListener()); 379eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek // remove the tag when the animation is finished 380eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addListener(new AnimatorListenerAdapter() { 381eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek @Override 382eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek public void onAnimationEnd(Animator animation) { 383eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_ANIMATOR_HEIGHT, null); 3848df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_HEIGHT, null); 385eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_END_HEIGHT, null); 386eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 387eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek }); 3888efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek startAnimator(animator); 389eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_ANIMATOR_HEIGHT, animator); 3908df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_HEIGHT, child.getActualHeight()); 3918df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_HEIGHT, newEndValue); 392eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 393eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 394708a6c120da6750d281195ef15a240a5627efed4Selim Cinek private void startInsetAnimation(final ExpandableView child, 395b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek StackViewState viewState, long duration, long delay) { 396708a6c120da6750d281195ef15a240a5627efed4Selim Cinek Integer previousStartValue = getChildTag(child, TAG_START_TOP_INSET); 397708a6c120da6750d281195ef15a240a5627efed4Selim Cinek Integer previousEndValue = getChildTag(child, TAG_END_TOP_INSET); 398708a6c120da6750d281195ef15a240a5627efed4Selim Cinek int newEndValue = viewState.clipTopAmount; 399708a6c120da6750d281195ef15a240a5627efed4Selim Cinek if (previousEndValue != null && previousEndValue == newEndValue) { 400708a6c120da6750d281195ef15a240a5627efed4Selim Cinek return; 401708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } 402708a6c120da6750d281195ef15a240a5627efed4Selim Cinek ValueAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_TOP_INSET); 403708a6c120da6750d281195ef15a240a5627efed4Selim Cinek if (!mAnimationFilter.animateTopInset) { 404708a6c120da6750d281195ef15a240a5627efed4Selim Cinek // just a local update was performed 405708a6c120da6750d281195ef15a240a5627efed4Selim Cinek if (previousAnimator != null) { 406708a6c120da6750d281195ef15a240a5627efed4Selim Cinek // we need to increase all animation keyframes of the previous animator by the 407708a6c120da6750d281195ef15a240a5627efed4Selim Cinek // relative change to the end value 408708a6c120da6750d281195ef15a240a5627efed4Selim Cinek PropertyValuesHolder[] values = previousAnimator.getValues(); 409708a6c120da6750d281195ef15a240a5627efed4Selim Cinek int relativeDiff = newEndValue - previousEndValue; 410708a6c120da6750d281195ef15a240a5627efed4Selim Cinek int newStartValue = previousStartValue + relativeDiff; 411708a6c120da6750d281195ef15a240a5627efed4Selim Cinek values[0].setIntValues(newStartValue, newEndValue); 412708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setTag(TAG_START_TOP_INSET, newStartValue); 413708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setTag(TAG_END_TOP_INSET, newEndValue); 414708a6c120da6750d281195ef15a240a5627efed4Selim Cinek previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); 415708a6c120da6750d281195ef15a240a5627efed4Selim Cinek return; 416708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } else { 417708a6c120da6750d281195ef15a240a5627efed4Selim Cinek // no new animation needed, let's just apply the value 418708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setClipTopAmount(newEndValue); 419708a6c120da6750d281195ef15a240a5627efed4Selim Cinek return; 420708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } 421708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } 422708a6c120da6750d281195ef15a240a5627efed4Selim Cinek 423708a6c120da6750d281195ef15a240a5627efed4Selim Cinek ValueAnimator animator = ValueAnimator.ofInt(child.getClipTopAmount(), newEndValue); 424708a6c120da6750d281195ef15a240a5627efed4Selim Cinek animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 425708a6c120da6750d281195ef15a240a5627efed4Selim Cinek @Override 426708a6c120da6750d281195ef15a240a5627efed4Selim Cinek public void onAnimationUpdate(ValueAnimator animation) { 427708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setClipTopAmount((int) animation.getAnimatedValue()); 428708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } 429708a6c120da6750d281195ef15a240a5627efed4Selim Cinek }); 430708a6c120da6750d281195ef15a240a5627efed4Selim Cinek animator.setInterpolator(mFastOutSlowInInterpolator); 43160d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator); 432708a6c120da6750d281195ef15a240a5627efed4Selim Cinek animator.setDuration(newDuration); 433708a6c120da6750d281195ef15a240a5627efed4Selim Cinek if (delay > 0 && (previousAnimator == null || !previousAnimator.isRunning())) { 434708a6c120da6750d281195ef15a240a5627efed4Selim Cinek animator.setStartDelay(delay); 435708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } 436708a6c120da6750d281195ef15a240a5627efed4Selim Cinek animator.addListener(getGlobalAnimationFinishedListener()); 437708a6c120da6750d281195ef15a240a5627efed4Selim Cinek // remove the tag when the animation is finished 438708a6c120da6750d281195ef15a240a5627efed4Selim Cinek animator.addListener(new AnimatorListenerAdapter() { 439708a6c120da6750d281195ef15a240a5627efed4Selim Cinek @Override 440708a6c120da6750d281195ef15a240a5627efed4Selim Cinek public void onAnimationEnd(Animator animation) { 441708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setTag(TAG_ANIMATOR_TOP_INSET, null); 442708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setTag(TAG_START_TOP_INSET, null); 443708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setTag(TAG_END_TOP_INSET, null); 444708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } 445708a6c120da6750d281195ef15a240a5627efed4Selim Cinek }); 446708a6c120da6750d281195ef15a240a5627efed4Selim Cinek startAnimator(animator); 447708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setTag(TAG_ANIMATOR_TOP_INSET, animator); 448708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setTag(TAG_START_TOP_INSET, child.getClipTopAmount()); 449708a6c120da6750d281195ef15a240a5627efed4Selim Cinek child.setTag(TAG_END_TOP_INSET, newEndValue); 450708a6c120da6750d281195ef15a240a5627efed4Selim Cinek } 451708a6c120da6750d281195ef15a240a5627efed4Selim Cinek 452b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek private void startAlphaAnimation(final View child, 453b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek final ViewState viewState, long duration, long delay) { 4548df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek Float previousStartValue = getChildTag(child,TAG_START_ALPHA); 455eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek Float previousEndValue = getChildTag(child,TAG_END_ALPHA); 4568df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek final float newEndValue = viewState.alpha; 4578df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousEndValue != null && previousEndValue == newEndValue) { 458eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek return; 459eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 460eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_ALPHA); 4618df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (!mAnimationFilter.animateAlpha) { 4628df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // just a local update was performed 4638df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousAnimator != null) { 4648df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // we need to increase all animation keyframes of the previous animator by the 4658df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // relative change to the end value 4668df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek PropertyValuesHolder[] values = previousAnimator.getValues(); 4678df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float relativeDiff = newEndValue - previousEndValue; 4688df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float newStartValue = previousStartValue + relativeDiff; 4698df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek values[0].setFloatValues(newStartValue, newEndValue); 4708df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_ALPHA, newStartValue); 4718df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_ALPHA, newEndValue); 4728df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); 4738df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek return; 4748df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek } else { 4758df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // no new animation needed, let's just apply the value 4768df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setAlpha(newEndValue); 4778df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (newEndValue == 0) { 4788df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setVisibility(View.INVISIBLE); 4798df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek } 480eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 481eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 482eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 483eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek ObjectAnimator animator = ObjectAnimator.ofFloat(child, View.ALPHA, 4848df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.getAlpha(), newEndValue); 485eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.setInterpolator(mFastOutSlowInInterpolator); 486eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek // Handle layer type 487eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setLayerType(View.LAYER_TYPE_HARDWARE, null); 488eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addListener(new AnimatorListenerAdapter() { 489eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek public boolean mWasCancelled; 490eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 491eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek @Override 492eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek public void onAnimationEnd(Animator animation) { 4931efb240c1a0aeca9492cf8891794712adfdb1fa7Selim Cinek child.setLayerType(View.LAYER_TYPE_NONE, null); 4948df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (newEndValue == 0 && !mWasCancelled) { 495eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setVisibility(View.INVISIBLE); 496eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 497c5baa3eb0893cb764e7810f8c68e89b04653df86Selim Cinek // remove the tag when the animation is finished 498eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_ANIMATOR_ALPHA, null); 4998df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_ALPHA, null); 500eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_END_ALPHA, null); 501eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 502eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 503eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek @Override 504eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek public void onAnimationCancel(Animator animation) { 505eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek mWasCancelled = true; 506eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 507eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 508eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek @Override 509eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek public void onAnimationStart(Animator animation) { 510eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek mWasCancelled = false; 511eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 512eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek }); 51360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator); 5143af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek animator.setDuration(newDuration); 5158efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (delay > 0 && (previousAnimator == null || !previousAnimator.isRunning())) { 5168efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek animator.setStartDelay(delay); 5178efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 518eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addListener(getGlobalAnimationFinishedListener()); 519eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 5208efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek startAnimator(animator); 521eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_ANIMATOR_ALPHA, animator); 5228df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_ALPHA, child.getAlpha()); 5238df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_ALPHA, newEndValue); 524572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 525572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek 526b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek private void startZTranslationAnimation(final View child, 527b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek final ViewState viewState, long duration, long delay) { 5288df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek Float previousStartValue = getChildTag(child,TAG_START_TRANSLATION_Z); 529eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek Float previousEndValue = getChildTag(child,TAG_END_TRANSLATION_Z); 5308df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float newEndValue = viewState.zTranslation; 5318df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousEndValue != null && previousEndValue == newEndValue) { 532eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek return; 533eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 534eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_TRANSLATION_Z); 5358df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (!mAnimationFilter.animateZ) { 5368df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // just a local update was performed 5378df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousAnimator != null) { 5388df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // we need to increase all animation keyframes of the previous animator by the 5398df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // relative change to the end value 5408df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek PropertyValuesHolder[] values = previousAnimator.getValues(); 5418df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float relativeDiff = newEndValue - previousEndValue; 5428df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float newStartValue = previousStartValue + relativeDiff; 5438df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek values[0].setFloatValues(newStartValue, newEndValue); 5448df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_TRANSLATION_Z, newStartValue); 5458df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_TRANSLATION_Z, newEndValue); 5468df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); 5478df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek return; 5488df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek } else { 5498df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // no new animation needed, let's just apply the value 5508df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTranslationZ(newEndValue); 551eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 552eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 553eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 554eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek ObjectAnimator animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Z, 5558df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.getTranslationZ(), newEndValue); 556eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.setInterpolator(mFastOutSlowInInterpolator); 55760d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator); 5583af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek animator.setDuration(newDuration); 5598efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (delay > 0 && (previousAnimator == null || !previousAnimator.isRunning())) { 5608efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek animator.setStartDelay(delay); 5618efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 562eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addListener(getGlobalAnimationFinishedListener()); 563eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek // remove the tag when the animation is finished 564eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addListener(new AnimatorListenerAdapter() { 565eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek @Override 566eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek public void onAnimationEnd(Animator animation) { 567eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_ANIMATOR_TRANSLATION_Z, null); 5688df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_TRANSLATION_Z, null); 569eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_END_TRANSLATION_Z, null); 570eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 571eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek }); 5728efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek startAnimator(animator); 573eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_ANIMATOR_TRANSLATION_Z, animator); 5748df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_TRANSLATION_Z, child.getTranslationZ()); 5758df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_TRANSLATION_Z, newEndValue); 576eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 577eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 578b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek private void startYTranslationAnimation(final View child, 579b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek ViewState viewState, long duration, long delay) { 5808df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek Float previousStartValue = getChildTag(child,TAG_START_TRANSLATION_Y); 581eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek Float previousEndValue = getChildTag(child,TAG_END_TRANSLATION_Y); 5828df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float newEndValue = viewState.yTranslation; 5838df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousEndValue != null && previousEndValue == newEndValue) { 584eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek return; 585eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 586eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_TRANSLATION_Y); 5878df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (!mAnimationFilter.animateY) { 5888df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // just a local update was performed 5898df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousAnimator != null) { 5908df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // we need to increase all animation keyframes of the previous animator by the 5918df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // relative change to the end value 5928df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek PropertyValuesHolder[] values = previousAnimator.getValues(); 5938df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float relativeDiff = newEndValue - previousEndValue; 5948df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float newStartValue = previousStartValue + relativeDiff; 5958df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek values[0].setFloatValues(newStartValue, newEndValue); 5968df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_TRANSLATION_Y, newStartValue); 5978df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_TRANSLATION_Y, newEndValue); 5988df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); 5998df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek return; 6008df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek } else { 6018df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // no new animation needed, let's just apply the value 6028df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTranslationY(newEndValue); 6038df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek return; 604eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 605eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 606eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 607eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek ObjectAnimator animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, 6088df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.getTranslationY(), newEndValue); 609eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.setInterpolator(mFastOutSlowInInterpolator); 61060d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator); 6113af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek animator.setDuration(newDuration); 6128efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (delay > 0 && (previousAnimator == null || !previousAnimator.isRunning())) { 6138efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek animator.setStartDelay(delay); 6148efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 615eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addListener(getGlobalAnimationFinishedListener()); 616eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek // remove the tag when the animation is finished 617eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek animator.addListener(new AnimatorListenerAdapter() { 618eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek @Override 619eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek public void onAnimationEnd(Animator animation) { 620eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_ANIMATOR_TRANSLATION_Y, null); 6218df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_TRANSLATION_Y, null); 622eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_END_TRANSLATION_Y, null); 623eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 624eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek }); 6258efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek startAnimator(animator); 626eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek child.setTag(TAG_ANIMATOR_TRANSLATION_Y, animator); 6278df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_TRANSLATION_Y, child.getTranslationY()); 6288df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_TRANSLATION_Y, newEndValue); 629eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 630eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 631b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek private void startScaleAnimation(final View child, 632b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek ViewState viewState, long duration) { 6338df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek Float previousStartValue = getChildTag(child, TAG_START_SCALE); 634d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi Float previousEndValue = getChildTag(child, TAG_END_SCALE); 6358df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float newEndValue = viewState.scale; 6368df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousEndValue != null && previousEndValue == newEndValue) { 637d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi return; 638d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi } 639d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_SCALE); 6408df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (!mAnimationFilter.animateScale) { 6418df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // just a local update was performed 6428df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek if (previousAnimator != null) { 6438df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // we need to increase all animation keyframes of the previous animator by the 6448df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // relative change to the end value 6458df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek PropertyValuesHolder[] values = previousAnimator.getValues(); 6468df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float relativeDiff = newEndValue - previousEndValue; 6478df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek float newStartValue = previousStartValue + relativeDiff; 6488df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek values[0].setFloatValues(newStartValue, newEndValue); 6498df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek values[1].setFloatValues(newStartValue, newEndValue); 6508df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_SCALE, newStartValue); 6518df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_SCALE, newEndValue); 6528df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime()); 6538df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek return; 6548df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek } else { 6558df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // no new animation needed, let's just apply the value 6568df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setScaleX(newEndValue); 6578df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setScaleY(newEndValue); 658d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi } 659d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi } 660d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi 661d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi PropertyValuesHolder holderX = 6628df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek PropertyValuesHolder.ofFloat(View.SCALE_X, child.getScaleX(), newEndValue); 663d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi PropertyValuesHolder holderY = 6648df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek PropertyValuesHolder.ofFloat(View.SCALE_Y, child.getScaleY(), newEndValue); 665d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(child, holderX, holderY); 666d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi animator.setInterpolator(mFastOutSlowInInterpolator); 66760d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator); 668d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi animator.setDuration(newDuration); 669d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi animator.addListener(getGlobalAnimationFinishedListener()); 670d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi // remove the tag when the animation is finished 671d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi animator.addListener(new AnimatorListenerAdapter() { 672d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi @Override 673d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi public void onAnimationEnd(Animator animation) { 674d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi child.setTag(TAG_ANIMATOR_SCALE, null); 6758df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_SCALE, null); 676d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi child.setTag(TAG_END_SCALE, null); 677d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi } 678d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi }); 6798efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek startAnimator(animator); 680d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi child.setTag(TAG_ANIMATOR_SCALE, animator); 6818df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_START_SCALE, child.getScaleX()); 6828df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek child.setTag(TAG_END_SCALE, newEndValue); 683d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi } 684d552d9d8e964c102e6832610be46cf2c041e8829Jorim Jaggi 6858efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek private void startAnimator(ValueAnimator animator) { 6868efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek mAnimatorSet.add(animator); 6873af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek animator.start(); 6883af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek } 6893af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek 6903af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek /** 6913af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek * @return an adapter which ensures that onAnimationFinished is called once no animation is 6923af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek * running anymore 6933af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek */ 6943af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek private AnimatorListenerAdapter getGlobalAnimationFinishedListener() { 6953af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek if (!mAnimationListenerPool.empty()) { 6963af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek return mAnimationListenerPool.pop(); 6973af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek } 6983af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek 6993af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek // We need to create a new one, no reusable ones found 7003af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek return new AnimatorListenerAdapter() { 7013af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek private boolean mWasCancelled; 7023af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek 7033af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek @Override 7043af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek public void onAnimationEnd(Animator animation) { 7053af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek mAnimatorSet.remove(animation); 7063af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek if (mAnimatorSet.isEmpty() && !mWasCancelled) { 7073af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek onAnimationFinished(); 7083af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek } 7093af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek mAnimationListenerPool.push(this); 7103af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek } 7113af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek 7123af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek @Override 7133af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek public void onAnimationCancel(Animator animation) { 7143af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek mWasCancelled = true; 7153af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek } 7163af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek 7173af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek @Override 7183af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek public void onAnimationStart(Animator animation) { 7193af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek mWasCancelled = false; 7203af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek } 7213af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek }; 7223af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek } 7233af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek 72402af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek private static <T> T getChildTag(View child, int tag) { 725eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek return (T) child.getTag(tag); 726eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 727eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 728eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek /** 729eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek * Cancel the previous animator and get the duration of the new animation. 73039610545f0c2714a3526bc935effe57b421542d1Selim Cinek * 73160d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi * @param duration the new duration 732eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek * @param previousAnimator the animator which was running before 733eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek * @return the new duration 734eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek */ 73560d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi private long cancelAnimatorAndGetNewDuration(long duration, ValueAnimator previousAnimator) { 73660d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi long newDuration = duration; 737eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek if (previousAnimator != null) { 7388df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // We take either the desired length of the new animation or the remaining time of 7398df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek // the previous animator, whichever is longer. 7408df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek newDuration = Math.max(previousAnimator.getDuration() 7418df56452cb696ebdee82df6fb255892eabf3febcSelim Cinek - previousAnimator.getCurrentPlayTime(), newDuration); 7423af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek previousAnimator.cancel(); 743eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 7443af00cf10660c7fdc0582dc12361c13673d0c9bbSelim Cinek return newDuration; 745eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 746eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 747eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private void onAnimationFinished() { 748eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek mHostLayout.onChildAnimationFinished(); 749eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek } 750eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek 751eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek /** 752eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek * Process the animationEvents for a new animation 753eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek * 754eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek * @param animationEvents the animation events for the animation to perform 75539610545f0c2714a3526bc935effe57b421542d1Selim Cinek * @param finalState the final state to animate to 75639610545f0c2714a3526bc935effe57b421542d1Selim Cinek */ 757eb973565f3efc6417ca35363e4d6c642947775d8Selim Cinek private void processAnimationEvents( 7580dd6881ea481c855976214807c17595b34a2920aJorim Jaggi ArrayList<NotificationStackScrollLayout.AnimationEvent> animationEvents, 759572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek StackScrollState finalState) { 7608d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek for (NotificationStackScrollLayout.AnimationEvent event : animationEvents) { 7618efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek final ExpandableView changingView = (ExpandableView) event.changingView; 7628efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (event.animationType == 7638efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_ADD) { 7648efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 7658efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // This item is added, initialize it's properties. 766b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek StackViewState viewState = finalState 7678efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek .getViewStateForView(changingView); 7688efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (viewState == null) { 7698efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // The position for this child was never generated, let's continue. 7708efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek continue; 7718efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 7728efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (changingView.getVisibility() == View.GONE) { 7738efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // The view was set to gone but the state never removed 7748efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek finalState.removeViewStateForView(changingView); 7758efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek continue; 77639610545f0c2714a3526bc935effe57b421542d1Selim Cinek } 777b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek finalState.applyState(changingView, viewState); 7788efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek mNewAddChildren.add(changingView); 7798efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 7808efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } else if (event.animationType == 7818efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_REMOVE) { 7828efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (changingView.getVisibility() == View.GONE) { 78395ed59283bd25fb363d13c000a7408bcafb5e93eSelim Cinek mHostLayout.getOverlay().remove(changingView); 7848efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek continue; 7858efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 7868efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 7878efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // Find the amount to translate up. This is needed in order to understand the 7888efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // direction of the remove animation (either downwards or upwards) 789b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek StackViewState viewState = finalState 7908efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek .getViewStateForView(event.viewAfterChangingView); 7918efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek int actualHeight = changingView.getActualHeight(); 7928efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // upwards by default 7938efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek float translationDirection = -1.0f; 7948efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek if (viewState != null) { 7958efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // there was a view after this one, Approximate the distance the next child 7968efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // travelled 7978efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek translationDirection = ((viewState.yTranslation 7988efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek - (changingView.getTranslationY() + actualHeight / 2.0f)) * 2 / 7998efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek actualHeight); 8008efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek translationDirection = Math.max(Math.min(translationDirection, 1.0f),-1.0f); 8018efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek 8028efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 80360d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi changingView.performRemoveAnimation(ANIMATION_DURATION_APPEAR_DISAPPEAR, 80460d07c597c3f996deb3f2743466fe5279ca15e8dJorim Jaggi translationDirection, new Runnable() { 8058efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek @Override 8068efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek public void run() { 8078efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek // remove the temporary overlay 8088efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek mHostLayout.getOverlay().remove(changingView); 8098efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek } 8108efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek }); 811b036ca4de8e93d83bcdc093fbf8f096dc18a810dSelim Cinek } else if (event.animationType == 812f336f4c13ad3be15e2b44266cd786685975425f2Selim Cinek NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT) { 813f336f4c13ad3be15e2b44266cd786685975425f2Selim Cinek // A race condition can trigger the view to be added to the overlay even though 814f336f4c13ad3be15e2b44266cd786685975425f2Selim Cinek // it is swiped out. So let's remove it 815f336f4c13ad3be15e2b44266cd786685975425f2Selim Cinek mHostLayout.getOverlay().remove(changingView); 816572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 8178efa6dde2b4f2cdbf046b87b7366404c3cc46219Selim Cinek mNewEvents.add(event); 818572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 819572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek } 8208d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek 821475b21dfe517ec04f435f6b02f4a53083d040db4Jorim Jaggi public void animateOverScrollToAmount(float targetAmount, final boolean onTop, 822475b21dfe517ec04f435f6b02f4a53083d040db4Jorim Jaggi final boolean isRubberbanded) { 8238d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek final float startOverScrollAmount = mHostLayout.getCurrentOverScrollAmount(onTop); 8249012958742c7a66b37ba5f2196f9086bb1980e6bJorim Jaggi if (targetAmount == startOverScrollAmount) { 8259012958742c7a66b37ba5f2196f9086bb1980e6bJorim Jaggi return; 8269012958742c7a66b37ba5f2196f9086bb1980e6bJorim Jaggi } 8278d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek cancelOverScrollAnimators(onTop); 8288d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek ValueAnimator overScrollAnimator = ValueAnimator.ofFloat(startOverScrollAmount, 8298d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek targetAmount); 8308d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek overScrollAnimator.setDuration(ANIMATION_DURATION_STANDARD); 8318d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek overScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 8328d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek @Override 8338d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek public void onAnimationUpdate(ValueAnimator animation) { 8348d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek float currentOverScroll = (float) animation.getAnimatedValue(); 83547c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi mHostLayout.setOverScrollAmount( 836475b21dfe517ec04f435f6b02f4a53083d040db4Jorim Jaggi currentOverScroll, onTop, false /* animate */, false /* cancelAnimators */, 837475b21dfe517ec04f435f6b02f4a53083d040db4Jorim Jaggi isRubberbanded); 8388d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek } 8398d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek }); 8408d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek overScrollAnimator.setInterpolator(mFastOutSlowInInterpolator); 84147c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi overScrollAnimator.addListener(new AnimatorListenerAdapter() { 84247c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi @Override 84347c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi public void onAnimationEnd(Animator animation) { 84447c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi if (onTop) { 84547c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi mTopOverScrollAnimator = null; 84647c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi } else { 84747c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi mBottomOverScrollAnimator = null; 84847c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi } 84947c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi } 85047c85a3525dcd0bbd3168632830e8ab491d18462Jorim Jaggi }); 8518d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek overScrollAnimator.start(); 8528d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek if (onTop) { 8538d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek mTopOverScrollAnimator = overScrollAnimator; 8548d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek } else { 8558d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek mBottomOverScrollAnimator = overScrollAnimator; 8568d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek } 8578d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek } 8588d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek 8598d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek public void cancelOverScrollAnimators(boolean onTop) { 8608d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek ValueAnimator currentAnimator = onTop ? mTopOverScrollAnimator : mBottomOverScrollAnimator; 8618d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek if (currentAnimator != null) { 8628d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek currentAnimator.cancel(); 8638d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek } 8648d9ff9c2c66bc1d3b92eb6992d58599ff80ed6dcSelim Cinek } 86502af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek 86602af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek /** 86702af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek * Get the end value of the height animation running on a view or the actualHeight 86802af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek * if no animation is running. 86902af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek */ 87002af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek public static int getFinalActualHeight(ExpandableView view) { 87102af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek if (view == null) { 87202af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek return 0; 87302af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek } 87402af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek ValueAnimator heightAnimator = getChildTag(view, TAG_ANIMATOR_HEIGHT); 87502af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek if (heightAnimator == null) { 87602af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek return view.getActualHeight(); 87702af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek } else { 87802af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek return getChildTag(view, TAG_END_HEIGHT); 87902af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek } 88002af41efe54eb2cc8fde7311e4cf5f0e5ff2373cSelim Cinek } 881572bbd42a473980c2d59af80d378f6270ba6860aSelim Cinek} 882