Last active
June 1, 2016 23:42
-
-
Save darwind/8bba058aa495c178a66fd744ad7b39b2 to your computer and use it in GitHub Desktop.
Circular reveal splashscreen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**MainActivity** | |
package it.rugaard.circularreveal; | |
public class MainActivity extends AppCompatActivity { | |
private boolean isRevealed; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
View rootLayout = LayoutInflater.from(this).inflate(R.layout.activity_main, null); | |
setContentView(rootLayout); | |
rootLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
final View myView = findViewById(R.id.view); | |
// get the center for the clipping circle | |
int cx = myView.getMeasuredWidth() / 2; | |
int cy = myView.getMeasuredHeight() / 2; | |
// get the final radius for the clipping circle | |
int finalRadius = Math.max(myView.getWidth(), myView.getHeight()) / 2; | |
// create the animator for this view (the start radius is zero) | |
Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius); | |
anim.setDuration(500); | |
// make the view visible and start the animation | |
myView.setVisibility(View.VISIBLE); | |
anim.start(); | |
isRevealed = true; | |
} | |
}); | |
((RelativeLayout.LayoutParams) findViewById(R.id.revealButton).getLayoutParams()).topMargin = getResources().getDimensionPixelSize(R.dimen.statusbar_height); | |
findViewById(R.id.revealButton).setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
final View myView = findViewById(R.id.view); | |
if (!isRevealed) { | |
// get the center for the clipping circle | |
int cx = myView.getMeasuredWidth() / 2; | |
int cy = myView.getMeasuredHeight() / 2; | |
// get the final radius for the clipping circle | |
int finalRadius = Math.max(myView.getWidth(), myView.getHeight()) / 2; | |
// create the animator for this view (the start radius is zero) | |
Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius); | |
anim.setDuration(500); | |
// make the view visible and start the animation | |
myView.setVisibility(View.VISIBLE); | |
anim.start(); | |
isRevealed = true; | |
} else { | |
myView.setVisibility(View.INVISIBLE); | |
isRevealed = false; | |
} | |
} | |
}); | |
} | |
} | |
**styles.xml** | |
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> | |
<!-- Customize your theme here. --> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="android:windowTranslucentStatus">true</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
</style> | |
</resources> | |
**activity_main.xml** | |
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="it.rugaard.circularreveal.MainActivity"> | |
<TextView | |
android:id="@+id/view" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_centerInParent="true" | |
android:background="@android:color/holo_red_dark" | |
android:gravity="center" | |
android:text="Hello World!" | |
android:textColor="@android:color/white" | |
android:textSize="24sp" | |
android:visibility="invisible" /> | |
<Button | |
android:id="@+id/revealButton" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Reveal!" /> | |
</RelativeLayout> | |
**dimens.xml** | |
<resources> | |
<!-- Default screen margins, per the Android Design guidelines. --> | |
<dimen name="activity_horizontal_margin">16dp</dimen> | |
<dimen name="activity_vertical_margin">16dp</dimen> | |
<dimen name="statusbar_height">24dp</dimen> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment