Search in sources :

Example 41 with LayoutTransition

use of android.animation.LayoutTransition in project android_frameworks_base by AOSPA.

the class RenderSessionImpl method removeChild.

/**
     * Removes a child from its current parent.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #acquire(long)} was not called.
     *
     * @see RenderSession#removeChild(Object, IAnimationListener)
     */
public Result removeChild(final View childView, IAnimationListener listener) {
    checkLock();
    invalidateRenderingSize();
    final ViewGroup parent = (ViewGroup) childView.getParent();
    if (listener != null) {
        new AnimationThread(this, "moveChild", listener) {

            @Override
            public Result preAnimation() {
                parent.setLayoutTransition(new LayoutTransition());
                return removeView(parent, childView);
            }

            @Override
            public void postAnimation() {
                parent.setLayoutTransition(null);
            }
        }.start();
        // always return success since the real status will come through the listener.
        return SUCCESS.createResult();
    }
    Result result = removeView(parent, childView);
    if (!result.isSuccess()) {
        return result;
    }
    return render(false);
}
Also used : AnimationThread(android.animation.AnimationThread) ViewGroup(android.view.ViewGroup) LayoutTransition(android.animation.LayoutTransition) Result(com.android.ide.common.rendering.api.Result)

Example 42 with LayoutTransition

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

the class RenderSessionImpl method moveChild.

/**
     * Moves a view to a new parent at a given location
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #acquire(long)} was not called.
     *
     * @see RenderSession#moveChild(Object, Object, int, Map, IAnimationListener)
     */
public Result moveChild(final ViewGroup newParentView, final View childView, final int index, Map<String, String> layoutParamsMap, final IAnimationListener listener) {
    checkLock();
    invalidateRenderingSize();
    LayoutParams layoutParams = null;
    if (layoutParamsMap != null) {
        // need to create a new LayoutParams object for the new parent.
        layoutParams = newParentView.generateLayoutParams(new BridgeLayoutParamsMapAttributes(layoutParamsMap));
    }
    // get the current parent of the view that needs to be moved.
    final ViewGroup previousParent = (ViewGroup) childView.getParent();
    if (listener != null) {
        final LayoutParams params = layoutParams;
        // parent views are different we fake the animation through a no animation thread.
        if (previousParent != newParentView) {
            new Thread("not animated moveChild") {

                @Override
                public void run() {
                    Result result = moveView(previousParent, newParentView, childView, index, params);
                    if (!result.isSuccess()) {
                        listener.done(result);
                    }
                    // ready to do the work, acquire the scene.
                    result = acquire(250);
                    if (!result.isSuccess()) {
                        listener.done(result);
                        return;
                    }
                    try {
                        result = render(false);
                        if (result.isSuccess()) {
                            listener.onNewFrame(RenderSessionImpl.this.getSession());
                        }
                    } finally {
                        release();
                    }
                    listener.done(result);
                }
            }.start();
        } else {
            new AnimationThread(this, "moveChild", listener) {

                @Override
                public Result preAnimation() {
                    // set up the transition for the parent.
                    LayoutTransition transition = new LayoutTransition();
                    previousParent.setLayoutTransition(transition);
                    // tweak the animation durations and start delays (to match the duration of
                    // animation playing just before).
                    // Note: Cannot user Animation.setDuration() directly. Have to set it
                    // on the LayoutTransition.
                    transition.setDuration(LayoutTransition.DISAPPEARING, 100);
                    // CHANGE_DISAPPEARING plays after DISAPPEARING
                    transition.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 100);
                    transition.setDuration(LayoutTransition.CHANGE_DISAPPEARING, 100);
                    transition.setDuration(LayoutTransition.CHANGE_APPEARING, 100);
                    // CHANGE_APPEARING plays after CHANGE_APPEARING
                    transition.setStartDelay(LayoutTransition.APPEARING, 100);
                    transition.setDuration(LayoutTransition.APPEARING, 100);
                    return moveView(previousParent, newParentView, childView, index, params);
                }

                @Override
                public void postAnimation() {
                    previousParent.setLayoutTransition(null);
                    newParentView.setLayoutTransition(null);
                }
            }.start();
        }
        // always return success since the real status will come through the listener.
        return SUCCESS.createResult(layoutParams);
    }
    Result result = moveView(previousParent, newParentView, childView, index, layoutParams);
    if (!result.isSuccess()) {
        return result;
    }
    result = render(false);
    if (layoutParams != null && result.isSuccess()) {
        result = result.getCopyWithData(layoutParams);
    }
    return result;
}
Also used : BridgeLayoutParamsMapAttributes(com.android.layoutlib.bridge.android.BridgeLayoutParamsMapAttributes) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams) AnimationThread(android.animation.AnimationThread) ViewGroup(android.view.ViewGroup) LayoutTransition(android.animation.LayoutTransition) AnimationThread(android.animation.AnimationThread) Result(com.android.ide.common.rendering.api.Result)

Example 43 with LayoutTransition

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

the class RenderSessionImpl method removeChild.

/**
     * Removes a child from its current parent.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #acquire(long)} was not called.
     *
     * @see RenderSession#removeChild(Object, IAnimationListener)
     */
public Result removeChild(final View childView, IAnimationListener listener) {
    checkLock();
    invalidateRenderingSize();
    final ViewGroup parent = (ViewGroup) childView.getParent();
    if (listener != null) {
        new AnimationThread(this, "moveChild", listener) {

            @Override
            public Result preAnimation() {
                parent.setLayoutTransition(new LayoutTransition());
                return removeView(parent, childView);
            }

            @Override
            public void postAnimation() {
                parent.setLayoutTransition(null);
            }
        }.start();
        // always return success since the real status will come through the listener.
        return SUCCESS.createResult();
    }
    Result result = removeView(parent, childView);
    if (!result.isSuccess()) {
        return result;
    }
    return render(false);
}
Also used : AnimationThread(android.animation.AnimationThread) ViewGroup(android.view.ViewGroup) LayoutTransition(android.animation.LayoutTransition) Result(com.android.ide.common.rendering.api.Result)

Example 44 with LayoutTransition

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

the class RenderSessionImpl method insertChild.

/**
     * Insert a new child into an existing parent.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #acquire(long)} was not called.
     *
     * @see RenderSession#insertChild(Object, ILayoutPullParser, int, IAnimationListener)
     */
public Result insertChild(final ViewGroup parentView, ILayoutPullParser childXml, final int index, IAnimationListener listener) {
    checkLock();
    BridgeContext context = getContext();
    // create a block parser for the XML
    BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(childXml, context, false);
    // inflate the child without adding it to the root since we want to control where it'll
    // get added. We do pass the parentView however to ensure that the layoutParams will
    // be created correctly.
    final View child = mInflater.inflate(blockParser, parentView, false);
    blockParser.ensurePopped();
    invalidateRenderingSize();
    if (listener != null) {
        new AnimationThread(this, "insertChild", listener) {

            @Override
            public Result preAnimation() {
                parentView.setLayoutTransition(new LayoutTransition());
                return addView(parentView, child, index);
            }

            @Override
            public void postAnimation() {
                parentView.setLayoutTransition(null);
            }
        }.start();
        // always return success since the real status will come through the listener.
        return SUCCESS.createResult(child);
    }
    // add it to the parentView in the correct location
    Result result = addView(parentView, child, index);
    if (!result.isSuccess()) {
        return result;
    }
    result = render(false);
    if (result.isSuccess()) {
        result = result.getCopyWithData(child);
    }
    return result;
}
Also used : AnimationThread(android.animation.AnimationThread) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) LayoutTransition(android.animation.LayoutTransition) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser) Result(com.android.ide.common.rendering.api.Result)

Example 45 with LayoutTransition

use of android.animation.LayoutTransition in project android_frameworks_base by DirtyUnicorns.

the class ViewGroup method initFromAttributes.

private void initFromAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewGroup, defStyleAttr, defStyleRes);
    final int N = a.getIndexCount();
    for (int i = 0; i < N; i++) {
        int attr = a.getIndex(i);
        switch(attr) {
            case R.styleable.ViewGroup_clipChildren:
                setClipChildren(a.getBoolean(attr, true));
                break;
            case R.styleable.ViewGroup_clipToPadding:
                setClipToPadding(a.getBoolean(attr, true));
                break;
            case R.styleable.ViewGroup_animationCache:
                setAnimationCacheEnabled(a.getBoolean(attr, true));
                break;
            case R.styleable.ViewGroup_persistentDrawingCache:
                setPersistentDrawingCache(a.getInt(attr, PERSISTENT_SCROLLING_CACHE));
                break;
            case R.styleable.ViewGroup_addStatesFromChildren:
                setAddStatesFromChildren(a.getBoolean(attr, false));
                break;
            case R.styleable.ViewGroup_alwaysDrawnWithCache:
                setAlwaysDrawnWithCacheEnabled(a.getBoolean(attr, true));
                break;
            case R.styleable.ViewGroup_layoutAnimation:
                int id = a.getResourceId(attr, -1);
                if (id > 0) {
                    setLayoutAnimation(AnimationUtils.loadLayoutAnimation(mContext, id));
                }
                break;
            case R.styleable.ViewGroup_descendantFocusability:
                setDescendantFocusability(DESCENDANT_FOCUSABILITY_FLAGS[a.getInt(attr, 0)]);
                break;
            case R.styleable.ViewGroup_splitMotionEvents:
                setMotionEventSplittingEnabled(a.getBoolean(attr, false));
                break;
            case R.styleable.ViewGroup_animateLayoutChanges:
                boolean animateLayoutChanges = a.getBoolean(attr, false);
                if (animateLayoutChanges) {
                    setLayoutTransition(new LayoutTransition());
                }
                break;
            case R.styleable.ViewGroup_layoutMode:
                setLayoutMode(a.getInt(attr, LAYOUT_MODE_UNDEFINED));
                break;
            case R.styleable.ViewGroup_transitionGroup:
                setTransitionGroup(a.getBoolean(attr, false));
                break;
            case R.styleable.ViewGroup_touchscreenBlocksFocus:
                setTouchscreenBlocksFocus(a.getBoolean(attr, false));
                break;
        }
    }
    a.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) LayoutTransition(android.animation.LayoutTransition) Paint(android.graphics.Paint)

Aggregations

LayoutTransition (android.animation.LayoutTransition)89 ViewGroup (android.view.ViewGroup)37 View (android.view.View)19 AnimationThread (android.animation.AnimationThread)18 Result (com.android.ide.common.rendering.api.Result)18 AdapterView (android.widget.AdapterView)13 ListView (android.widget.ListView)13 AbsListView (android.widget.AbsListView)12 ExpandableListView (android.widget.ExpandableListView)12 ActionMenuView (android.widget.ActionMenuView)10 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)10 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)10 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)10 MenuView (com.android.internal.view.menu.MenuView)10 Paint (android.graphics.Paint)8 TypedArray (android.content.res.TypedArray)7 LayoutParams (android.view.ViewGroup.LayoutParams)7 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)7 TransitionListener (android.animation.LayoutTransition.TransitionListener)6 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)6