Created
January 6, 2015 18:23
-
-
Save ozodrukh/c9343e7073907c5c5d2c to your computer and use it in GitHub Desktop.
Fragment Circular Reveal animation
This file contains 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
import android.graphics.Color; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.view.ViewTreeObserver; | |
import android.view.animation.AccelerateInterpolator; | |
import java.util.Random; | |
import butterknife.ButterKnife; | |
import butterknife.InjectView; | |
import codetail.animation.Animator; | |
import codetail.animation.ViewAnimationUtils; | |
import codetail.utils.ViewUtils; | |
public class RandomFragment extends Fragment { | |
@InjectView(R.id.container) | |
View container; | |
@InjectView(R.id.first) | |
View first; | |
@InjectView(R.id.second) | |
View second; | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
ViewUtils.setBackground(container, null); | |
return inflater.inflate(R.layout.sample_fragment, container, false); | |
} | |
@Override | |
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
ButterKnife.inject(this, view); | |
ViewUtils.setBackground(view, null); | |
first.setBackgroundColor(randomColor()); | |
second.setBackgroundColor(randomColor()); | |
first.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
reveal(); | |
ViewUtils.removeGlobalListeners(first, this); | |
} | |
}); | |
} | |
void reveal(){ | |
View view = container; | |
int finalRadius = Math.max(view.getWidth(), view.getHeight()); | |
Animator animator = | |
ViewAnimationUtils.createCircularReveal(view, 0, 0, 0, finalRadius); | |
animator.setInterpolator(new AccelerateInterpolator()); | |
animator.setDuration(3500); | |
animator.start(); | |
} | |
static int randomColor(){ | |
Random random = new Random(); | |
return Color.HSVToColor(new float[]{ | |
random.nextInt(360), | |
0.70f, | |
0.70f | |
}); | |
} | |
} |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<codetail.widget.RevealFrameLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<LinearLayout | |
android:id="@+id/container" | |
android:background="@null" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:weightSum="2"> | |
<FrameLayout | |
android:id="@+id/first" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_weight="1"/> | |
<FrameLayout | |
android:id="@+id/second" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_weight="1"/> | |
</LinearLayout> | |
</codetail.widget.RevealFrameLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment