Java Code Examples for android.view.View#setRotation()

The following examples show how to use android.view.View#setRotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Rotate.java    From Transitions-Everywhere with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Animator createAnimator(@NonNull ViewGroup sceneRoot, @Nullable TransitionValues startValues,
                               @Nullable TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    final View view = endValues.view;
    float startRotation = (Float) startValues.values.get(PROPNAME_ROTATION);
    float endRotation = (Float) endValues.values.get(PROPNAME_ROTATION);
    if (startRotation != endRotation) {
        view.setRotation(startRotation);
        return ObjectAnimator.ofFloat(view, View.ROTATION,
                startRotation, endRotation);
    }
    return null;
}
 
Example 2
Source File: PagedView.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
@Override
public void screenScrolled(View v, int i, float scrollProgress) {
    float rotation =
            (mUp ? TRANSITION_SCREEN_ROTATION : -TRANSITION_SCREEN_ROTATION) * scrollProgress;

    float translationX = v.getMeasuredWidth() * scrollProgress;

    float rotatePoint =
            (v.getMeasuredWidth() * 0.5f) /
                    (float) Math.tan(Math.toRadians((double) (TRANSITION_SCREEN_ROTATION * 0.5f)));

    v.setPivotX(v.getMeasuredWidth() * 0.5f);
    if (mUp) {
        v.setPivotY(-rotatePoint);
    } else {
        v.setPivotY(v.getMeasuredHeight() + rotatePoint);
    }
    v.setRotation(rotation);
    v.setTranslationX(translationX);
}
 
Example 3
Source File: RotateDownTransformer.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
@Override
public void transformItem(View view, float position, boolean isHorizontal, int scrolled) {
    float rotation;
    float width = view.getWidth();
    float height = view.getHeight();
    if (isHorizontal) {
        rotation = ROT_MOD * position * -1.25f;
        view.setPivotX(width * 0.5f);
        view.setPivotY(height);
        view.setTranslationX(0f);
    } else {
        rotation = ROT_MOD * position;
        view.setPivotY(height * 0.5f);
        view.setPivotX(view.getWidth());
        view.setTranslationY(0f);
    }
    view.setRotation(rotation);
}
 
Example 4
Source File: ABaseTransformer.java    From EasyTabs with MIT License 6 votes vote down vote up
/**
 * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)}.
 * <p>
 * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
 * not modify the same page properties. For instance changing from a transformation that applies rotation to a
 * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
 * alpha.
 * 
 * @param page
 *            Apply the transformation to this page
 * @param position
 *            Position of page relative to the current front-and-center position of the pager. 0 is front and
 *            center. 1 is one full page position to the right, and -1 is one page position to the left.
 */
protected void onPreTransform(View page, float position) {
	final float width = page.getWidth();

	page.setRotationX(0);
	page.setRotationY(0);
	page.setRotation(0);
	page.setScaleX(1);
	page.setScaleY(1);
	page.setPivotX(0);
	page.setPivotY(0);
	page.setTranslationY(0);
	page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

	if (hideOffscreenPages()) {
		page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
		page.setEnabled(false);
	} else {
		page.setEnabled(true);
		page.setAlpha(1f);
	}
}
 
Example 5
Source File: TurnLayoutManager.java    From turn-layout-manager with Apache License 2.0 6 votes vote down vote up
/**
 * Given that the orientation is {@link Orientation#HORIZONTAL}, apply rotation if enabled.
 */
private void setChildRotationHorizontal(@Gravity int gravity, View child, int radius, Point center) {
    if (!rotate) {
        child.setRotation(0);
        return;
    }
    boolean childPastCenter = (child.getX() + child.getWidth() / 2) > center.x;
    float directionMult;
    if (gravity == Gravity.END) {
        directionMult = childPastCenter ? 1 : -1;
    } else {
        directionMult = childPastCenter ? -1 : 1;
    }
    final float opposite = Math.abs(child.getX() + child.getWidth() / 2.0f - center.x);
    child.setRotation((float) (directionMult * Math.toDegrees(Math.asin(opposite / radius))));
}
 
Example 6
Source File: RotateUpTransformer.java    From WanAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
	final float width = view.getWidth();
	final float rotation = ROT_MOD * position;

	view.setPivotX(width * 0.5f);
	view.setPivotY(0f);
	view.setTranslationX(0f);
	view.setRotation(rotation);
}
 
