Convert Figma logo to code with AI

jd-alexander logoLikeButton

Twitter's heart animation for Android

3,012
387
3,012
16

Top Related Projects

Android like button with delightful star animation inspired by Twitter's heart. See blog post for description.

Android library to create buttons with Twitter's heart like animation.

This is a UI lib for Android. Effects like shining.

Quick Overview

LikeButton is an Android library that provides a customizable button with a Twitter-like animation for liking/unliking. It offers a smooth and engaging user experience for implementing like functionality in Android applications.

Pros

  • Easy to integrate and customize
  • Smooth and visually appealing animation
  • Supports both XML and programmatic implementation
  • Lightweight and efficient

Cons

  • Limited to Android platform
  • May require additional customization for complex use cases
  • Documentation could be more comprehensive
  • Not actively maintained (last update was several years ago)

Code Examples

  1. Basic XML implementation:
<com.like.LikeButton
    app:icon_type="heart"
    app:icon_size="25dp"
    android:id="@+id/star_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

This code adds a heart-shaped like button to the layout.

  1. Programmatic implementation:
LikeButton likeButton = new LikeButton(this);
likeButton.setOnLikeListener(new OnLikeListener() {
    @Override
    public void liked(LikeButton likeButton) {
        // Handle like action
    }

    @Override
    public void unLiked(LikeButton likeButton) {
        // Handle unlike action
    }
});

This code creates a LikeButton programmatically and sets up a listener for like/unlike actions.

  1. Customizing button appearance:
likeButton.setCircleStartColor(Color.GRAY);
likeButton.setCircleEndColor(Color.BLUE);
likeButton.setExplodingDotColorsRes(R.array.exploding_colors);
likeButton.setIcon(IconType.Heart);
likeButton.setIconSizeDp(30);

This code demonstrates how to customize various aspects of the LikeButton's appearance.

Getting Started

To use LikeButton in your Android project:

  1. Add the JitPack repository to your build file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency:
dependencies {
    implementation 'com.github.jd-alexander:LikeButton:0.2.3'
}
  1. Add the LikeButton to your layout XML or create it programmatically as shown in the code examples above.

Competitor Comparisons

Android like button with delightful star animation inspired by Twitter's heart. See blog post for description.

Pros of LikeAnimation

  • More customizable animation options
  • Smoother and more complex animations
  • Better performance for larger numbers of animated elements

Cons of LikeAnimation

  • Slightly more complex implementation
  • Less straightforward API for basic use cases
  • Requires more setup for simple animations

Code Comparison

LikeButton:

LikeButton likeButton = (LikeButton) findViewById(R.id.star_button);
likeButton.setOnLikeListener(new OnLikeListener() {
    @Override
    public void liked(LikeButton likeButton) {
        // Handle like action
    }
});

LikeAnimation:

ImageView imageView = (ImageView) findViewById(R.id.imageView);
AnimatorSet animatorSet = new AnimatorSet();
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(imageView, "scaleX", 0f, 1f);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(imageView, "scaleY", 0f, 1f);
animatorSet.playTogether(scaleXAnimator, scaleYAnimator);
animatorSet.start();

LikeButton offers a simpler implementation for basic like functionality, while LikeAnimation provides more control over the animation process. LikeAnimation requires more code to set up but allows for greater customization of the animation sequence.

Android library to create buttons with Twitter's heart like animation.

Pros of SparkButton

  • More customizable animation options, including particle effects
  • Supports both XML and programmatic implementation
  • Includes a circular reveal animation for a more dynamic effect

Cons of SparkButton

  • Slightly more complex implementation due to additional features
  • May have a higher performance impact due to particle animations
  • Less frequently updated compared to LikeButton

Code Comparison

LikeButton implementation:

LikeButton likeButton = findViewById(R.id.star_button);
likeButton.setOnLikeListener(new OnLikeListener() {
    @Override
    public void liked(LikeButton likeButton) {
        // Handle like action
    }
});

SparkButton implementation:

SparkButton sparkButton = findViewById(R.id.spark_button);
sparkButton.setAnimationSpeed(1.5f);
sparkButton.setChecked(false);
sparkButton.setParticleSystem(new SparkButtonBuilder(this).setParticleColor(Color.RED).build());
sparkButton.setEventListener(new SparkEventListener() {
    @Override
    public void onEvent(ImageView button, boolean buttonState) {
        // Handle button state change
    }
});

The code comparison shows that SparkButton offers more customization options out of the box, such as animation speed and particle system configuration. However, this also means it requires more lines of code for a basic implementation compared to LikeButton.

This is a UI lib for Android. Effects like shining.

Pros of ShineButton

  • More visually appealing with shimmering effect and customizable colors
  • Supports both icon and text buttons
  • Offers more animation options and customization

Cons of ShineButton

  • Slightly more complex implementation due to additional features
  • May have higher performance overhead for complex animations
  • Less frequently updated compared to LikeButton

Code Comparison

LikeButton:

LikeButton likeButton = (LikeButton) findViewById(R.id.star_button);
likeButton.setOnLikeListener(new OnLikeListener() {
    @Override
    public void liked(LikeButton likeButton) {
        // Handle like action
    }
});

ShineButton:

ShineButton shineButton = (ShineButton) findViewById(R.id.shine_button);
shineButton.init(activity);
shineButton.setChecked(true);
shineButton.setOnCheckStateChangeListener(new ShineButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(View view, boolean checked) {
        // Handle state change
    }
});

