summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore20
-rw-r--r--AndroidManifest.xml1
-rw-r--r--gen/com/lc8n/blauploader/R.java79
-rw-r--r--res/drawable-ldpi/binary.pngbin0 -> 310 bytes
-rw-r--r--res/drawable-ldpi/compressed.pngbin0 -> 1108 bytes
-rw-r--r--res/drawable-ldpi/folder.pngbin0 -> 295 bytes
-rw-r--r--res/drawable-ldpi/generic.pngbin0 -> 275 bytes
-rw-r--r--res/drawable-ldpi/image.pngbin0 -> 371 bytes
-rw-r--r--res/drawable-ldpi/link.pngbin0 -> 314 bytes
-rw-r--r--res/drawable-ldpi/movie.pngbin0 -> 272 bytes
-rw-r--r--res/drawable-ldpi/music.pngbin0 -> 315 bytes
-rw-r--r--res/drawable-ldpi/text.pngbin0 -> 288 bytes
-rw-r--r--res/drawable-ldpi/unknown.pngbin0 -> 307 bytes
-rw-r--r--res/drawable-mdpi/up_arrow.pngbin0 -> 899 bytes
-rw-r--r--res/layout/browser.xml32
-rw-r--r--res/layout/filerow.xml51
-rw-r--r--src/com/lc8n/blauploader/FileArrayAdapter.java165
-rw-r--r--src/com/lc8n/blauploader/FileBrowser.java257
18 files changed, 420 insertions, 185 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fb8e9e0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,20 @@
+# built application files
+*.apk
+*.ap_
+
+# files for the dex VM
+*.dex
+
+# Java class files
+*.class
+
+# generated files
+bin/
+gen/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Eclipse project files
+.classpath
+.project
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a6b1c56..fe7b93e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -23,6 +23,7 @@
</activity>
<activity
android:name="com.lc8n.blauploader.FileBrowser"
+ android:windowSoftInputMode="stateHidden"
android:label="@string/app_name" >
<!--
diff --git a/gen/com/lc8n/blauploader/R.java b/gen/com/lc8n/blauploader/R.java
index f841ffc..53065e1 100644
--- a/gen/com/lc8n/blauploader/R.java
+++ b/gen/com/lc8n/blauploader/R.java
@@ -44,39 +44,56 @@ containing a value of this type.
public static final int exampleString=0x7f010000;
}
public static final class drawable {
- public static final int icon=0x7f020000;
- public static final int marcus72=0x7f020001;
+ public static final int binary=0x7f020000;
+ public static final int compressed=0x7f020001;
+ public static final int folder=0x7f020002;
+ public static final int generic=0x7f020003;
+ public static final int icon=0x7f020004;
+ public static final int image=0x7f020005;
+ public static final int link=0x7f020006;
+ public static final int marcus72=0x7f020007;
+ public static final int movie=0x7f020008;
+ public static final int music=0x7f020009;
+ public static final int text=0x7f02000a;
+ public static final int unknown=0x7f02000b;
+ public static final int up_arrow=0x7f02000c;
}
public static final class id {
- public static final int ProgressBar01=0x7f070014;
- public static final int Record=0x7f070012;
- public static final int Stop=0x7f070013;
- public static final int audio=0x7f070003;
- public static final int browse=0x7f070002;
- public static final int content=0x7f070008;
- public static final int directoryname=0x7f070000;
- public static final int filelist=0x7f070001;
- public static final int filename=0x7f070005;
- public static final int getlocation=0x7f070016;
- public static final int handle=0x7f07000d;
- public static final int imgquality=0x7f07000e;
- public static final int locate=0x7f070004;
- public static final int location=0x7f070015;
- public static final int menuBrowse=0x7f070019;
- public static final int menuExit=0x7f07001c;
- public static final int menuLocate=0x7f07001b;
- public static final int menuRecord=0x7f07001a;
- public static final int menu_settings=0x7f070018;
- public static final int resize=0x7f07000b;
- public static final int rotateleft=0x7f070009;
- public static final int rotateright=0x7f07000a;
- public static final int slidingDrawer1=0x7f07000c;
- public static final int tab1=0x7f07000f;
- public static final int tab2=0x7f070010;
- public static final int tab3=0x7f070011;
- public static final int thumbnail=0x7f070007;
- public static final int uploadfile=0x7f070006;
- public static final int uploadlocation=0x7f070017;
+ public static final int ProgressBar01=0x7f07001a;
+ public static final int Record=0x7f070018;
+ public static final int Stop=0x7f070019;
+ public static final int audio=0x7f070009;
+ public static final int browse=0x7f070008;
+ public static final int content=0x7f07000e;
+ public static final int directoryname=0x7f070001;
+ public static final int fileicon=0x7f070004;
+ public static final int filelist=0x7f070003;
+ public static final int filemodified=0x7f070007;
+ public static final int filename=0x7f07000b;
+ public static final int filesize=0x7f070006;
+ public static final int filetext=0x7f070005;
+ public static final int getlocation=0x7f07001c;
+ public static final int goDirButton=0x7f070002;
+ public static final int handle=0x7f070013;
+ public static final int imgquality=0x7f070014;
+ public static final int locate=0x7f07000a;
+ public static final int location=0x7f07001b;
+ public static final int menuBrowse=0x7f07001f;
+ public static final int menuExit=0x7f070022;
+ public static final int menuLocate=0x7f070021;
+ public static final int menuRecord=0x7f070020;
+ public static final int menu_settings=0x7f07001e;
+ public static final int resize=0x7f070011;
+ public static final int rotateleft=0x7f07000f;
+ public static final int rotateright=0x7f070010;
+ public static final int slidingDrawer1=0x7f070012;
+ public static final int tab1=0x7f070015;
+ public static final int tab2=0x7f070016;
+ public static final int tab3=0x7f070017;
+ public static final int thumbnail=0x7f07000d;
+ public static final int upDirButton=0x7f070000;
+ public static final int uploadfile=0x7f07000c;
+ public static final int uploadlocation=0x7f07001d;
}
public static final class layout {
public static final int activity_main=0x7f030000;
diff --git a/res/drawable-ldpi/binary.png b/res/drawable-ldpi/binary.png
new file mode 100644
index 0000000..c86d3e9
--- /dev/null
+++ b/res/drawable-ldpi/binary.png
Binary files differ
diff --git a/res/drawable-ldpi/compressed.png b/res/drawable-ldpi/compressed.png
new file mode 100644
index 0000000..1959b85
--- /dev/null
+++ b/res/drawable-ldpi/compressed.png
Binary files differ
diff --git a/res/drawable-ldpi/folder.png b/res/drawable-ldpi/folder.png
new file mode 100644
index 0000000..df03153
--- /dev/null
+++ b/res/drawable-ldpi/folder.png
Binary files differ
diff --git a/res/drawable-ldpi/generic.png b/res/drawable-ldpi/generic.png
new file mode 100644
index 0000000..478e06e
--- /dev/null
+++ b/res/drawable-ldpi/generic.png
Binary files differ
diff --git a/res/drawable-ldpi/image.png b/res/drawable-ldpi/image.png
new file mode 100644
index 0000000..1fe3209
--- /dev/null
+++ b/res/drawable-ldpi/image.png
Binary files differ
diff --git a/res/drawable-ldpi/link.png b/res/drawable-ldpi/link.png
new file mode 100644
index 0000000..f53339b
--- /dev/null
+++ b/res/drawable-ldpi/link.png
Binary files differ
diff --git a/res/drawable-ldpi/movie.png b/res/drawable-ldpi/movie.png
new file mode 100644
index 0000000..131e9dc
--- /dev/null
+++ b/res/drawable-ldpi/movie.png
Binary files differ
diff --git a/res/drawable-ldpi/music.png b/res/drawable-ldpi/music.png
new file mode 100644
index 0000000..8cbbe02
--- /dev/null
+++ b/res/drawable-ldpi/music.png
Binary files differ
diff --git a/res/drawable-ldpi/text.png b/res/drawable-ldpi/text.png
new file mode 100644
index 0000000..c43fb62
--- /dev/null
+++ b/res/drawable-ldpi/text.png
Binary files differ
diff --git a/res/drawable-ldpi/unknown.png b/res/drawable-ldpi/unknown.png
new file mode 100644
index 0000000..e4e2982
--- /dev/null
+++ b/res/drawable-ldpi/unknown.png
Binary files differ
diff --git a/res/drawable-mdpi/up_arrow.png b/res/drawable-mdpi/up_arrow.png
new file mode 100644
index 0000000..7303851
--- /dev/null
+++ b/res/drawable-mdpi/up_arrow.png
Binary files differ
diff --git a/res/layout/browser.xml b/res/layout/browser.xml
index e4edd98..4ba2fe4 100644
--- a/res/layout/browser.xml
+++ b/res/layout/browser.xml
@@ -3,15 +3,35 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
- <TextView
- android:id="@+id/directoryname"
- android:layout_width="fill_parent"
- android:layout_height="50dp"
- android:background="#CCCCCC" />
+
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+ <ImageButton
+ android:id="@+id/upDirButton"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:src="@drawable/up_arrow" />
+
+ <EditText
+ android:id="@+id/directoryname"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="0.5"
+ android:inputType="textUri" />
+
+ <ImageButton
+ android:id="@+id/goDirButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@android:drawable/ic_media_play" />
+
+ </LinearLayout>
<ListView
android:id="@+id/filelist"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
-
</LinearLayout> \ No newline at end of file
diff --git a/res/layout/filerow.xml b/res/layout/filerow.xml
index 2780514..abede54 100644
--- a/res/layout/filerow.xml
+++ b/res/layout/filerow.xml
@@ -1,6 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
-<TextView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="30sp">
-</TextView>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+ <ImageView android:id="@+id/fileicon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="5dp"/>
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/filetext"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textStyle="bold">
+ </TextView>
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/filesize"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5">
+ </TextView>
+
+ <TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/filemodified"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.5"
+ android:gravity="right"
+ android:layout_marginRight="5dp" >
+
+ </TextView>
+ </LinearLayout>
+ </LinearLayout>
+</LinearLayout> \ No newline at end of file
diff --git a/src/com/lc8n/blauploader/FileArrayAdapter.java b/src/com/lc8n/blauploader/FileArrayAdapter.java
new file mode 100644
index 0000000..f15293f
--- /dev/null
+++ b/src/com/lc8n/blauploader/FileArrayAdapter.java
@@ -0,0 +1,165 @@
+package com.lc8n.blauploader;
+
+import java.io.File;
+import java.util.Calendar;
+
+import android.app.Activity;
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+//This class is used to create a list of files
+public class FileArrayAdapter extends ArrayAdapter<File> {
+
+ private Context context;
+ private int layoutResourceId;
+ private File[] files = null;
+
+ public FileArrayAdapter(Context context, int layoutResourceId,
+ File[] files) {
+ super(context, layoutResourceId, files);
+ this.context = context;
+ this.layoutResourceId = layoutResourceId;
+ this.files = files;
+ }
+
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View row = convertView;
+ FileHolder holder = null;
+
+ if(row == null)
+ {
+ LayoutInflater inflater = ((Activity)context).getLayoutInflater();
+ row = inflater.inflate(layoutResourceId, parent, false);
+
+ //Connect the holder to the GUI objects
+ holder = new FileHolder();
+ holder.fileIcon = (ImageView)row.findViewById(R.id.fileicon);
+ holder.fileName = (TextView)row.findViewById(R.id.filetext);
+ holder.fileSize = (TextView)row.findViewById(R.id.filesize);
+ holder.fileModified = (TextView)row.findViewById(R.id.filemodified);
+
+ row.setTag(holder);
+ }
+ else
+ {
+ holder = (FileHolder)row.getTag();
+ }
+
+ File file = files[position];
+
+ if (file.isDirectory()) {
+ holder.fileIcon.setImageResource(R.drawable.folder);
+
+ //If it's a folder, the file size is irrelevant. Get the number of files inside instead
+ if (file.list()!= null) {
+ int numFiles = file.list().length;
+ if (numFiles == 1) {
+ holder.fileSize.setText("1 File");
+ } else if (numFiles == 0) {
+ holder.fileSize.setText("Empty");
+ } else {
+ holder.fileSize.setText(numFiles+" Files");
+ }
+ } else {
+ holder.fileSize.setText("Empty");
+ }
+ } else {
+
+ //Check the file extension to set the icon
+ String[] fileParts = file.getName().split("\\.");
+ if (fileParts.length != 0) {
+ String extension = fileParts[fileParts.length-1];
+
+ if (extension.equalsIgnoreCase("jpg") || extension.equalsIgnoreCase("jpeg") || extension.equalsIgnoreCase("png") || extension.equalsIgnoreCase("gif")) {
+ holder.fileIcon.setImageResource(R.drawable.image);
+ } else if (extension.equalsIgnoreCase("mp3") || extension.equalsIgnoreCase("wav") || extension.equalsIgnoreCase("aac") || extension.equalsIgnoreCase("wma")) {
+ holder.fileIcon.setImageResource(R.drawable.music);
+ } else if (extension.equalsIgnoreCase("mp4") || extension.equalsIgnoreCase("avi") || extension.equalsIgnoreCase("mkv") || extension.equalsIgnoreCase("3gp")) {
+ holder.fileIcon.setImageResource(R.drawable.movie);
+ } else if (extension.equalsIgnoreCase("txt") || extension.equalsIgnoreCase("pdf") || extension.equalsIgnoreCase("rtf") || extension.equalsIgnoreCase("log")) {
+ holder.fileIcon.setImageResource(R.drawable.text);
+ } else if (extension.equalsIgnoreCase("zip") || extension.equalsIgnoreCase("gz") || extension.equalsIgnoreCase("rar") || extension.equalsIgnoreCase("bz2")) {
+ holder.fileIcon.setImageResource(R.drawable.compressed);
+ } else if (extension.equalsIgnoreCase("exe") || extension.equalsIgnoreCase("apk") ) {
+ holder.fileIcon.setImageResource(R.drawable.binary);
+ } else {
+ holder.fileIcon.setImageResource(R.drawable.unknown);
+ }
+
+ } else {
+ //We probably can't get here, but you never know
+ holder.fileIcon.setImageResource(R.drawable.generic);
+ }
+
+ long fileSizeBytes = file.length();
+ double floatFileSize = 0;
+ String strFileSize = "";
+
+ //Round it to the largest unit, and print it with 2 decimal places
+ if(fileSizeBytes > 1073741824) {
+ floatFileSize = (double)fileSizeBytes / 1073741824;
+ strFileSize = String.format("%.2f", floatFileSize) + " GB";
+ } else if (fileSizeBytes > 1048576) {
+ floatFileSize = (double)fileSizeBytes / 1048576;
+ strFileSize = String.format("%.2f", floatFileSize) + " MB";
+ } else if (fileSizeBytes > 1024) {
+ floatFileSize = (double)fileSizeBytes / 1024;
+ strFileSize = String.format("%.2f", floatFileSize) + " kB";
+ } else {
+ strFileSize = fileSizeBytes + "B";
+ }
+
+ holder.fileSize.setText(strFileSize);
+ }
+
+ holder.fileName.setText(file.getName());
+
+ //File modified time is a unix timestamp, turn it into a readable date/time
+ Calendar fileModTime = Calendar.getInstance();
+ fileModTime.setTimeInMillis(file.lastModified());
+
+ //Add leading 0s
+ int hour = fileModTime.get(Calendar.HOUR_OF_DAY);
+ String time;
+ if (hour < 10) {
+ time = "0" + hour;
+ } else {
+ time = String.valueOf(hour);
+ }
+
+ int minute = fileModTime.get(Calendar.HOUR);
+ if (minute < 10) {
+ time += ":0" + minute;
+ } else {
+ time += ":" + String.valueOf(minute);
+ }
+
+ if (hour < 12) {
+ time += " AM";
+ } else {
+ time += " PM";
+ }
+ holder.fileModified.setText(fileModTime.get(Calendar.DAY_OF_MONTH)+"/"+(fileModTime.get(Calendar.MONTH)+1)+"/"+fileModTime.get(Calendar.YEAR)+" "+time);
+
+ return row;
+ }
+
+ static class FileHolder
+ {
+ ImageView fileIcon;
+ TextView fileName;
+ TextView fileSize;
+ TextView fileModified;
+
+ }
+
+}
+
+
diff --git a/src/com/lc8n/blauploader/FileBrowser.java b/src/com/lc8n/blauploader/FileBrowser.java
index 890ee28..29f5af5 100644
--- a/src/com/lc8n/blauploader/FileBrowser.java
+++ b/src/com/lc8n/blauploader/FileBrowser.java
@@ -30,12 +30,16 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.SmsManager;
+import android.util.Log;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
-import android.view.View;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
@@ -43,11 +47,12 @@ public class FileBrowser extends Activity {
/** Called when the activity is first created. */
private List<String> directoryEntries = new ArrayList<String>();
- private File currentDirectory = new File("/");
+ private File[] files;
+ private File currentDirectory = new File("/mnt/sdcard");
private float fileSize = 0;
private Handler pbHandle = null;
private ProgressDialog progressDialog;
- private ListView fileList;
+ private ListView fileListView;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -56,54 +61,88 @@ public class FileBrowser extends Activity {
setContentView(R.layout.browser);
directoryEntries.clear();
+
+ files = currentDirectory.listFiles();
+// fileList = new ArrayList<File>(files);
+// //directoryEntries.add("Directory:"+currentDirectory.getAbsolutePath());
+// directoryEntries.add("Up One Level");
+// if (files != null)
+// {
+// for (File file: files)
+// {
+// fileList.add(file);
+// directoryEntries.add(file.getAbsolutePath());
+//// System.out.println(file.getPath());
+// }
+// }
- File[] files = currentDirectory.listFiles();
- //directoryEntries.add("Directory:"+currentDirectory.getAbsolutePath());
- directoryEntries.add("Up One Level");
- if (files != null)
- {
- for (File file: files)
- {
- directoryEntries.add(file.getAbsolutePath());
-// System.out.println(file.getPath());
- }
- }
-
- TextView header = (TextView)findViewById(R.id.directoryname);
+ final EditText header = (EditText)findViewById(R.id.directoryname);
header.setText(currentDirectory.getAbsolutePath());
- ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.filerow, this.directoryEntries);
- fileList = (ListView)findViewById(R.id.filelist);
+
+ //Listen for events from the file path box
+ header.setOnEditorActionListener(new TextView.OnEditorActionListener() {
+
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+
+ File checkFile = new File (header.getText().toString());
+
+ //When enter/confirm/go/done (how many possibilities are there) is hit, try and go to the path entered
+ if (actionId == EditorInfo.IME_ACTION_GO || actionId == KeyEvent.KEYCODE_ENTER || actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE) {
+ if (checkFile.exists() && checkFile.isDirectory()) {
+ currentDirectory = checkFile;
+ browseTo(currentDirectory);
+ } else {
+ //TODO: Error message if it doesn't exist. Maybe upload if it's a file?
+ }
+ }
+ //I have no idea why I have to return something for this function
+ return true;
+ }
+ });
- fileList.setAdapter(directoryList);
+ //Go button does the same as hitting enter, try and go to the folder
+ ImageButton goToDir = (ImageButton) findViewById(R.id.goDirButton);
+ goToDir.setOnClickListener(new View.OnClickListener() {
+
+ public void onClick(View v) {
+ File checkFile = new File (header.getText().toString());
+ if (checkFile.exists() && checkFile.isDirectory()) {
+ currentDirectory = checkFile;
+ browseTo(currentDirectory);
+ } else {
+ //TODO: Error message if it doesn't exist. Maybe upload if it's a file?
+ }
+ }});
- fileList.setOnItemClickListener(new ListView.OnItemClickListener() {
-
+ //Up button goes to the folder above the current one
+ ImageButton upDir = (ImageButton) findViewById(R.id.upDirButton);
+ upDir.setOnClickListener(new View.OnClickListener() {
+
+ public void onClick(View v) {
+ //Go up unless there is no parent (if the result is null)
+ if (currentDirectory.getParentFile() != null) {
+ currentDirectory = currentDirectory.getParentFile();
+ browseTo(currentDirectory);
+ }
+ }});
+
+ //ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.filerow, this.directoryEntries);
+
+ //Use the FileArrayAdapter to apply the list of files to the list view
+ fileListView = (ListView)findViewById(R.id.filelist);
+ FileArrayAdapter fileAdapter = new FileArrayAdapter(this, R.layout.filerow, files);
+ fileListView.setAdapter(fileAdapter);
+
+ //Handler for clicks on the list
+ fileListView.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);
+ File chosenFile = files[position];
+
+ //If it's a folder, open it, if not, upload the file
if (chosenFile.isDirectory())
{
currentDirectory = chosenFile;
@@ -111,17 +150,12 @@ public class FileBrowser extends Activity {
}
else
{
-
- //upload it
+ //Upload it
+ //TODO: Ask for confirmation before uploading (maybe send them to the fileshare screen? or a popup to let them rename)
try {
fileSize = chosenFile.length();
-
-
-
-
-
FileUpload fu = new FileUpload(chosenFile,pbHandle);
Thread thread = new Thread(fu);
@@ -139,28 +173,21 @@ public class FileBrowser extends Activity {
}
}
-
- }
}
-
-
+
});
+
+ //Show progress while it's uploading
+ //TODO: Make it use the filesize, not percent
progressDialog = new ProgressDialog(this);
-
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Blauploading...");
progressDialog.setCancelable(true);
progressDialog.setProgress(0);
-
-//
-//
-
-
-
pbHandle = new Handler(){
@Override
@@ -190,96 +217,40 @@ public class FileBrowser extends Activity {
}
- public void browseTo(File dir)
- {
+ //Reload the screen with the specified folder
+ public void browseTo(File dir) {
directoryEntries.clear();
-
- File[] files = dir.listFiles();
- //directoryEntries.add("Current Directory:"+currentDirectory.getAbsolutePath());
- directoryEntries.add("Up One Level");
+
+ //Get a list of files
+ if (dir.listFiles() != null) {
+ files = dir.listFiles();
+ } else {
+ files = new File[0];
+ }
+
+ //Set the text box to the new folder
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.getAbsolutePath());
- System.out.println(file.getPath());
- }
- }
- ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.filerow, this.directoryEntries);
-
- fileList.setAdapter(directoryList);
+// if(files != null)
+// {
+// for (File file: files)
+// {
+// directoryEntries.add(file.getAbsolutePath());
+// System.out.println(file.getPath());
+// }
+// }
+// ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.filerow, this.directoryEntries);
+//
+// fileListView.setAdapter(directoryList);
+//
+ FileArrayAdapter fileAdapter = new FileArrayAdapter(this, R.layout.filerow, files);
+ fileListView.setAdapter(fileAdapter);
}
- //Override
- protected void onListItemClick(ListView 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();
- }
-
- }
-
- }
-
-
-
- }
-
+ //Set up menu options to go to other screens
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();