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

The following are Jave code examples for showing how to use setRotation() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Expert-Android-Programming   File: ABaseTransformer.java   Source Code and License Vote up 7 votes
/**
 * 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 2
Project: yjPlay   File: MatrixManager.java   Source Code and License Vote up 7 votes
@SuppressWarnings("SuspiciousNameCombination")
public void rotate(@NonNull View view, @IntRange(from = 0, to = 359) int rotation) {
    if (!ready()) {
        requestedRotation = rotation;
        requestedModificationView = new WeakReference<>(view);
        return;
    }

    boolean swapWidthHeight = ((rotation / QUARTER_ROTATION) % 2) == 1;
    boolean currentWidthHeightSwapped = ((currentRotation / QUARTER_ROTATION) % 2) == 1;

    //Makes sure the width and height are correctly swapped
    if (swapWidthHeight != currentWidthHeightSwapped) {
        int tempX = intrinsicVideoSize.x;
        intrinsicVideoSize.x = intrinsicVideoSize.y;
        intrinsicVideoSize.y = tempX;

        //We re-apply the scale to make sure it is correct
        scale(view, currentScaleType);
    }

    currentRotation = rotation;
    view.setRotation(rotation);
}
 
Example 3
Project: PageTransformerHelp   File: ABaseTransformer.java   Source Code and License Vote up 7 votes
/**
	 * 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 4
Project: TYT   File: DynamicGridView.java   Source Code and License Vote up 7 votes
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void updateWobbleState(int visibleItemCount) {
    for (int i = 0; i < visibleItemCount; i++) {
        View child = getChildAt(i);

        if (child != null) {
            if (mMobileItemId != INVALID_ID && Boolean.TRUE != child.getTag(R.id.wobble_tag)) {
                if (i % 2 == 0)
                    animateWobble(child);
                else
                    animateWobbleInverse(child);
                child.setTag(R.id.wobble_tag, true);
            } else if (mMobileItemId == INVALID_ID && child.getRotation() != 0) {
                child.setRotation(0);
                child.setTag(R.id.wobble_tag, false);
            }
        }

    }
}
 
Example 5
Project: turn-layout-manager   File: TurnLayoutManager.java   Source Code and License Vote up 7 votes
/**
 * 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 - center.x);
    child.setRotation((float) (directionMult * Math.toDegrees(Math.asin(opposite / radius))));
}
 
Example 6
Project: ArcLayout-master   File: DemoLikePathActivity.java   Source Code and License Vote up 7 votes
private Animator createShowItemAnimator(View item) {

    float dx = fab.getX() - item.getX();
    float dy = fab.getY() - item.getY();

    item.setRotation(0f);
    item.setTranslationX(dx);
    item.setTranslationY(dy);

    Animator anim = ObjectAnimator.ofPropertyValuesHolder(
        item,
        AnimatorUtils.rotation(0f, 720f),
        AnimatorUtils.translationX(dx, 0f),
        AnimatorUtils.translationY(dy, 0f)
    );

    return anim;
  }
 
Example 7
Project: SwipeSectorLayout   File: SwipeSectorLayout.java   Source Code and License Vote up 6 votes
private void setViewLocation(float percentage) {
    final int windowWidth = getWidth();
    final int halfWindowWidth = windowWidth / 2;
    final int radius = (int)Math.round(halfWindowWidth / Math.sin(Math.toRadians(mDegreeUnit)));
    final float HORIZON_SCALE = 1.1f;

    for(int i = 0; i < mReusableViews.size(); i++) {
        View view = mReusableViews.get(i);
        float degree = mDegreeUnit * i - mDegreeUnit * percentage;
        int threshold = mDegreeUnit * (mReusableViews.size() - 1);

        while(Math.abs(degree) >= threshold) {
            if(degree < 0)
                degree += (mReusableViews.size())* mDegreeUnit;
            else
                degree -= (mReusableViews.size()) * mDegreeUnit;
        }

        view.setRotation(degree);
        int left = (int)Math.round(
                halfWindowWidth + HORIZON_SCALE * radius * Math.sin(Math.toRadians(degree)) - mItemViewWidth / 2
        );
        int bottom = (int)Math.round(
                radius * Math.cos(Math.toRadians(degree)) - radius * Math.cos(Math.toRadians(mDegreeUnit))
        );
        view.setTranslationX(left);
        view.setTranslationY(-bottom);

        //Log.d("setting", String.format("(%d) degree: %.4f, position: (%d, %d)", i, degree, left, bottom));
    }
}
 
Example 8
Project: JewelryUI   File: CircleZoomLayoutManager.java   Source Code and License Vote up 6 votes
@Override
protected void setItemViewProperty(View itemView, float targetOffset) {
    itemView.setRotation(targetOffset);
    float scale = calculateScale(itemView,targetOffset);
    itemView.setScaleX(scale);
    itemView.setScaleY(scale);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        itemView.setZ(scale);
    }
}
 
Example 9
Project: GitHub   File: RotateDownTransformer.java   Source Code and License Vote up 6 votes
@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
Project: FlipLayout   File: FlipLayout.java   Source Code and License Vote up 6 votes
private void restoreView(View v) {
    v.setVisibility(endVisibility);
    v.setPivotY(v.getHeight() / 2);
    v.setPivotX(v.getWidth() / 2);
    v.setRotation(0);
    v.setRotationX(0);
    v.setRotationY(0);
    v.setTranslationX(0);
    v.setTranslationY(0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        v.setTranslationZ(0);
    }
}
 
Example 11
Project: andcoachmark   File: RightOfCircleActionDescriptionRenderer.java   Source Code and License Vote up 6 votes
@Override
public void render(CoachmarkViewLayout layout, View actionDescription, View actionArrow) {

    RectF circleRectangle = layout.calcCircleRectF();

    actionDescription.setX((int) (circleRectangle.right + actionArrow.getWidth()));
    actionDescription.setY(circleRectangle.centerY() - (actionDescription.getHeight() / 2));

    actionArrow.setRotation(180);
    actionArrow.setX(circleRectangle.right);
    actionArrow.setY(circleRectangle.centerY() - (actionArrow.getHeight() / 2));
}
 
Example 12
Project: andcoachmark   File: TopOfCircleActionDescriptionRenderer.java   Source Code and License Vote up 6 votes
@Override
public void render(CoachmarkViewLayout layout, View actionDescription, View actionArrow) {

    RectF circleRectangle = layout.calcCircleRectF();

    actionDescription.setX(circleRectangle.centerX() - (actionDescription.getWidth() / 2));
    actionDescription.setY(circleRectangle.top - actionArrow.getHeight() - actionDescription.getHeight());

    actionArrow.setRotation(90);
    actionArrow.setX(circleRectangle.centerX() - (actionArrow.getWidth() / 2));
    actionArrow.setY(circleRectangle.top - actionArrow.getHeight());
}
 
Example 13
Project: photo-editor-android   File: MultiTouchListener.java   Source Code and License Vote up 6 votes
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 14
Project: NeteaseCloudMusic   File: ViewUtil.java   Source Code and License Vote up 6 votes
public static void rotateView(View view,float fromDegree,float toDegree){
    if (Build.VERSION.SDK_INT < 11) {
        RotateAnimation animation = new RotateAnimation(fromDegree, toDegree, Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        animation.setDuration(100);
        animation.setFillAfter(true);
        view.startAnimation(animation);
    } else {
        view.setRotation(toDegree);
    }
}
 
Example 15
Project: PlusGram   File: ViewProxy.java   Source Code and License Vote up 6 votes
public static void setRotation(View view, float rotation) {
    if (View10.NEED_PROXY) {
        View10.wrap(view).setRotation(rotation);
    } else {
        view.setRotation(rotation);
    }
}
 
Example 16
Project: AndroidAnimationTools   File: ViewAnimatorBuilder.java   Source Code and License Vote up 5 votes
@Override
public void setValue(View target, float value) {
    target.setRotation(value);
}
 
Example 17
Project: RLibrary   File: RenRenCallback.java   Source Code and License Vote up 5 votes
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    //Log.i(TAG, "onChildDraw: dx:" + dX + " dy:" + dY);
    //人人影视的效果
    //if (isCurrentlyActive) {
    //先根据滑动的dxdy 算出现在动画的比例系数fraction
    float swipeValue = (float) Math.sqrt(dX * dX + dY * dY);
    final float threshold = getThreshold(recyclerView, viewHolder);
    float fraction = swipeValue / threshold;
    //边界修正 最大为1
    if (fraction > 1) {
        fraction = 1;
    } else if (fraction < -1) {
        fraction = -1;
    }
    //对每个ChildView进行缩放 位移
    int childCount = recyclerView.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = recyclerView.getChildAt(i);
        //第几层,举例子,count =7, 最后一个TopView(6)是第0层,
        int level = childCount - i - 1;
        if (level > 0) {
            child.setScaleX(1 - SCALE_GAP * level + fraction * SCALE_GAP);

            if (level < MAX_SHOW_COUNT - 1) {
                child.setScaleY(1 - SCALE_GAP * level + fraction * SCALE_GAP);
                child.setTranslationY(TRANS_Y_GAP * level - fraction * TRANS_Y_GAP);
            } else {
                //child.setTranslationY((float) (mTranslationYGap * (level - 1) - fraction * mTranslationYGap));
            }
        } else {
            //最上层
            //rotate
            if (dX < -50) {
                child.setRotation(-fraction * MAX_ROTATION);
            } else if (dX > 50) {
                child.setRotation(fraction * MAX_ROTATION);
            } else {
                child.setRotation(0);
            }

            if (mSwipeListener != null) {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                final int adapterPosition = params.getViewAdapterPosition();
                mSwipeListener.onSwipeTo(recyclerView.findViewHolderForAdapterPosition(adapterPosition), dX);
            }
        }
    }
}
 
Example 18
Project: LuaViewPlayground   File: ViewHelper.java   Source Code and License Vote up 5 votes
static void setRotation(View view, float rotation) {
    view.setRotation(rotation);
}
 
Example 19
Project: RNLearn_Project1   File: RotationAnimationPropertyUpdater.java   Source Code and License Vote up 5 votes
@Override
protected void setProperty(View view, float propertyValue) {
  view.setRotation((float) Math.toDegrees(propertyValue));
}
 
Example 20
Project: GitHub   File: WoWoRotationAnimation.java   Source Code and License Vote up 5 votes
@Override
protected void toMiddleState(View view, float offset) {
    view.setRotationX(fromX + (toX - fromX) * offset);
    view.setRotationY(fromY + (toY - fromY) * offset);
    view.setRotation(fromZ + (toZ - fromZ) * offset);
}