root / src / com / rackspace / cloud / android / widget / GroupsListView.java @ 378fe36a
History | View | Annotate | Download (4.3 kB)
1 |
package com.rackspace.cloud.android.widget; |
---|---|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
import java.util.HashMap; |
7 |
import java.util.List; |
8 |
import java.util.Map; |
9 |
|
10 |
import android.content.Context; |
11 |
import android.util.AttributeSet; |
12 |
import android.view.LayoutInflater; |
13 |
import android.view.View; |
14 |
import android.view.ViewGroup; |
15 |
import android.widget.BaseExpandableListAdapter; |
16 |
import android.widget.ExpandableListView; |
17 |
import android.widget.ImageView; |
18 |
import android.widget.TextView; |
19 |
|
20 |
import com.rackspace.cloud.android.AndroidCloudApplication; |
21 |
import com.rackspace.cloud.android.R; |
22 |
import com.rackspace.cloud.files.api.client.GroupResource; |
23 |
import com.rackspace.cloud.servers.api.client.Account; |
24 |
|
25 |
public class GroupsListView extends ExpandableListView{ |
26 |
LayoutInflater inflater; |
27 |
GroupsListAdapter adapter; |
28 |
public GroupsListView(Context context) { |
29 |
super(context);
|
30 |
// TODO Auto-generated constructor stub
|
31 |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
32 |
setAdapter(adapter=new GroupsListAdapter());
|
33 |
} |
34 |
|
35 |
|
36 |
|
37 |
public GroupsListView(Context context, AttributeSet attrs) { |
38 |
super(context, attrs);
|
39 |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
40 |
setAdapter(adapter=new GroupsListAdapter());
|
41 |
|
42 |
} |
43 |
|
44 |
public GroupsListView(Context context, AttributeSet attrs, int defStyle) { |
45 |
super(context, attrs, defStyle);
|
46 |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
47 |
setAdapter(adapter=new GroupsListAdapter());
|
48 |
} |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
public GroupsListAdapter getGroupsAdapter() {
|
54 |
return adapter;
|
55 |
} |
56 |
|
57 |
public class GroupsListAdapter extends BaseExpandableListAdapter{ |
58 |
Map<Long,Long> childToGroup = new HashMap<Long,Long>(); |
59 |
public GroupsListAdapter() {
|
60 |
|
61 |
} |
62 |
|
63 |
|
64 |
@Override
|
65 |
public View getChildView(int groupPosition, int childPosition, |
66 |
boolean isLastChild, View convertView, ViewGroup parent) { |
67 |
View v = inflater.inflate(R.layout.groupsrow, null); |
68 |
ImageView imageIcon = (ImageView) v.findViewById(R.id.image); |
69 |
|
70 |
TextView textFileName = (TextView) v.findViewById(R.id.name); |
71 |
String gr = (String) getChild(groupPosition, childPosition); |
72 |
String displayName = Account.getAccount().getDisplayNameForUUID(gr, GroupsListView.this.getContext());
|
73 |
if(displayName!=null) |
74 |
textFileName.setText(displayName); |
75 |
else
|
76 |
textFileName.setText(gr); |
77 |
imageIcon.setImageResource(R.drawable.user); |
78 |
|
79 |
return v;
|
80 |
} |
81 |
|
82 |
@Override
|
83 |
public View getGroupView(int groupPosition, boolean isExpanded, |
84 |
View convertView, ViewGroup parent) {
|
85 |
View v = inflater.inflate(R.layout.groupsrow, null); |
86 |
ImageView imageIcon = (ImageView) v.findViewById(R.id.image); |
87 |
TextView textFileName = (TextView) v.findViewById(R.id.name); |
88 |
GroupResource gr = (GroupResource) getGroup(groupPosition); |
89 |
textFileName.setText(gr.getName()); |
90 |
|
91 |
imageIcon.setImageResource(R.drawable.group); |
92 |
//imageIcon.setVisibility(View.GONE);
|
93 |
return v;
|
94 |
} |
95 |
|
96 |
@Override
|
97 |
public int getChildrenCount(int groupPosition) { |
98 |
if(getGroups().size()>groupPosition)
|
99 |
return getGroups().get(groupPosition).getUsers().size();
|
100 |
return 0; |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public Object getGroup(int groupPosition) { |
105 |
if(getGroups().size()>groupPosition)
|
106 |
return getGroups().get(groupPosition);
|
107 |
return null; |
108 |
} |
109 |
|
110 |
@Override
|
111 |
public int getGroupCount() { |
112 |
return getGroups().size();
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public Object getChild(int groupPosition, int childPosition) { |
117 |
if(getGroups().size()>groupPosition)
|
118 |
if(getGroups().get(groupPosition).getUsers().size()>childPosition)
|
119 |
return getGroups().get(groupPosition).getUsers().get(childPosition);
|
120 |
return null; |
121 |
} |
122 |
|
123 |
@Override
|
124 |
public long getChildId(int groupPosition, int childPosition) { |
125 |
return childPosition;
|
126 |
} |
127 |
|
128 |
@Override
|
129 |
public long getGroupId(int groupPosition) { |
130 |
return groupPosition*1000; |
131 |
} |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
@Override
|
138 |
public boolean hasStableIds() { |
139 |
// TODO Auto-generated method stub
|
140 |
return true; |
141 |
} |
142 |
|
143 |
@Override
|
144 |
public boolean isChildSelectable(int groupPosition, int childPosition) { |
145 |
// TODO Auto-generated method stub
|
146 |
return true; |
147 |
} |
148 |
|
149 |
public void refreshMap(){ |
150 |
childToGroup.clear(); |
151 |
for(GroupResource g : getGroups()){
|
152 |
for(String s : g.getUsers()){ |
153 |
} |
154 |
} |
155 |
} |
156 |
|
157 |
} |
158 |
public GroupsListAdapter getListdapter() {
|
159 |
return adapter;
|
160 |
} |
161 |
|
162 |
List<GroupResource> getGroups(){
|
163 |
return ((AndroidCloudApplication)getContext().getApplicationContext()).getGroups();
|
164 |
} |
165 |
|
166 |
|
167 |
} |