1 /*
2  * Copyright (C) 2008 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.stk;
18 
19 import com.android.internal.telephony.cat.Item;
20 
21 import android.content.Context;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.ArrayAdapter;
26 import android.widget.ImageView;
27 import android.widget.TextView;
28 
29 import java.util.List;
30 
31 /**
32  * Icon list view adapter to show the list of STK items.
33  */
34 public class StkMenuAdapter extends ArrayAdapter<Item> {
35     private final LayoutInflater mInflater;
36     private boolean mIcosSelfExplanatory = false;
37 
StkMenuAdapter(Context context, List<Item> items, boolean icosSelfExplanatory)38     public StkMenuAdapter(Context context, List<Item> items,
39             boolean icosSelfExplanatory) {
40         super(context, 0, items);
41         mInflater = LayoutInflater.from(context);
42         mIcosSelfExplanatory = icosSelfExplanatory;
43     }
44 
45     @Override
getView(int position, View convertView, ViewGroup parent)46     public View getView(int position, View convertView, ViewGroup parent) {
47         final Item item = getItem(position);
48 
49         if (convertView == null) {
50             convertView = mInflater.inflate(R.layout.stk_menu_item, parent,
51                     false);
52         }
53 
54         if (!mIcosSelfExplanatory || (mIcosSelfExplanatory && item.icon == null)) {
55             ((TextView) convertView.findViewById(R.id.text)).setText(item.text);
56         }
57         ImageView imageView = ((ImageView) convertView.findViewById(R.id.icon));
58         if (item.icon == null) {
59             imageView.setVisibility(View.GONE);
60         } else {
61             imageView.setImageBitmap(item.icon);
62             imageView.setVisibility(View.VISIBLE);
63         }
64 
65         return convertView;
66     }
67 }
68