Skip to content

Commit 768a275

Browse files
committed
Adding horizontal rotation of texts mdgspace#27
1 parent 9d8a330 commit 768a275

File tree

4 files changed

+77
-20
lines changed

4 files changed

+77
-20
lines changed

app/src/main/java/com/sdsmdg/harjot/rotatingtextlibrary/MainActivity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ public void onClick(View view) {
115115
}
116116
}
117117
});
118+
119+
Button buttonChange = findViewById(R.id.change);
120+
buttonChange.setOnClickListener(new View.OnClickListener() {
121+
@Override
122+
public void onClick(View view) {
123+
boolean apply = rotatable.getApplyHorizontal();
124+
rotatable.setApplyHorizontal(!apply);
125+
rotatable2.setApplyHorizontal(!apply);
126+
}
127+
});
118128
}
119129

120130
public void replaceWord(View view) {

app/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
android:layout_height="match_parent"
5252
android:layout_alignParentBottom="true">
5353

54+
<Button
55+
android:id="@+id/change"
56+
android:layout_width="wrap_content"
57+
android:layout_height="wrap_content"
58+
android:layout_above="@id/pause_button"
59+
android:text="Change" />
60+
5461
<Button
5562
android:id="@+id/pause_button"
5663
android:layout_width="wrap_content"

rotatingtext/src/main/java/com/sdsmdg/harjot/rotatingtext/RotatingTextSwitcher.java

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,31 @@ protected void onDraw(Canvas canvas) {
174174
}
175175

176176
private void animateInHorizontal() {
177-
ValueAnimator animator = ValueAnimator.ofFloat(0.0f, getHeight());
178-
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
179-
@Override
180-
public void onAnimationUpdate(ValueAnimator valueAnimator) {
181-
pathIn = new Path();
182-
pathIn.moveTo(0.0f, (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
183-
pathIn.lineTo(getWidth(), (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
184-
rotatable.setPathIn(pathIn);
185-
}
186-
});
177+
ValueAnimator animator;
178+
if(!rotatable.getApplyHorizontal()) {
179+
animator = ValueAnimator.ofFloat(0.0f, getHeight());
180+
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
181+
@Override
182+
public void onAnimationUpdate(ValueAnimator valueAnimator) {
183+
pathIn = new Path();
184+
pathIn.moveTo(0.0f, (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
185+
pathIn.lineTo(getWidth(), (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
186+
rotatable.setPathIn(pathIn);
187+
}
188+
});
189+
}
190+
else {
191+
animator = ValueAnimator.ofFloat(-getWidth(),0.0f );
192+
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
193+
@Override
194+
public void onAnimationUpdate(ValueAnimator valueAnimator) {
195+
pathIn = new Path();
196+
pathIn.moveTo((Float) valueAnimator.getAnimatedValue(), 2*getHeight()/3.0f);
197+
pathIn.lineTo((Float) valueAnimator.getAnimatedValue() +90000.0F, 2*getHeight()/3.0f);
198+
rotatable.setPathIn(pathIn);
199+
}
200+
});
201+
}
187202
animator.addListener(new AnimatorListenerAdapter()
188203
{
189204
@Override
@@ -198,16 +213,31 @@ public void onAnimationEnd(Animator animation)
198213
}
199214

200215
private void animateOutHorizontal() {
201-
ValueAnimator animator = ValueAnimator.ofFloat(getHeight(), getHeight() * 2.0f);
202-
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
203-
@Override
204-
public void onAnimationUpdate(ValueAnimator valueAnimator) {
205-
pathOut = new Path();
206-
pathOut.moveTo(0.0f, (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
207-
pathOut.lineTo(getWidth(), (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
208-
rotatable.setPathOut(pathOut);
209-
}
210-
});
216+
ValueAnimator animator;
217+
if(!rotatable.getApplyHorizontal()) {
218+
animator = ValueAnimator.ofFloat(getHeight(), getHeight() * 2.0f);
219+
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
220+
@Override
221+
public void onAnimationUpdate(ValueAnimator valueAnimator) {
222+
pathOut = new Path();
223+
pathOut.moveTo(0.0f, (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
224+
pathOut.lineTo(getWidth(), (Float) valueAnimator.getAnimatedValue() - paint.getFontMetrics().bottom);
225+
rotatable.setPathOut(pathOut);
226+
}
227+
});
228+
}
229+
else {
230+
animator = ValueAnimator.ofFloat(0.0f,getWidth()+10.0f);
231+
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
232+
@Override
233+
public void onAnimationUpdate(ValueAnimator valueAnimator) {
234+
pathOut = new Path();
235+
pathOut.moveTo((Float) valueAnimator.getAnimatedValue(), 2*getHeight()/3.0f);
236+
pathOut.lineTo((Float) valueAnimator.getAnimatedValue() + 90000.0F, 2*getHeight()/3.0f);
237+
rotatable.setPathOut(pathOut);
238+
}
239+
});
240+
}
211241
animator.setInterpolator(rotatable.getInterpolator());
212242
animator.setDuration(rotatable.getAnimationDuration());
213243
animator.start();

rotatingtext/src/main/java/com/sdsmdg/harjot/rotatingtext/models/Rotatable.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class Rotatable {
4141
private int nCycles = 0, countCycles = 0;
4242
private String initialWord = "";
4343

44+
private boolean applyHorizontal = false;
45+
4446
public Rotatable(int updateDuration, String... text) {
4547
this.updateDuration = updateDuration;
4648
this.text = text;
@@ -107,6 +109,14 @@ public String getInitialWord() {
107109
return initialWord;
108110
}
109111

112+
public void setApplyHorizontal(Boolean bool) {
113+
applyHorizontal = bool;
114+
}
115+
116+
public boolean getApplyHorizontal() {
117+
return applyHorizontal;
118+
}
119+
110120
public String[] getText() {
111121
return text;
112122
}

0 commit comments

Comments
 (0)