blob: 882163bd6b0e4a54a5b44e5fcba477d0b090ac7e [file] [log] [blame]
Chris Craik65b04b62015-08-27 14:34:17 -07001/*
2 * Copyright (C) 2015 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 */
16package com.android.test.uibench;
17
18import android.animation.ObjectAnimator;
19import android.animation.ValueAnimator;
20import android.content.Context;
21import android.graphics.Canvas;
John Reck2ccaf6a2016-05-26 14:36:42 -070022import android.graphics.ColorFilter;
23import android.graphics.PixelFormat;
Chris Craik65b04b62015-08-27 14:34:17 -070024import android.graphics.Color;
25import android.graphics.Paint;
John Reck2ccaf6a2016-05-26 14:36:42 -070026import android.graphics.drawable.Drawable;
Chris Craik65b04b62015-08-27 14:34:17 -070027import android.os.Bundle;
Aurimas Liutikas1d6c6da2018-04-03 17:08:29 -070028import androidx.appcompat.app.AppCompatActivity;
Chris Craik65b04b62015-08-27 14:34:17 -070029import android.view.View;
30
31/**
32 * Draws hundreds of levels of overdraw over the content area.
33 *
34 * This should all be optimized out by the renderer.
35 */
36public class FullscreenOverdrawActivity extends AppCompatActivity {
John Reck2ccaf6a2016-05-26 14:36:42 -070037 private class OverdrawDrawable extends Drawable {
Chris Craik65b04b62015-08-27 14:34:17 -070038 Paint paint = new Paint();
39 int mColorValue = 0;
40
Chris Craik65b04b62015-08-27 14:34:17 -070041 @SuppressWarnings("unused")
42 public void setColorValue(int colorValue) {
43 mColorValue = colorValue;
John Reck2ccaf6a2016-05-26 14:36:42 -070044 invalidateSelf();
Chris Craik65b04b62015-08-27 14:34:17 -070045 }
46
47 @Override
John Reck2ccaf6a2016-05-26 14:36:42 -070048 public void draw(Canvas canvas) {
Chris Craik65b04b62015-08-27 14:34:17 -070049 paint.setColor(Color.rgb(mColorValue, 255 - mColorValue, 255));
50
51 for (int i = 0; i < 400; i++) {
John Reck2ccaf6a2016-05-26 14:36:42 -070052 canvas.drawRect(getBounds(), paint);
Chris Craik65b04b62015-08-27 14:34:17 -070053 }
54 }
John Reck2ccaf6a2016-05-26 14:36:42 -070055
56 @Override
57 public void setAlpha(int alpha) {
58 }
59
60 @Override
61 public void setColorFilter(ColorFilter colorFilter) {
62 }
63
64 @Override
65 public int getOpacity() {
66 return PixelFormat.OPAQUE;
67 }
Chris Craik65b04b62015-08-27 14:34:17 -070068 }
69 @Override
70 protected void onCreate(Bundle savedInstanceState) {
71 super.onCreate(savedInstanceState);
72
John Reck2ccaf6a2016-05-26 14:36:42 -070073 OverdrawDrawable overdraw = new OverdrawDrawable();
74 getWindow().setBackgroundDrawable(overdraw);
Chris Craik65b04b62015-08-27 14:34:17 -070075
John Reck2ccaf6a2016-05-26 14:36:42 -070076 setContentView(new View(this));
77
78 ObjectAnimator objectAnimator = ObjectAnimator.ofInt(overdraw, "colorValue", 0, 255);
Chris Craik65b04b62015-08-27 14:34:17 -070079 objectAnimator.setRepeatMode(ValueAnimator.REVERSE);
80 objectAnimator.setRepeatCount(ValueAnimator.INFINITE);
81 objectAnimator.start();
82 }
83}