Debian Codegraph @

tests/HwAccelerationTest/src/com/android/test/hwui/RevealActivity.java

raw symbols SCIP
1 /*
2 * Copyright (C) 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
17 package com.android.test.hwui;
18
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;
34
35 public class RevealActivity extends Activity implements OnClickListener {
36
37 private static final int DURATION = 800;
38
39 private boolean mShouldBlock;
40 private int mIteration = 0;
41
42 private AnimatorListener mListener = new AnimatorListener() {
43
44 @Override
45 public void onAnimationStart(Animator animation) {
46 Log.d("Reveal", "onAnimatorStart " + animation);
47 }
48
49 @Override
50 public void onAnimationRepeat(Animator animation) {
51 Log.d("Reveal", "onAnimationRepeat " + animation);
52 }
53
54 @Override
55 public void onAnimationEnd(Animator animation) {
56 Log.d("Reveal", "onAnimationEnd " + animation);
57 }
58
59 @Override
60 public void onAnimationCancel(Animator animation) {
61 Log.d("Reveal", "onAnimationCancel " + animation);
62 }
63 };
64
65 @Override
66 protected void onCreate(Bundle savedInstanceState) {
67 super.onCreate(savedInstanceState);
68
69 final LinearLayout layout = new LinearLayout(this);
70 layout.setOrientation(LinearLayout.VERTICAL);
71
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);
78
79 revealView.setOnClickListener(this);
80 }
81
82 @Override
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);
89 if (mIteration < 2) {
90 animator.setDuration(DURATION);
91 animator.start();
92 } else {
93 AnimatorSet set = new AnimatorSet();
94 set.playTogether(animator);
95 set.setDuration(DURATION);
96 set.addListener(mListener);
97 set.start();
98 }
99
100 mIteration = (mIteration + 1) % 4;
101 mShouldBlock = !mShouldBlock;
102 if (mShouldBlock) {
103 view.post(sBlockThread);
104 }
105 }
106
107 private final static Runnable sBlockThread = new Runnable() {
108 @Override
109 public void run() {
110 try {
111 Thread.sleep(DURATION);
112 } catch (InterruptedException e) {
113 }
114 }
115 };
116
117 static class MyView extends View {
118
119 public MyView(Context context) {
120 super(context);
121 }
122
123 @Override
124 protected void onDraw(Canvas canvas) {
125 canvas.drawColor(Color.RED);
126 }
127 }
128 }