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.content.Intent; 20 import android.os.Bundle; 21 import android.widget.ArrayAdapter; 22 import android.widget.ListAdapter; 23 import android.widget.ListView; 24 25 import com.android.benchmark.registry.BenchmarkRegistry; 26 import com.android.benchmark.ui.automation.Automator; 27 import com.android.benchmark.ui.automation.Interaction; 28 29 import java.io.File; 30 31 public class TextScrollActivity extends ListActivityBase { 32 33 public static final String EXTRA_HIT_RATE = ".TextScrollActivity.EXTRA_HIT_RATE"; 34 35 private static final int PARAGRAPH_COUNT = 200; 36 37 private int mHitPercentage = 100; 38 private Automator mAutomator; 39 private String mName; 40 41 @Override 42 public void onCreate(Bundle savedInstanceState) { 43 mHitPercentage = getIntent().getIntExtra(EXTRA_HIT_RATE, 44 mHitPercentage); 45 super.onCreate(savedInstanceState); 46 final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 47 final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 48 final int id = getIntent().getIntExtra(BenchmarkRegistry.EXTRA_ID, -1); 49 50 if (id == -1) { 51 finish(); 52 return; 53 } 54 55 mName = BenchmarkRegistry.getBenchmarkName(this, id); 56 57 mAutomator = new Automator(getName(), runId, iteration, getWindow(), 58 new Automator.AutomateCallback() { 59 @Override 60 public void onPostAutomate() { 61 Intent result = new Intent(); 62 setResult(RESULT_OK, result); 63 finish(); 64 } 65 66 @Override 67 public void onAutomate() { 68 ListView v = (ListView) findViewById(android.R.id.list); 69 70 int[] coordinates = new int[2]; 71 v.getLocationOnScreen(coordinates); 72 73 int x = coordinates[0]; 74 int y = coordinates[1]; 75 76 float width = v.getWidth(); 77 float height = v.getHeight(); 78 79 float middleX = (x + width) / 2; 80 float middleY = (y + height) / 2; 81 82 Interaction flingUp = Interaction.newFlingUp(middleX, middleY); 83 Interaction flingDown = Interaction.newFlingDown(middleX, middleY); 84 85 addInteraction(flingUp); 86 addInteraction(flingDown); 87 addInteraction(flingUp); 88 addInteraction(flingDown); 89 addInteraction(flingUp); 90 addInteraction(flingDown); 91 addInteraction(flingUp); 92 addInteraction(flingDown); 93 } 94 }); 95 96 mAutomator.start(); 97 } 98 99 @Override 100 protected void onPause() { 101 super.onPause(); 102 if (mAutomator != null) { 103 mAutomator.cancel(); 104 mAutomator = null; 105 } 106 } 107 108 @Override 109 protected ListAdapter createListAdapter() { 110 return new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, 111 Utils.buildParagraphListWithHitPercentage(PARAGRAPH_COUNT, 80)); 112 } 113 114 @Override 115 protected String getName() { 116 return mName; 117 } 118 } 119