2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.test.hwui;
19 import android.animation.Animator;
20 import android.animation.Animator.AnimatorListener;
21 import android.animation.AnimatorSet;
22 import android.app.Activity;
23 import android.content.Context;
24 import android.graphics.Canvas;
25 import android.graphics.Color;
26 import android.os.Bundle;
27 import android.util.Log;
28 import android.view.View;
29 import android.view.View.OnClickListener;
30 import android.view.ViewAnimationUtils;
31 import android.widget.LinearLayout;
32 import android.widget.LinearLayout.LayoutParams;
33 import android.widget.ProgressBar;
35 public class RevealActivity extends Activity implements OnClickListener {
37 private static final int DURATION = 800;
39 private boolean mShouldBlock;
40 private int mIteration = 0;
42 private AnimatorListener mListener = new AnimatorListener() {
45 public void onAnimationStart(Animator animation) {
46 Log.d("Reveal", "onAnimatorStart " + animation);
50 public void onAnimationRepeat(Animator animation) {
51 Log.d("Reveal", "onAnimationRepeat " + animation);
55 public void onAnimationEnd(Animator animation) {
56 Log.d("Reveal", "onAnimationEnd " + animation);
60 public void onAnimationCancel(Animator animation) {
61 Log.d("Reveal", "onAnimationCancel " + animation);
66 protected void onCreate(Bundle savedInstanceState) {
67 super.onCreate(savedInstanceState);
69 final LinearLayout layout = new LinearLayout(this);
70 layout.setOrientation(LinearLayout.VERTICAL);
72 ProgressBar spinner = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
73 layout.addView(spinner, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
74 View revealView = new MyView(this);
75 layout.addView(revealView,
76 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
77 setContentView(layout);
79 revealView.setOnClickListener(this);
83 public void onClick(View view) {
84 Animator animator = ViewAnimationUtils.createCircularReveal(view,
85 view.getWidth() / 2, view.getHeight() / 2,
86 0, Math.max(view.getWidth(), view.getHeight()));
87 Log.d("Reveal", "Calling start...");
88 animator.addListener(mListener);
90 animator.setDuration(DURATION);
93 AnimatorSet set = new AnimatorSet();
94 set.playTogether(animator);
95 set.setDuration(DURATION);
96 set.addListener(mListener);
100 mIteration = (mIteration + 1) % 4;
101 mShouldBlock = !mShouldBlock;
103 view.post(sBlockThread);
107 private final static Runnable sBlockThread = new Runnable() {
111 Thread.sleep(DURATION);
112 } catch (InterruptedException e) {
117 static class MyView extends View {
119 public MyView(Context context) {
124 protected void onDraw(Canvas canvas) {
125 canvas.drawColor(Color.RED);