Skip to content

Instantly share code, notes, and snippets.

@thejakeofink
Created April 15, 2016 16:18
Show Gist options
  • Save thejakeofink/5534e50f87bc58c14414f0c236bcf009 to your computer and use it in GitHub Desktop.
Save thejakeofink/5534e50f87bc58c14414f0c236bcf009 to your computer and use it in GitHub Desktop.
package com.thejakeofink.circlularrevealanimation;
import android.animation.Animator;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewAnimationUtils;
public class CircularRevealActivity extends AppCompatActivity {
FloatingActionButton fab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final View overlay = findViewById(R.id.overlayView);
if (overlay != null) {
overlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int fabXCenter;
int fabYCenter;
int[] fabCoords = new int[2];
fab.getLocationOnScreen(fabCoords);
fabXCenter = fabCoords[0] + (fab.getMeasuredWidth() / 2);
fabYCenter = fabCoords[1];
Animator circularHide = ViewAnimationUtils.createCircularReveal(overlay,
fabXCenter, fabYCenter,
(int) Math.hypot(overlay.getMeasuredWidth(), overlay.getMeasuredHeight()), 0);
circularHide.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
overlay.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
circularHide.setInterpolator(new FastOutSlowInInterpolator());
circularHide.start();
}
});
}
fab = (FloatingActionButton) findViewById(R.id.fab);
if (fab != null) {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int fabXCenter;
int fabYCenter;
int[] fabCoords = new int[2];
fab.getLocationOnScreen(fabCoords);
fabXCenter = fabCoords[0] + (fab.getMeasuredWidth() / 2);
fabYCenter = fabCoords[1];
Animator circularReveal = ViewAnimationUtils.createCircularReveal(overlay,
fabXCenter, fabYCenter, 0,
(int) Math.hypot(overlay.getMeasuredWidth(), overlay.getMeasuredHeight()));
overlay.setVisibility(View.VISIBLE);
circularReveal.setInterpolator(new FastOutSlowInInterpolator());
circularReveal.start();
}
});
}
}
@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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment