summaryrefslogtreecommitdiff
path: root/src/com/lc8n/blauploader
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/lc8n/blauploader')
-rw-r--r--src/com/lc8n/blauploader/FileShare.java266
-rw-r--r--src/com/lc8n/blauploader/FileUpload.java5
2 files changed, 139 insertions, 132 deletions
diff --git a/src/com/lc8n/blauploader/FileShare.java b/src/com/lc8n/blauploader/FileShare.java
index f03e37f..007cfdb 100644
--- a/src/com/lc8n/blauploader/FileShare.java
+++ b/src/com/lc8n/blauploader/FileShare.java
@@ -5,7 +5,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import android.app.Activity;
@@ -39,14 +38,15 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
-import android.widget.Toast;
+
+import com.lc8n.util.FileUploader;
public class FileShare extends Activity {
private EditText text;
- private float fileSize;
+ private long fileSize;
private Handler pbHandle = null;
- private ProgressDialog progressDialog;
- private ProgressDialog preparing;
+ //private ProgressDialog progressDialog;
+ //private ProgressDialog preparing;
private String fileName;
private Thread thread;
private AlertDialog alert;
@@ -54,7 +54,7 @@ public class FileShare extends Activity {
private File blaFile;
private ImageView thumbView;
private int imgRotate = 0;
-
+ private Context context = this;
public void onCreate(Bundle savedInstanceState)
{
@@ -87,130 +87,130 @@ public class FileShare extends Activity {
});
//Set up progress dialog which will show upload progress
- progressDialog = new ProgressDialog(this);
-
- progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- progressDialog.setMessage("Blauploading...");
- progressDialog.setCancelable(true);
- progressDialog.setProgress(0);
-
-
- progressDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getText(R.string.cancel), new DialogInterface.OnClickListener() {
-
- public void onClick(DialogInterface dialog, int which) {
- // Cancel the upload!
- progressDialog.dismiss();
- thread.interrupt();
-
-
- }
- });
+// progressDialog = new ProgressDialog(this);
+//
+// progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+// progressDialog.setMessage("Blauploading...");
+// progressDialog.setCancelable(true);
+// progressDialog.setProgress(0);
+//
+//
+// progressDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getText(R.string.cancel), new DialogInterface.OnClickListener() {
+//
+// public void onClick(DialogInterface dialog, int which) {
+// // Cancel the upload!
+// progressDialog.dismiss();
+// thread.interrupt();
+//
+//
+// }
+// });
//Set up preparing dialog which will be shown when connecting to FTP
- preparing = new ProgressDialog(this);
- preparing.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- preparing.setMessage("Preparing to Blaupload...");
- preparing.setCancelable(true);
- preparing.setButton(AlertDialog.BUTTON_NEGATIVE, getText(R.string.cancel), new DialogInterface.OnClickListener() {
-
- public void onClick(DialogInterface dialog, int which) {
- // Cancel the upload!
- progressDialog.dismiss();
- thread.interrupt();
-
- }
- });
-
+// preparing = new ProgressDialog(this);
+// preparing.setProgressStyle(maxProgressDialog.STYLE_SPINNER);
+// preparing.setMessage("Preparing to Blaupload...");
+// preparing.setCancelable(true);
+// preparing.setButton(AlertDialog.BUTTON_NEGATIVE, getText(R.string.cancel), new DialogInterface.OnClickListener() {
+//
+// public void onClick(DialogInterface dialog, int which) {
+// // Cancel the upload!
+// progressDialog.dismiss();
+// thread.interrupt();
+//
+// }
+// });
+//
//Handles responses from the FTP thread
- pbHandle = new Handler(){
-
- @Override
- public void handleMessage(Message msg) {
-
- //Get the current progress (file size completed in bytes)
- long progress = msg.getData().getLong("progress_update");
- float percent = (progress/fileSize)*100.0f;
- Integer intProgress = Math.round(percent);
-
- int kB = Math.round(progress / 1024);
-
- //TODO: Make this not terrible
- //Checks for filesize - 10kB because that's the last guaranteed response
- //But there might be more, which would result in multiple SMSs
- //Need a nicer way of cleaning up when it's done
- if(intProgress==100 || progress>(fileSize-10240)) {
- SmsManager sms = SmsManager.getDefault();
- sms.sendTextMessage("07927278978", null, "New image blauploaded: http://www.blaupload.co.uk/"+fileName,null, null);
- blaFile.delete();
- progressDialog.dismiss();
- }
- else {
- //Really not sure why this is in an else
- //Close the prepare dialog and start the progress dialog
- preparing.dismiss();
- progressDialog.show();
- progressDialog.setProgress(kB);
- }
-
- int code = msg.getData().getInt("response");
-
- //Handle FTP response codes
- switch (code) {
- case 0:
- break;
- case 600:
- alert.setMessage("File Already Exists! Please Rename");
- alert.show();
- progressDialog.dismiss();
- thread.interrupt();
- break;
- case 226:
- //This is the response code for complete, but we usually don't receive it
- //TODO: Make sure we receive it
- //SmsManager sms = SmsManager.getDefault();
- //sms.sendTextMessage("07927278978", null, "New image blauploaded: http://www.blaupload.co.uk/"+fileName,null, null);
- progressDialog.dismiss();
- break;
- case 800:
- alert.setMessage("Unable To Connect To Server!");
- alert.show();
- progressDialog.dismiss();
- break;
- case 801:
- alert.setMessage("Unable To Log In!");
- alert.show();
- progressDialog.dismiss();
- break;
- case 804:
- alert.setMessage("Unable To Get File List!");
- alert.show();
- progressDialog.dismiss();
- break;
- case 805:
- alert.setMessage("Unable To Get Upload File!");
- alert.show();
- progressDialog.dismiss();
- break;
- case 806:
- alert.setMessage("FTP Server Did Not Respond!");
- alert.show();
- progressDialog.dismiss();
- break;
- case 807:
- alert.setMessage("Unable To Log Out!");
- alert.show();
- progressDialog.dismiss();
- break;
- default:
- alert.setMessage("Response Code: "+code);
- alert.show();
- progressDialog.dismiss();
- break;
-
- }
- }
- };
+// pbHandle = new Handler(){
+//
+// @Override
+// public void handleMessage(Message msg) {
+//
+// //Get the current progress (file size completed in bytes)
+// long progress = msg.getData().getLong("progress_update");
+// float percent = (progress/fileSize)*100.0f;
+// Integer intProgress = Math.round(percent);
+//
+// int kB = Math.round(progress / 1024);
+//
+// //TODO: Make this not terrible
+// //Checks for filesize - 10kB because that's the last guaranteed response
+// //But there might be more, which would result in multiple SMSs
+// //Need a nicer way of cleaning up when it's done
+// if(intProgress==100 || progress>(fileSize-10240)) {
+// SmsManager sms = SmsManager.getDefault();
+// sms.sendTextMessage("07927278978", null, "New image blauploaded: http://www.blaupload.co.uk/"+fileName,null, null);
+// blaFile.delete();
+// progressDialog.dismiss();
+// }
+// else {
+// //Really not sure why this is in an else
+// //Close the prepare dialog and start the progress dialog
+// preparing.dismiss();
+// progressDialog.show();
+// progressDialog.setProgress(kB);
+// }
+//
+// int code = msg.getData().getInt("response");
+//
+// //Handle FTP response codes
+// switch (code) {
+// case 0:
+// break;
+// case 600:
+// alert.setMessage("File Already Exists! Please Rename");
+// alert.show();
+// progressDialog.dismiss();
+// thread.interrupt();
+// break;
+// case 226:
+// //This is the response code for complete, but we usually don't receive it
+// //TODO: Make sure we receive it
+// //SmsManager sms = SmsManager.getDefault();
+// //sms.sendTextMessage("07927278978", null, "New image blauploaded: http://www.blaupload.co.uk/"+fileName,null, null);
+// progressDialog.dismiss();
+// break;
+// case 800:
+// alert.setMessage("Unable To Connect To Server!");
+// alert.show();
+// progressDialog.dismiss();
+// break;
+// case 801:
+// alert.setMessage("Unable To Log In!");
+// alert.show();
+// progressDialog.dismiss();
+// break;
+// case 804:
+// alert.setMessage("Unable To Get File List!");
+// alert.show();
+// progressDialog.dismiss();
+// break;
+// case 805:
+// alert.setMessage("Unable To Get Upload File!");
+// alert.show();
+// progressDialog.dismiss();
+// break;
+// case 806:
+// alert.setMessage("FTP Server Did Not Respond!");
+// alert.show();
+// progressDialog.dismissmax();
+// break;
+// case 807:
+// alert.setMessage("Unable To Log Out!");
+// alert.show();
+// progressDialog.dismiss();
+// break;
+// default:
+// alert.setMessage("Response Code: "+code);
+// alert.show();
+// progressDialog.dismiss();
+// break;
+//
+// }
+// }
+// };
//Handler for "Upload" button
//This is where the magic happens
@@ -221,7 +221,7 @@ public class FileShare extends Activity {
//Show the preparing dialog while this is all happening
//TODO: There is lag between pressing upload and this happening. Why?
- preparing.show();
+ //preparing.show();
//Check box for resizing/reducing quality of image
CheckBox checkBox = (CheckBox)findViewById(R.id.resize);
@@ -260,10 +260,14 @@ public class FileShare extends Activity {
fileSize = blaFile.length();
//Start the upload
- FileUpload uploader = new FileUpload(blaFile, pbHandle);
- thread = new Thread(uploader);
- thread.start();
- progressDialog.setMax(Math.round(fileSize/1024));
+// FileUpload uploader = new FileUpload(blaFile, pbHandle);
+ FileUploader uploader2 = new FileUploader(context);
+ uploader2.prepare((int)fileSize/1024);
+ uploader2.execute(blaFile);
+
+// thread = new Thread(uploader);
+// thread.start();
+// progressDialog.setMax(Math.round(fileSize/1024));
}
diff --git a/src/com/lc8n/blauploader/FileUpload.java b/src/com/lc8n/blauploader/FileUpload.java
index 1d41f8c..2eaea4a 100644
--- a/src/com/lc8n/blauploader/FileUpload.java
+++ b/src/com/lc8n/blauploader/FileUpload.java
@@ -59,10 +59,13 @@ public class FileUpload implements Runnable{
}
+ public void httpUpload (File file, Handler pbHandle) {
+
+ }
+
public void uploadFile(File file, Handler pbHandle)
{
-
int code = 0;
FileInputStream fis = null;
try {