Example usage for android.view View getScaleX

List of usage examples for android.view View getScaleX

Introduction

In this page you can find the example usage for android.view View getScaleX.

Prototype

@ViewDebug.ExportedProperty(category = "drawing")
public float getScaleX() 

Source Link

Document

The amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width.

Usage

From source file:Main.java

/**
 * Maps a coordinate in the root to a descendent.
 *//*w ww.  java  2 s  .com*/
public static float mapCoordInSelfToDescendent(View descendant, View root, float[] coord,
        Matrix tmpInverseMatrix) {
    ArrayList<View> ancestorChain = new ArrayList<View>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    tmpInverseMatrix.set(IDENTITY_MATRIX);
    for (int i = count - 1; i >= 0; i--) {
        View ancestor = ancestorChain.get(i);
        View next = i > 0 ? ancestorChain.get(i - 1) : null;

        pt[0] += ancestor.getScrollX();
        pt[1] += ancestor.getScrollY();

        if (next != null) {
            pt[0] -= next.getLeft();
            pt[1] -= next.getTop();
            next.getMatrix().invert(tmpInverseMatrix);
            tmpInverseMatrix.mapPoints(pt);
            scale *= next.getScaleX();
        }
    }

    coord[0] = pt[0];
    coord[1] = pt[1];
    return scale;
}

From source file:Main.java

/**
 * Maps a coordinate in the root to a descendent.
 *///from w  w  w.  ja va2s.c  om
public static float mapCoordInSelfToDescendent(View descendant, View root, float[] coord,
        Matrix tmpInverseMatrix) {
    ArrayList<View> ancestorChain = new ArrayList<>();

    float[] pt = { coord[0], coord[1] };

    View v = descendant;
    while (v != root) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);

    float scale = 1.0f;
    int count = ancestorChain.size();
    tmpInverseMatrix.set(IDENTITY_MATRIX);
    for (int i = count - 1; i >= 0; i--) {
        View ancestor = ancestorChain.get(i);
        View next = i > 0 ? ancestorChain.get(i - 1) : null;

        pt[0] += ancestor.getScrollX();
        pt[1] += ancestor.getScrollY();

        if (next != null) {
            pt[0] -= next.getLeft();
            pt[1] -= next.getTop();
            next.getMatrix().invert(tmpInverseMatrix);
            tmpInverseMatrix.mapPoints(pt);
            scale *= next.getScaleX();
        }
    }

    coord[0] = pt[0];
    coord[1] = pt[1];
    return scale;
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticButton.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        if (listener != null) {
            if (view.getScaleX() == 1) {
                ViewCompat.animate(view).setDuration(duration).scaleX(scale).scaleY(scale)
                        .setInterpolator(new CycleInterpolator(0.5f))
                        .setListener(new ViewPropertyAnimatorListener() {

                            @Override
                            public void onAnimationStart(final View view) {
                            }/*  w  ww . j  a  va 2  s  .  c  o  m*/

                            @Override
                            public void onAnimationEnd(final View v) {
                                onClick();
                            }

                            @Override
                            public void onAnimationCancel(final View view) {
                            }
                        }).withLayer().start();
            }
        }
    }
    return super.dispatchTouchEvent(event);
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticCheckButton.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        if (listener != null) {
            if (view.getScaleX() == 1) {
                ViewCompat.animate(view).setDuration(duration).scaleX(scale).scaleY(scale)
                        .setInterpolator(new CycleInterpolator(0.5f))
                        .setListener(new ViewPropertyAnimatorListener() {

                            @Override
                            public void onAnimationStart(final View view) {
                            }//from   w w w .  j  a v a 2s . c  o  m

                            @Override
                            public void onAnimationEnd(final View v) {
                                checked = !checked;
                                onClick();
                            }

                            @Override
                            public void onAnimationCancel(final View view) {
                            }
                        }).withLayer().start();
            }
        }
    }
    return super.dispatchTouchEvent(event);
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticLayout.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        if (listener != null) {
            if (view.getScaleX() == 1) {
                for (int i = 0; i < this.getChildCount(); i++) {
                    ViewCompat.animate(this.getChildAt(i)).setDuration(duration).scaleX(scale).scaleY(scale)
                            .setInterpolator(new CycleInterpolator(0.5f))
                            .setListener(new ViewPropertyAnimatorListener() {

                                @Override
                                public void onAnimationStart(final View view) {
                                }//from   ww w. ja v  a  2 s  .co m

                                @Override
                                public void onAnimationEnd(final View v) {
                                    onClick();
                                }

                                @Override
                                public void onAnimationCancel(final View view) {
                                }
                            }).withLayer().start();
                }

                ViewCompat.animate(view).setDuration(duration).scaleX(scale).scaleY(scale)
                        .setInterpolator(new CycleInterpolator(0.5f))
                        .setListener(new ViewPropertyAnimatorListener() {

                            @Override
                            public void onAnimationStart(final View view) {
                            }

                            @Override
                            public void onAnimationEnd(final View v) {
                                onClick();
                            }

                            @Override
                            public void onAnimationCancel(final View view) {
                            }
                        }).withLayer().start();
            }
        }
    }
    return super.dispatchTouchEvent(event);
}

