|
10 | 10 | import android.content.Context;
|
11 | 11 | import android.graphics.Point;
|
12 | 12 | import android.os.Build;
|
| 13 | +import android.util.Log; |
13 | 14 | import android.view.ContextMenu;
|
14 | 15 | import android.view.ContextMenu.ContextMenuInfo;
|
15 |
| -import android.view.LayoutInflater; |
16 |
| -import android.view.MenuItem; |
17 | 16 | import android.view.View;
|
18 | 17 | import android.view.View.OnCreateContextMenuListener;
|
19 | 18 | import android.view.ViewGroup;
|
20 |
| -import android.widget.AdapterView.OnItemLongClickListener; |
21 | 19 | import android.widget.AdapterView;
|
| 20 | +import android.widget.AdapterView.OnItemClickListener; |
22 | 21 | import android.widget.ArrayAdapter;
|
23 | 22 | import android.widget.ImageView;
|
24 | 23 | import android.widget.LinearLayout;
|
25 | 24 | import android.widget.ListView;
|
26 | 25 | import android.widget.TextView;
|
27 |
| -import android.widget.AdapterView.OnItemClickListener; |
28 |
| - |
29 |
| -import android.util.Log; |
30 | 26 |
|
31 | 27 | /**
|
32 | 28 | * A column of MindmapNodes, i.e. one level in the mind map. It extends
|
@@ -359,57 +355,16 @@ public MindmapNodeAdapter(Context context, int textViewResourceId, ArrayList<Min
|
359 | 355 | @Override
|
360 | 356 | public View getView(int position, View convertView, ViewGroup parent) {
|
361 | 357 |
|
362 |
| - // if convertView was specified, we will use this. Otherwise, we create |
363 |
| - // a new view based on the R.layout.mindmap_node_list_item layout. |
364 |
| - |
365 |
| - // TODO: instead of loading a XML, we can generate the whole view in the MindmapNode. |
366 |
| - // TODO: why do we need to open the same node twice, once as view and once as node, and then pass stuff around the node? should all go in the initializer or somewhere, and allow us to update the view somehow |
| 358 | + // if convertView was specified, we cast it to a MindmapNode and then refresh it's design |
| 359 | + // otherwise, we load the MindmapNode from the specified position in the column, and display it |
367 | 360 | MindmapNode view = (MindmapNode)convertView;
|
368 | 361 | if ( view == null ) {
|
369 | 362 | view = mindmapNodes.get(position);
|
370 | 363 | }
|
371 | 364 |
|
372 |
| - MindmapNode node = mindmapNodes.get(position); |
373 |
| - // get the node for which we generate the view |
374 |
| - if ( node != null) { |
375 |
| - |
376 |
| - // the mindmap_node_list_item consists of a ImageView (icon), a TextView (node text), and another TextView ("+" button) |
377 |
| - ImageView icon = (ImageView) view.findViewById(R.id.icon); |
378 |
| - icon.setImageResource(node.icon_res_id); |
379 |
| - icon.setContentDescription(node.icon_name); |
380 |
| - |
381 |
| - TextView text = (TextView) view.findViewById(R.id.label); |
382 |
| - text.setTextColor(getContext().getResources().getColor(android.R.color.primary_text_light)); |
383 |
| - text.setText(node.text); |
384 |
| - |
385 |
| - TextView expandable = (TextView) view.findViewById(R.id.expandable); |
386 |
| - expandable.setTextColor(getContext().getResources().getColor(android.R.color.primary_text_light)); |
387 |
| - if ( node.isExpandable ) { |
388 |
| - expandable.setText("+"); |
389 |
| - } else { |
390 |
| - expandable.setText(""); |
391 |
| - } |
392 |
| - |
393 |
| - // if the node is selected and has child nodes, give it a special background |
394 |
| - if ( node.getIsSelected() && node.getNumChildMindmapNodes() > 0 ) { |
395 |
| - int backgroundColor; |
396 |
| - |
397 |
| - // menu bar: if we are at least at API 11, the Home button is kind of a back button in the app |
398 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
399 |
| - backgroundColor = getContext().getResources().getColor(android.R.color.holo_blue_bright); |
400 |
| - } else { |
401 |
| - backgroundColor = getContext().getResources().getColor(android.R.color.darker_gray); |
402 |
| - } |
403 |
| - |
404 |
| - view.setBackgroundColor(backgroundColor); |
405 |
| - } else { |
406 |
| - view.setBackgroundColor(0); |
407 |
| - } |
408 |
| - |
409 |
| - } |
410 |
| - |
411 |
| - Log.d(MainApplication.TAG, "Created a ListView item view"); |
412 |
| - |
| 365 | + // tell the node to refresh it's view |
| 366 | + view.refreshView(); |
| 367 | + |
413 | 368 | return view;
|
414 | 369 | }
|
415 | 370 |
|
|
0 commit comments