1
1
package ch .benediktkoeppel .code .droidplane ;
2
2
3
3
import java .io .FileNotFoundException ;
4
- import java .io .IOException ;
5
4
import java .io .InputStream ;
6
5
7
- import javax .xml .parsers .DocumentBuilder ;
8
- import javax .xml .parsers .DocumentBuilderFactory ;
9
- import javax .xml .parsers .ParserConfigurationException ;
10
-
11
6
import org .acra .ACRA ;
12
- import org .xml .sax .SAXException ;
13
7
14
8
import android .annotation .SuppressLint ;
15
9
import android .app .ActionBar ;
31
25
32
26
import com .google .analytics .tracking .android .EasyTracker ;
33
27
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
-
46
28
/**
47
29
* The MainActivity can be started from the App Launcher, or with a File Open
48
30
* intent. If the MainApplication was already running, the previously used
55
37
public class MainActivity extends Activity {
56
38
57
39
MainApplication application ;
58
- private MindmapNode nextContextMenuMindmapNode ;
40
+
41
+ public final static String INTENT_START_HELP = "ch.benediktkoeppel.code.droidplane.INTENT_START_HELP" ;
59
42
60
43
@ Override
61
44
public void onStart () {
@@ -91,22 +74,21 @@ public void onCreate(Bundle savedInstanceState) {
91
74
String action = intent .getAction ();
92
75
String type = intent .getType ();
93
76
94
- // start measuring the document load time
95
- long loadDocumentStartTime = System .currentTimeMillis ();
96
-
97
77
// 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
+ ) {
100
82
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 ();
106
85
107
86
// create a new HorizontalMindmapView
108
87
application .horizontalMindmapView = new HorizontalMindmapView (getApplicationContext ());
109
88
89
+ // prepare loading of the Mindmap file
90
+ InputStream mm = null ;
91
+
110
92
// determine whether we are started from the EDIT or VIEW intent, or whether we are started from the launcher
111
93
// started from ACTION_EDIT/VIEW intent
112
94
if ((Intent .ACTION_EDIT .equals (action )||Intent .ACTION_VIEW .equals (action )) && type != null ) {
@@ -135,53 +117,26 @@ public void onCreate(Bundle savedInstanceState) {
135
117
// store the Uri. Next time the MainActivity is started, we'll
136
118
// check whether the Uri has changed (-> load new document) or
137
119
// remained the same (-> reuse previous document)
138
- application .setUri (uri );
120
+ application .mindmap . setUri (uri );
139
121
}
140
122
141
123
// started from the launcher
142
124
else {
143
-
144
125
Log .d (MainApplication .TAG , "started from app launcher intent" );
145
126
146
127
// display the default Mindmap "example.mm", from the resources
147
128
mm = getApplicationContext ().getResources ().openRawResource (R .raw .example );
148
129
}
149
130
131
+ // load the mindmap
150
132
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 );
178
134
179
135
// add the HorizontalMindmapView to the Layout Wrapper
180
136
((LinearLayout )findViewById (R .id .layout_wrapper )).addView (application .horizontalMindmapView );
181
137
182
-
183
138
// navigate down into the root node
184
- application .horizontalMindmapView .down (application .document . getDocumentElement ());
139
+ application .horizontalMindmapView .down (application .mindmap . getRootNode ());
185
140
}
186
141
187
142
// otherwise, we can display the existing HorizontalMindmapView again
@@ -242,13 +197,6 @@ public void onCreate(Bundle savedInstanceState) {
242
197
@ Override
243
198
public boolean onCreateOptionsMenu (android .view .Menu menu ) {
244
199
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
-
252
200
MenuInflater inflater = getMenuInflater ();
253
201
inflater .inflate (R .menu .main , menu );
254
202
return true ;
@@ -286,6 +234,14 @@ public boolean onOptionsItemSelected(android.view.MenuItem item) {
286
234
case R .id .top :
287
235
application .horizontalMindmapView .top ();
288
236
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 );
289
245
290
246
// App button (top left corner)
291
247
case android .R .id .home :
@@ -296,12 +252,6 @@ public boolean onOptionsItemSelected(android.view.MenuItem item) {
296
252
return true ;
297
253
}
298
254
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
-
305
255
/*
306
256
* (non-Javadoc)
307
257
*
@@ -355,12 +305,14 @@ public boolean onContextItemSelected(MenuItem item) {
355
305
break ;
356
306
}
357
307
308
+
309
+
358
310
311
+ // Node pushedNode = currentListedNodes.get(position);
312
+
359
313
360
314
361
315
362
- //
363
- // int menuItemIndex = item.getItemId();
364
316
//
365
317
//
366
318
// public boolean onContextItemSelected(MenuItem item) {
0 commit comments