TypedTextView

Additional

Language
Java
Version
1.1.2 (Oct 31, 2019)
Created
Jun 10, 2019
Updated
Oct 31, 2019 (Retired)
Owner
Purushottam Pawar (iamporus)
Contributors
Purushottam Pawar (iamporus)
PurushottamPawar
2
Activity
Badge
Generate
Download
Source code

TypedTextView

Custom implementation of Android's TextView simulating a keyboard/typewriter.

Features

  • display a blinking cursor after every character typed.
  • characters are displayed on the screen with random speed which simulates human behavior.
  • emit audio keystrokes with typed characters.
  • Lifecycle-aware component. Character typing and audio stops/resumes as per Activity/Fragment state.
  • support to maintain state across Activity/Fragment lifecycle.
  • delay on sensing comma(,) and full stops(.) to simulate user pauses.
  • display sentences on new line on sensing full stops in passed text.

Gradle

  • Step 1. Add the JitPack repository to your build file.

Add following in your Project level build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}
  • Step 2. Add the dependency
dependencies {
  ...
  implementation 'com.github.iamporus:TypedTextView:x.y.z'
}

The latest version of TypedTextView is

Usage - XML

Simple Usage

<com.prush.typedtextview.TypedTextView
        android:id="@+id/typedTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:textSize="24sp"
        app:typed_text="Once there lived a monkey in a jamun tree by a river. The monkey was alone. He had no friends, no family, but he was happy and content."/>

Customizations

<com.prush.typedtextview.TypedTextView
        android:id="@+id/typedTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:textSize="24sp"
        app:randomize_typing_speed="true"
        app:randomize_type_seed="75"
        app:show_cursor="true"
        app:cursor_blink_speed="530"
        app:sentence_pause="1500"
        app:split_sentences="true"
        app:play_keystrokes_audio="true"                                   //use default audio 
        app:play_keystrokes_audio_res="@raw/your_audio_keystroke_res_id"   //OR use custom audio
        app:typed_text="Once there lived a monkey in a jamun tree by a river. The monkey was alone. He had no friends, no family, but he was happy and content."
        app:typing_speed="175"/>

Usage - Java

Simple Usage

TypedTextView typedTextView = findViewById( R.id.typedTextView );

typedTextView.setTypedText( "Once there lived a monkey in a jamun tree by a river. The monkey was alone. He had no friends, no family, but he was happy and content." );

//Attach TypedTextView's lifecycle to Activity's lifecycle.
getLifecycle().addObserver( typedTextView.getLifecycleObserver() );

Customizations

TypedTextView typedTextView = findViewById( R.id.typedTextView );

//Using Builder

TypedTextView.Builder builder = new TypedTextView.Builder( typedTextView )
                .setTypingSpeed( 175 )
                .splitSentences( true )
                .setSentencePause( 1500 )
                .setCursorBlinkSpeed( 530 )
                .randomizeTypingSpeed( true )
                .showCursor( false )
                .playKeyStrokesAudio( true )
                .randomizeTypeSeed( 250 );

typedTextView = builder.build();

typedTextView.setTypedText( "Once there lived a monkey in a jamun tree by a river. The monkey was alone. He had no friends, no family, but he was happy and content." );

//----------------------------------------------------- OR ---------------------------------------------------------------

//Set typing speed
typedTextView.setTypingSpeed( 175 );

//Configure sentences
typedTextView.splitSentences( true );
typedTextView.setSentencePause( 1500 );

//Configure Cursor
typedTextView.showCursor( true );
typedTextView.setCursorBlinkSpeed( 530 );

//Configure randomizing typing speed to simulate human behaviour
typedTextView.randomizeTypingSpeed( true );
typedTextView.randomizeTypeSeed( 75 );

//Play default keystrokes audio
typedTextView.playKeyStrokesAudio( true );
        
//OR play custom keystrokes audio
typedTextView.playKeyStrokesAudio( R.raw.your_audio_keystroke_res_id );
        
//Set text to be typed
typedTextView.setTypedText( "Once there lived a monkey in a jamun tree by a river. The monkey was alone. He had no friends, no family, but he was happy and content." );

//Attach TypedTextView's lifecycle to Activity's lifecycle.
getLifecycle().addObserver( typedTextView.getLifecycleObserver() );
        
//Set listener to invoke other actions based on status.
typedTextView.setOnCharacterTypedListener( new TypedTextView.OnCharacterTypedListener()
{
  @Override
  public void onCharacterTyped( char character, int index )
  {
    Log.d( TAG, "onCharacterTyped: " + character + " at index " + index );
  }
});

License

Copyright 2019 Purushottam Pawar

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.