Search in sources :

Example 1 with ViewOverlay

use of android.view.ViewOverlay in project android_frameworks_base by ResurrectionRemix.

the class Crossfade method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    final boolean useParentOverlay = mFadeBehavior != FADE_BEHAVIOR_REVEAL;
    final View view = endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    Rect startBounds = (Rect) startVals.get(PROPNAME_BOUNDS);
    Rect endBounds = (Rect) endVals.get(PROPNAME_BOUNDS);
    Bitmap startBitmap = (Bitmap) startVals.get(PROPNAME_BITMAP);
    Bitmap endBitmap = (Bitmap) endVals.get(PROPNAME_BITMAP);
    final BitmapDrawable startDrawable = (BitmapDrawable) startVals.get(PROPNAME_DRAWABLE);
    final BitmapDrawable endDrawable = (BitmapDrawable) endVals.get(PROPNAME_DRAWABLE);
    if (Transition.DBG) {
        Log.d(LOG_TAG, "StartBitmap.sameAs(endBitmap) = " + startBitmap.sameAs(endBitmap) + " for start, end: " + startBitmap + ", " + endBitmap);
    }
    if (startDrawable != null && endDrawable != null && !startBitmap.sameAs(endBitmap)) {
        ViewOverlay overlay = useParentOverlay ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
        if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
            overlay.add(endDrawable);
        }
        overlay.add(startDrawable);
        // The transition works by placing the end drawable under the start drawable and
        // gradually fading out the start drawable. So it's not really a cross-fade, but rather
        // a reveal of the end scene over time. Also, animate the bounds of both drawables
        // to mimic the change in the size of the view itself between scenes.
        ObjectAnimator anim;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // Fade out completely halfway through the transition
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 255, 0, 0);
        } else {
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 0);
        }
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // TODO: some way to auto-invalidate views based on drawable changes? callbacks?
                view.invalidate(startDrawable.getBounds());
            }
        });
        ObjectAnimator anim1 = null;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // start fading in halfway through the transition
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 0, 1);
        } else if (mFadeBehavior == FADE_BEHAVIOR_CROSSFADE) {
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1);
        }
        if (Transition.DBG) {
            Log.d(LOG_TAG, "Crossfade: created anim " + anim + " for start, end values " + startValues + ", " + endValues);
        }
        anim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                ViewOverlay overlay = useParentOverlay ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
                overlay.remove(startDrawable);
                if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
                    overlay.remove(endDrawable);
                }
            }
        });
        AnimatorSet set = new AnimatorSet();
        set.playTogether(anim);
        if (anim1 != null) {
            set.playTogether(anim1);
        }
        if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE && !startBounds.equals(endBounds)) {
            if (Transition.DBG) {
                Log.d(LOG_TAG, "animating from startBounds to endBounds: " + startBounds + ", " + endBounds);
            }
            Animator anim2 = ObjectAnimator.ofObject(startDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
            set.playTogether(anim2);
            if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE) {
                // TODO: How to handle resizing with a CROSSFADE (vs. REVEAL) effect
                // when we are animating the view directly?
                Animator anim3 = ObjectAnimator.ofObject(endDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
                set.playTogether(anim3);
            }
        }
        return set;
    } else {
        return null;
    }
}
Also used : ViewOverlay(android.view.ViewOverlay) Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) ViewGroup(android.view.ViewGroup) AnimatorSet(android.animation.AnimatorSet) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ValueAnimator(android.animation.ValueAnimator) SurfaceView(android.view.SurfaceView) TextureView(android.view.TextureView) View(android.view.View) Bitmap(android.graphics.Bitmap) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 2 with ViewOverlay

use of android.view.ViewOverlay in project android_frameworks_base by DirtyUnicorns.

