1/*
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;
22import android.graphics.ColorFilter;
23import android.graphics.PixelFormat;
24import android.graphics.Color;
25import android.graphics.Paint;
26import android.graphics.drawable.Drawable;
27import android.os.Bundle;
28import android.support.v7.app.AppCompatActivity;
29import 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 {
37    private class OverdrawDrawable extends Drawable {
38        Paint paint = new Paint();
39        int mColorValue = 0;
40
41        @SuppressWarnings("unused")
42        public void setColorValue(int colorValue) {
43            mColorValue = colorValue;
44            invalidateSelf();
45        }
46
47        @Override
48        public void draw(Canvas canvas) {
49            paint.setColor(Color.rgb(mColorValue, 255 - mColorValue, 255));
50
51            for (int i = 0; i < 400; i++) {
52                canvas.drawRect(getBounds(), paint);
53            }
54        }
55
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        }
68    }
69    @Override
70    protected void onCreate(Bundle savedInstanceState) {
71        super.onCreate(savedInstanceState);
72
73        OverdrawDrawable overdraw = new OverdrawDrawable();
74        getWindow().setBackgroundDrawable(overdraw);
75
76        setContentView(new View(this));
77
78        ObjectAnimator objectAnimator = ObjectAnimator.ofInt(overdraw, "colorValue", 0, 255);
79        objectAnimator.setRepeatMode(ValueAnimator.REVERSE);
80        objectAnimator.setRepeatCount(ValueAnimator.INFINITE);
81        objectAnimator.start();
82    }
83}
84