Skip to content

Commit d018981

Browse files
author
Benedikt Koeppel
committed
MindmapNode is now a proper GUI element
- new icon (plus/minus when expandable/contractable) - MindmapNode can be added as GUI element. This happens in the NodeColumn ListView at the moment
1 parent 1b57f23 commit d018981

File tree

8 files changed

+83
-62
lines changed

8 files changed

+83
-62
lines changed

res/drawable-xhdpi/minus_alt.png

298 Bytes
Loading

res/drawable-xhdpi/plus_alt.png

304 Bytes
Loading

res/drawable/minus_alt.png

205 Bytes
Loading

res/drawable/plus_alt.png

212 Bytes
Loading

res/layout/mindmap_node_list_item.xml

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="fill_parent"
4-
android:layout_height="36dip"
4+
android:layout_height="wrap_content"
55
android:gravity="left|center"
66
android:paddingBottom="6dip"
77
android:paddingLeft="6dip"
@@ -21,15 +21,18 @@
2121
android:layout_height="wrap_content"
2222
android:layout_width="0dp"
2323
android:textSize="16sp"
24-
android:textIsSelectable="false" />
25-
26-
<TextView
27-
android:id="@+id/expandable"
28-
android:layout_weight="0"
29-
android:layout_width="wrap_content"
30-
android:layout_height="wrap_content"
31-
android:textSize="32sp"
3224
android:textIsSelectable="false"
3325
android:layout_marginRight="6dip" />
26+
27+
<ImageView
28+
android:id="@+id/expandable"
29+
android:layout_width="24dip"
30+
android:layout_weight="0"
31+
android:layout_height="24dip"
32+
android:layout_marginRight="6dip"
33+
android:layout_marginTop="6dip"
34+
android:layout_marginBottom="6dip"
35+
android:contentDescription="@string/noicon"
36+
android:layout_gravity="top" />
3437

3538
</LinearLayout>

res/values/identifiers.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<item name="contextcopy" type="id" />
4+
<item name="contextopenlink" type="id" />
5+
6+
</resources>

src/ch/benediktkoeppel/code/droidplane/MindmapNode.java

+58-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99

1010
import android.content.Context;
1111
import android.net.Uri;
12+
import android.os.Build;
13+
import android.util.TypedValue;
1214
import android.view.ContextMenu;
1315
import android.view.ContextMenu.ContextMenuInfo;
16+
import android.view.Gravity;
1417
import android.view.View;
18+
import android.view.ViewGroup;
19+
import android.widget.AbsListView;
20+
import android.widget.ImageView;
1521
import android.widget.LinearLayout;
22+
import android.widget.TextView;
1623

1724

1825

@@ -114,11 +121,61 @@ public MindmapNode(Context context, Node node) {
114121

115122
// load the layout from the XML file
116123
// TODO: somehow the height of the item is wrong
117-
inflate(context, R.layout.mindmap_node_list_item, this);
124+
MindmapNode.inflate(context, R.layout.mindmap_node_list_item, this);
125+
refreshView();
118126

119127
}
120128

121129

130+
public void refreshView() {
131+
132+
// the mindmap_node_list_item consists of a ImageView (icon), a TextView (node text), and another TextView ("+" button)
133+
ImageView iconView = (ImageView)findViewById(R.id.icon);
134+
iconView.setImageResource(icon_res_id);
135+
iconView.setContentDescription(icon_name);
136+
137+
TextView textView = (TextView) findViewById(R.id.label);
138+
textView.setTextColor(getContext().getResources().getColor(android.R.color.primary_text_light));
139+
textView.setText(text);
140+
141+
ImageView expandable = (ImageView) findViewById(R.id.expandable);
142+
if ( isExpandable ) {
143+
if ( getIsSelected() ) {
144+
expandable.setImageResource(R.drawable.minus_alt);
145+
} else {
146+
expandable.setImageResource(R.drawable.plus_alt);
147+
}
148+
}
149+
150+
// if the node is selected and has child nodes, give it a special background
151+
if ( getIsSelected() && getNumChildMindmapNodes() > 0 ) {
152+
int backgroundColor;
153+
154+
// menu bar: if we are at least at API 11, the Home button is kind of a back button in the app
155+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
156+
backgroundColor = getContext().getResources().getColor(android.R.color.holo_blue_bright);
157+
} else {
158+
backgroundColor = getContext().getResources().getColor(android.R.color.darker_gray);
159+
}
160+
161+
setBackgroundColor(backgroundColor);
162+
} else {
163+
setBackgroundColor(0);
164+
}
165+
166+
// set the layout parameter
167+
// TODO: this should not be necessary. The problem is that the inflate
168+
// (in the constructor) loads the XML as child of this LinearView, so
169+
// the MindmapNode-LinearView wraps the root LinearView from the
170+
// mindmap_node_list_item XML file.
171+
setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT));
172+
setGravity(Gravity.LEFT | Gravity.CENTER);
173+
// int paddingPx = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6, getResources().getDisplayMetrics());
174+
// setPadding(paddingPx, paddingPx, 0, paddingPx);
175+
}
176+
177+
178+
122179

123180
/**
124181
* Returns the XML Node of which this MindmapNode was derived

src/ch/benediktkoeppel/code/droidplane/NodeColumn.java

+7-52
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,19 @@
1010
import android.content.Context;
1111
import android.graphics.Point;
1212
import android.os.Build;
13+
import android.util.Log;
1314
import android.view.ContextMenu;
1415
import android.view.ContextMenu.ContextMenuInfo;
15-
import android.view.LayoutInflater;
16-
import android.view.MenuItem;
1716
import android.view.View;
1817
import android.view.View.OnCreateContextMenuListener;
1918
import android.view.ViewGroup;
20-
import android.widget.AdapterView.OnItemLongClickListener;
2119
import android.widget.AdapterView;
20+
import android.widget.AdapterView.OnItemClickListener;
2221
import android.widget.ArrayAdapter;
2322
import android.widget.ImageView;
2423
import android.widget.LinearLayout;
2524
import android.widget.ListView;
2625
import android.widget.TextView;
27-
import android.widget.AdapterView.OnItemClickListener;
28-
29-
import android.util.Log;
3026

3127
/**
3228
* 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
359355
@Override
360356
public View getView(int position, View convertView, ViewGroup parent) {
361357

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
367360
MindmapNode view = (MindmapNode)convertView;
368361
if ( view == null ) {
369362
view = mindmapNodes.get(position);
370363
}
371364

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+
413368
return view;
414369
}
415370

0 commit comments

Comments
 (0)