Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 70 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Rotating text is an Android library that can be used to make text switching pain
Just add the following dependency in your app's `build.gradle`
```
dependencies {
compile 'com.sdsmdg.harjot:rotatingtext:1.0.2'
implementation 'in.ac.iitr.mdg:rotatingtext:1.1.0-alpha'
}
```

Expand Down Expand Up @@ -112,6 +112,71 @@ rotatingTextWrapper.setContent("This is ? and ?", rotatable, rotatable2);
#### Result
<img src="/screens/gif_example_3.gif"/>

## Example Usage 4 (Changing Colors)
#### XML

```
<com.sdsmdg.harjot.rotatingtext.RotatingTextWrapper
android:id="@+id/custom_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
```

#### Java

```
Integer[] color = new Integer[]{Color.parseColor("#ecc19c"),Color.parseColor("#1e847f"),Color.parseColor("#000000")};

Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Raleway-Light.ttf");
Typeface typeface2 = Typeface.createFromAsset(getAssets(), "fonts/Reckoner_Bold.ttf");

RotatingTextWrapper rotatingTextWrapper = (RotatingTextWrapper) findViewById(R.id.custom_switcher);
rotatingTextWrapper.setSize(35);
rotatingTextWrapper.setTypeface(typeface2);

Rotatable rotatable = new Rotatable(color , 1000, "Rotating", "Text", "Library");
rotatable.setSize(30);
rotatable.setTypeface(typeface);
rotatable.setInterpolator(new AccelerateInterpolator());
rotatable.setAnimationDuration(500);

rotatingTextWrapper.setContent("This is ?", rotatable);
```
#### Result
<img src="/screens/gif_example_4.gif"/>

## Example Usage 5 (Stop rotations after given number of cycles)
#### XML

```
<com.sdsmdg.harjot.rotatingtext.RotatingTextWrapper
android:id="@+id/custom_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
```

#### Java

```
String word;
int nCycles;

RotatingTextWrapper rotatingTextWrapper = (RotatingTextWrapper) findViewById(R.id.custom_switcher);
rotatingTextWrapper.setSize(35);

Rotatable rotatable = new Rotatable(Color.parseColor("#FFA036"), 1000, "Word", "Word01", "Word02");
rotatable.setSize(35);
rotatable.setAnimationDuration(500);

rotatingTextWrapper.setContent("This is ?", rotatable);
word = rotatable.getTextAt(0); //Set the index of the word on which you want the rotation to stop
nCycles = 2;
rotatable.setCycles(nCycles);
rotatable.setInitialWord(word);
```
#### Result
<img src="/screens/gif_example_5.gif"/>

# Documentation

Rotating text is made of two parts : `RotatingTextWrapper` and `Rotatable`. <br>
Expand All @@ -138,8 +203,10 @@ For eg : `rotatingTextWrapper.setContent("This is ?", rotatble);`. Here the `?`
|Interpolator | setInterpolator(...) | Set the animation interpolator used while switching text |
|Update Duration | setUpdateDuration(...) | Set the interval between switching the words |
|Animation Duration | setAnimationDuration(...) | Set the duration of the switching animation |
|Center Align | setCenter(...) |Align the rotating text to center of the textview if set to **true** |

|Center Align | setCenter(...) | Align the rotating text to center of the textview if set to **true** |
|Text | getTextAt(...) | Get the rotating text at a particular index |
|Initial Word | setInitialWord(...) | Set the word on which the rotation has to stop |
|Cycles | setCycles(...) | Set the number of cyles of rotations needed before stopping |

# License
RotatingText is licensed under `MIT license`. View [license](LICENSE.md).
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ 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 addNewWord(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
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"



// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
43 changes: 43 additions & 0 deletions rotatingtext/bintray.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apply plugin: 'com.jfrog.bintray'

version = libraryVersion

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")

configurations = ['archives']
pkg {
repo = bintrayRepo
name = bintrayName
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
publish = true
publicDownloadNumbers = true
}
}
18 changes: 9 additions & 9 deletions rotatingtext/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apply plugin: 'com.android.library'

ext {
bintrayRepo = 'RotatingText'
bintrayName = 'rotatingtext'
bintrayRepo = 'rotating-text' //Repo name in bintray dashboard
bintrayName = 'com.sdsmdg.harjot.rotatingtextlibrary' // package name of the bintray repo

publishedGroupId = 'com.sdsmdg.harjot'
publishedGroupId = 'in.ac.iitr.mdg'
libraryName = 'RotatingText'
artifact = 'rotatingtext'

Expand All @@ -13,11 +13,11 @@ ext {
siteUrl = 'https://github.com/sdsmdg/RotatingText'
gitUrl = 'https://github.com/sdsmdg/RotatingText.git'

libraryVersion = '1.0.2'
libraryVersion = '1.1.0-alpha'

developerId = 'harjot-oberai'
developerName = 'Harjot Singh Oberai'
developerEmail = 'harjot.oberai@gmail.com'
developerId = 'naman' // This is the bintray username under which the library has been published
developerName = 'Harjot Singh Oberai' // Developer's name
developerEmail = 'namanmishra1900@gmail.com'

licenseName = 'The MIT License'
licenseUrl = 'https://opensource.org/licenses/MIT'
Expand Down Expand Up @@ -54,6 +54,6 @@ dependencies {

}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
apply from: 'bintray.gradle'
apply from: 'install.gradle'

42 changes: 42 additions & 0 deletions rotatingtext/install.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apply plugin: 'com.github.dcendents.android-maven'

group = publishedGroupId

install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
groupId publishedGroupId
artifactId artifact

// Add your description here
name libraryName
description libraryDescription
url siteUrl

// Set your license
licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl

}
}
}
}
}
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(), 4.8f*getHeight()/6);
pathIn.lineTo((Float) valueAnimator.getAnimatedValue() + getWidth(), 4.8f*getHeight()/6);
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(), 4.8f*getHeight()/6);
pathOut.lineTo((Float) valueAnimator.getAnimatedValue() + getWidth(), 4.8f*getHeight()/6);
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
Binary file added screens/gif_example_4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screens/gif_example_5.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.