The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 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 | |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 19 | import com.android.internal.telephony.cat.Item; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 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 | |
| 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 Godachi | c77445b | 2018-02-28 02:51:56 +0530 | [diff] [blame] | 63 | // Add content description for the icon. |
| 64 | imageView.setContentDescription(StkAppService.TEXT_ICON_FROM_COMMAND); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | return convertView; |
| 68 | } |
| 69 | } |