Android Open Source - transitions-everywhere Transition Utils






From Project

Back to project page transitions-everywhere.

License

The source code is released under:

Apache License

If you think the Android project transitions-everywhere listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 The Android Open Source Project
 */* ww w.j  av  a2  s .com*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.transitions.everywhere;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.os.Build;
import android.transitions.everywhere.utils.ViewUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * Static utility methods for Transitions.
 *
 * @hide
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class TransitionUtils {
    private static int MAX_IMAGE_SIZE = (1024 * 1024);

    public static Animator mergeAnimators(Animator animator1, Animator animator2) {
        if (animator1 == null) {
            return animator2;
        } else if (animator2 == null) {
            return animator1;
        } else {
            AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.playTogether(animator1, animator2);
            return animatorSet;
        }
    }

    public static Transition mergeTransitions(Transition... transitions) {
        int count = 0;
        int nonNullIndex = -1;
        for (int i = 0; i < transitions.length; i++) {
            if (transitions[i] != null) {
                count++;
                nonNullIndex = i;
            }
        }

        if (count == 0) {
            return null;
        }

        if (count == 1) {
            return transitions[nonNullIndex];
        }

        TransitionSet transitionSet = new TransitionSet();
        for (int i = 0; i < transitions.length; i++) {
            if (transitions[i] != null) {
                transitionSet.addTransition(transitions[i]);
            }
        }
        return transitionSet;
    }

    /**
     * Creates a View using the bitmap copy of <code>view</code>. If <code>view</code> is large,
     * the copy will use a scaled bitmap of the given view.
     *
     * @param sceneRoot The ViewGroup in which the view copy will be displayed.
     * @param view The view to create a copy of.
     * @param parent The parent of view.
     */
    public static View copyViewImage(ViewGroup sceneRoot, View view, View parent) {
        Matrix matrix = new Matrix();
        matrix.setTranslate(-parent.getScrollX(), -parent.getScrollY());
        ViewUtils.transformMatrixToGlobal(view, matrix);
        ViewUtils.transformMatrixToLocal(sceneRoot, matrix);
        RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
        matrix.mapRect(bounds);
        int left = Math.round(bounds.left);
        int top = Math.round(bounds.top);
        int right = Math.round(bounds.right);
        int bottom = Math.round(bounds.bottom);

        ImageView copy = new ImageView(view.getContext());
        copy.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Bitmap bitmap = createViewBitmap(view, matrix, bounds);
        if (bitmap != null) {
            copy.setImageBitmap(bitmap);
        }
        int widthSpec = View.MeasureSpec.makeMeasureSpec(right - left, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(bottom - top, View.MeasureSpec.EXACTLY);
        copy.measure(widthSpec, heightSpec);
        copy.layout(left, top, right, bottom);
        return copy;
    }

    /**
     * Creates a Bitmap of the given view, using the Matrix matrix to transform to the local
     * coordinates. <code>matrix</code> will be modified during the bitmap creation.
     *
     * <p>If the bitmap is large, it will be scaled uniformly down to at most 1MB size.</p>
     * @param view The view to create a bitmap for.
     * @param matrix The matrix converting the view local coordinates to the coordinates that
     *               the bitmap will be displayed in. <code>matrix</code> will be modified before
     *               returning.
     * @param bounds The bounds of the bitmap in the destination coordinate system (where the
     *               view should be presented. Typically, this is matrix.mapRect(viewBounds);
     * @return A bitmap of the given view or null if bounds has no width or height.
     */
    public static Bitmap createViewBitmap(View view, Matrix matrix, RectF bounds) {
        Bitmap bitmap = null;
        int bitmapWidth = Math.round(bounds.width());
        int bitmapHeight = Math.round(bounds.height());
        if (bitmapWidth > 0 && bitmapHeight > 0) {
            float scale = Math.min(1f, ((float)MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight));
            bitmapWidth *= scale;
            bitmapHeight *= scale;
            matrix.postTranslate(-bounds.left, -bounds.top);
            matrix.postScale(scale, scale);
            bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            canvas.concat(matrix);
            view.draw(canvas);
        }
        return bitmap;
    }

}




Java Source Code List

android.transitions.everywhere.ArcMotion.java
android.transitions.everywhere.AutoTransition.java
android.transitions.everywhere.ChangeBounds.java
android.transitions.everywhere.ChangeClipBounds.java
android.transitions.everywhere.ChangeImageTransform.java
android.transitions.everywhere.ChangeTransform.java
android.transitions.everywhere.CircularPropagation.java
android.transitions.everywhere.Explode.java
android.transitions.everywhere.Fade.java
android.transitions.everywhere.IntProperty.java
android.transitions.everywhere.PathMotion.java
android.transitions.everywhere.PathParser.java
android.transitions.everywhere.PatternPathMotion.java
android.transitions.everywhere.Scene.java
android.transitions.everywhere.SidePropagation.java
android.transitions.everywhere.Slide.java
android.transitions.everywhere.TransitionInflater.java
android.transitions.everywhere.TransitionManager.java
android.transitions.everywhere.TransitionPropagation.java
android.transitions.everywhere.TransitionSet.java
android.transitions.everywhere.TransitionUtils.java
android.transitions.everywhere.TransitionValuesMaps.java
android.transitions.everywhere.TransitionValues.java
android.transitions.everywhere.Transition.java
android.transitions.everywhere.TranslationAnimationCreator.java
android.transitions.everywhere.VisibilityPropagation.java
android.transitions.everywhere.Visibility.java
android.transitions.everywhere.hidden.ChangeScroll.java
android.transitions.everywhere.hidden.ChangeText.java
android.transitions.everywhere.hidden.Crossfade.java
android.transitions.everywhere.hidden.Recolor.java
android.transitions.everywhere.hidden.Rotate.java
android.transitions.everywhere.utils.AnimatorUtils.java
android.transitions.everywhere.utils.ArrayMap.java
android.transitions.everywhere.utils.ContainerHelpers.java
android.transitions.everywhere.utils.MapCollections.java
android.transitions.everywhere.utils.MatrixUtils.java
android.transitions.everywhere.utils.Objects.java
android.transitions.everywhere.utils.PropertyCompatObject.java
android.transitions.everywhere.utils.RectEvaluator.java
android.transitions.everywhere.utils.ReflectionUtils.java
android.transitions.everywhere.utils.ViewGroupOverlayUtils.java
android.transitions.everywhere.utils.ViewGroupUtilsJellyBeanMr2.java
android.transitions.everywhere.utils.ViewGroupUtils.java
android.transitions.everywhere.utils.ViewOverlayPreJellybean.java
android.transitions.everywhere.utils.ViewOverlayUtils.java
android.transitions.everywhere.utils.ViewUtilsKitKat.java
android.transitions.everywhere.utils.ViewUtilsLolipop.java
android.transitions.everywhere.utils.ViewUtils.java
com.github.andkulikov.transitions.everywhere.MainActivity.java