the class Crossfade method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    final boolean useParentOverlay = mFadeBehavior != FADE_BEHAVIOR_REVEAL;
    final View view = endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    Rect startBounds = (Rect) startVals.get(PROPNAME_BOUNDS);
    Rect endBounds = (Rect) endVals.get(PROPNAME_BOUNDS);
    Bitmap startBitmap = (Bitmap) startVals.get(PROPNAME_BITMAP);
    Bitmap endBitmap = (Bitmap) endVals.get(PROPNAME_BITMAP);
    final BitmapDrawable startDrawable = (BitmapDrawable) startVals.get(PROPNAME_DRAWABLE);
    final BitmapDrawable endDrawable = (BitmapDrawable) endVals.get(PROPNAME_DRAWABLE);
    if (Transition.DBG) {
        Log.d(LOG_TAG, "StartBitmap.sameAs(endBitmap) = " + startBitmap.sameAs(endBitmap) + " for start, end: " + startBitmap + ", " + endBitmap);
    }
    if (startDrawable != null && endDrawable != null && !startBitmap.sameAs(endBitmap)) {
        ViewOverlay overlay = useParentOverlay ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
        if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
            overlay.add(endDrawable);
        }
        overlay.add(startDrawable);
        // The transition works by placing the end drawable under the start drawable and
        // gradually fading out the start drawable. So it's not really a cross-fade, but rather
        // a reveal of the end scene over time. Also, animate the bounds of both drawables
        // to mimic the change in the size of the view itself between scenes.
        ObjectAnimator anim;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // Fade out completely halfway through the transition
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 255, 0, 0);
        } else {
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 0);
        }
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // TODO: some way to auto-invalidate views based on drawable changes? callbacks?
                view.invalidate(startDrawable.getBounds());
            }
        });
        ObjectAnimator anim1 = null;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // start fading in halfway through the transition
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 0, 1);
        } else if (mFadeBehavior == FADE_BEHAVIOR_CROSSFADE) {
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1);
        }
        if (Transition.DBG) {
            Log.d(LOG_TAG, "Crossfade: created anim " + anim + " for start, end values " + startValues + ", " + endValues);
        }
        anim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                ViewOverlay overlay = useParentOverlay ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
                overlay.remove(startDrawable);
                if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
                    overlay.remove(endDrawable);
                }
            }
        });
        AnimatorSet set = new AnimatorSet();
        set.playTogether(anim);
        if (anim1 != null) {
            set.playTogether(anim1);
        }
        if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE && !startBounds.equals(endBounds)) {
            if (Transition.DBG) {
                Log.d(LOG_TAG, "animating from startBounds to endBounds: " + startBounds + ", " + endBounds);
            }
            Animator anim2 = ObjectAnimator.ofObject(startDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
            set.playTogether(anim2);
            if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE) {
                // TODO: How to handle resizing with a CROSSFADE (vs. REVEAL) effect
                // when we are animating the view directly?
                Animator anim3 = ObjectAnimator.ofObject(endDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
                set.playTogether(anim3);
            }
        }
        return set;
    } else {
        return null;
    }
}
Also used : ViewOverlay(android.view.ViewOverlay) Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) ViewGroup(android.view.ViewGroup) AnimatorSet(android.animation.AnimatorSet) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ValueAnimator(android.animation.ValueAnimator) SurfaceView(android.view.SurfaceView) TextureView(android.view.TextureView) View(android.view.View) Bitmap(android.graphics.Bitmap) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 3 with ViewOverlay

use of android.view.ViewOverlay in project android_frameworks_base by crdroidandroid.

