Search in sources :

Example 1 with Transposable

use of com.android.launcher3.views.Transposable in project Neo-Launcher by NeoApplications.

the class DragLayer method onLayout.

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    RotationMode rotation = mActivity.getRotationMode();
    if (!rotation.isTransposed) {
        super.onLayout(changed, left, top, right, bottom);
        return;
    }
    final int count = getChildCount();
    final int parentWidth = right - left;
    final int parentHeight = bottom - top;
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }
        final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
        if (lp instanceof LayoutParams) {
            final LayoutParams dlp = (LayoutParams) lp;
            if (dlp.customPosition) {
                child.layout(dlp.x, dlp.y, dlp.x + dlp.width, dlp.y + dlp.height);
                continue;
            }
        }
        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();
        int childLeft;
        int childTop;
        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }
        final int layoutDirection = getLayoutDirection();
        int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
        if (child instanceof Transposable) {
            absoluteGravity = rotation.toNaturalGravity(absoluteGravity);
            switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.CENTER_HORIZONTAL:
                    childTop = (parentHeight - height) / 2 + lp.topMargin - lp.bottomMargin;
                    break;
                case Gravity.RIGHT:
                    childTop = width / 2 + lp.rightMargin - height / 2;
                    break;
                case Gravity.LEFT:
                default:
                    childTop = parentHeight - lp.leftMargin - width / 2 - height / 2;
            }
            switch(absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
                case Gravity.CENTER_VERTICAL:
                    childLeft = (parentWidth - width) / 2 + lp.leftMargin - lp.rightMargin;
                    break;
                case Gravity.BOTTOM:
                    childLeft = parentWidth - width / 2 - height / 2 - lp.bottomMargin;
                    break;
                case Gravity.TOP:
                default:
                    childLeft = height / 2 - width / 2 + lp.topMargin;
            }
        } else {
            switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = (parentWidth - width) / 2 + lp.leftMargin - lp.rightMargin;
                    break;
                case Gravity.RIGHT:
                    childLeft = parentWidth - width - lp.rightMargin;
                    break;
                case Gravity.LEFT:
                default:
                    childLeft = lp.leftMargin;
            }
            switch(absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
                case Gravity.TOP:
                    childTop = lp.topMargin;
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = (parentHeight - height) / 2 + lp.topMargin - lp.bottomMargin;
                    break;
                case Gravity.BOTTOM:
                    childTop = parentHeight - height - lp.bottomMargin;
                    break;
                default:
                    childTop = lp.topMargin;
            }
        }
        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}
Also used : FrameLayout(android.widget.FrameLayout) RotationMode(com.android.launcher3.graphics.RotationMode) Transposable(com.android.launcher3.views.Transposable) View(android.view.View) TextView(android.widget.TextView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 2 with Transposable

use of com.android.launcher3.views.Transposable in project Neo-Launcher by NeoApplications.

the class DragLayer method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    RotationMode rotation = mActivity.getRotationMode();
    int count = getChildCount();
    if (!rotation.isTransposed || getMode(widthMeasureSpec) != EXACTLY || getMode(heightMeasureSpec) != EXACTLY) {
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            child.setRotation(rotation.surfaceRotation);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    } else {
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == GONE) {
                continue;
            }
            if (!(child instanceof Transposable)) {
                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
            } else {
                measureChildWithMargins(child, heightMeasureSpec, 0, widthMeasureSpec, 0);
                child.setPivotX(child.getMeasuredWidth() / 2);
                child.setPivotY(child.getMeasuredHeight() / 2);
                child.setRotation(rotation.surfaceRotation);
            }
        }
        setMeasuredDimension(getSize(widthMeasureSpec), getSize(heightMeasureSpec));
    }
}
Also used : RotationMode(com.android.launcher3.graphics.RotationMode) Transposable(com.android.launcher3.views.Transposable) View(android.view.View) TextView(android.widget.TextView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 3 with Transposable

use of com.android.launcher3.views.Transposable in project Neo-Launcher by NeoApplications.

the class Utilities method getDescendantCoordRelativeToAncestor.

/**
 * 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 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.
 * @param ignoreTransform If true, view transform is ignored
 * @param outRotation If not null, and {@param ignoreTransform} is true, this is set to the
 *                   overall rotation of the view in degrees.
 * @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, float[] coord, boolean includeRootScroll, boolean ignoreTransform, float[] outRotation) {
    float scale = 1.0f;
    View v = descendant;
    while (v != ancestor && v != null) {
        // which is very strange... ignore the scroll.
        if (v != descendant || includeRootScroll) {
            offsetPoints(coord, -v.getScrollX(), -v.getScrollY());
        }
        if (ignoreTransform) {
            if (v instanceof Transposable) {
                RotationMode m = ((Transposable) v).getRotationMode();
                if (m.isTransposed) {
                    sMatrix.setRotate(m.surfaceRotation, v.getPivotX(), v.getPivotY());
                    sMatrix.mapPoints(coord);
                    if (outRotation != null) {
                        outRotation[0] += m.surfaceRotation;
                    }
                }
            }
        } else {
            v.getMatrix().mapPoints(coord);
        }
        offsetPoints(coord, v.getLeft(), v.getTop());
        scale *= v.getScaleX();
        v = (View) v.getParent();
    }
    return scale;
}
Also used : RotationMode(com.android.launcher3.graphics.RotationMode) Transposable(com.android.launcher3.views.Transposable) View(android.view.View)

Aggregations

View (android.view.View)3 RotationMode (com.android.launcher3.graphics.RotationMode)3 Transposable (com.android.launcher3.views.Transposable)3 TextView (android.widget.TextView)2 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)2 FrameLayout (android.widget.FrameLayout)1