Browse files

Enabling text view from a context menu accessed by longclick on the l…

…istview
  • Loading branch information...
1 parent b02e9ce commit b17d6b2967fdf8136782cadd4f8b739c09e81316 @matburt committed Feb 24, 2010
View
3 AndroidManifest.xml
@@ -20,5 +20,8 @@
<activity android:name="SimpleTextDisplay"
android:label="Org view">
</activity>
+ <activity android:name="OrgContextMenu"
+ android:label="OrgMenu">
+ </activity>
</application>
</manifest>
View
12 res/layout/longcontext.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TableLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_height="fill_parent"
+ android:layout_width="fill_parent"
+ android:background="#000044">
+ <TableRow>
+ <Button
+ android:id="@+id/documentMode"
+ android:text="View as Document" />
+ </TableRow>
+</TableLayout>
View
30 src/com/matburt/mobileorg/MobileOrgActivity.java
@@ -11,6 +11,7 @@
import android.widget.ListView;
import android.widget.BaseAdapter;
import android.widget.TextView;
+import android.widget.AdapterView;
import android.content.Intent;
import android.content.Context;
import android.util.Log;
@@ -70,7 +71,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
TextView thisView = (TextView)convertView.findViewById(R.id.orgItem);
thisView.setText(this.thisNode.subNodes.get(position).nodeName);
- Log.d("MobileOrg", "Returning view item: " + this.thisNode.subNodes.get(position).nodeName);
+ Log.d("MobileOrg", "Returning view item: " +
+ this.thisNode.subNodes.get(position).nodeName);
convertView.setTag(thisView);
return convertView;
}
@@ -89,9 +91,20 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.initializeTables();
+ ListView lv = this.getListView();
+ lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener
+ (){
+ @Override
+ public boolean onItemLongClick(AdapterView<?> av, View v,
+ int pos, long id) {
+ onLongListItemClick(v,pos,id);
+ return true;
+ }
+ });
}
public void runParser() {
+ MobileOrgApplication appInst = (MobileOrgApplication)this.getApplication();
ArrayList<String> allOrgList = this.getOrgFiles();
OrgFileParser ofp = new OrgFileParser(allOrgList);
ofp.parse();
@@ -122,11 +135,24 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
+ protected void onLongListItemClick(View av, int pos, long id) {
+ Intent dispIntent = new Intent();
+ MobileOrgApplication appInst = (MobileOrgApplication)this.getApplication();
+ dispIntent.setClassName("com.matburt.mobileorg",
+ "com.matburt.mobileorg.OrgContextMenu");
+ if (appInst.nodeSelection == null) {
+ appInst.nodeSelection = new ArrayList<Integer>();
+ }
+
+ appInst.nodeSelection.add(new Integer(pos));
+ dispIntent.putIntegerArrayListExtra("nodePath", appInst.nodeSelection);
+ startActivity(dispIntent);
+ }
+
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Intent dispIntent = new Intent();
MobileOrgApplication appInst = (MobileOrgApplication)this.getApplication();
- Log.d("OVA", "Item selected was: " + position);
dispIntent.setClassName("com.matburt.mobileorg",
"com.matburt.mobileorg.MobileOrgActivity");
if (appInst.nodeSelection == null) {
View
58 src/com/matburt/mobileorg/OrgContextMenu.java
@@ -0,0 +1,58 @@
+package com.matburt.mobileorg;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.content.Intent;
+import android.widget.Button;
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import android.view.View;
+import android.view.View.OnClickListener;
+
+public class OrgContextMenu extends Activity implements OnClickListener
+{
+ public static final String LT = "MobileOrg";
+ ArrayList<Integer> npath;
+ private Button docButton;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.longcontext);
+ this.docButton = (Button)this.findViewById(R.id.documentMode);
+ this.docButton.setOnClickListener(this);
+ this.poplateDisplay();
+ }
+
+ public void poplateDisplay() {
+ Intent txtIntent = getIntent();
+ this.npath = txtIntent.getIntegerArrayListExtra("nodePath");
+ }
+
+ public void onClick(View v) {
+ MobileOrgApplication appInst = (MobileOrgApplication)this.getApplication();
+ Node thisNode = appInst.rootNode;
+ Intent textIntent = new Intent();
+ String displayBuffer = new String();
+ for (int idx = 0; idx < this.npath.size(); idx++) {
+ thisNode = thisNode.subNodes.get(
+ this.npath.get(idx));
+ }
+ for (int idx = 0; idx < thisNode.subNodes.size(); idx++) {
+ displayBuffer += thisNode.subNodes.get(idx).nodeName +
+ "\n" + thisNode.subNodes.get(idx).nodePayload + "\n\n";
+ }
+
+ textIntent.setClassName("com.matburt.mobileorg",
+ "com.matburt.mobileorg.SimpleTextDisplay");
+ textIntent.putExtra("txtValue", displayBuffer);
+ startActivity(textIntent);
+ }
+}
View
58 src/com/matburt/mobileorg/SimpleTextDisplay.java
@@ -28,61 +28,7 @@ public void onCreate(Bundle savedInstanceState) {
public void poplateDisplay() {
Intent txtIntent = getIntent();
- String srcName = txtIntent.getStringExtra("fileValue");
- SQLiteDatabase appdb = this.openOrCreateDatabase("MobileOrg",
- MODE_PRIVATE, null);
- Cursor result = appdb.rawQuery("SELECT file from files" +
- " WHERE name = '" + srcName + "'", null);
- String displayTxt;
- if (result != null) {
- if (result.getCount() > 0) {
- result.moveToFirst();
- Log.d(LT, "Reading file: " + result.getString(0));
- displayTxt = this.readOrgFile(result.getString(0));
- Log.d(LT, "Running file through Parser");
- /* OrgFileParser ofp = new OrgFileParser(result.getString(0));
- ofp.parse(); */
- }
- else {
- displayTxt = "File not found";
- }
- }
- else {
- displayTxt = "Database error";
- }
- Log.d(LT, "Setting text to: " + displayTxt);
- this.orgDisplay.setText(displayTxt);
- }
-
- public String readOrgFile(String orgFile) {
- FileInputStream fs;
- String output = "";
- try {
- fs = this.openFileInput(orgFile);
- }
- catch (java.io.FileNotFoundException e) {
- Log.e(LT, "Could not read file");
- return "Could not read file";
- }
- Log.d(LT, "File opened");
- try {
- byte[] reader = new byte[fs.available()];
- Log.d(LT, "Read loop");
- fs.read(reader);
- Log.d(LT, "Read all data");
- output = new String(reader);
- } catch(IOException e) {
- Log.e(LT, e.getMessage());
- } finally {
- if (fs != null) {
- try {
- fs.close();
- } catch (IOException e) {
- Log.e(LT, e.getMessage());
- }
- }
- }
- Log.d(LT, "Returning data");
- return output;
+ String srcText = txtIntent.getStringExtra("txtValue");
+ this.orgDisplay.setText(srcText);
}
}

0 comments on commit b17d6b2

Please sign in to comment.