the class Crossfade method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    final boolean useParentOverlay = mFadeBehavior != FADE_BEHAVIOR_REVEAL;
    final View view = endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    Rect startBounds = (Rect) startVals.get(PROPNAME_BOUNDS);
    Rect endBounds = (Rect) endVals.get(PROPNAME_BOUNDS);
    Bitmap startBitmap = (Bitmap) startVals.get(PROPNAME_BITMAP);
    Bitmap endBitmap = (Bitmap) endVals.get(PROPNAME_BITMAP);
    final BitmapDrawable startDrawable = (BitmapDrawable) startVals.get(PROPNAME_DRAWABLE);
    final BitmapDrawable endDrawable = (BitmapDrawable) endVals.get(PROPNAME_DRAWABLE);
    if (Transition.DBG) {
        Log.d(LOG_TAG, "StartBitmap.sameAs(endBitmap) = " + startBitmap.sameAs(endBitmap) + " for start, end: " + startBitmap + ", " + endBitmap);
    }
    if (startDrawable != null && endDrawable != null && !startBitmap.sameAs(endBitmap)) {
        ViewOverlay overlay = useParentOverlay ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
        if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
            overlay.add(endDrawable);
        }
        overlay.add(startDrawable);
        // The transition works by placing the end drawable under the start drawable and
        // gradually fading out the start drawable. So it's not really a cross-fade, but rather
        // a reveal of the end scene over time. Also, animate the bounds of both drawables
        // to mimic the change in the size of the view itself between scenes.
        ObjectAnimator anim;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // Fade out completely halfway through the transition
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 255, 0, 0);
        } else {
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 0);
        }
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // TODO: some way to auto-invalidate views based on drawable changes? callbacks?
                view.invalidate(startDrawable.getBounds());
            }
        });
        ObjectAnimator anim1 = null;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // start fading in halfway through the transition
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 0, 1);
        } else if (mFadeBehavior == FADE_BEHAVIOR_CROSSFADE) {
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1);
        }
        if (Transition.DBG) {
            Log.d(LOG_TAG, "Crossfade: created anim " + anim + " for start, end values " + startValues + ", " + endValues);
        }
        anim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                ViewOverlay overlay = useParentOverlay ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
                overlay.remove(startDrawable);
                if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
                    overlay.remove(endDrawable);
                }
            }
        });
        AnimatorSet set = new AnimatorSet();
        set.playTogether(anim);
        if (anim1 != null) {
            set.playTogether(anim1);
        }
        if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE && !startBounds.equals(endBounds)) {
            if (Transition.DBG) {
                Log.d(LOG_TAG, "animating from startBounds to endBounds: " + startBounds + ", " + endBounds);
            }
            Animator anim2 = ObjectAnimator.ofObject(startDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
            set.playTogether(anim2);
            if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE) {
                // TODO: How to handle resizing with a CROSSFADE (vs. REVEAL) effect
                // when we are animating the view directly?
                Animator anim3 = ObjectAnimator.ofObject(endDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
                set.playTogether(anim3);
            }
        }
        return set;
    } else {
        return null;
    }
}
Also used : ViewOverlay(android.view.ViewOverlay) Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) ViewGroup(android.view.ViewGroup) AnimatorSet(android.animation.AnimatorSet) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ValueAnimator(android.animation.ValueAnimator) SurfaceView(android.view.SurfaceView) TextureView(android.view.TextureView) View(android.view.View) Bitmap(android.graphics.Bitmap) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 4 with ViewOverlay

use of android.view.ViewOverlay in project android_frameworks_base by AOSPA.

