Skip to content

Commit 9d8a330

Browse files
Option for changing color of the Rotating texts mdgspace#9 (mdgspace#29)
Co-authored-by: Ritik kumar <[email protected]>
1 parent 8ed21ea commit 9d8a330

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class MainActivity extends AppCompatActivity {
3333
EditText e1;
3434

3535
Button button;
36+
Integer[] color = new Integer[]{Color.BLUE,Color.MAGENTA,Color.RED};
3637

3738
@Override
3839
protected void onCreate(Bundle savedInstanceState) {
@@ -48,19 +49,19 @@ protected void onCreate(Bundle savedInstanceState) {
4849
rotatingTextWrapper.setTypeface(typeface2);
4950

5051
// rotatable = new Rotatable(Color.parseColor("#FFA036"), 1000, "Word00", "Word01", "Word02");
52+
rotatable = new Rotatable(color , 1000, "rotating", "text", "library");
53+
rotatable.setSize(25);
54+
rotatable.setTypeface(typeface);
55+
rotatable.setInterpolator(new AccelerateInterpolator());
56+
rotatable.setAnimationDuration(500);
57+
5158
rotatable2 = new Rotatable(Color.parseColor("#123456"), 1000, "word", "word01", "word02");
5259
rotatable2.setSize(25);
5360
rotatable2.setTypeface(typeface);
5461
rotatable2.setInterpolator(new DecelerateInterpolator());
5562
rotatable2.setAnimationDuration(500);
5663

5764

58-
rotatable = new Rotatable(Color.parseColor("#FFA036"), 1000, "rotating", "text", "library");
59-
rotatable.setSize(25);
60-
rotatable.setTypeface(typeface);
61-
rotatable.setInterpolator(new AccelerateInterpolator());
62-
rotatable.setAnimationDuration(500);
63-
6465
word = rotatable.getTextAt(0);
6566

6667
rotatingTextWrapper.setContent("?abc ? abc", rotatable, rotatable2);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
</LinearLayout>
3939

4040
<Button
41+
android:id="@+id/replace_button"
4142
android:layout_width="wrap_content"
4243
android:layout_height="wrap_content"
4344
android:layout_below="@id/replaceLayout"

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,28 @@ protected void onDraw(Canvas canvas) {
147147
updatePaint();
148148
rotatable.setUpdated(false);
149149
}
150+
150151
String text = currentText;
152+
int number = rotatable.getCurrentWordNumber();
153+
int arrayLength = rotatable.colorArraySize();
154+
151155
if (rotatable.getPathIn() != null) {
152156
canvas.drawTextOnPath(text, rotatable.getPathIn(), 0.0f, 0.0f, paint);
153-
}
154-
if (rotatable.getPathOut() != null) {
155157

156-
canvas.drawTextOnPath(oldText, rotatable.getPathOut(), 0.0f, 0.0f, paint);
158+
if(rotatable.useArray()) {
159+
if (number < arrayLength && number > 0) {
160+
paint.setColor(rotatable.getColorFromArray(number-1));
161+
} else {
162+
paint.setColor(rotatable.getColorFromArray(arrayLength-1));
163+
}
164+
}
165+
166+
if (rotatable.getPathOut() != null) {
167+
canvas.drawTextOnPath(oldText, rotatable.getPathOut(), 0.0f, 0.0f, paint);
168+
if(number < arrayLength && rotatable.useArray()) {
169+
paint.setColor(rotatable.getColorFromArray(number));
170+
}
171+
}
157172
}
158173
}
159174
}

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sdsmdg.harjot.rotatingtext.models;
22

33
import android.graphics.Color;
4+
import android.graphics.Paint;
45
import android.graphics.Path;
56
import android.graphics.Typeface;
67
import android.view.animation.Interpolator;
@@ -19,6 +20,9 @@ public class Rotatable {
1920
private int animationDuration = 1000;
2021
private int currentWordNumber;
2122

23+
private Integer[] color_array={Color.BLACK};
24+
private boolean useArray = false;
25+
2226
private float size = 24.0f;
2327
private int strokeWidth = -1;
2428

@@ -37,7 +41,6 @@ public class Rotatable {
3741
private int nCycles = 0, countCycles = 0;
3842
private String initialWord = "";
3943

40-
4144
public Rotatable(int updateDuration, String... text) {
4245
this.updateDuration = updateDuration;
4346
this.text = text;
@@ -51,10 +54,30 @@ public Rotatable(int color, int updateDuration, String... text) {
5154
currentWordNumber = -1;
5255
}
5356

57+
public Rotatable(Integer[] color_array, int updateDuration, String... text) {
58+
this.color_array = color_array;
59+
this.updateDuration = updateDuration;
60+
this.text = text;
61+
currentWordNumber = -1;
62+
useArray = true;
63+
}
64+
5465
public int getColor() {
5566
return color;
5667
}
5768

69+
public boolean useArray() {
70+
return useArray;
71+
}
72+
73+
public int getColorFromArray(int pos) {
74+
return color_array[pos];
75+
}
76+
77+
public int colorArraySize() {
78+
return color_array.length;
79+
}
80+
5881
public void setColor(int color) {
5982
this.color = color;
6083
setUpdated(true);
@@ -189,6 +212,8 @@ public String getCurrentWord() {
189212
return text[currentWordNumber];
190213
}
191214

215+
public int getCurrentWordNumber() { return currentWordNumber; }
216+
192217
public String getPreviousWord() {
193218
if (currentWordNumber <= 0)
194219
return text[(text.length - 1)];

0 commit comments

Comments
 (0)