Example 7
Source File: RotateDownTransformer.java    From Banner with Apache License 2.0 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
    final float width = view.getWidth();
    final float height = view.getHeight();
    final float rotation = ROT_MOD * position * -1.25f;

    view.setPivotX(width * 0.5f);
    view.setPivotY(height);
    view.setRotation(rotation);
}
 
Example 8
Source File: RotateUpTransformer.java    From MNImageBrowser with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
	final float width = view.getWidth();
	final float rotation = ROT_MOD * position;

	view.setPivotX(width * 0.5f);
	view.setPivotY(0f);
	view.setTranslationX(0f);
	view.setRotation(rotation);
}
 
Example 9
Source File: RotateDownTransformer.java    From PageTransformerHelp with Apache License 2.0 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
	final float width = view.getWidth();
	final float height = view.getHeight();
	final float rotation = ROT_MOD * position * -1.25f;

	view.setPivotX(width * 0.5f);
	view.setPivotY(height);
	view.setRotation(rotation);
}
 
Example 10
Source File: FreeFlowContainer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
protected void returnItemToPoolIfNeeded(FreeFlowItem freeflowItem) {
	View v = freeflowItem.view;
	v.setTranslationX(0);
	v.setTranslationY(0);
	v.setRotation(0);
	v.setScaleX(1f);
	v.setScaleY(1f);
	v.setAlpha(1);
	viewpool.returnViewToPool(v);
}
 
Example 11
Source File: MultiTouchListener.java    From photo-editor-android with MIT License 5 votes vote down vote up
private static void move(View view, TransformInfo info) {
    computeRenderOffset(view, info.pivotX, info.pivotY);
    adjustTranslation(view, info.deltaX, info.deltaY);

    float scale = view.getScaleX() * info.deltaScale;
    scale = Math.max(info.minimumScale, Math.min(info.maximumScale, scale));
    view.setScaleX(scale);
    view.setScaleY(scale);

    float rotation = adjustAngle(view.getRotation() + info.deltaAngle);
    view.setRotation(rotation);
}
 
Example 12
Source File: FreeFlowContainer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
protected void returnItemToPoolIfNeeded(FreeFlowItem freeflowItem) {
	View v = freeflowItem.view;
	v.setTranslationX(0);
	v.setTranslationY(0);
	v.setRotation(0);
	v.setScaleX(1f);
	v.setScaleY(1f);
	v.setAlpha(1);
	viewpool.returnViewToPool(v);
}
 
Example 13
Source File: RotateUpTransformer.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
@Override
public void transformPage(View page, float position) {
	final float width = page.getWidth();
	final float rotation = ROT_MOD * position;

	page.setPivotX(width * 0.5f);
	page.setPivotY(0f);
	page.setTranslationX(0f);
	page.setRotation(rotation);
}
 
Example 14
Source File: ExpandIconStateHelper.java    From revolution-irc with GNU General Public License v3.0 4 votes vote down vote up
public static void setExpanded(View view, boolean expanded) {
    view.setRotation(expanded ? 180.f : 0.f);
}
 
Example 15
Source File: SmartRefreshHorizontal.java    From SmartRefreshHorizontal with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        int width = right - left;
        int height = bottom - top;
        int div = (height - width) / 2;
        if (isInLayout) {
            RefreshComponent header = mRefreshHeader;
            RefreshComponent footer = mRefreshFooter;

            final View thisView = this;
            int paddingLeft = thisView.getPaddingLeft();
            int paddingRight = thisView.getPaddingRight();
            int paddingTop = thisView.getPaddingTop();
            int paddingBottom = thisView.getPaddingBottom();

            for (int i = 0, len = getChildCount(); i < len; i++) {
                View child = getChildAt(i);
                if (!isRefreshComponent(child) && child.getVisibility() != GONE) {
                    int t = paddingLeft;
                    int w = child.getMeasuredWidth();
                    int h = child.getMeasuredHeight();
                    int r = width - paddingTop;
//
                    ViewGroup.LayoutParams params = child.getLayoutParams();
                    if (params instanceof MarginLayoutParams) {
                        MarginLayoutParams lp = (MarginLayoutParams) params;
                        t += lp.leftMargin;
                        r -= lp.topMargin;
                    }
//
                    div = (h - w) / 2;
                    t -= div;
                    r -= div;
//
                    child.setRotation(90);
                    child.setTag(R.id.srl_tag, "GONE");
                    child.layout(r - w, t, r, t + h);
                }
            }
            super.onLayout(changed, left, top, right, bottom);
        } else {
            top -= div;
            left += div;
            isInLayout = true;
            super.layout(left, top, left + width, top + height);
            isInLayout = false;
        }

    }
 
