Permalink
Browse files

Now storing the state in the Application object in order to re-use th…

…e Activity context
  • Loading branch information...
1 parent 950dcd7 commit 507da770041864488e2e927d1fda7a2403392634 @matburt committed Feb 23, 2010
View
@@ -4,7 +4,9 @@
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name='android.permission.INTERNET' />
- <application android:label="@string/app_name" android:icon="@drawable/icon">
+ <application android:name=".MobileOrgApplication"
+ android:label="@string/app_name"
+ android:icon="@drawable/icon">
<activity android:name="MobileOrgActivity"
android:label="MobileOrg">
<intent-filter>
@@ -1,6 +1,7 @@
package com.matburt.mobileorg;
import android.app.ListActivity;
+import android.app.Application;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@@ -32,10 +33,11 @@ public OrgViewAdapter(Context context, Node ndx, ArrayList<Integer> selection) {
this.thisNode = ndx;
this.lInflator = LayoutInflater.from(context);
this.nodeSelection = selection;
-
+ Log.d("OVA", "Selection Stack");
if (selection != null) {
for (int idx = 0; idx < selection.size(); idx++) {
this.thisNode = this.thisNode.subNodes.get(idx);
+ Log.d("OVA", this.thisNode.nodeName);
}
}
}
@@ -79,7 +81,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
private static final int OP_MENU_CAPTURE = 4;
private static final String LT = "MobileOrg";
private static Node rootNode = null;
- private ArrayList<Integer> menuList;
private Synchronizer appSync;
/** Called when the activity is first created. */
@@ -93,15 +94,19 @@ public void onCreate(Bundle savedInstanceState)
@Override
public void onResume() {
super.onResume();
- ArrayList<String> allOrgList = this.getOrgFiles();
- OrgFileParser ofp = new OrgFileParser(allOrgList);
- ofp.parse();
- MobileOrgActivity.rootNode = ofp.rootNode;
+ MobileOrgApplication appInst = (MobileOrgApplication)this.getApplication();
+ if (appInst.rootNode == null) {
+ ArrayList<String> allOrgList = this.getOrgFiles();
+ OrgFileParser ofp = new OrgFileParser(allOrgList);
+ ofp.parse();
+ appInst.rootNode = ofp.rootNode;
+ }
+
Intent nodeIntent = getIntent();
- this.menuList = nodeIntent.getIntegerArrayListExtra("nodePath");
+ appInst.nodeSelection = nodeIntent.getIntegerArrayListExtra("nodePath");
this.setListAdapter(new OrgViewAdapter(this,
- MobileOrgActivity.rootNode,
- this.menuList));
+ appInst.rootNode,
+ appInst.nodeSelection));
}
@Override
@@ -116,14 +121,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Intent dispIntent = new Intent();
+ MobileOrgApplication appInst = (MobileOrgApplication)this.getApplication();
dispIntent.setClassName("com.matburt.mobileorg",
"com.matburt.mobileorg.MobileOrgActivity");
- if (this.menuList == null) {
- this.menuList = new ArrayList<Integer>();
+ if (appInst.nodeSelection == null) {
+ appInst.nodeSelection = new ArrayList<Integer>();
}
- this.menuList.add(new Integer(position));
- dispIntent.putIntegerArrayListExtra("nodePath", this.menuList);
+ appInst.nodeSelection.add(new Integer(position));
+ dispIntent.putIntegerArrayListExtra("nodePath", appInst.nodeSelection);
startActivity(dispIntent);
}
@@ -0,0 +1,9 @@
+package com.matburt.mobileorg;
+
+import android.app.Application;
+import java.util.ArrayList;
+
+public class MobileOrgApplication extends Application {
+ public Node rootNode = null;
+ public ArrayList<Integer> nodeSelection;
+}
@@ -45,8 +45,6 @@ public void parse() {
nodeStack.pop();
}
- Log.d(LT, "(File) Adding '" + fileNode.nodeName +
- "' to " + nodeStack.peek().nodeName);
nodeStack.peek().addChildNode(fileNode);
nodeStack.push(fileNode);
while ((thisLine = breader.readLine()) != null) {
@@ -75,20 +73,14 @@ public void parse() {
try {
Node lastNode = nodeStack.peek();
lastNode.addChildNode(newNode);
- Log.d(LT, "(morestars) Adding '" + newNode.nodeName +
- "' to " + lastNode.nodeName);
} catch (EmptyStackException e) {
- Log.d(LT, "Adding '" + newNode.nodeName +
- "' to top");
}
nodeStack.push(newNode);
nodeDepth++;
}
else if (numstars == nodeDepth) {
nodeStack.pop();
nodeStack.peek().addChildNode(newNode);
- Log.d(LT, "(samestars) Adding '" + newNode.nodeName +
- "' to '" + nodeStack.peek().nodeName + "'");
nodeStack.push(newNode);
}
else if (numstars < nodeDepth) {
@@ -98,8 +90,6 @@ else if (numstars < nodeDepth) {
Node lastNode = nodeStack.peek();
lastNode.addChildNode(newNode);
- Log.d(LT, "(lesstars) Adding '" + newNode.nodeName +
- "' to '" + lastNode.nodeName + "'");
nodeStack.push(newNode);
nodeDepth++;
}
@@ -108,8 +98,6 @@ else if (numstars < nodeDepth) {
else {
Node lastNode = nodeStack.peek();
lastNode.addPayload(thisLine);
- Log.d(LT, "Adding payload: '" + thisLine +
- "' to '" + lastNode.nodeName + "'");
}
}
nodeStack.pop();

0 comments on commit 507da77

Please sign in to comment.