the class Crossfade method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    final boolean useParentOverlay = mFadeBehavior != FADE_BEHAVIOR_REVEAL;
    final View view = endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    Rect startBounds = (Rect) startVals.get(PROPNAME_BOUNDS);
    Rect endBounds = (Rect) endVals.get(PROPNAME_BOUNDS);
    Bitmap startBitmap = (Bitmap) startVals.get(PROPNAME_BITMAP);
    Bitmap endBitmap = (Bitmap) endVals.get(PROPNAME_BITMAP);
    final BitmapDrawable startDrawable = (BitmapDrawable) startVals.get(PROPNAME_DRAWABLE);
    final BitmapDrawable endDrawable = (BitmapDrawable) endVals.get(PROPNAME_DRAWABLE);
    if (Transition.DBG) {
        Log.d(LOG_TAG, "StartBitmap.sameAs(endBitmap) = " + startBitmap.sameAs(endBitmap) + " for start, end: " + startBitmap + ", " + endBitmap);
    }
    if (startDrawable != null && endDrawable != null && !startBitmap.sameAs(endBitmap)) {
        ViewOverlay overlay = useParentOverlay ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
        if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
            overlay.add(endDrawable);
        }
        overlay.add(startDrawable);
        // The transition works by placing the end drawable under the start drawable and
        // gradually fading out the start drawable. So it's not really a cross-fade, but rather
        // a reveal of the end scene over time. Also, animate the bounds of both drawables
        // to mimic the change in the size of the view itself between scenes.
        ObjectAnimator anim;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // Fade out completely halfway through the transition
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 255, 0, 0);
        } else {
            anim = ObjectAnimator.ofInt(startDrawable, "alpha", 0);
        }
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // TODO: some way to auto-invalidate views based on drawable changes? callbacks?
                view.invalidate(startDrawable.getBounds());
            }
        });
        ObjectAnimator anim1 = null;
        if (mFadeBehavior == FADE_BEHAVIOR_OUT_IN) {
            // start fading in halfway through the transition
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 0, 1);
        } else if (mFadeBehavior == FADE_BEHAVIOR_CROSSFADE) {
            anim1 = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1);
        }
        if (Transition.DBG) {
            Log.d(LOG_TAG, "Crossfade: created anim " + anim + " for start, end values " + startValues + ", " + endValues);
        }
        anim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                ViewOverlay overlay = useParentOverlay ? ((ViewGroup) view.getParent()).getOverlay() : view.getOverlay();
                overlay.remove(startDrawable);
                if (mFadeBehavior == FADE_BEHAVIOR_REVEAL) {
                    overlay.remove(endDrawable);
                }
            }
        });
        AnimatorSet set = new AnimatorSet();
        set.playTogether(anim);
        if (anim1 != null) {
            set.playTogether(anim1);
        }
        if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE && !startBounds.equals(endBounds)) {
            if (Transition.DBG) {
                Log.d(LOG_TAG, "animating from startBounds to endBounds: " + startBounds + ", " + endBounds);
            }
            Animator anim2 = ObjectAnimator.ofObject(startDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
            set.playTogether(anim2);
            if (mResizeBehavior == RESIZE_BEHAVIOR_SCALE) {
                // TODO: How to handle resizing with a CROSSFADE (vs. REVEAL) effect
                // when we are animating the view directly?
                Animator anim3 = ObjectAnimator.ofObject(endDrawable, "bounds", sRectEvaluator, startBounds, endBounds);
                set.playTogether(anim3);
            }
        }
        return set;
    } else {
        return null;
    }
}
Also used : ViewOverlay(android.view.ViewOverlay) Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) ViewGroup(android.view.ViewGroup) AnimatorSet(android.animation.AnimatorSet) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ValueAnimator(android.animation.ValueAnimator) SurfaceView(android.view.SurfaceView) TextureView(android.view.TextureView) View(android.view.View) Bitmap(android.graphics.Bitmap) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 5 with ViewOverlay

use of android.view.ViewOverlay in project incubator-weex by apache.

the class WXComponent method clearBoxShadow.

protected void clearBoxShadow() {
    if (!BoxShadowUtil.isBoxShadowEnabled()) {
        WXLogUtils.w("BoxShadow", "box-shadow disabled");
        return;
    }
    if (getDomObject() != null && getDomObject().getStyles() != null) {
        Object obj = getDomObject().getStyles().get(Constants.Name.BOX_SHADOW);
        if (obj == null) {
            return;
        }
    }
    View target = mHost;
    if (this instanceof WXVContainer) {
        target = ((WXVContainer) this).getBoxShadowHost(true);
    }
    if (target != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        ViewOverlay overlay = target.getOverlay();
        if (overlay != null) {
            overlay.clear();
        }
    }
    mLastBoxShadowId = null;
}
Also used : ViewOverlay(android.view.ViewOverlay) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) IWXObject(com.taobao.weex.common.IWXObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) View(android.view.View)

Aggregations

View (android.view.View)7 ViewOverlay (android.view.ViewOverlay)7 Animator (android.animation.Animator)6 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)6 AnimatorSet (android.animation.AnimatorSet)6 ObjectAnimator (android.animation.ObjectAnimator)6 ValueAnimator (android.animation.ValueAnimator)6 Bitmap (android.graphics.Bitmap)6 Rect (android.graphics.Rect)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 SurfaceView (android.view.SurfaceView)6 TextureView (android.view.TextureView)6 ViewGroup (android.view.ViewGroup)6 RectEvaluator (android.animation.RectEvaluator)1 Nullable (androidx.annotation.Nullable)1 JSONObject (com.alibaba.fastjson.JSONObject)1 IWXObject (com.taobao.weex.common.IWXObject)1 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)1 WXDomObject (com.taobao.weex.dom.WXDomObject)1