Convert Figma logo to code with AI

romainpiel logoTitanic

(DEPRECATED) Android experiment showing a sinking TextView

1,850
550
1,850
2

Top Related Projects

A topic-centric list of HQ open datasets.

A repository of data on coronavirus cases and deaths in the U.S.

16,760

Data and code behind the articles and graphics at FiveThirtyEight

An index of all our open-source data, analysis, libraries, tools, and guides.

Quick Overview

Titanic is an Android library that provides a simple and customizable implementation of the "Floating Action Button" (FAB) design pattern. It allows developers to easily add expandable FABs to their Android applications, enhancing the user interface with a modern and interactive element.

Pros

  • Easy integration into existing Android projects
  • Customizable appearance and behavior
  • Smooth animations for expanding and collapsing the FAB
  • Lightweight library with minimal dependencies

Cons

  • Limited documentation and examples
  • Not actively maintained (last update was several years ago)
  • May not be fully compatible with the latest Android design guidelines
  • Lacks some advanced features found in more comprehensive FAB libraries

Code Examples

  1. Adding a Titanic FAB to your layout:
<com.romainpiel.titanic.library.TitanicMenu
    android:id="@+id/titanic_menu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp" />
  1. Initializing and customizing the FAB in your Activity or Fragment:
val titanicMenu: TitanicMenu = findViewById(R.id.titanic_menu)
titanicMenu.setMenuItems(arrayOf(
    TitanicMenuItem(R.drawable.ic_action_1, "Action 1"),
    TitanicMenuItem(R.drawable.ic_action_2, "Action 2"),
    TitanicMenuItem(R.drawable.ic_action_3, "Action 3")
))
titanicMenu.setOnClickListener { item ->
    // Handle item click
}
  1. Programmatically expanding or collapsing the FAB:
// Expand the FAB
titanicMenu.expand()

// Collapse the FAB
titanicMenu.collapse()

Getting Started

  1. Add the Titanic library to your project's build.gradle file:
dependencies {
    implementation 'com.romainpiel.titanic:library:1.0.0'
}
  1. Add the TitanicMenu to your layout XML file (see example 1 above).

  2. Initialize and customize the FAB in your Activity or Fragment (see example 2 above).

  3. Handle item clicks and customize the FAB's behavior as needed.

Competitor Comparisons

A topic-centric list of HQ open datasets.

Pros of awesome-public-datasets

  • Extensive collection of public datasets across various domains
  • Regularly updated with new datasets and community contributions
  • Well-organized structure with categories for easy navigation

Cons of awesome-public-datasets

  • No specific data analysis or visualization tools provided
  • Requires users to navigate to external sources for dataset access

Code comparison

Not applicable, as awesome-public-datasets is a curated list of datasets without code, while Titanic is a specific dataset analysis project.

Additional notes

Titanic focuses on a single dataset (Titanic passenger data) and provides analysis code, while awesome-public-datasets is a comprehensive resource for finding various public datasets without specific analysis tools.

Titanic is suitable for those looking to practice data analysis on a well-known dataset, while awesome-public-datasets serves as a valuable reference for researchers and data scientists seeking diverse datasets for their projects.

A repository of data on coronavirus cases and deaths in the U.S.

Pros of covid-19-data

  • Actively maintained with frequent updates
  • Comprehensive dataset covering multiple countries and regions
  • Well-documented with clear data sources and methodologies

Cons of covid-19-data

  • Large repository size due to extensive data files
  • Requires more complex data processing for analysis
  • Limited visualization or analysis tools included

Code Comparison

Titanic (Python):

def clean_data(df):
    df = df.drop(['Ticket', 'Cabin'], axis=1)
    df['Age'].fillna(df['Age'].median(), inplace=True)
    df['Embarked'].fillna(df['Embarked'].mode()[0], inplace=True)
    return df

covid-19-data (CSV data example):

date,county,state,fips,cases,deaths
2020-01-21,Snohomish,Washington,53061,1,0
2020-01-22,Snohomish,Washington,53061,1,0
2020-01-23,Snohomish,Washington,53061,1,0

The Titanic repository focuses on a specific dataset for machine learning, while covid-19-data provides raw data for COVID-19 analysis. Titanic includes data processing code, whereas covid-19-data primarily consists of data files. The covid-19-data repository is more extensive and regularly updated, making it suitable for ongoing research and analysis of the pandemic.

16,760

Data and code behind the articles and graphics at FiveThirtyEight

Pros of data

  • Larger scope with diverse datasets across multiple topics
  • Regularly updated with new datasets
  • Well-documented with detailed README files for each dataset

Cons of data

  • Less focused on a specific problem or analysis
  • May require more preprocessing for specific use cases
  • Larger repository size, potentially slower to clone

Code comparison

Titanic:

train_df = pd.read_csv('../input/train.csv')
test_df = pd.read_csv('../input/test.csv')

train_df['Sex'] = train_df['Sex'].map({'female': 0, 'male': 1}).astype(int)
test_df['Sex'] = test_df['Sex'].map({'female': 0, 'male': 1}).astype(int)

data:

import pandas as pd

data = pd.read_csv('datasets/some_dataset.csv')
data['column'] = pd.to_datetime(data['column'])
data = data.groupby('category').mean()

Summary

Titanic focuses on a specific dataset and problem, making it more suitable for beginners or those interested in the Titanic survival prediction challenge. data offers a wider range of datasets and topics, making it more versatile for various data analysis projects. The code examples show that Titanic involves more specific preprocessing for the Titanic dataset, while data demonstrates general data manipulation techniques applicable to multiple datasets.

An index of all our open-source data, analysis, libraries, tools, and guides.

Pros of everything

  • Larger and more comprehensive dataset covering various topics and news stories
  • Regularly updated with new data and analyses
  • Includes detailed documentation and methodologies for each dataset

Cons of everything

  • Less focused on a specific topic or problem, potentially overwhelming for users
  • Requires more data processing and cleaning for specific use cases
  • May have inconsistent data formats across different datasets

Code comparison

While a direct code comparison is not relevant due to the different nature of these repositories, we can highlight some differences in their data handling approaches:

everything:

import pandas as pd

df = pd.read_csv('data/filename.csv')
df.head()

Titanic:

public class Passenger {
    private String name;
    private int age;
    private boolean survived;
    // ...
}

Summary

Everything is a comprehensive data repository with a wide range of topics, while Titanic focuses on a specific dataset for machine learning. Everything offers more diverse data but requires more processing, whereas Titanic provides a more structured and focused approach for a single problem. The choice between them depends on the user's specific needs and data analysis goals.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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.