Coder Social home page Coder Social logo

rotatingtext's Introduction

RotatingText

platform API License: MIT By-MDG

Rotating text is an Android library that can be used to make text switching painless and beautiful, with the use of interpolators, typefaces and more customisations.

Usage

Just add the following dependency in your app's build.gradle

dependencies {
      compile 'com.sdsmdg.harjot:rotatingtext:1.0.2'
}

Example Usage 1 (Simple)

XML

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

Java

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);

Result

Example Usage 2 (Typeface + Interpolator)

XML

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

Java

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.parseColor("#FFA036"), 1000, "Word", "Word01", "Word02");
rotatable.setSize(35);
rotatable.setAnimationDuration(500);
rotatable.setTypeface(typeface);
rotatable.setInterpolator(new BounceInterpolator());

rotatingTextWrapper.setContent("This is ?", rotatable);

Result

Example Usage 3 (Multiple Rotatables)

XML

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

Java

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.parseColor("#FFA036"), 1000, "Word", "Word01", "Word02");
rotatable.setSize(35);
rotatable.setTypeface(typeface);
rotatable.setInterpolator(new AccelerateInterpolator());
rotatable.setAnimationDuration(500);

Rotatable rotatable2 = new Rotatable(Color.parseColor("#123456"), 1000, "Word03", "Word04", "Word05");
rotatable2.setSize(25);
rotatable2.setTypeface(typeface);
rotatable2.setInterpolator(new DecelerateInterpolator());
rotatable2.setAnimationDuration(500);

rotatingTextWrapper.setContent("This is ? and ?", rotatable, rotatable2);

Result

Documentation

Rotating text is made of two parts : RotatingTextWrapper and Rotatable.
Each rotatable encapsulates the collection of words that are two be periodically switched and also defines various properties related to these words, like, size, color, animation interpolator etc.
Each Rotatable must be a part of a RotatingTextWrapper. This defines the actual layout of the text and the positions of the rotating text.

For eg : rotatingTextWrapper.setContent("This is ?", rotatble);. Here the ? denotes the postion of the rotatable.

RotatingTextWrapper

Property Function Description
Content setContent(...) Set the actual content. Composed of a String and array of Rotatables.
Typeface setTypeface(...) Set the typeface of the non-rotating text
Size setSize(...) Set the size of the non-rotating text
Pause pause(x) Method to pause the 'x'th rotatable
Resume resume(x) Method to resume the 'x'th rotatable

Rotatable

Property Function Description
Color setColor(...) Set the color of the rotating text associated with this rotatable
Size setSize(...) Set the size of the rotating text associated with this rotatable
Typeface setTypeface(...) Set the typeface of the rotating text associated with this rotatable
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

License

RotatingText is licensed under MIT license. View license.

rotatingtext's People

Contributors

anu-123-gif avatar codermayhem avatar dev-ritik avatar harjot-oberai avatar jkomyno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rotatingtext's Issues

Update Text

How can I update the text of an existing rotatable?

MEMORY LEAK !!!!

be aware this can cause you a huge memory leak.
I spent few days to find what caused app crash due to memory issue, and this was the problem.

take a look at android monitor, memory, watch "Dump java heap"

Support for API 16

Hello, thanks for this great library but don't you think minimum Api level 19 is too high.
If its possible can you please bring it down to Api 16.
Thank you

Let's go for v1.1-alpha

  • Compile the changelog since the last version (1.0.2).
  • Update the README to reflect on how to use the updated library.
  • Push the changes to repositories to get the updated alpha dependency.
  • Test and release v1.1

Create a separate branch for these changes.

How to rotate a DynamicLayout newly implemented in your API?

Hi,

I'm using your API "RotatingText" on my Android app (https://github.com/mdg-iitr/RotatingText).
I've seen a bug: when the text is too long, the last letters overlap on top of each other.
That's because you don't use any layout (dynamiclayout e.g.) in your widget-class RotatingTextSwitcher.

So I use a dynamiclayout. A new problem occurs: it's not animated (in other words: its texts are not rotated). Indeed, I must use layout.draw(canvas); and I can't use canvas.drawTextOnPath(). That explains why there isn't any animation.

Please, can you tell me how to make my dynamiclayout and/or it's text rotate in these conditions?

I have created a well-received Stackoverflow question. A bounty of 300 is available ;-) : https://stackoverflow.com/questions/60028812/android-rotating-text-i-use-dynamiclayout-drawcanvas-but-it-doesnt-animate-a

I hope you will answer me as soon as possible,
Thank you in advance,
Best regards,

For every one second a new timer thread is being created.

For every one second a new timer thread is being created.
which is making more CPU usage every second. Can you solve the problem.

Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/Reckoner_Bold.ttf");
RotatingTextWrapper rotatingTextWrapper = (RotatingTextWrapper) findViewById(R.id.custom_switcher);
rotatingTextWrapper.setSize(35);
Rotatable rotatable = new Rotatable(Color.parseColor("#FFA036"), 1000, " Why ?", "What ?", " How ?");
rotatable.setSize(35);
rotatable.setAnimationDuration(500);
rotatable.setTypeface(custom_font);
rotatable.setInterpolator(new BounceInterpolator());
rotatingTextWrapper.setContent("?",rotatable );

screenshot 8

Add option to stop rotation after one cycle.

how do i disable auto slide feature from it??

i would like to slide only one cycle and the effect to be ended.

am i missing? or there is no fuctionality for that.
or i should implement this by some stupid way (eg. disable the view)
??

ANR

sorry ,after a long time ,I got a ANR. what should I do ? thanks

Nothing happen Getting error

Process: com.ekincare.development, PID: 1407
java.lang.ClassCastException: dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper cannot be cast to android.app.Activity
at com.sdsmdg.harjot.rotatingtext.RotatingTextSwitcher$9.run(RotatingTextSwitcher.java:287)
at java.util.TimerThread.mainLoop(Timer.java:562)
at java.util.TimerThread.run(Timer.java:512)
2022-06-02 19:06:35.944 1407-2875/com.ekincare.development E/Apxor: Observed Application crash

Adding horizontal rotation of texts!

Right now in the updated code, the texts rotate vertically only. A new feature can be added wherein the entered texts can rotate horizontally.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.