FreeRDP
Loading...
Searching...
No Matches
com.freerdp.freerdpcore.utils.SeparatedListAdapter Class Reference
Inheritance diagram for com.freerdp.freerdpcore.utils.SeparatedListAdapter:
Collaboration diagram for com.freerdp.freerdpcore.utils.SeparatedListAdapter:

Public Member Functions

 SeparatedListAdapter (Context context)
 
void addSection (String section, Adapter adapter)
 
void setSectionTitle (int section, String title)
 
Object getItem (int position)
 
int getCount ()
 
int getViewTypeCount ()
 
int getItemViewType (int position)
 
boolean areAllItemsSelectable ()
 
boolean isEnabled (int position)
 
View getView (int position, View convertView, ViewGroup parent)
 
long getItemId (int position)
 
String getSectionForPosition (int position)
 

Data Fields

final Map< String, Adapter > sections = new LinkedHashMap<>()
 
final ArrayAdapter< String > headers
 

Static Public Attributes

static final int TYPE_SECTION_HEADER = 0
 

Detailed Description

Definition at line 26 of file SeparatedListAdapter.java.

Constructor & Destructor Documentation

◆ SeparatedListAdapter()

com.freerdp.freerdpcore.utils.SeparatedListAdapter.SeparatedListAdapter ( Context  context)
inline

Definition at line 33 of file SeparatedListAdapter.java.

34 {
35 headers = new ArrayAdapter<>(context, R.layout.list_header);
36 }

Member Function Documentation

◆ addSection()

void com.freerdp.freerdpcore.utils.SeparatedListAdapter.addSection ( String  section,
Adapter  adapter 
)
inline

Definition at line 38 of file SeparatedListAdapter.java.

39 {
40 this.headers.add(section);
41 this.sections.put(section, adapter);
42 }

◆ areAllItemsSelectable()

boolean com.freerdp.freerdpcore.utils.SeparatedListAdapter.areAllItemsSelectable ( )
inline

Definition at line 129 of file SeparatedListAdapter.java.

130 {
131 return false;
132 }

◆ getCount()

int com.freerdp.freerdpcore.utils.SeparatedListAdapter.getCount ( )
inline

Definition at line 83 of file SeparatedListAdapter.java.

84 {
85 // total together all sections, plus one for each section header (except if the section is
86 // empty)
87 int total = 0;
88 for (Adapter adapter : this.sections.values())
89 total += ((adapter.getCount() > 0) ? adapter.getCount() + 1 : 0);
90 return total;
91 }

◆ getItem()

Object com.freerdp.freerdpcore.utils.SeparatedListAdapter.getItem ( int  position)
inline

Definition at line 58 of file SeparatedListAdapter.java.

59 {
60 for (int i = 0; i < headers.getCount(); i++)
61 {
62 String section = headers.getItem(i);
63 Adapter adapter = sections.get(section);
64
65 // ignore empty sections
66 if (adapter.getCount() > 0)
67 {
68 int size = adapter.getCount() + 1;
69
70 // check if position inside this section
71 if (position == 0)
72 return section;
73 if (position < size)
74 return adapter.getItem(position - 1);
75
76 // otherwise jump into next section
77 position -= size;
78 }
79 }
80 return null;
81 }

◆ getItemId()

long com.freerdp.freerdpcore.utils.SeparatedListAdapter.getItemId ( int  position)
inline

Definition at line 166 of file SeparatedListAdapter.java.

167 {
168 for (int i = 0; i < headers.getCount(); i++)
169 {
170 String section = headers.getItem(i);
171 Adapter adapter = sections.get(section);
172 if (adapter.getCount() > 0)
173 {
174 int size = adapter.getCount() + 1;
175
176 // check if position inside this section
177 if (position < size)
178 return adapter.getItemId(position - 1);
179
180 // otherwise jump into next section
181 position -= size;
182 }
183 }
184 return -1;
185 }

◆ getItemViewType()

int com.freerdp.freerdpcore.utils.SeparatedListAdapter.getItemViewType ( int  position)
inline

Definition at line 102 of file SeparatedListAdapter.java.

103 {
104 int type = 1;
105 for (int i = 0; i < headers.getCount(); i++)
106 {
107 String section = headers.getItem(i);
108 Adapter adapter = sections.get(section);
109
110 // skip empty sections
111 if (adapter.getCount() > 0)
112 {
113 int size = adapter.getCount() + 1;
114
115 // check if position inside this section
116 if (position == 0)
117 return TYPE_SECTION_HEADER;
118 if (position < size)
119 return type + adapter.getItemViewType(position - 1);
120
121 // otherwise jump into next section
122 position -= size;
123 type += adapter.getViewTypeCount();
124 }
125 }
126 return -1;
127 }

◆ getSectionForPosition()

String com.freerdp.freerdpcore.utils.SeparatedListAdapter.getSectionForPosition ( int  position)
inline

Definition at line 187 of file SeparatedListAdapter.java.

188 {
189 int curPos = 0;
190 for (int i = 0; i < headers.getCount(); i++)
191 {
192 String section = headers.getItem(i);
193 Adapter adapter = sections.get(section);
194 if (adapter.getCount() > 0)
195 {
196 int size = adapter.getCount() + 1;
197
198 // check if position inside this section
199 if (position >= curPos && position < (curPos + size))
200 return section;
201
202 // otherwise jump into next section
203 curPos += size;
204 }
205 }
206 return null;
207 }

◆ getView()

View com.freerdp.freerdpcore.utils.SeparatedListAdapter.getView ( int  position,
View  convertView,
ViewGroup  parent 
)
inline

Definition at line 139 of file SeparatedListAdapter.java.

140 {
141 int sectionnum = 0;
142 for (int i = 0; i < headers.getCount(); i++)
143 {
144 String section = headers.getItem(i);
145 Adapter adapter = sections.get(section);
146
147 // skip empty sections
148 if (adapter.getCount() > 0)
149 {
150 int size = adapter.getCount() + 1;
151
152 // check if position inside this section
153 if (position == 0)
154 return headers.getView(sectionnum, convertView, parent);
155 if (position < size)
156 return adapter.getView(position - 1, null, parent);
157
158 // otherwise jump into next section
159 position -= size;
160 }
161 sectionnum++;
162 }
163 return null;
164 }

◆ getViewTypeCount()

int com.freerdp.freerdpcore.utils.SeparatedListAdapter.getViewTypeCount ( )
inline

Definition at line 93 of file SeparatedListAdapter.java.

94 {
95 // assume that headers count as one, then total all sections
96 int total = 1;
97 for (Adapter adapter : this.sections.values())
98 total += adapter.getViewTypeCount();
99 return total;
100 }

◆ isEnabled()

boolean com.freerdp.freerdpcore.utils.SeparatedListAdapter.isEnabled ( int  position)
inline

Definition at line 134 of file SeparatedListAdapter.java.

135 {
136 return (getItemViewType(position) != TYPE_SECTION_HEADER);
137 }

◆ setSectionTitle()

void com.freerdp.freerdpcore.utils.SeparatedListAdapter.setSectionTitle ( int  section,
String  title 
)
inline

Definition at line 44 of file SeparatedListAdapter.java.

45 {
46 String oldTitle = this.headers.getItem(section);
47
48 // remove/add to headers array
49 this.headers.remove(oldTitle);
50 this.headers.insert(title, section);
51
52 // remove/add to section map
53 Adapter adapter = this.sections.get(oldTitle);
54 this.sections.remove(oldTitle);
55 this.sections.put(title, adapter);
56 }

Field Documentation

◆ headers

final ArrayAdapter<String> com.freerdp.freerdpcore.utils.SeparatedListAdapter.headers

Definition at line 31 of file SeparatedListAdapter.java.

◆ sections

final Map<String, Adapter> com.freerdp.freerdpcore.utils.SeparatedListAdapter.sections = new LinkedHashMap<>()

Definition at line 30 of file SeparatedListAdapter.java.

◆ TYPE_SECTION_HEADER

final int com.freerdp.freerdpcore.utils.SeparatedListAdapter.TYPE_SECTION_HEADER = 0
static

Definition at line 29 of file SeparatedListAdapter.java.


The documentation for this class was generated from the following file: