Skip to content

Commit

Permalink
Merge pull request #33 from Anu-123-gif/RotatingText-horizontal
Browse files Browse the repository at this point in the history
Adding horizontal rotation of texts #27
  • Loading branch information
CoderMayhem authored Jun 29, 2020
2 parents 9d8a330 + 9b29c94 commit d3187c4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public void onClick(View view) {
}
}
});

Button buttonChange = findViewById(R.id.change);
buttonChange.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean apply = rotatable.getApplyHorizontal();
rotatable.setApplyHorizontal(!apply);
rotatable2.setApplyHorizontal(!apply);
}
});
}

public void replaceWord(View view) {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
android:layout_height="match_parent"
android:layout_alignParentBottom="true">

<Button
android:id="@+id/change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/pause_button"
android:text="Change" />

<Button
android:id="@+id/pause_button"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,31 @@ protected void onDraw(Canvas canvas) {
}

private void animateInHorizontal() {
ValueAnimator animator = ValueAnimator.ofFloat(0.0f, getHeight());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
pathIn = new Path();
pathIn.moveTo(0.0f, (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
pathIn.lineTo(getWidth(), (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
rotatable.setPathIn(pathIn);
}
});
ValueAnimator animator;
if(!rotatable.getApplyHorizontal()) {
animator = ValueAnimator.ofFloat(0.0f, getHeight());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
pathIn = new Path();
pathIn.moveTo(0.0f, (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
pathIn.lineTo(getWidth(), (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
rotatable.setPathIn(pathIn);
}
});
}
else {
animator = ValueAnimator.ofFloat(-getWidth(),0.0f );
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
pathIn = new Path();
pathIn.moveTo((Float) valueAnimator.getAnimatedValue(), 2*getHeight()/3.0f);
pathIn.lineTo((Float) valueAnimator.getAnimatedValue() + getWidth(), 2*getHeight()/3.0f);
rotatable.setPathIn(pathIn);
}
});
}
animator.addListener(new AnimatorListenerAdapter()
{
@Override
Expand All @@ -198,16 +213,31 @@ public void onAnimationEnd(Animator animation)
}

private void animateOutHorizontal() {
ValueAnimator animator = ValueAnimator.ofFloat(getHeight(), getHeight() * 2.0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
pathOut = new Path();
pathOut.moveTo(0.0f, (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
pathOut.lineTo(getWidth(), (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
rotatable.setPathOut(pathOut);
}
});
ValueAnimator animator;
if(!rotatable.getApplyHorizontal()) {
animator = ValueAnimator.ofFloat(getHeight(), getHeight() * 2.0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
pathOut = new Path();
pathOut.moveTo(0.0f, (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
pathOut.lineTo(getWidth(), (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
rotatable.setPathOut(pathOut);
}
});
}
else {
animator = ValueAnimator.ofFloat(0.0f,getWidth()+10.0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
pathOut = new Path();
pathOut.moveTo((Float) valueAnimator.getAnimatedValue(), 2*getHeight()/3.0f);
pathOut.lineTo((Float) valueAnimator.getAnimatedValue() + getWidth(), 2*getHeight()/3.0f);
rotatable.setPathOut(pathOut);
}
});
}
animator.setInterpolator(rotatable.getInterpolator());
animator.setDuration(rotatable.getAnimationDuration());
animator.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Rotatable {
private int nCycles = 0, countCycles = 0;
private String initialWord = "";

private boolean applyHorizontal = false;

public Rotatable(int updateDuration, String... text) {
this.updateDuration = updateDuration;
this.text = text;
Expand Down Expand Up @@ -107,6 +109,14 @@ public String getInitialWord() {
return initialWord;
}

public void setApplyHorizontal(Boolean bool) {
applyHorizontal = bool;
}

public boolean getApplyHorizontal() {
return applyHorizontal;
}

public String[] getText() {
return text;
}
Expand Down

0 comments on commit d3187c4

Please sign in to comment.