blob: d27be6932530cd47b9fc5c93953661a61a7b0da3 [file] [log] [blame]
John Reckd3de42c2014-07-15 14:29:33 -07001/*
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
17package com.android.test.hwui;
18
19import android.animation.ValueAnimator;
20import android.app.Activity;
21import android.content.Context;
22import android.graphics.Canvas;
23import android.graphics.Color;
24import android.os.Bundle;
25import android.view.View;
26import android.view.View.OnClickListener;
27import android.view.ViewAnimationUtils;
28import android.widget.LinearLayout;
29import android.widget.LinearLayout.LayoutParams;
30import android.widget.ProgressBar;
31
32public class RevealActivity extends Activity implements OnClickListener {
33
34 private static final int DURATION = 800;
35
36 private boolean mShouldBlock;
37
38 @Override
39 protected void onCreate(Bundle savedInstanceState) {
40 super.onCreate(savedInstanceState);
41
42 final LinearLayout layout = new LinearLayout(this);
43 layout.setOrientation(LinearLayout.VERTICAL);
44
45 ProgressBar spinner = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
46 layout.addView(spinner, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
47 View revealView = new MyView(this);
48 layout.addView(revealView,
49 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
50 setContentView(layout);
51
52 revealView.setOnClickListener(this);
53 }
54
55 @Override
56 public void onClick(View view) {
57 ValueAnimator animator = ViewAnimationUtils.createCircularReveal(view,
58 view.getWidth() / 2, view.getHeight() / 2,
59 0, Math.max(view.getWidth(), view.getHeight()));
60 animator.setDuration(DURATION);
61 animator.setAllowRunningAsynchronously(true);
62 animator.start();
63
64 mShouldBlock = !mShouldBlock;
65 if (mShouldBlock) {
66 view.post(sBlockThread);
67 }
68 }
69
70 private final static Runnable sBlockThread = new Runnable() {
71 @Override
72 public void run() {
73 try {
74 Thread.sleep(DURATION);
75 } catch (InterruptedException e) {
76 }
77 }
78 };
79
80 static class MyView extends View {
81
82 public MyView(Context context) {
83 super(context);
84 }
85
86 @Override
87 protected void onDraw(Canvas canvas) {
88 canvas.drawColor(Color.RED);
89 }
90 }
91}