Skip to content

Commit 7b688c2

Browse files
author
Benedikt Koeppel
committed
Pulled from master to get bugfixes and code cleanup
Merge branch 'master' into feature-context-menu Conflicts: res/values/strings.xml src/ch/benediktkoeppel/code/droidplane/HorizontalMindmapView.java src/ch/benediktkoeppel/code/droidplane/MainActivity.java src/ch/benediktkoeppel/code/droidplane/MindmapNode.java src/ch/benediktkoeppel/code/droidplane/NodeColumn.java
2 parents d018981 + 3b9f51a commit 7b688c2

File tree

8 files changed

+210
-231
lines changed

8 files changed

+210
-231
lines changed

res/menu/main.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
<item android:id="@+id/top"
99
android:title="@string/gototop"
1010
android:showAsAction="ifRoom" />
11-
11+
<item android:id="@+id/help"
12+
android:title="@string/help"
13+
android:showAsAction="never" />
14+
1215
</menu>

res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
<string name="novalidfile">Please start DroidPlane by opening a *.mm file"</string>
1313
<string name="copynodetext">Copy Node Text</string>
1414
<string name="openlink">Open Link</string>
15+
<string name="help">Help</string>
1516
</resources>

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

+6-58
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
import java.util.ArrayList;
44

5-
import org.w3c.dom.Element;
6-
import org.w3c.dom.Node;
7-
8-
import android.app.AlertDialog;
95
import android.content.Context;
10-
import android.content.DialogInterface;
116
import android.os.Handler;
127
import android.util.Log;
138
import android.view.GestureDetector;
@@ -18,7 +13,6 @@
1813
import android.view.ViewGroup;
1914
import android.widget.AdapterView;
2015
import android.widget.AdapterView.OnItemClickListener;
21-
import android.widget.AdapterView.OnItemLongClickListener;
2216
import android.widget.HorizontalScrollView;
2317
import android.widget.LinearLayout;
2418
import android.widget.ListView;
@@ -115,7 +109,7 @@ public HorizontalMindmapViewRunnable(HorizontalMindmapView horizontalMindmapView
115109
}
116110

117111
@Override
118-
public void run() {
112+
public void run() {
119113
horizontalMindmapView.fullScroll(FOCUS_RIGHT);
120114
}
121115
}
@@ -195,25 +189,8 @@ public String getTitleOfRightmostParent() {
195189

196190
if ( !nodeColumns.isEmpty() ) {
197191

198-
Node parent = nodeColumns.get(nodeColumns.size()-1).getParentNode();
199-
200-
// TODO: this really does not belong here. HorizontalMindmapView
201-
// should not have to care about Node/Element/MindmapNode stuff.
202-
// Instead, we should only have MindmapNodes everywhere, and a
203-
// MindmapNode should have a proper getPlainText() method.
204-
// we need to check if this node is an ELEMENT_NODE, and if it has tag "node"
205-
if ( parent.getNodeType()==Node.ELEMENT_NODE && ((Element)parent).getTagName().equals("node") ) {
206-
String title = ((Element)parent).getAttribute("TEXT");
207-
Log.d(MainApplication.TAG, "getTitleOfRightmostParent returns " + title);
208-
return title;
209-
}
210-
211-
// the parent node did not have the "node" tag, or was not an
212-
// ELEMENT_NODE. In either case, we don't know it's title.
213-
else {
214-
Log.d(MainApplication.TAG, "getTitleOfRightmostParent returned \"\" because the parent is no Mindmap Node");
215-
return "";
216-
}
192+
MindmapNode parent = nodeColumns.get(nodeColumns.size()-1).getParentNode();
193+
return parent.text;
217194

218195
}
219196

@@ -261,7 +238,7 @@ public void top() {
261238
removeAllColumns();
262239

263240
// go down into the root node
264-
down(MainApplication.getInstance().document.getDocumentElement());
241+
down(MainApplication.getInstance().mindmap.getRootNode());
265242
}
266243

267244
/**
@@ -310,7 +287,7 @@ public void up(boolean force) {
310287
*
311288
* @param node
312289
*/
313-
public void down(Node node) {
290+
public void down(MindmapNode node) {
314291

315292
// add a new column for this node and add it to the
316293
// HorizontalMindmapView
@@ -396,7 +373,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
396373
clickedNodeColumn.setItemColor(position);
397374

398375
// and drill down
399-
down(clickedNode.getNode());
376+
down(clickedNode);
400377
}
401378

402379
// otherwise (no children) then we just update the application title to the new parent node
@@ -405,34 +382,6 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
405382
}
406383
}
407384

408-
409-
410-
//
411-
// // Handler when an item is long clicked
412-
// // TODO do this!
413-
// @Override
414-
// public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
415-
//
416-
// // get the clicked column
417-
// NodeColumn clickedNodeColumn = NodeColumn.getNodeColumnFromListView((ListView)parent);
418-
//
419-
// // then get the clicked node
420-
// MindmapNode clickedNode = clickedNodeColumn.getNodeAtPosition(position);
421-
//
422-
// AlertDialog.Builder builder = new AlertDialog.Builder(MainApplication.getMainActivityInstance());
423-
// builder.setMessage(clickedNode.text);
424-
// builder.setCancelable(true);
425-
// builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
426-
// public void onClick(DialogInterface dialog, int which) {
427-
// return;
428-
// }
429-
// });
430-
//
431-
// AlertDialog alert = builder.create();
432-
// alert.show();
433-
//
434-
// return true;
435-
// }
436385

437386
/*
438387
* (non-Javadoc)
@@ -534,7 +483,6 @@ private NodeColumn getLeftmostVisibleColumn() {
534483
* Get the number of pixels that are visible on the leftmost column.
535484
* @return
536485
*/
537-
// TODO: this is ugly, DRY from getLeftmostVisibleColumn() !
538486
private int getVisiblePixelOfLeftmostColumn() {
539487

540488
// how much we are horizontally scrolled

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

+27-75
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
package ch.benediktkoeppel.code.droidplane;
22

33
import java.io.FileNotFoundException;
4-
import java.io.IOException;
54
import java.io.InputStream;
65

7-
import javax.xml.parsers.DocumentBuilder;
8-
import javax.xml.parsers.DocumentBuilderFactory;
9-
import javax.xml.parsers.ParserConfigurationException;
10-
116
import org.acra.ACRA;
12-
import org.xml.sax.SAXException;
137

148
import android.annotation.SuppressLint;
159
import android.app.ActionBar;
@@ -31,18 +25,6 @@
3125

3226
import com.google.analytics.tracking.android.EasyTracker;
3327

34-
// TODO: think about a strategy to strip out Log.v and Log.d messages for releases
35-
36-
// TODO: stop using DOM Nodes, and switch to MindmapNodes
37-
// TODO: start using a SAX parser and build my own MindMap, dynamically build branches when user drills down, truncate branches when they are not used anymore. How will we do Edit Node / Insert Node, if we are using a SAX parser? Maybe we should not go for a SAX parser but find a more efficient DOM parser?
38-
39-
// TODO: allow us to open multiple files and display their root nodes and file names in the leftmost column.
40-
// TODO: long-click on a root node shows a "close file" or "close this mindmap" menu
41-
// TODO: add a progress bar when opening a file (or a spinner or so)
42-
// TODO: can we get built-in icons as SVG?
43-
// TODO: properly parse rich text nodes
44-
// TODO: implement OnItemLongClickListener with a context menu (show all icons, follow link, copy text, and ultimately also edit)
45-
4628
/**
4729
* The MainActivity can be started from the App Launcher, or with a File Open
4830
* intent. If the MainApplication was already running, the previously used
@@ -55,7 +37,8 @@
5537
public class MainActivity extends Activity {
5638

5739
MainApplication application;
58-
private MindmapNode nextContextMenuMindmapNode;
40+
41+
public final static String INTENT_START_HELP = "ch.benediktkoeppel.code.droidplane.INTENT_START_HELP";
5942

6043
@Override
6144
public void onStart() {
@@ -91,22 +74,21 @@ public void onCreate(Bundle savedInstanceState) {
9174
String action = intent.getAction();
9275
String type = intent.getType();
9376

94-
// start measuring the document load time
95-
long loadDocumentStartTime = System.currentTimeMillis();
96-
9777
// if the application was reset, or the document has changed, we need to re-initialize everything
98-
// TODO: factor this stuff out. we really should have a loadDocument(InputStream) method somewhere
99-
if ( application.document == null || application.getUri() != intent.getData() ) {
78+
if ( application.mindmap == null || application.mindmap.document == null
79+
|| (application.mindmap.getUri()!=intent.getData() && intent.getData()!=null)
80+
|| (intent.getBooleanExtra(INTENT_START_HELP,false))
81+
) {
10082

101-
// Mindmap stuff
102-
InputStream mm = null;
103-
// XML document builder. The document itself is in the MainApplication
104-
DocumentBuilderFactory docBuilderFactory;
105-
DocumentBuilder docBuilder;
83+
// create a new Mindmap
84+
application.mindmap = new Mindmap();
10685

10786
// create a new HorizontalMindmapView
10887
application.horizontalMindmapView = new HorizontalMindmapView(getApplicationContext());
10988

89+
// prepare loading of the Mindmap file
90+
InputStream mm = null;
91+
11092
// determine whether we are started from the EDIT or VIEW intent, or whether we are started from the launcher
11193
// started from ACTION_EDIT/VIEW intent
11294
if ((Intent.ACTION_EDIT.equals(action)||Intent.ACTION_VIEW.equals(action)) && type != null) {
@@ -135,53 +117,26 @@ public void onCreate(Bundle savedInstanceState) {
135117
// store the Uri. Next time the MainActivity is started, we'll
136118
// check whether the Uri has changed (-> load new document) or
137119
// remained the same (-> reuse previous document)
138-
application.setUri(uri);
120+
application.mindmap.setUri(uri);
139121
}
140122

141123
// started from the launcher
142124
else {
143-
144125
Log.d(MainApplication.TAG, "started from app launcher intent");
145126

146127
// display the default Mindmap "example.mm", from the resources
147128
mm = getApplicationContext().getResources().openRawResource(R.raw.example);
148129
}
149130

131+
// load the mindmap
150132
Log.d(MainApplication.TAG, "InputStream fetched, now starting to load document");
151-
152-
// load the Mindmap from the InputStream
153-
docBuilderFactory = DocumentBuilderFactory.newInstance();
154-
try {
155-
docBuilder = docBuilderFactory.newDocumentBuilder();
156-
application.document = docBuilder.parse(mm);
157-
} catch (ParserConfigurationException e) {
158-
ACRA.getErrorReporter().putCustomData("Exception", "ParserConfigurationException");
159-
e.printStackTrace();
160-
return;
161-
} catch (SAXException e) {
162-
ACRA.getErrorReporter().putCustomData("Exception", "SAXException");
163-
e.printStackTrace();
164-
return;
165-
} catch (IOException e) {
166-
ACRA.getErrorReporter().putCustomData("Exception", "IOException");
167-
e.printStackTrace();
168-
return;
169-
}
170-
171-
long loadDocumentEndTime = System.currentTimeMillis();
172-
EasyTracker.getTracker().sendTiming("document", loadDocumentEndTime-loadDocumentStartTime, "loadDocument", "loadTime");
173-
Log.d(MainApplication.TAG, "Document loaded");
174-
175-
long numNodes = application.document.getElementsByTagName("node").getLength();
176-
EasyTracker.getTracker().sendEvent("document", "loadDocument", "numNodes", numNodes);
177-
133+
application.mindmap.loadDocument(mm);
178134

179135
// add the HorizontalMindmapView to the Layout Wrapper
180136
((LinearLayout)findViewById(R.id.layout_wrapper)).addView(application.horizontalMindmapView);
181137

182-
183138
// navigate down into the root node
184-
application.horizontalMindmapView.down(application.document.getDocumentElement());
139+
application.horizontalMindmapView.down(application.mindmap.getRootNode());
185140
}
186141

187142
// otherwise, we can display the existing HorizontalMindmapView again
@@ -242,13 +197,6 @@ public void onCreate(Bundle savedInstanceState) {
242197
@Override
243198
public boolean onCreateOptionsMenu(android.view.Menu menu) {
244199

245-
// TODO: add "Find" button and menu -> should search underneath the
246-
// current node (or with an option, under the root node)
247-
248-
// TODO: menu "Open"
249-
250-
// TODO: settings (to set the number of horizontal and vertical columns)
251-
252200
MenuInflater inflater = getMenuInflater();
253201
inflater.inflate(R.menu.main, menu);
254202
return true;
@@ -286,6 +234,14 @@ public boolean onOptionsItemSelected(android.view.MenuItem item) {
286234
case R.id.top:
287235
application.horizontalMindmapView.top();
288236
break;
237+
238+
// "Help" menu action
239+
case R.id.help:
240+
241+
// create a new intent (without URI)
242+
Intent helpIntent = new Intent(this, MainActivity.class);
243+
helpIntent.putExtra(INTENT_START_HELP, true);
244+
startActivity(helpIntent);
289245

290246
// App button (top left corner)
291247
case android.R.id.home:
@@ -296,12 +252,6 @@ public boolean onOptionsItemSelected(android.view.MenuItem item) {
296252
return true;
297253
}
298254

299-
300-
// TODO: this is a very ugly workaround. I can't figure out which MindmapNode generated the context menu, so
301-
public void setNextContextMenuMindmapNode(MindmapNode mindmapNode) {
302-
this.nextContextMenuMindmapNode = mindmapNode;
303-
}
304-
305255
/*
306256
* (non-Javadoc)
307257
*
@@ -355,12 +305,14 @@ public boolean onContextItemSelected(MenuItem item) {
355305
break;
356306
}
357307

308+
309+
358310

311+
// Node pushedNode = currentListedNodes.get(position);
312+
359313

360314

361315

362-
//
363-
// int menuItemIndex = item.getItemId();
364316
//
365317
//
366318
// public boolean onContextItemSelected(MenuItem item) {

0 commit comments

Comments
 (0)