blob: 8a7a9a67bfc49897b3e1edb4d5955e73ab099951 [file] [log] [blame]
Aurimas Liutikas88c7ff12023-08-10 12:42:26 -07001/*
2* Copyright (C) 2011-2014 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.internal.widget;
18
19import android.content.Context;
20import android.graphics.drawable.Drawable;
21import android.view.View;
22import android.view.ViewGroup;
23import android.widget.BaseAdapter;
24
25import java.util.List;
26
27public class AccountViewAdapter extends BaseAdapter {
28
29 private List<AccountElements> mData;
30 private Context mContext;
31
32 /**
33 * Constructor
34 *
35 * @param context The context where the View associated with this Adapter is running
36 * @param data A list with AccountElements data type. The list contains the data of each
37 * account and the each member of AccountElements will correspond to one item view.
38 */
39 public AccountViewAdapter(Context context, final List<AccountElements> data) {
40 mContext = context;
41 mData = data;
42 }
43
44 @Override
45 public int getCount() {
46 return mData.size();
47 }
48
49 @Override
50 public Object getItem(int position) {
51 return mData.get(position);
52 }
53
54 @Override
55 public long getItemId(int position) {
56 return position;
57 }
58
59 public void updateData(final List<AccountElements> data) {
60 mData = data;
61 notifyDataSetChanged();
62 }
63
64 @Override
65 public View getView(int position, View convertView, ViewGroup parent) {
66 AccountItemView view;
67 if (convertView == null) {
68 view = new AccountItemView(mContext);
69 } else {
70 view = (AccountItemView) convertView;
71 }
72 AccountElements elements = (AccountElements) getItem(position);
73 view.setViewItem(elements);
74 return view;
75 }
76
77 public static class AccountElements {
78 private int mIcon;
79 private Drawable mDrawable;
80 private String mName;
81 private String mNumber;
82
83 /**
84 * Constructor
85 * A structure with basic element of an Account, icon, name and number
86 *
87 * @param icon Account icon id
88 * @param name Account name
89 * @param num Account number
90 */
91 public AccountElements(int icon, String name, String number) {
92 this(icon, null, name, number);
93 }
94
95 /**
96 * Constructor
97 * A structure with basic element of an Account, drawable, name and number
98 *
99 * @param drawable Account drawable
100 * @param name Account name
101 * @param num Account number
102 */
103 public AccountElements(Drawable drawable, String name, String number) {
104 this(0, drawable, name, number);
105 }
106
107 private AccountElements(int icon, Drawable drawable, String name, String number) {
108 mIcon = icon;
109 mDrawable = drawable;
110 mName = name;
111 mNumber = number;
112 }
113
114 public int getIcon() {
115 return mIcon;
116 }
117 public String getName() {
118 return mName;
119 }
120 public String getNumber() {
121 return mNumber;
122 }
123 public Drawable getDrawable() {
124 return mDrawable;
125 }
126 }
127}