1 /*
2  * Copyright (C) 2013 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.bluetooth;
18 
19 import com.android.cts.verifier.PassFailButtons;
20 import com.android.cts.verifier.R;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 
25 import android.content.Context;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.widget.BaseAdapter;
30 import android.widget.ImageView;
31 import android.widget.TextView;
32 
33 class TestAdapter extends BaseAdapter {
34     Context context;
35     List<Test> tests;
36     LayoutInflater inflater;
37 
38     private class Test {
39         private boolean mPassed;
40         private final int mInstructions;
41 
Test(int instructions)42         protected Test(int instructions) {
43             this.mPassed = false;
44             this.mInstructions = instructions;
45         }
46     }
47 
TestAdapter(Context context, List<Integer> testInstructions)48     public TestAdapter(Context context, List<Integer> testInstructions) {
49         this.context = context;
50         inflater = LayoutInflater.from(context);
51         this.tests = new ArrayList<Test>();
52         for (int t : testInstructions) {
53             this.tests.add(new Test(t));
54         }
55     }
56 
57     @Override
getCount()58     public int getCount() {
59         return tests.size();
60     }
61 
62     @Override
getItem(int position)63     public Object getItem(int position) {
64         return tests.get(position);
65     }
66 
setTestPass(int position)67     public void setTestPass(int position) {
68         tests.get(position).mPassed = true;
69     }
70 
clearTestPass(int position)71     public void clearTestPass(int position) {
72         tests.get(position).mPassed = false;
73     }
74 
75     @Override
getItemId(int position)76     public long getItemId(int position) {
77         return position;
78     }
79 
80     @Override
getView(int position, View convertView, ViewGroup parent)81     public View getView(int position, View convertView, ViewGroup parent) {
82         ViewGroup vg;
83 
84         if (convertView != null) {
85             vg = (ViewGroup) convertView;
86         } else {
87             vg = (ViewGroup) inflater.inflate(R.layout.ble_test_item, null);
88         }
89 
90         Test test = tests.get(position);
91         if (test.mPassed) {
92             ((ImageView) vg.findViewById(R.id.status)).setImageResource(R.drawable.fs_good);
93         } else {
94             ((ImageView) vg.findViewById(R.id.status)).
95                             setImageResource(R.drawable.fs_indeterminate);
96         }
97         ((TextView) vg.findViewById(R.id.instructions)).setText(test.mInstructions);
98 
99         return vg;
100     }
101 }
102