Search in sources :

Example 61 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class ChangeText method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null || !(startValues.view instanceof TextView) || !(endValues.view instanceof TextView)) {
        return null;
    }
    final TextView view = (TextView) endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    final CharSequence startText = startVals.get(PROPNAME_TEXT) != null ? (CharSequence) startVals.get(PROPNAME_TEXT) : "";
    final CharSequence endText = endVals.get(PROPNAME_TEXT) != null ? (CharSequence) endVals.get(PROPNAME_TEXT) : "";
    final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd;
    if (view instanceof EditText) {
        startSelectionStart = startVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
        startSelectionEnd = startVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_END) : startSelectionStart;
        endSelectionStart = endVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
        endSelectionEnd = endVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_END) : endSelectionStart;
    } else {
        startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1;
    }
    if (!startText.equals(endText)) {
        final int startColor;
        final int endColor;
        if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
            view.setText(startText);
            if (view instanceof EditText) {
                setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
            }
        }
        Animator anim;
        if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
            startColor = endColor = 0;
            anim = ValueAnimator.ofFloat(0, 1);
            anim.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (startText.equals(view.getText())) {
                        // Only set if it hasn't been changed since anim started
                        view.setText(endText);
                        if (view instanceof EditText) {
                            setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                        }
                    }
                }
            });
        } else {
            startColor = (Integer) startVals.get(PROPNAME_TEXT_COLOR);
            endColor = (Integer) endVals.get(PROPNAME_TEXT_COLOR);
            // Fade out start text
            ValueAnimator outAnim = null, inAnim = null;
            if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_OUT) {
                outAnim = ValueAnimator.ofInt(255, 0);
                outAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int currAlpha = (Integer) animation.getAnimatedValue();
                        view.setTextColor(currAlpha << 24 | startColor & 0xff0000 | startColor & 0xff00 | startColor & 0xff);
                    }
                });
                outAnim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (startText.equals(view.getText())) {
                            // Only set if it hasn't been changed since anim started
                            view.setText(endText);
                            if (view instanceof EditText) {
                                setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                            }
                        }
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });
            }
            if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_IN) {
                inAnim = ValueAnimator.ofInt(0, 255);
                inAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int currAlpha = (Integer) animation.getAnimatedValue();
                        view.setTextColor(currAlpha << 24 | Color.red(endColor) << 16 | Color.green(endColor) << 8 | Color.red(endColor));
                    }
                });
                inAnim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });
            }
            if (outAnim != null && inAnim != null) {
                anim = new AnimatorSet();
                ((AnimatorSet) anim).playSequentially(outAnim, inAnim);
            } else if (outAnim != null) {
                anim = outAnim;
            } else {
                // Must be an in-only animation
                anim = inAnim;
            }
        }
        TransitionListener transitionListener = new TransitionListenerAdapter() {

            int mPausedColor = 0;

            @Override
            public void onTransitionPause(Transition transition) {
                if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                    view.setText(endText);
                    if (view instanceof EditText) {
                        setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                    }
                }
                if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                    mPausedColor = view.getCurrentTextColor();
                    view.setTextColor(endColor);
                }
            }

            @Override
            public void onTransitionResume(Transition transition) {
                if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                    view.setText(startText);
                    if (view instanceof EditText) {
                        setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
                    }
                }
                if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                    view.setTextColor(mPausedColor);
                }
            }
        };
        addListener(transitionListener);
        if (DBG) {
            Log.d(LOG_TAG, "createAnimator returning " + anim);
        }
        return anim;
    }
    return null;
}
Also used : EditText(android.widget.EditText) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView)

Example 62 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class Transition method runAnimators.

/**
     * This is called internally once all animations have been set up by the
     * transition hierarchy.
     *
     * @hide
     */
protected void runAnimators() {
    if (DBG) {
        Log.d(LOG_TAG, "runAnimators() on " + this);
    }
    start();
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    // Now start every Animator that was previously created for this transition
    for (Animator anim : mAnimators) {
        if (DBG) {
            Log.d(LOG_TAG, "  anim: " + anim);
        }
        if (runningAnimators.containsKey(anim)) {
            start();
            runAnimator(anim, runningAnimators);
        }
    }
    mAnimators.clear();
    end();
}
Also used : Animator(android.animation.Animator)

Example 63 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class Transition method createAnimators.

/**
     * This method, essentially a wrapper around all calls to createAnimator for all
     * possible target views, is called with the entire set of start/end
     * values. The implementation in Transition iterates through these lists
     * and calls {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}
     * with each set of start/end values on this transition. The
     * TransitionSet subclass overrides this method and delegates it to
     * each of its children in succession.
     *
     * @hide
     */
protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues, TransitionValuesMaps endValues, ArrayList<TransitionValues> startValuesList, ArrayList<TransitionValues> endValuesList) {
    if (DBG) {
        Log.d(LOG_TAG, "createAnimators() for " + this);
    }
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    long minStartDelay = Long.MAX_VALUE;
    int minAnimator = mAnimators.size();
    SparseLongArray startDelays = new SparseLongArray();
    int startValuesListCount = startValuesList.size();
    for (int i = 0; i < startValuesListCount; ++i) {
        TransitionValues start = startValuesList.get(i);
        TransitionValues end = endValuesList.get(i);
        if (start != null && !start.targetedTransitions.contains(this)) {
            start = null;
        }
        if (end != null && !end.targetedTransitions.contains(this)) {
            end = null;
        }
        if (start == null && end == null) {
            continue;
        }
        // Only bother trying to animate with values that differ between start/end
        boolean isChanged = start == null || end == null || isTransitionRequired(start, end);
        if (isChanged) {
            if (DBG) {
                View view = (end != null) ? end.view : start.view;
                Log.d(LOG_TAG, "  differing start/end values for view " + view);
                if (start == null || end == null) {
                    Log.d(LOG_TAG, "    " + ((start == null) ? "start null, end non-null" : "start non-null, end null"));
                } else {
                    for (String key : start.values.keySet()) {
                        Object startValue = start.values.get(key);
                        Object endValue = end.values.get(key);
                        if (startValue != endValue && !startValue.equals(endValue)) {
                            Log.d(LOG_TAG, "    " + key + ": start(" + startValue + "), end(" + endValue + ")");
                        }
                    }
                }
            }
            // TODO: what to do about targetIds and itemIds?
            Animator animator = createAnimator(sceneRoot, start, end);
            if (animator != null) {
                // Save animation info for future cancellation purposes
                View view = null;
                TransitionValues infoValues = null;
                if (end != null) {
                    view = end.view;
                    String[] properties = getTransitionProperties();
                    if (view != null && properties != null && properties.length > 0) {
                        infoValues = new TransitionValues();
                        infoValues.view = view;
                        TransitionValues newValues = endValues.viewValues.get(view);
                        if (newValues != null) {
                            for (int j = 0; j < properties.length; ++j) {
                                infoValues.values.put(properties[j], newValues.values.get(properties[j]));
                            }
                        }
                        int numExistingAnims = runningAnimators.size();
                        for (int j = 0; j < numExistingAnims; ++j) {
                            Animator anim = runningAnimators.keyAt(j);
                            AnimationInfo info = runningAnimators.get(anim);
                            if (info.values != null && info.view == view && ((info.name == null && getName() == null) || info.name.equals(getName()))) {
                                if (info.values.equals(infoValues)) {
                                    // Favor the old animator
                                    animator = null;
                                    break;
                                }
                            }
                        }
                    }
                } else {
                    view = (start != null) ? start.view : null;
                }
                if (animator != null) {
                    if (mPropagation != null) {
                        long delay = mPropagation.getStartDelay(sceneRoot, this, start, end);
                        startDelays.put(mAnimators.size(), delay);
                        minStartDelay = Math.min(delay, minStartDelay);
                    }
                    AnimationInfo info = new AnimationInfo(view, getName(), this, sceneRoot.getWindowId(), infoValues);
                    runningAnimators.put(animator, info);
                    mAnimators.add(animator);
                }
            }
        }
    }
    if (startDelays.size() != 0) {
        for (int i = 0; i < startDelays.size(); i++) {
            int index = startDelays.keyAt(i);
            Animator animator = mAnimators.get(index);
            long delay = startDelays.valueAt(i) - minStartDelay + animator.getStartDelay();
            animator.setStartDelay(delay);
        }
    }
}
Also used : Animator(android.animation.Animator) SparseLongArray(android.util.SparseLongArray) SurfaceView(android.view.SurfaceView) View(android.view.View) TextureView(android.view.TextureView) ListView(android.widget.ListView)

Example 64 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class Transition method resume.

/**
     * Resumes this transition, sending out calls to {@link
     * TransitionListener#onTransitionPause(Transition)} to all listeners
     * and pausing all running animators started by this transition.
     *
     * @hide
     */
public void resume(View sceneRoot) {
    if (mPaused) {
        if (!mEnded) {
            ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
            int numOldAnims = runningAnimators.size();
            WindowId windowId = sceneRoot.getWindowId();
            for (int i = numOldAnims - 1; i >= 0; i--) {
                AnimationInfo info = runningAnimators.valueAt(i);
                if (info.view != null && windowId != null && windowId.equals(info.windowId)) {
                    Animator anim = runningAnimators.keyAt(i);
                    anim.resume();
                }
            }
            if (mListeners != null && mListeners.size() > 0) {
                ArrayList<TransitionListener> tmpListeners = (ArrayList<TransitionListener>) mListeners.clone();
                int numListeners = tmpListeners.size();
                for (int i = 0; i < numListeners; ++i) {
                    tmpListeners.get(i).onTransitionResume(this);
                }
            }
        }
        mPaused = false;
    }
}
Also used : Animator(android.animation.Animator) WindowId(android.view.WindowId) ArrayList(java.util.ArrayList)

Example 65 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class Transition method forceToEnd.

/**
     * Force the transition to move to its end state, ending all the animators.
     *
     * @hide
     */
void forceToEnd(ViewGroup sceneRoot) {
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    int numOldAnims = runningAnimators.size();
    if (sceneRoot != null) {
        WindowId windowId = sceneRoot.getWindowId();
        for (int i = numOldAnims - 1; i >= 0; i--) {
            AnimationInfo info = runningAnimators.valueAt(i);
            if (info.view != null && windowId != null && windowId.equals(info.windowId)) {
                Animator anim = runningAnimators.keyAt(i);
                anim.end();
            }
        }
    }
}
Also used : Animator(android.animation.Animator) WindowId(android.view.WindowId)

Aggregations

Animator (android.animation.Animator)1413 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)868 ObjectAnimator (android.animation.ObjectAnimator)724 ValueAnimator (android.animation.ValueAnimator)630 AnimatorSet (android.animation.AnimatorSet)285 View (android.view.View)230 ViewGroup (android.view.ViewGroup)110 ArrayList (java.util.ArrayList)104 PropertyValuesHolder (android.animation.PropertyValuesHolder)96 Paint (android.graphics.Paint)79 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)75 ImageView (android.widget.ImageView)68 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)67 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)65 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)64 TextView (android.widget.TextView)61 RenderNodeAnimator (android.view.RenderNodeAnimator)51 ViewPropertyAnimator (android.view.ViewPropertyAnimator)51 Rect (android.graphics.Rect)50 Interpolator (android.view.animation.Interpolator)49