Java Code Examples for android.widget.ImageView#getRotation()

The following examples show how to use android.widget.ImageView#getRotation() . 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: SingleRvFragment.java    From ExpandableRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void onParentCollapsed(RecyclerView rv, ParentViewHolder pvh, int position,
        boolean pendingCause, boolean byUser)
{
    Logger.e(TAG,
             "onParentCollapsed=" + position + ",tag=" + rv.getTag() + ",byUser=" + byUser);

    if (pvh == null) return;
    ImageView arrow = pvh.getView(R.id.arrow);
    if (arrow.getVisibility() != View.VISIBLE) return;
    float currRotate = arrow.getRotation();
    float rotate = 360;
    //未展开完全并且当前旋转角度小于180,逆转回去
    if (currRotate < 180) {
        rotate = 0;
    }
    if (pendingCause) {
        arrow.setRotation(rotate);
    } else {
        arrow.animate()
             .rotation(rotate)
             .setDuration(mItemAnimator.getRemoveDuration() + 180)
             .start();
    }
}
 
Example 2
Source File: MultipleRvFragment.java    From ExpandableRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void onParentExpanded(RecyclerView rv, ParentViewHolder pvh, int position,
        boolean pendingCause, boolean byUser)
{
    Logger.e(TAG, "onParentExpanded=" + position + "," + rv.getTag() + ",byUser=" + byUser);
    if (pvh == null) return;
    ImageView arrow = pvh.getView(R.id.arrow);
    if (arrow.getVisibility() != View.VISIBLE) return;
    float currRotate = arrow.getRotation();
    //重置为从0开始旋转
    if (currRotate == 360) {
        arrow.setRotation(0);
    }
    if (pendingCause) {
        arrow.setRotation(180);
    } else {
        arrow.animate()
             .rotation(180)
             .setDuration(mItemAnimator.getAddDuration() + 180)
             .start();
    }
}
 
Example 3
Source File: MultipleRvFragment.java    From ExpandableRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void onParentCollapsed(RecyclerView rv, ParentViewHolder pvh, int position,
        boolean pendingCause, boolean byUser)
{
    Logger.e(TAG,
            "onParentCollapsed=" + position + ",tag=" + rv.getTag() + ",byUser=" + byUser);

    if (pvh == null) return;
    final ImageView arrow = pvh.getView(R.id.arrow);
    if (arrow.getVisibility() != View.VISIBLE) return;
    final float currRotate = arrow.getRotation();
    float rotate = 360;
    //未展开完全并且当前旋转角度小于180,逆转回去
    if (currRotate < 180) {
        rotate = 0;
    }
    if (pendingCause) {
        arrow.setRotation(rotate);
    } else {
        arrow.animate().rotation(rotate)
                .setDuration(mItemAnimator.getRemoveDuration() + 180).start();
    }
}
 
Example 4
Source File: SingleRvFragment.java    From ExpandableRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void onParentExpanded(RecyclerView rv, ParentViewHolder pvh, int position,
        boolean pendingCause, boolean byUser)
{
    Logger.e(TAG, "onParentExpanded=" + position + "," + rv.getTag() + ",byUser=" + byUser);
    if (pvh == null) return;
    ImageView arrow = pvh.getView(R.id.arrow);
    if (arrow.getVisibility() != View.VISIBLE) return;
    float currRotate = arrow.getRotation();
    //重置为从0开始旋转
    if (currRotate == 360) {
        arrow.setRotation(0);
    }
    if (pendingCause) {
        arrow.setRotation(180);
    } else {
        arrow.animate()
             .rotation(180)
             .setDuration(mItemAnimator.getAddDuration() + 180)
             .start();
    }

    //            if (byUser) {
    //                int scrollToPos =
    //                        pvh.getAdapterPosition() + ((MyParent) pvh.getParent()).getChildCount();
    //                rv.scrollToPosition(scrollToPos);
    //            }
}
 
Example 5
Source File: CompassView.java    From android with Apache License 2.0 5 votes vote down vote up
/**
 * Resets compass to point to North.
 */
