Search in sources :

Example 11 with View

use of android.view.View in project Launcher3 by chislon.

the class Utilities method mapCoordInSelfToDescendent.

/**
     * Inverse of {@link #getDescendantCoordRelativeToSelf(View, int[])}.
     */
public static float mapCoordInSelfToDescendent(View descendant, View root, int[] coord) {
    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;
    Matrix inverse = new Matrix();
    int count = ancestorChain.size();
    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(inverse);
            inverse.mapPoints(pt);
            scale *= next.getScaleX();
        }
    }
    coord[0] = (int) Math.round(pt[0]);
    coord[1] = (int) Math.round(pt[1]);
    return scale;
}
Also used : ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) ArrayList(java.util.ArrayList) View(android.view.View) Paint(android.graphics.Paint)

Example 12 with View

use of android.view.View in project Launcher3 by chislon.

the class Utilities method getDescendantCoordRelativeToParent.

/**
     * Given a coordinate relative to the descendant, find the coordinate in a parent view's
     * coordinates.
     *
     * @param descendant The descendant to which the passed coordinate is relative.
     * @param root 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 getDescendantCoordRelativeToParent(View descendant, View root, int[] coord, boolean includeRootScroll) {
    ArrayList<View> ancestorChain = new ArrayList<View>();
    float[] pt = { coord[0], coord[1] };
    View v = descendant;
    while (v != root && v != null) {
        ancestorChain.add(v);
        v = (View) v.getParent();
    }
    ancestorChain.add(root);
    float scale = 1.0f;
    int count = ancestorChain.size();
    for (int i = 0; i < count; i++) {
        View v0 = ancestorChain.get(i);
        // which is very strange... ignore the scroll.
        if (v0 != descendant || includeRootScroll) {
            pt[0] -= v0.getScrollX();
            pt[1] -= v0.getScrollY();
        }
        v0.getMatrix().mapPoints(pt);
        pt[0] += v0.getLeft();
        pt[1] += v0.getTop();
        scale *= v0.getScaleX();
    }
    coord[0] = (int) Math.round(pt[0]);
    coord[1] = (int) Math.round(pt[1]);
    return scale;
}
Also used : ArrayList(java.util.ArrayList) View(android.view.View) Paint(android.graphics.Paint)

Example 13 with View

use of android.view.View in project Launcher3 by chislon.

the class PagedView method onFlingToDelete.

public void onFlingToDelete(PointF vel) {
    final long startTime = AnimationUtils.currentAnimationTimeMillis();
    // NOTE: Because it takes time for the first frame of animation to actually be
    // called and we expect the animation to be a continuation of the fling, we have
    // to account for the time that has elapsed since the fling finished.  And since
    // we don't have a startDelay, we will always get call to update when we call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {

        private int mCount = -1;

        private long mStartTime;

        private float mOffset;

        /* Anonymous inner class ctor */
        {
            mStartTime = startTime;
        }

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };
    final Rect from = new Rect();
    final View dragView = mDragView;
    from.left = (int) dragView.getTranslationX();
    from.top = (int) dragView.getTranslationY();
    AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION);
    final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);
    // Create and start the animation
    ValueAnimator mDropAnim = new ValueAnimator();
    mDropAnim.setInterpolator(tInterpolator);
    mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION);
    mDropAnim.setFloatValues(0f, 1f);
    mDropAnim.addUpdateListener(updateCb);
    mDropAnim.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator animation) {
            onAnimationEndRunnable.run();
        }
    });
    mDropAnim.start();
    mDeferringForDelete = true;
}
Also used : Rect(android.graphics.Rect) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) TimeInterpolator(android.animation.TimeInterpolator) View(android.view.View)

Example 14 with View

use of android.view.View in project Launcher3 by chislon.

the class PagedView method onRequestFocusInDescendants.

@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    int focusablePage;
    if (mNextPage != INVALID_PAGE) {
        focusablePage = mNextPage;
    } else {
        focusablePage = mCurrentPage;
    }
    View v = getPageAt(focusablePage);
    if (v != null) {
        return v.requestFocus(direction, previouslyFocusedRect);
    }
    return false;
}
Also used : View(android.view.View)

Example 15 with View

use of android.view.View in project Launcher3 by chislon.

the class PagedView method dispatchDraw.

@Override
protected void dispatchDraw(Canvas canvas) {
    int halfScreenSize = getViewportWidth() / 2;
    // mOverScrollX is equal to getScrollX() when we're within the normal scroll range.
    // Otherwise it is equal to the scaled overscroll position.
    int screenCenter = mOverScrollX + halfScreenSize;
    if (screenCenter != mLastScreenCenter || mForceScreenScrolled) {
        // set mForceScreenScrolled before calling screenScrolled so that screenScrolled can
        // set it for the next frame
        mForceScreenScrolled = false;
        screenScrolled(screenCenter);
        mLastScreenCenter = screenCenter;
    }
    // Find out which screens are visible; as an optimization we only call draw on them
    final int pageCount = getChildCount();
    if (pageCount > 0) {
        getVisiblePages(mTempVisiblePagesRange);
        final int leftScreen = mTempVisiblePagesRange[0];
        final int rightScreen = mTempVisiblePagesRange[1];
        if (leftScreen != -1 && rightScreen != -1) {
            final long drawingTime = getDrawingTime();
            // Clip to the bounds
            canvas.save();
            canvas.clipRect(getScrollX(), getScrollY(), getScrollX() + getRight() - getLeft(), getScrollY() + getBottom() - getTop());
            // Draw all the children, leaving the drag view for last
            for (int i = pageCount - 1; i >= 0; i--) {
                final View v = getPageAt(i);
                if (v == mDragView)
                    continue;
                if (mForceDrawAllChildrenNextFrame || (leftScreen <= i && i <= rightScreen && shouldDrawChild(v))) {
                    drawChild(canvas, v, drawingTime);
                }
            }
            // Draw the drag view on top (if there is one)
            if (mDragView != null) {
                drawChild(canvas, mDragView, drawingTime);
            }
            mForceDrawAllChildrenNextFrame = false;
            canvas.restore();
        }
    }
}
Also used : View(android.view.View)

Aggregations

View (android.view.View)17009 TextView (android.widget.TextView)5834 ImageView (android.widget.ImageView)3323 ListView (android.widget.ListView)2098 RecyclerView (android.support.v7.widget.RecyclerView)1838 AdapterView (android.widget.AdapterView)1715 ViewGroup (android.view.ViewGroup)1568 Intent (android.content.Intent)1026 Paint (android.graphics.Paint)951 Button (android.widget.Button)876 OnClickListener (android.view.View.OnClickListener)808 AbsListView (android.widget.AbsListView)795 LayoutInflater (android.view.LayoutInflater)771 LinearLayout (android.widget.LinearLayout)656 ArrayList (java.util.ArrayList)638 RemoteView (android.widget.RemoteViews.RemoteView)600 ScrollView (android.widget.ScrollView)566 Rect (android.graphics.Rect)534 SuppressLint (android.annotation.SuppressLint)433 Context (android.content.Context)405