1 /* 2 * Copyright 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.example.android.revealeffectbasic; 17 18 import android.animation.Animator; 19 import android.os.Bundle; 20 import android.support.annotation.Nullable; 21 import android.support.v4.app.Fragment; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewAnimationUtils; 25 import android.view.ViewGroup; 26 import android.view.animation.AccelerateDecelerateInterpolator; 27 28 import com.example.android.common.logger.Log; 29 30 /** 31 * This sample shows a view that is revealed when a button is clicked. 32 */ 33 public class RevealEffectBasicFragment extends Fragment { 34 35 private final static String TAG = "RevealEffectBasicFragment"; 36 37 @Override 38 public void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 setHasOptionsMenu(true); 41 } 42 43 @Override 44 public View onCreateView(LayoutInflater inflater, ViewGroup container, 45 Bundle savedInstanceState) { 46 return inflater.inflate(R.layout.reveal_effect_basic, container, false); 47 } 48 49 @Override 50 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 51 final View shape = view.findViewById(R.id.circle); 52 final View button = view.findViewById(R.id.button); 53 // Set a listener to reveal the view when clicked. 54 button.setOnClickListener(new View.OnClickListener() { 55 @Override 56 public void onClick(View view) { 57 // Create a reveal {@link Animator} that starts clipping the view from 58 // the top left corner until the whole view is covered. 59 Animator circularReveal = ViewAnimationUtils.createCircularReveal( 60 shape, 61 0, 62 0, 63 0, 64 (float) Math.hypot(shape.getWidth(), shape.getHeight())); 65 circularReveal.setInterpolator(new AccelerateDecelerateInterpolator()); 66 67 // Finally start the animation 68 circularReveal.start(); 69 70 Log.d(TAG, "Starting Reveal animation"); 71 } 72 }); 73 super.onViewCreated(view, savedInstanceState); 74 } 75 }