() Android experiment showing a sinking TextView

Related tags

Label / Form Titanic
Overview

Titanic for Android

This library is DEPRECATED, as I don't have time to mainatin it anymore. But feel free to go through the code and copy that into your project, it still does its job.

Titanic is an Android experiment reproducing this effect.

ScreenShot

How to use

Add a TitanicTextView to your layout:

<com.romainpiel.titanic.TitanicTextView
    android:id="@+id/titanic_tv"
    android:text="@string/loading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#212121"
    android:textSize="70sp"/>

To start the animation:

titanic = new Titanic();
titanic.start(myTitanicTextView);

You may want to keep track of the titanic instance after the animation is started if you want to stop it.

To stop it:

titanic.cancel();

How does it work?

Quick version

Titanic is a simple illusion obtained by applying an animated translation on the TextView TextPaint Shader's matrix.

Less quick version

What is a Shader?

A Shader is a class defining spans of colors. It is installed in a Paint. It's usually following a certain strategy, so you have LinearGradient shaders, RadialGradient shaders BitmapShader shaders, etc...

Shader attributes:

  • tile mode: how the shader color spans should be repeated on the x and y axis.
  • local matrix: can be used to apply transformations on the shader

Why are you bugging me with these notions?

Well because it is exaclty what we are using in this experiment.

In TitanicTextView, we create a BitmapShader containing a wave bitmap.

We set the tile mode to:

  • x: TileMode.REPEAT. The bitmap is repeated on the x-axis
  • y: Tilemode.CLAMP. The edge colors are repeated outside the bitmap on the y-axis

We have a maskX and a maskY variable that will define the position of the shader. So at every onDraw() we will take in account these values and translate the shader's local matrix at the right position.

We also have a variable offsetY to make the value maskY usable. So when maskY is equal to 0, the wave is at the center of the view.

How is it animating?

The animation is based on Android Animator API. I am not going to go through that part. Go read the documentation if you need some explanations.

In this experiment there are 2 animations.

  • One is moving the wave horizontally from 0 to 200 (the width of the wave bitmap).
  • The second one is moving the wave vertically from the bottom half to the top half.

To animate these translations, all we need is to apply an animator on maskX and maskY. The position of the shader's matrix will be updated automatically in onDraw().

I want more examples

Glad you said that. Go check out Shimmer-android. It's based on the same concept with a LinearGradient shader.

Sample

See the sample for a common use of this library.

License

Copyright 2014 Romain Piel

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.
You might also like...
A simple and flexible Checked TextView or Checkable TextView
A simple and flexible Checked TextView or Checkable TextView

CheckableTextView Checkable TextView [KOTLIN] âš¡ A simple and flexible Checked TextView or Checkable TextView written in Kotlin âš¡ What's New Animation

Mentions-TextView - Make Mentions and hashtags clickable in Textview
Mentions-TextView - Make Mentions and hashtags clickable in Textview

Mentions Textview Custome Textview with Mentions and hashtags being clickable. D

A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.
A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.

Apex Apex is just a simple proof of concept to demonstrate how easily you can build your own UI Toolkit from scratch. This code base is most likely fu

A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.
A basic, incomplete, buggy, far from efficient UI toolkit for Kotlin/Android. An experiment for fun and to learn.

Apex Apex is just a simple proof of concept to demonstrate how easily you can build your own UI Toolkit from scratch. This code base is most likely fu

a 3d database ORM experiment. (used in two commercial projects)

Android-TriOrm a 3d database ORM experiment for Android. (used in two commercial projects). based around small tables concept and JVM Serialization. H

Exploring Kotlin Symbol Processing - KSP. This is just an experiment.

KSP example Exploring Kotlin Symbol Processing - KSP. This is just an experiment. Project contains 2 modules Processing Example Processing module is t

A repo to experiment with Continuation R, A implementations in Kotlin

A repo to experiment with Continuation R, A implementations in Kotlin

An application for conducting an experiment on the energy consumption of the screen on a test stand
An application for conducting an experiment on the energy consumption of the screen on a test stand

energy-consumption-screen-test-app An application for conducting an experiment on the energy consumption of the screen on a test stand The Application

A sandbox where I will experiment with new techniques, concepts, and technologies.
A sandbox where I will experiment with new techniques, concepts, and technologies.

A sandbox where I will experiment with new techniques, concepts, and technologies. Here you will find some DDD, CQRS, Clean Architecture, Event-Driven Architecture, Serverless, Microservices, RabbitMQ, gRPC, SOLID, Design Patterns, and more.

An experiment with cellular automata; Functional mod for Rem's Engine.
An experiment with cellular automata; Functional mod for Rem's Engine.

Cellular Automata This is an experiment with cellular automata. A functional mod for Rem's Engine. When experimenting, I found the Sierpinski Triangle

A thought experiment on architecture, object-oriented programming, and composability.

Journal3 There's barely anything special about the features that Journal3 is offering, it's literally yet another journaling application. What is spec

Pick any of your favorite github repository and create a mini android app showing its details on an android app.
Pick any of your favorite github repository and create a mini android app showing its details on an android app.

Github Browser Pick any of your favorite github repository and create a mini android app showing its details on an android app. Screens navigation gra

Example of Android project showing integration with Kotlin and Dagger 2

kotlin-dagger-example This project demonstrate how to setup an Android Project with Kotlin and Dagger 2. It's based on Dagger 2 example ##Known issues

Android library for showing progress in a highly customizable pie.
Android library for showing progress in a highly customizable pie.

ProgressPieView Android library for showing progress in a highly customizable pie. Choose from the broad spectre of styleable elements: ppvStrokeWidth

Example of Android project showing integration with Kotlin and Dagger 2

kotlin-dagger-example This project demonstrate how to setup an Android Project with Kotlin and Dagger 2. It's based on Dagger 2 example ##Known issues

Custom UI control for android which is showing data as a segments and a value inside them.
Custom UI control for android which is showing data as a segments and a value inside them.

Segmented Bar View for Android Custom UI control for android which is showing data as a segments and a value inside them. Screenshots Install From rep

An app showing all details for various Lenovo Thinkpad models. Made to try out Jepack Compose for Android.

ThinkRchive An app showing all details for various Lenovo Thinkpad models. Made to try out Jepack Compose for Android. WORK IN PROGRESS GOALS: Use Ret

A full-stack application showing the power 💪 of KOTLIN. Entire android app + backend Apis written in Kotlin 🔥
A full-stack application showing the power 💪 of KOTLIN. Entire android app + backend Apis written in Kotlin 🔥

Gamebaaz 🎮 A full-stack application showing the power 💪 of KOTLIN. Entire android app + backend Apis written in Kotlin 🔥 Android Backend Jetpack Co

Android application showing list of Countries with National capital and flag.

Countries Android application showing list of Countries with National capital and flag. Implemented using Android MVVM architecture and used RxJava, D

Owner
Romain Piel
Romain Piel
Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Manabu S. 4k Jan 8, 2023
This is based on an open source autosizing textview for Android.

SizeAdjustingTextView This is based on an open source autosizing textview for Android I found a few weeks ago. The initial approach didn't resize mult

Elliott Chenger 255 Dec 29, 2022
A TextView that automatically resizes text to fit perfectly within its bounds.

AutoFitTextView A TextView that automatically resizes text to fit perfectly within its bounds. Usage dependencies { compile 'me.grantland:autofitt

Grantland Chew 4.2k Jan 8, 2023
A TextView that simulates the effect from the app Secret where the characters fade in/out at different speeds.

SecretTextView A TextView that simulates the effect from the app Secret where the characters fade in/out at different speeds. How To Use Use it just l

Matt Kula 611 Nov 7, 2022
An easy, flexible way to add a shimmering effect to any view in an Android app.

Shimmer for Android Shimmer is an Android library that provides an easy way to add a shimmer effect to any view in your Android app. It is useful as a

Facebook 5.1k Dec 31, 2022
:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

LIBRARY IS NO LONGER MAINTAINED If you want to adopt + maintain this library, please drop me a message - [email protected] Android Full Justific

Mathew Kurian 1.9k Dec 29, 2022
RoundedLetterView like the one in Android 5.0 Contacts app

RoundedLetterView RoundedLetterView like the one in Android 5.0 Contacts app Attributes to choose from: rlv_titleText - The text in the first row. rlv

Pavlos-Petros Tournaris 653 Nov 11, 2022
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use <com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

goka 270 Nov 11, 2022
Android Library to make it easy to create CodeEditor or IDE that support any languages and themes

CodeView Android Library to make it easy to create your CodeEditor or IDE for any programming language even for your programming language, just config

Amr Hesham 294 Jan 6, 2023
Android experiment showing a sinking TextView

Titanic is an Android experiment reproducing this effect.

Romain Piel 1.8k Dec 15, 2022