Takt Android Library

repository·master·Indexed 22 days ago

https://github.com/wasabeef/takt

An Android library for measuring and displaying real-time FPS using the Android Choreographer API. It provides a customizable on-screen overlay and a listener for FPS updates, with support for a no-op version for production builds.

Tokens
699
Snippets
5
Records
5
Agent score
28%

What's inside Takt

  1. Install Takt via Gradle

    master

    To use Takt in your Android project, add mavenCentral() to your repositories and include the following dependencies. It is recommended to use debugImplementation for the full library and releaseImplementation with the no-op version to ensure the FPS overlay does not appear in production builds.

    repositories {
      mavenCentral()
    }
    
    dependencies {
      releaseImplementation 'jp.wasabeef:takt-no-op:2.1.1'
      debugImplementation 'jp.wasabeef:takt:2.1.1'
    }
  2. Initialize Takt in your Application class

    master

    For a basic setup, call Takt.stock(this) within your Application class's onCreate method. This will start the FPS measurement and display the overlay.

    class MyApplication : Application() {
      override fun onCreate() {
        super.onCreate()
        Takt.stock(this)
      }
    }
  3. Set the overlay position using Seat

    master

    Use the seat() method to position the FPS overlay on the screen. The available Seat constants are:

    • TOP_RIGHT, TOP_LEFT, TOP_CENTER
    • CENTER
    • RIGHT_CENTER, LEFT_CENTER
    • BOTTOM_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER
    Takt.stock(this)
      .seat(Seat.RIGHT_CENTER)
  4. Hide the FPS label while keeping the listener

    master

    If you want to monitor FPS via a listener without displaying the visual overlay on the screen, call .hide() during initialization.

    Takt.stock(this)
      .hide()
      .listener { fps -> Log.d("Excellent!", fps.toString() + " fps") }
  5. Configure Takt options and listeners

    master

    You can customize the FPS overlay using a builder pattern after calling Takt.stock(this).

    Available configuration methods:

    • seat(Seat seat): Sets the position of the overlay.
    • interval(int ms): Sets the measurement interval in milliseconds.
    • color(int color): Sets the text color.
    • size(int size): Sets the text size.
    • alpha(float alpha): Sets the text transparency (alpha).
    • listener(Audience audience): Provides a callback to receive FPS updates.
    • useCustomControl: Enables manual start/stop (disabled by default).
    • showOverlaySetting: Enables/disables showing system overlay settings (enabled by default).
    Takt.stock(this)
      .seat(Seat.BOTTOM_RIGHT)
      .interval(250)
      .color(Color.WHITE)
      .size(14f)
      .alpha(.5f)
      .listener { fps ->
        Log.d("Excellent!", fps.toString() + " fps")
      }