• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.cts.verifier;
18 
19 import com.android.cts.verifier.TestListAdapter.TestListItem;
20 
21 import android.app.ListActivity;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.view.View;
25 import android.widget.ListView;
26 
27 /** {@link ListActivity} that displays a list of manual tests. */
28 public abstract class AbstractTestListActivity extends ListActivity {
29     private static final int LAUNCH_TEST_REQUEST_CODE = 9001;
30 
31     protected TestListAdapter mAdapter;
32 
setTestListAdapter(TestListAdapter adapter)33     protected void setTestListAdapter(TestListAdapter adapter) {
34         mAdapter = adapter;
35         setListAdapter(mAdapter);
36         mAdapter.loadTestResults();
37     }
38 
getIntent(int position)39     private Intent getIntent(int position) {
40         TestListItem item = mAdapter.getItem(position);
41         return item.intent;
42     }
43 
44     @Override
onActivityResult(int requestCode, int resultCode, Intent data)45     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
46         super.onActivityResult(requestCode, resultCode, data);
47         switch (requestCode) {
48             case LAUNCH_TEST_REQUEST_CODE:
49                 handleLaunchTestResult(resultCode, data);
50                 break;
51 
52             default:
53                 throw new IllegalArgumentException("Unknown request code: " + requestCode);
54         }
55     }
56 
57     @Override
onCreate(Bundle savedInstanceState)58     protected void onCreate(Bundle savedInstanceState) {
59         super.onCreate(savedInstanceState);
60         setContentView(R.layout.list_content);
61     }
62 
handleLaunchTestResult(int resultCode, Intent data)63     private void handleLaunchTestResult(int resultCode, Intent data) {
64         if (resultCode == RESULT_OK) {
65             TestResult testResult = TestResult.fromActivityResult(resultCode, data);
66             mAdapter.setTestResult(testResult);
67         }
68     }
69 
70     /** Launch the activity when its {@link ListView} item is clicked. */
71     @Override
onListItemClick(ListView listView, View view, int position, long id)72     protected void onListItemClick(ListView listView, View view, int position, long id) {
73         super.onListItemClick(listView, view, position, id);
74         Intent intent = getIntent(position);
75         startActivityForResult(intent, LAUNCH_TEST_REQUEST_CODE);
76     }
77 }
78