Skip to content

Instantly share code, notes, and snippets.

@chibaye
Forked from prinsu03/Animated_LikeButton
Created November 21, 2022 07:42
Show Gist options
  • Save chibaye/645c2ae323dfd5e8218b767cadeeee8b to your computer and use it in GitHub Desktop.
Save chibaye/645c2ae323dfd5e8218b767cadeeee8b to your computer and use it in GitHub Desktop.
Animated_LikeButton Like Twitter
package com.example.prince.like_button_animation;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.like.LikeButton;
import com.like.OnAnimationEndListener;
import com.like.OnLikeListener;
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
import com.mikepenz.iconics.IconicsDrawable;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity implements OnLikeListener,
OnAnimationEndListener {
public static final String TAG = "MainActivity";
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.star_button)
LikeButton starButton;
@BindView(R.id.heart_button)
LikeButton likeButton;
@BindView(R.id.thumb_button)
LikeButton thumbButton;
@BindView(R.id.smile_button)
LikeButton smileButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
starButton.setOnAnimationEndListener(this);
starButton.setOnLikeListener(this);
likeButton.setOnLikeListener(this);
likeButton.setOnAnimationEndListener(this);
smileButton.setOnLikeListener(this);
smileButton.setOnAnimationEndListener(this);
thumbButton.setOnLikeListener(this);
thumbButton.setOnAnimationEndListener(this);
thumbButton.setLiked(true);
usingCustomIcons();
}
public void usingCustomIcons() {
//shown when the button is in its default state or when unLiked.
smileButton.setUnlikeDrawable(new BitmapDrawable(getResources(), new IconicsDrawable(this, CommunityMaterial.Icon.cmd_emoticon).colorRes(android.R.color.darker_gray).sizeDp(25).toBitmap()));
//shown when the button is liked!
smileButton.setLikeDrawable(new BitmapDrawable(getResources(), new IconicsDrawable(this, CommunityMaterial.Icon.cmd_emoticon).colorRes(android.R.color.holo_purple).sizeDp(25).toBitmap()));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void liked(LikeButton likeButton) {
Toast.makeText(this, "Liked!", Toast.LENGTH_SHORT).show();
}
@Override
public void unLiked(LikeButton likeButton) {
Toast.makeText(this, "Disliked!", Toast.LENGTH_SHORT).show();
}
@Override public void onAnimationEnd(LikeButton likeButton) {
Log.d(TAG, "Animation End for %s" + likeButton);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment