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 com.example.android.common.logger.Log;
19 
20 import android.animation.Animator;
21 import android.animation.ValueAnimator;
22 import android.support.v4.app.Fragment;
23 import android.os.Bundle;
24 import android.view.LayoutInflater;
25 import android.view.MotionEvent;
26 import android.view.View;
27 import android.view.ViewAnimationUtils;
28 import android.view.ViewGroup;
29 import android.view.animation.AccelerateDecelerateInterpolator;
30 
31 /**
32  * This sample shows a view that is revealed when a button is clicked.
33  */
34 public class RevealEffectBasicFragment extends Fragment {
35 
36     private final static String TAG = "RevealEffectBasicFragment";
37 
38     @Override
onCreate(Bundle savedInstanceState)39     public void onCreate(Bundle savedInstanceState) {
40         super.onCreate(savedInstanceState);
41         setHasOptionsMenu(true);
42     }
43 
44     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)45     public View onCreateView(LayoutInflater inflater, ViewGroup container,
46             Bundle savedInstanceState) {
47         final View rootView = inflater.inflate(R.layout.reveal_effect_basic, container, false);
48 
49         View button = rootView.findViewById(R.id.button);
50 
51         // Set a listener to reveal the view when clicked.
52         button.setOnClickListener(new View.OnClickListener() {
53             @Override
54             public void onClick(View view) {
55                 View shape = rootView.findViewById(R.id.circle);
56 
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 animator = ViewAnimationUtils.createCircularReveal(
60                         shape,
61                         0,
62                         0,
63                         0,
64                         (float) Math.hypot(shape.getWidth(), shape.getHeight()));
65 
66                 // Set a natural ease-in/ease-out interpolator.
67                 animator.setInterpolator(new AccelerateDecelerateInterpolator());
68 
69                 // Finally start the animation
70                 animator.start();
71 
72                 Log.d(TAG, "Starting Reveal animation");
73             }
74         });
75 
76         return rootView;
77     }
78 
79 }