JumpingBeans Android Library

repository·master·Indexed 22 days ago

https://github.com/frakbot/jumpingbeans

An Android library for adding animated 'jumping' text effects to TextViews, such as Hangouts-style typing indicators. It supports appending jumping dots or animating specific character ranges as blocks or waves. Includes a builder for customizing loop duration, wave patterns, and duty cycles.

Tokens
773
Snippets
3
Records
6
Agent score
28%

What's inside JumpingBeans

  1. Stop JumpingBeans animations to prevent leaks

    master
    Because JumpingBeans uses Spans to achieve animation, you must call stopJumping() on your JumpingBeans instance when the TextView is detached from the view tree or when the containing Activity/Fragment is paused. This ensures proper resource cleanup.
  2. Install JumpingBeans via Gradle

    master

    To use JumpingBeans in your Android project, ensure jcenter() is included in your root build.gradle file, then add the dependency to your module's build.gradle.

    // In root build.gradle
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    // In module build.gradle
    dependencies {
        compile 'net.frakbot:jumpingbeans:1.3.0'
    }
  3. Important caveats and limitations of JumpingBeans

    master

    To avoid resource waste and unexpected behavior, follow these rules:

    • Do not change text in the TextView before calling stopJumping(); this causes unnecessary invalidation and wasted resources.
    • Do not reuse the same animation on a different view; create a new JumpingBeans instance for every view.
    • Do not use multiple instances on a single TextView; calling cleanup on one will affect all others on that view.
    • Avoid large text blocks; the library is optimized for small views with a few words. Large text can cause expensive relayouts.
    • Do not use attributes that strip Spans, such as textAllCaps.
  4. Append jumping dots to a TextView

    master

    You can emulate the Hangouts-style typing indicator by appending three jumping dots to a TextView. This method automatically handles the trailing ... (either by using existing dots or appending them).

    final TextView textView1 = (TextView) findViewById(R.id.jumping_text_1);
    jumpingBeans1 = JumpingBeans.with(textView1)
            .appendJumpingDots()
            .build();
  5. Make a subsection of text jump

    master

    You can animate a specific range of characters within a TextView. You can choose to animate them as a single block or as a wave.

    final TextView textView2 = (TextView) findViewById(R.id.jumping_text_2);
    jumpingBeans2 = JumpingBeans.with(textView2)
            .makeTextJump(0, textView2.getText().toString().indexOf(' '))
            .setIsWave(false)
            .setLoopDuration(1000)  // ms
            .build();
  6. Customize JumpingBeans animation properties

    master

    Use the JumpingBeans.Builder to fine-tune the animation behavior:

    • setIsWave(boolean): Set whether the animation follows a wave pattern.
    • setLoopDuration(int): Set the duration of the animation loop in milliseconds.
    • setWavePerCharDelay(int): Set the delay between characters in a wave animation.
    • setAnimatedDutyCycle(float): Adjust the pause duration between jumping cycles.