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 */ 16 17 package com.android.benchmark.ui; 18 19 import android.animation.ObjectAnimator; 20 import android.animation.ValueAnimator; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.graphics.Canvas; 24 import android.graphics.Color; 25 import android.graphics.Paint; 26 import android.support.v7.app.AppCompatActivity; 27 import android.os.Bundle; 28 import android.view.MotionEvent; 29 import android.view.View; 30 31 import com.android.benchmark.R; 32 import com.android.benchmark.registry.BenchmarkRegistry; 33 import com.android.benchmark.ui.automation.Automator; 34 import com.android.benchmark.ui.automation.Interaction; 35 36 public class FullScreenOverdrawActivity extends AppCompatActivity { 37 38 private Automator mAutomator; 39 40 private class OverdrawView extends View { 41 Paint paint = new Paint(); 42 int mColorValue = 0; 43 44 public OverdrawView(Context context) { 45 super(context); 46 } 47 48 @SuppressWarnings("unused") 49 public void setColorValue(int colorValue) { 50 mColorValue = colorValue; 51 invalidate(); 52 } 53 54 @Override 55 public boolean onTouchEvent(MotionEvent event) { 56 ObjectAnimator objectAnimator = ObjectAnimator.ofInt(this, "colorValue", 0, 255); 57 objectAnimator.setRepeatMode(ValueAnimator.REVERSE); 58 objectAnimator.setRepeatCount(100); 59 objectAnimator.start(); 60 return super.onTouchEvent(event); 61 } 62 63 @Override 64 protected void onDraw(Canvas canvas) { 65 paint.setColor(Color.rgb(mColorValue, 255 - mColorValue, 255)); 66 67 for (int i = 0; i < 10; i++) { 68 canvas.drawRect(0, 0, getWidth(), getHeight(), paint); 69 } 70 } 71 } 72 73 @Override 74 protected void onCreate(Bundle savedInstanceState) { 75 super.onCreate(savedInstanceState); 76 77 final OverdrawView overdrawView = new OverdrawView(this); 78 overdrawView.setKeepScreenOn(true); 79 setContentView(overdrawView); 80 81 final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 82 final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 83 84 String name = BenchmarkRegistry.getBenchmarkName(this, R.id.benchmark_overdraw); 85 86 mAutomator = new Automator(name, runId, iteration, getWindow(), 87 new Automator.AutomateCallback() { 88 @Override 89 public void onPostAutomate() { 90 Intent result = new Intent(); 91 setResult(RESULT_OK, result); 92 finish(); 93 } 94 95 @Override 96 public void onAutomate() { 97 int[] coordinates = new int[2]; 98 overdrawView.getLocationOnScreen(coordinates); 99 100 int x = coordinates[0]; 101 int y = coordinates[1]; 102 103 float width = overdrawView.getWidth(); 104 float height = overdrawView.getHeight(); 105 106 float middleX = (x + width) / 5; 107 float middleY = (y + height) / 5; 108 109 addInteraction(Interaction.newTap(middleX, middleY)); 110 } 111 }); 112 113 mAutomator.start(); 114 } 115 } 116