From source file:com.taobao.weex.ui.component.WXSliderNeighbor.java

private void updateScaleAndAlpha(View view, float alpha, float scale) {
    if (null == view) {
        return;// w w  w  .jav  a 2s . c o  m
    }
    if (alpha >= 0 && view.getAlpha() != alpha) {
        view.setAlpha(alpha);
    }
    if (scale >= 0 && view.getScaleX() != scale) {
        view.setScaleX(scale);
        view.setScaleY(scale);
    }
}

From source file:me.lizheng.deckview.helpers.DeckChildViewTransform.java

/**
 * Applies this transform to a view./*from   www . j a  va  2s  .  c o m*/
 */
public void applyToTaskView(View v, int duration, Interpolator interp, /*boolean allowLayers,*/
        boolean allowShadows/*, ValueAnimator.AnimatorUpdateListener updateCallback*/) {
    // Check to see if any properties have changed, and update the task view
    if (duration > 0) {
        ViewPropertyAnimator anim = v.animate();
        //            boolean requiresLayers = false;

        // Animate to the final state
        if (hasTranslationYChangedFrom(v.getTranslationY())) {
            anim.translationY(translationY);
        }
        //            if (allowShadows && hasTranslationZChangedFrom(v.getTranslationZ())) {
        //                anim.translationZ(translationZ);
        //            }
        if (hasScaleChangedFrom(v.getScaleX())) {
            anim.scaleX(scale).scaleY(scale);
            //                requiresLayers = true;
        }
        if (hasAlphaChangedFrom(v.getAlpha())) {
            // Use layers if we animate alpha
            anim.alpha(alpha);
            //                requiresLayers = true;
        }
        //            if (requiresLayers && allowLayers) {
        //                anim.withLayer();
        //            }
        //            if (updateCallback != null) {
        //                anim.setUpdateListener(updateCallback);
        //            } else {
        //                anim.setUpdateListener(null);
        //            }
        anim.setStartDelay(startDelay).setDuration(duration).setInterpolator(interp).start();
    } else {
        // Set the changed properties
        if (hasTranslationYChangedFrom(v.getTranslationY())) {
            v.setTranslationY(translationY);
        }
        if (allowShadows && hasTranslationZChangedFrom(ViewCompat.getTranslationZ(v))) {
            ViewCompat.setTranslationZ(v, translationZ);
        }
        if (hasScaleChangedFrom(v.getScaleX())) {
            v.setScaleX(scale);
            v.setScaleY(scale);
        }
        if (hasAlphaChangedFrom(v.getAlpha())) {
            v.setAlpha(alpha);
        }
    }
}

From source file:com.android.launcher3.Utilities.java

/**
 * Given a coordinate relative to the descendant, find the coordinate in a parent view's
 * coordinates.//from w  w  w.j  a  v a  2 s .c  o m
 *
 * @param descendant The descendant to which the passed coordinate is relative.
 * @param ancestor The root view to make the coordinates relative to.
 * @param coord The coordinate that we want mapped.
 * @param includeRootScroll Whether or not to account for the scroll of the descendant:
 *          sometimes this is relevant as in a child's coordinates within the descendant.
 * @return The factor by which this descendant is scaled relative to this DragLayer. Caution
 *         this scale factor is assumed to be equal in X and Y, and so if at any point this
 *         assumption fails, we will need to return a pair of scale factors.
 */
public static float getDescendantCoordRelativeToAncestor(View descendant, View ancestor, int[] coord,
        boolean includeRootScroll) {
    float[] pt = { coord[0], coord[1] };
    float scale = 1.0f;
    View v = descendant;
    while (v != ancestor && v != null) {
        // For TextViews, scroll has a meaning which relates to the text position
        // which is very strange... ignore the scroll.
        if (v != descendant || includeRootScroll) {
            pt[0] -= v.getScrollX();
            pt[1] -= v.getScrollY();
        }

        v.getMatrix().mapPoints(pt);
        pt[0] += v.getLeft();
        pt[1] += v.getTop();
        scale *= v.getScaleX();

        v = (View) v.getParent();
    }

    coord[0] = Math.round(pt[0]);
    coord[1] = Math.round(pt[1]);
    return scale;
}