Skip to content

Commit

Permalink
Option for changing color of the Rotating texts #9 (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Ritik kumar <[email protected]>
  • Loading branch information
Anu-123-gif and dev-ritik authored Jun 18, 2020
1 parent 8ed21ea commit 9d8a330
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MainActivity extends AppCompatActivity {
EditText e1;

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

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -48,19 +49,19 @@ protected void onCreate(Bundle savedInstanceState) {
rotatingTextWrapper.setTypeface(typeface2);

// rotatable = new Rotatable(Color.parseColor("#FFA036"), 1000, "Word00", "Word01", "Word02");
rotatable = new Rotatable(color , 1000, "rotating", "text", "library");
rotatable.setSize(25);
rotatable.setTypeface(typeface);
rotatable.setInterpolator(new AccelerateInterpolator());
rotatable.setAnimationDuration(500);

rotatable2 = new Rotatable(Color.parseColor("#123456"), 1000, "word", "word01", "word02");
rotatable2.setSize(25);
rotatable2.setTypeface(typeface);
rotatable2.setInterpolator(new DecelerateInterpolator());
rotatable2.setAnimationDuration(500);


rotatable = new Rotatable(Color.parseColor("#FFA036"), 1000, "rotating", "text", "library");
rotatable.setSize(25);
rotatable.setTypeface(typeface);
rotatable.setInterpolator(new AccelerateInterpolator());
rotatable.setAnimationDuration(500);

word = rotatable.getTextAt(0);

rotatingTextWrapper.setContent("?abc ? abc", rotatable, rotatable2);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</LinearLayout>

<Button
android:id="@+id/replace_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/replaceLayout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,28 @@ protected void onDraw(Canvas canvas) {
updatePaint();
rotatable.setUpdated(false);
}

String text = currentText;
int number = rotatable.getCurrentWordNumber();
int arrayLength = rotatable.colorArraySize();

if (rotatable.getPathIn() != null) {
canvas.drawTextOnPath(text, rotatable.getPathIn(), 0.0f, 0.0f, paint);
}
if (rotatable.getPathOut() != null) {

canvas.drawTextOnPath(oldText, rotatable.getPathOut(), 0.0f, 0.0f, paint);
if(rotatable.useArray()) {
if (number < arrayLength && number > 0) {
paint.setColor(rotatable.getColorFromArray(number-1));
} else {
paint.setColor(rotatable.getColorFromArray(arrayLength-1));
}
}

if (rotatable.getPathOut() != null) {
canvas.drawTextOnPath(oldText, rotatable.getPathOut(), 0.0f, 0.0f, paint);
if(number < arrayLength && rotatable.useArray()) {
paint.setColor(rotatable.getColorFromArray(number));
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sdsmdg.harjot.rotatingtext.models;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Typeface;
import android.view.animation.Interpolator;
Expand All @@ -19,6 +20,9 @@ public class Rotatable {
private int animationDuration = 1000;
private int currentWordNumber;

private Integer[] color_array={Color.BLACK};
private boolean useArray = false;

private float size = 24.0f;
private int strokeWidth = -1;

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


public Rotatable(int updateDuration, String... text) {
this.updateDuration = updateDuration;
this.text = text;
Expand All @@ -51,10 +54,30 @@ public Rotatable(int color, int updateDuration, String... text) {
currentWordNumber = -1;
}

public Rotatable(Integer[] color_array, int updateDuration, String... text) {
this.color_array = color_array;
this.updateDuration = updateDuration;
this.text = text;
currentWordNumber = -1;
useArray = true;
}

public int getColor() {
return color;
}

public boolean useArray() {
return useArray;
}

public int getColorFromArray(int pos) {
return color_array[pos];
}

public int colorArraySize() {
return color_array.length;
}

public void setColor(int color) {
this.color = color;
setUpdated(true);
Expand Down Expand Up @@ -189,6 +212,8 @@ public String getCurrentWord() {
return text[currentWordNumber];
}

public int getCurrentWordNumber() { return currentWordNumber; }

public String getPreviousWord() {
if (currentWordNumber <= 0)
return text[(text.length - 1)];
Expand Down

0 comments on commit 9d8a330

Please sign in to comment.