Example 16
Source File: ViewHelper.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
static void setRotation(View view, float rotation) {
    view.setRotation(rotation);
}
 
Example 17
Source File: Animer.java    From Animer with Apache License 2.0 4 votes vote down vote up
@Override
public void setValue(View view, float value) {
    view.setRotation(value);
}
 
Example 18
Source File: ViewHelper.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
static void setRotation(View view, float rotation) {
    view.setRotation(rotation);
}
 
Example 19
Source File: CardLayoutManager.java    From CardLayoutManager with Apache License 2.0 4 votes vote down vote up
private void fillChild(RecyclerView.Recycler recycler) {
    float proportion = 1;
    int paddingLeft = getPaddingLeft();
    int paddingRight = getPaddingRight();
    int paddingTop = getPaddingTop();
    int paddingBottom = getPaddingBottom();

    float perHeight = mYInterval / (mCount - 1);
    float perWidth = mXInterval / (mCount - 1);
    perHeight += perHeight / (mCount - 1);
    perWidth += perWidth / (mCount - 1);
    for (int i = mTopPosition; i < mTopPosition + mCount && i < getItemCount(); i++) {
        View child = mViewCaches.get(i);
        if (child == null) {
            child = recycler.getViewForPosition(i);
            child.setTranslationX(0);
            child.setTranslationY(0);
            child.setRotation(0);
            addView(child, 0);
            measureChildWithMargins(child, 0, 0);
            int width = getDecoratedMeasurementHorizontal(child);
            int height = getDecoratedMeasurementVertical(child);

            int left = (getWidth() - width + paddingLeft - paddingRight) / 2;
            int right = left + width;
            int top = (getHeight() - height + paddingTop - paddingBottom) / 2;
            int bottom = top + height;

            layoutDecoratedWithMargins(child, left, top, right, bottom);
        } else {
            attachView(child, 0);
            mViewCaches.remove(i);
        }
        fillChild(child, i, mDx, mDy);
        if (i == mTopPosition) {
            proportion = layoutTopChild(child);
        } else {
            int number = i - mTopPosition;
            if (i == mTopPosition + mCount - 1) {
                proportion = 0;
                number -= 1;
            }
            float origin = 1 - number * SCALE_INTERVAL;
            final float target = origin + proportion * SCALE_INTERVAL;
            float translationY = (child.getHeight()) * (1 - target) / 2 + (number - proportion) * perHeight;
            float translationX = (child.getWidth()) * (1 - target) / 2 + (number - proportion) * perWidth;
            child.setScaleX(target);
            child.setScaleY(target);
            switch (mTranxY) {
                case TOP:
                    translationY *= -1;
                case BOTTOM:
                    child.setTranslationY(translationY);
            }
            switch (mTranxX) {
                case LEFT:
                    translationX *= -1;
                case RIGHT:
                    child.setTranslationX(translationX);
            }
        }
    }
}
 
Example 20
Source File: ViewPropertyAnimatorHC.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
/**
 * This method handles setting the property values directly in the View object's fields.
 * propertyConstant tells it which property should be set, value is the value to set
 * the property to.
 *
 * @param propertyConstant The property to be set
 * @param value The value to set the property to
 */
private void setValue(int propertyConstant, float value) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //info.mTranslationX = value;
                v.setTranslationX(value);
                break;
            case TRANSLATION_Y:
                //info.mTranslationY = value;
                v.setTranslationY(value);
                break;
            case ROTATION:
                //info.mRotation = value;
                v.setRotation(value);
                break;
            case ROTATION_X:
                //info.mRotationX = value;
                v.setRotationX(value);
                break;
            case ROTATION_Y:
                //info.mRotationY = value;
                v.setRotationY(value);
                break;
            case SCALE_X:
                //info.mScaleX = value;
                v.setScaleX(value);
                break;
            case SCALE_Y:
                //info.mScaleY = value;
                v.setScaleY(value);
                break;
            case X:
                //info.mTranslationX = value - v.mLeft;
                v.setX(value);
                break;
            case Y:
                //info.mTranslationY = value - v.mTop;
                v.setY(value);
                break;
            case ALPHA:
                //info.mAlpha = value;
                v.setAlpha(value);
                break;
        }
    }
}