Home | History | Annotate | Download | only in ui
      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 package com.android.benchmark.ui;
     17 
     18 import android.content.Intent;
     19 import android.os.Bundle;
     20 import android.support.v4.app.FragmentManager;
     21 import android.support.v4.app.ListFragment;
     22 import android.support.v7.app.AppCompatActivity;
     23 import android.view.View;
     24 import android.widget.ArrayAdapter;
     25 import android.widget.ListView;
     26 
     27 import com.android.benchmark.R;
     28 import com.android.benchmark.ui.automation.Automator;
     29 import com.android.benchmark.ui.automation.Interaction;
     30 
     31 public class ShadowGridActivity extends AppCompatActivity {
     32     private Automator mAutomator;
     33     public static class MyListFragment extends ListFragment {
     34 	    @Override
     35 	    public void onViewCreated(View view, Bundle savedInstanceState) {
     36 		    super.onViewCreated(view, savedInstanceState);
     37 		    getListView().setDivider(null);
     38 	    }
     39     }
     40 
     41     @Override
     42     protected void onCreate(Bundle savedInstanceState) {
     43         super.onCreate(savedInstanceState);
     44         final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0);
     45         final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1);
     46 
     47         FragmentManager fm = getSupportFragmentManager();
     48         if (fm.findFragmentById(android.R.id.content) == null) {
     49             ListFragment listFragment = new MyListFragment();
     50 
     51             listFragment.setListAdapter(new ArrayAdapter<>(this,
     52                     R.layout.card_row, R.id.card_text, Utils.buildStringList(200)));
     53             fm.beginTransaction().add(android.R.id.content, listFragment).commit();
     54 
     55             String testName = getString(R.string.shadow_grid_name);
     56 
     57             mAutomator = new Automator(testName, 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             mAutomator.start();
     96         }
     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