blob: 4398280c9a2b100688333f50fb393b3aeac24280 [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
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
17package com.android.stk;
18
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070019import com.android.internal.telephony.cat.Item;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080020
21import android.content.Context;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.ArrayAdapter;
26import android.widget.ImageView;
27import android.widget.TextView;
28
29import java.util.List;
30
31/**
32 * Icon list view adapter to show the list of STK items.
33 */
34public class StkMenuAdapter extends ArrayAdapter<Item> {
35 private final LayoutInflater mInflater;
36 private boolean mIcosSelfExplanatory = false;
37
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
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);
Umashankar Godachic77445b2018-02-28 02:51:56 +053063 // Add content description for the icon.
64 imageView.setContentDescription(StkAppService.TEXT_ICON_FROM_COMMAND);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080065 }
66
67 return convertView;
68 }
69}