1 /*
2  * Copyright (C) 2012 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 android.taskswitching.appb;
18 
19 import android.app.ListActivity;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.os.Handler;
23 import android.view.WindowManager;
24 import android.widget.ArrayAdapter;
25 import android.widget.ListView;
26 
27 /**
28  * Simple activity to notify completion via broadcast after onResume.
29  * This is for measuring taskswitching time between two apps.
30  */
31 public class AppBActivity extends ListActivity {
32     static final String TAG = "AppBActivity";
33     private static final int NUMBER_ELEMENTS = 1000;
34     private static final String TASKSWITCHING_INTENT = "android.taskswitching.appb";
35     private Handler mHandler;
36 
37     private String[] mItems = new String[NUMBER_ELEMENTS];
38 
39     @Override
onCreate(Bundle icicle)40     public void onCreate(Bundle icicle) {
41         super.onCreate(icicle);
42         getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
43         for (int i = 0; i < NUMBER_ELEMENTS; i++) {
44             mItems[i] = "B" + Integer.toString(i);
45         }
46         setListAdapter(new ArrayAdapter<String>(this,
47                 android.R.layout.simple_list_item_1, mItems));
48         ListView view = getListView();
49         mHandler = new Handler();
50     }
51 
52     @Override
onResume()53     public void onResume() {
54         super.onResume();
55         mHandler.post(new Runnable() {
56 
57             @Override
58             public void run() {
59                 Intent intent = new Intent(TASKSWITCHING_INTENT);
60                 sendBroadcast(intent);
61             }
62         });
63     }
64 }
65