public void reset() {
  final ImageView image = (ImageView) findViewById(getImageId());
  if (image != null) {
    float newRotation = (image.getRotation() < 180) ? 0 : 360;
    image.animate().setDuration(ROTATION_ANIMATION_DURATION_MILLIS).rotation(newRotation);
    animate().setDuration(FADE_OUT_ANIMATION_DURATION_MILLIS).alpha(0f)
      .setStartDelay(ROTATION_ANIMATION_DURATION_MILLIS);
  }
}
 
Example 6
Source File: AnimationExampleActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void startAnimation(View view) {
	float dest = 0;
	final ImageView aniView = (ImageView) findViewById(R.id.imageView1);

	switch (view.getId()) {
	case R.id.Button01:

		dest = 360;
		if (aniView.getRotation() == 360) {
			dest = 0;
		}
		// ObjectAnimator animation1 = ObjectAnimator.ofFloat(aniView,
		// "rotation", dest);
		// animation1.setDuration(2000);
		// animation1.start();

		aniView.animate().rotation(dest).setDuration(1000).scaleX(2)
				.scaleY(2).withEndAction(new Runnable() {

					@Override
					public void run() {
						//
						aniView.animate()
								.rotationXBy(100)
								.rotation(
										Math.abs(360 - aniView
												.getRotation()))
								.scaleX(0.4F).scaleY(0.4F)
								.setDuration(1000);
					}
				});

		// Show how to load an animation from XML
		// Animation animation1 = AnimationUtils.loadAnimation(this,
		// R.anim.myanimation);
		// animation1.setAnimationListener(this);
		// animatedView1.startAnimation(animation1);
		break;

	case R.id.Button02:
		// Shows how to define a animation via code
		// Also use an Interpolator (BounceInterpolator)
		Paint paint = new Paint();
		TextView aniTextView = (TextView) findViewById(R.id.textView1);
		float measureTextCenter = paint.measureText(aniTextView.getText()
				.toString());
		dest = 0 - measureTextCenter;
		if (aniTextView.getX() < 0) {
			dest = 0;
		}
		ObjectAnimator animation2 = ObjectAnimator.ofFloat(aniTextView,
				"x", dest);
		animation2.setDuration(2000);
		animation2.start();
		break;

	case R.id.Button03:
		// Demonstrate fading and adding an AnimationListener

		dest = 1;
		if (aniView.getAlpha() > 0) {
			dest = 0;
		}
		ObjectAnimator animation3 = ObjectAnimator.ofFloat(aniView,
				"alpha", dest);
		animation3.setDuration(2000);
		animation3.start();
		break;

	case R.id.Button04:

		ObjectAnimator fadeOut = ObjectAnimator.ofFloat(aniView, "alpha",
				0f);
		fadeOut.setDuration(2000);
		ObjectAnimator mover = ObjectAnimator.ofFloat(aniView,
				"translationX", -500f, 0f);
		mover.setDuration(2000);
		ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView, "alpha",
				0f, 1f);
		fadeIn.setDuration(2000);
		AnimatorSet animatorSet = new AnimatorSet();

		animatorSet.play(mover).with(fadeIn).after(fadeOut);
		animatorSet.start();
		break;

	default:
		break;
	}

}
 
