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 
71     @Override
getItemId(int position)72     public long getItemId(int position) {
73         return position;
74     }
75 
76     @Override
getView(int position, View convertView, ViewGroup parent)77     public View getView(int position, View convertView, ViewGroup parent) {
78         ViewGroup vg;
79 
80         if (convertView != null) {
81             vg = (ViewGroup) convertView;
82         } else {
83             vg = (ViewGroup) inflater.inflate(R.layout.ble_test_item, null);
84         }
85 
86         Test test = tests.get(position);
87         if (test.mPassed) {
88             ((ImageView) vg.findViewById(R.id.status)).setImageResource(R.drawable.fs_good);
89         } else {
90             ((ImageView) vg.findViewById(R.id.status)).
91                             setImageResource(R.drawable.fs_indeterminate);
92         }
93         ((TextView) vg.findViewById(R.id.instructions)).setText(test.mInstructions);
94 
95         return vg;
96     }
97 }
98