Both libraries provide easy-to-use like/favorite buttons for Android applications. LikeButton offers a simpler implementation with basic animation, while ShineButton provides more visually appealing effects and customization options. LikeButton may be preferable for projects requiring a straightforward solution, whereas ShineButton is better suited for applications seeking more elaborate and eye-catching button animations.

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

Like Button

JitPack Build Status License Android Arsenal

Like Button is a library that allows you to create a button with animation effects similar to Twitter's heart when you like something.

Icon animations


Table of Contents

  1. Gradle Dependency

    1. Repository
    2. Dependency
  2. Basic Usage

    1. Like Button XML
    2. Attributes
  3. Button State

  4. Like Event Listener

  5. Icon Types

  6. Icon Size

  7. Custom Icons

  8. Circle Color Config

  9. Dots Color Config

  10. Animation Size

  11. Inspiration

  12. Contribution

  13. License


Gradle Dependency

Repository

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Dependency

Add this to your module's build.gradle file:

dependencies {
	...
	compile 'com.github.jd-alexander:LikeButton:0.2.3'
	}
}

Basic Usage

Like Button XML

To use this like button in your layout simply copy and paste the xml below. This provides the default heart button.

<com.like.LikeButton
            app:icon_type="heart"
            app:icon_size="25dp"
            android:id="@+id/star_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

Attributes

There are several other attributes that can be used to configure the button's behaviour and appearance. They are shown below and will be explained in the sections that follow long with their java counterparts.

<com.like.LikeButton
app:icon_type="Star"
app:circle_start_color="@color/colorPrimary"
app:like_drawable="@drawable/thumb_on"
app:unlike_drawable="@drawable/thumb_off"
app:dots_primary_color="@color/colorAccent"
app:dots_secondary_color="@color/colorPrimary"
app:circle_end_color="@color/colorAccent"
app:icon_size="25dp"
app:liked="true"
app:anim_scale_factor="2"
app:is_enabled="false"
/>


Button State

To set the inital liked state of the button you simply use the setLiked functionality via XML or Java. This will show the button in the liked state with the drawable that you selected.

XML

app:liked="true"

Java


likeButton.setLiked(true);

You can also set if the button is to be enabled or disabled. Once disabled, the animation, listener or any other functionality of the button won't be triggered.

XML

app:is_enabled="false"

Java


likeButton.setEnabled(false);

Like Event Listener

To listen to events from your like button, simply implement the listener that's triggered once the button is tapped.


likeButton.setOnLikeListener(new OnLikeListener() {
            @Override
            public void liked(LikeButton likeButton) {

            }

            @Override
            public void unLiked(LikeButton likeButton) {

            }
        });


Icon Types

The libary is bundled with three icons that you can use. A heart,thumb and a star.

XML

To set the respective icon via xml simply use the word in the icon type attribute.

app:icon_type="heart"

Java

If you would like to set the icon via Java then simply call the set icon method on the button.


likeButton.setIcon(IconType.Star);

Icon Size

XML

To set the icon size via xml simply use this attribute

app:icon_size="20dp"

Java

If you are doing it programmatically you can set it with either the method for pixels or dp.

likeButton.setIconSizePx(40);
likeButton.setIconSizeDp(20);

Note, it's very important that the size of the button is set even if you are planning to use custom drawables as described below as the library uses this value to determine the width and height of the effects that occur when the button is tapped.


Custom Icons

XML

In order to use custom icons instead of the ones bundled with the library you simply set the drawables that represent the liked and unliked state of the button.

app:like_drawable="@drawable/thumb_on"
app:unlike_drawable="@drawable/thumb_off"

Java

likeButton.setLikeDrawable(heart_on);
likeButton.setUnlikeDrawable(heart_off);

likeButton.setUnlikeDrawableRes(R.drawable.heart_off);
likeButton.setLikeDrawableRes(R.drawable.heart_on);

Circle Color Config

If you watch the animation closely you will notice that there's a circle that begins from the center of the icon and and then it animates away from the center before the exploding dots animate. These colours can be changed to suit the theme of your icon.

XML

app:circle_start_color="@color/colorPrimary"
app:circle_end_color="@color/colorAccent"

Java

likeButton.setCircleEndColorRes(R.color.colorAccent);
likeButton.setCircleEndColorRes(R.color.colorPrimary);

Dots Color Config

The dots that represent the outer animation can be coloured also.

XML

app:dots_primary_color="@color/colorAccent"
app:dots_secondary_color="@color/colorPrimary"

Java

likeButton.setExplodingDotColorsRes(R.color.colorPrimary,R.color.colorAccent);

Animation Size

To change the size of the dots that also contributes to the size of the overall like button view you can use the animation scale factor attribute via XML or it's Java equivalent

XML

app:anim_scale_factor="2.5"

Java

likeButton.setAnimationScaleFactor(2);

Inspiration

This library was made by possible based on code and design inspiration from these sources:

https://github.com/frogermcs/LikeAnimation

https://github.com/lightsmeki/android_twitter_heart_animation_button

https://dribbble.com/shots/2416983-Twitter-Heart-Animation

Contribution

Please fork repository and contribute using pull requests.

Any contributions, large or small, major features, bug fixes, additional language translations, unit/integration tests are welcomed and appreciated but will be thoroughly reviewed and discussed.

License

Copyright 2016 Joel Dean

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.