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 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and limitations under the 13 * License. 14 * 15 */ 16 17 package com.android.benchmark.ui; 18 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.support.v7.app.ActionBar; 22 import android.view.FrameMetrics; 23 import android.view.MotionEvent; 24 import android.widget.ArrayAdapter; 25 import android.widget.FrameLayout; 26 import android.widget.ListAdapter; 27 28 import com.android.benchmark.R; 29 import com.android.benchmark.ui.automation.Automator; 30 import com.android.benchmark.ui.automation.Interaction; 31 32 import java.io.File; 33 import java.util.List; 34 35 public class ListViewScrollActivity extends ListActivityBase { 36 37 private static final int LIST_SIZE = 400; 38 private static final int INTERACTION_COUNT = 4; 39 40 private Automator mAutomator; 41 42 @Override 43 public void onCreate(Bundle savedInstanceState) { 44 super.onCreate(savedInstanceState); 45 final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 46 final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 47 48 ActionBar actionBar = getSupportActionBar(); 49 if (actionBar != null) { 50 actionBar.setTitle(getTitle()); 51 } 52 53 mAutomator = new Automator(getName(), runId, iteration, getWindow(), 54 new Automator.AutomateCallback() { 55 @Override 56 public void onPostAutomate() { 57 Intent result = new Intent(); 58 setResult(RESULT_OK, result); 59 finish(); 60 } 61 62 @Override 63 public void onPostInteraction(List<FrameMetrics> metrics) {} 64 65 @Override 66 public void onAutomate() { 67 FrameLayout v = (FrameLayout) findViewById(R.id.list_fragment_container); 68 69 int[] coordinates = new int[2]; 70 v.getLocationOnScreen(coordinates); 71 72 int x = coordinates[0]; 73 int y = coordinates[1]; 74 75 float width = v.getWidth(); 76 float height = v.getHeight(); 77 78 float middleX = (x + width) / 5; 79 float middleY = (y + height) / 5; 80 81 Interaction flingUp = Interaction.newFlingUp(middleX, middleY); 82 Interaction flingDown = Interaction.newFlingDown(middleX, middleY); 83 84 for (int i = 0; i < INTERACTION_COUNT; i++) { 85 addInteraction(flingUp); 86 addInteraction(flingDown); 87 } 88 } 89 }); 90 91 mAutomator.start(); 92 } 93 94 @Override 95 protected void onPause() { 96 super.onPause(); 97 if (mAutomator != null) { 98 mAutomator.cancel(); 99 mAutomator = null; 100 } 101 } 102 103 @Override 104 protected ListAdapter createListAdapter() { 105 return new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, 106 Utils.buildStringList(LIST_SIZE)); 107 } 108 109 @Override 110 protected String getName() { 111 return getString(R.string.list_view_scroll_name); 112 } 113 } 114