Example 7
Source File: AnimationExampleActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void startAnimation(View view) {
	float dest = 0;
	final ImageView aniView = (ImageView) findViewById(R.id.imageView1);

	switch (view.getId()) {
	case R.id.Button01:

		dest = 360;
		if (aniView.getRotation() == 360) {
			dest = 0;
		}
		// ObjectAnimator animation1 = ObjectAnimator.ofFloat(aniView,
		// "rotation", dest);
		// animation1.setDuration(2000);
		// animation1.start();

		aniView.animate().rotation(dest).setDuration(1000).scaleX(2)
				.scaleY(2).withEndAction(new Runnable() {

					@Override
					public void run() {
						//
						aniView.animate()
								.rotationXBy(100)
								.rotation(
										Math.abs(360 - aniView
												.getRotation()))
								.scaleX(0.4F).scaleY(0.4F)
								.setDuration(1000);
					}
				});

		// Show how to load an animation from XML
		// Animation animation1 = AnimationUtils.loadAnimation(this,
		// R.anim.myanimation);
		// animation1.setAnimationListener(this);
		// animatedView1.startAnimation(animation1);
		break;

	case R.id.Button02:
		// Shows how to define a animation via code
		// Also use an Interpolator (BounceInterpolator)
		Paint paint = new Paint();
		TextView aniTextView = (TextView) findViewById(R.id.textView1);
		float measureTextCenter = paint.measureText(aniTextView.getText()
				.toString());
		dest = 0 - measureTextCenter;
		if (aniTextView.getX() < 0) {
			dest = 0;
		}
		ObjectAnimator animation2 = ObjectAnimator.ofFloat(aniTextView,
				"x", dest);
		animation2.setDuration(2000);
		animation2.start();
		break;

	case R.id.Button03:
		// Demonstrate fading and adding an AnimationListener

		dest = 1;
		if (aniView.getAlpha() > 0) {
			dest = 0;
		}
		ObjectAnimator animation3 = ObjectAnimator.ofFloat(aniView,
				"alpha", dest);
		animation3.setDuration(2000);
		animation3.start();
		break;

	case R.id.Button04:

		ObjectAnimator fadeOut = ObjectAnimator.ofFloat(aniView, "alpha",
				0f);
		fadeOut.setDuration(2000);
		ObjectAnimator mover = ObjectAnimator.ofFloat(aniView,
				"translationX", -500f, 0f);
		mover.setDuration(2000);
		ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView, "alpha",
				0f, 1f);
		fadeIn.setDuration(2000);
		AnimatorSet animatorSet = new AnimatorSet();

		animatorSet.play(mover).with(fadeIn).after(fadeOut);
		animatorSet.start();
		break;

	default:
		break;
	}

}
 
Example 8
Source File: AnimationExampleActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void startAnimation(View view) {
	float dest = 0;
	final ImageView aniView = (ImageView) findViewById(R.id.imageView1);

	switch (view.getId()) {
	case R.id.Button01:

		dest = 360;
		if (aniView.getRotation() == 360) {
			dest = 0;
		}
		// ObjectAnimator animation1 = ObjectAnimator.ofFloat(aniView,
		// "rotation", dest);
		// animation1.setDuration(2000);
		// animation1.start();

		aniView.animate().rotation(dest).setDuration(1000).scaleX(2)
				.scaleY(2).withEndAction(new Runnable() {

					@Override
					public void run() {
						//
						aniView.animate()
								.rotationXBy(100)
								.rotation(
										Math.abs(360 - aniView
												.getRotation()))
								.scaleX(0.4F).scaleY(0.4F)
								.setDuration(1000);
					}
				});

		// Show how to load an animation from XML
		// Animation animation1 = AnimationUtils.loadAnimation(this,
		// R.anim.myanimation);
		// animation1.setAnimationListener(this);
		// animatedView1.startAnimation(animation1);
		break;

	case R.id.Button02:
		// Shows how to define a animation via code
		// Also use an Interpolator (BounceInterpolator)
		Paint paint = new Paint();
		TextView aniTextView = (TextView) findViewById(R.id.textView1);
		float measureTextCenter = paint.measureText(aniTextView.getText()
				.toString());
		dest = 0 - measureTextCenter;
		if (aniTextView.getX() < 0) {
			dest = 0;
		}
		ObjectAnimator animation2 = ObjectAnimator.ofFloat(aniTextView,
				"x", dest);
		animation2.setDuration(2000);
		animation2.start();
		break;

	case R.id.Button03:
		// Demonstrate fading and adding an AnimationListener

		dest = 1;
		if (aniView.getAlpha() > 0) {
			dest = 0;
		}
		ObjectAnimator animation3 = ObjectAnimator.ofFloat(aniView,
				"alpha", dest);
		animation3.setDuration(2000);
		animation3.start();
		break;

	case R.id.Button04:

		ObjectAnimator fadeOut = ObjectAnimator.ofFloat(aniView, "alpha",
				0f);
		fadeOut.setDuration(2000);
		ObjectAnimator mover = ObjectAnimator.ofFloat(aniView,
				"translationX", -500f, 0f);
		mover.setDuration(2000);
		ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView, "alpha",
				0f, 1f);
		fadeIn.setDuration(2000);
		AnimatorSet animatorSet = new AnimatorSet();

		animatorSet.play(mover).with(fadeIn).after(fadeOut);
		animatorSet.start();
		break;

	default:
		break;
	}

}