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