From bffa5e5ea8a852bae02f724d9758edd54776b885 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 1 Feb 2013 01:02:20 +0000 Subject: Gave FileBrowser a layout file and a header --- src/com/lc8n/blauploader/FileBrowser.java | 106 ++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 13 deletions(-) (limited to 'src/com/lc8n') diff --git a/src/com/lc8n/blauploader/FileBrowser.java b/src/com/lc8n/blauploader/FileBrowser.java index 279ed2c..890ee28 100644 --- a/src/com/lc8n/blauploader/FileBrowser.java +++ b/src/com/lc8n/blauploader/FileBrowser.java @@ -23,7 +23,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import android.app.ListActivity; +import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; @@ -33,11 +33,13 @@ import android.telephony.SmsManager; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.View; +import android.view.View; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.TextView; -public class FileBrowser extends ListActivity { +public class FileBrowser extends Activity { /** Called when the activity is first created. */ private List directoryEntries = new ArrayList(); @@ -45,31 +47,108 @@ public class FileBrowser extends ListActivity { private float fileSize = 0; private Handler pbHandle = null; private ProgressDialog progressDialog; + private ListView fileList; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + + setContentView(R.layout.browser); directoryEntries.clear(); File[] files = currentDirectory.listFiles(); - directoryEntries.add("Directory:"+currentDirectory.getAbsolutePath()); + //directoryEntries.add("Directory:"+currentDirectory.getAbsolutePath()); directoryEntries.add("Up One Level"); if (files != null) { for (File file: files) { - directoryEntries.add(file.getPath()); + directoryEntries.add(file.getAbsolutePath()); // System.out.println(file.getPath()); } } + + TextView header = (TextView)findViewById(R.id.directoryname); + header.setText(currentDirectory.getAbsolutePath()); ArrayAdapter directoryList = new ArrayAdapter(this, R.layout.filerow, this.directoryEntries); + fileList = (ListView)findViewById(R.id.filelist); - this.setListAdapter(directoryList); + fileList.setAdapter(directoryList); + fileList.setOnItemClickListener(new ListView.OnItemClickListener() { + + + + public void onItemClick(AdapterView l, View v, int position, + long id) { + + String fileString = directoryEntries.get(position); + + + if(fileString.contains("Directory:")) + { + browseTo(currentDirectory); + } + else if (fileString.equals("Up One Level")) + { + System.out.println(currentDirectory.getParentFile().getPath()); + if (currentDirectory.getParent() != null) + { + currentDirectory = currentDirectory.getParentFile(); + browseTo(currentDirectory); + } + } + else + { + + + File chosenFile = new File(fileString); + if (chosenFile.isDirectory()) + { + currentDirectory = chosenFile; + browseTo(currentDirectory); + } + else + { + + //upload it + try { + + fileSize = chosenFile.length(); + + + + + + + FileUpload fu = new FileUpload(chosenFile,pbHandle); + Thread thread = new Thread(fu); + + thread.start(); + + SmsManager sms = SmsManager.getDefault(); + sms.sendTextMessage("07927278978", null, "New file blauploaded: http://www.blaupload.co.uk/"+chosenFile.getName(), null, null); + + + + } catch (Exception e) { + // TODO Auto-generated catch block + System.err.println(e.getMessage()); + e.printStackTrace(); + } + + } + + } + + } + + + + }); progressDialog = new ProgressDialog(this); - + progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage("Blauploading..."); @@ -116,25 +195,26 @@ public class FileBrowser extends ListActivity { directoryEntries.clear(); File[] files = dir.listFiles(); - directoryEntries.add("Current Directory:"+currentDirectory.getAbsolutePath()); + //directoryEntries.add("Current Directory:"+currentDirectory.getAbsolutePath()); directoryEntries.add("Up One Level"); - + TextView header = (TextView)findViewById(R.id.directoryname); + header.setText(currentDirectory.getAbsolutePath()); // System.out.println(files.length); if(files != null) { for (File file: files) { - directoryEntries.add(file.getPath()); + directoryEntries.add(file.getAbsolutePath()); System.out.println(file.getPath()); } } ArrayAdapter directoryList = new ArrayAdapter(this, R.layout.filerow, this.directoryEntries); - this.setListAdapter(directoryList); + fileList.setAdapter(directoryList); } - @Override + //Override protected void onListItemClick(ListView l, View v, int position, long id) { String fileString = directoryEntries.get(position); -- cgit v1.2.3