summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2013-01-31 22:17:03 +0000
committerJoe Robinson <joe@lc8n.com>2013-01-31 22:17:03 +0000
commit6ef031b66061629dc814c786521cb182b628f346 (patch)
treee2f8b35587fa61167b6f92a318e91ee7fa95183f /src
parent559305e42e1ea09b8d26085e8f8355bdb6ba0352 (diff)
I'm a bad person who doesn't commit to git
Diffstat (limited to 'src')
-rw-r--r--src/com/lc8n/blauploader/FileShare.java668
-rw-r--r--src/com/lc8n/blauploader/FileUpload.java34
-rw-r--r--src/com/lc8n/blauploader/SoundRecorder.java10
3 files changed, 477 insertions, 235 deletions
diff --git a/src/com/lc8n/blauploader/FileShare.java b/src/com/lc8n/blauploader/FileShare.java
index 6b474a5..f03e37f 100644
--- a/src/com/lc8n/blauploader/FileShare.java
+++ b/src/com/lc8n/blauploader/FileShare.java
@@ -1,7 +1,12 @@
package com.lc8n.blauploader;
import java.io.File;
+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;
import android.app.AlertDialog;
@@ -11,6 +16,12 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.CompressFormat;
+import android.graphics.BitmapFactory;
+import android.graphics.Matrix;
+import android.graphics.Point;
+import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -18,10 +29,17 @@ import android.os.Message;
import android.provider.MediaStore;
import android.telephony.SmsManager;
import android.util.Log;
+import android.view.Display;
import android.view.View;
+import android.view.animation.Animation;
+import android.view.animation.LinearInterpolator;
+import android.view.animation.RotateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
+import android.widget.CheckBox;
import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.Toast;
public class FileShare extends Activity {
private EditText text;
@@ -29,270 +47,466 @@ public class FileShare extends Activity {
private Handler pbHandle = null;
private ProgressDialog progressDialog;
private ProgressDialog preparing;
- private InputStream is;
private String fileName;
private Thread thread;
private AlertDialog alert;
private File file;
-
-
+ private File blaFile;
+ private ImageView thumbView;
+ private int imgRotate = 0;
+
public void onCreate(Bundle savedInstanceState)
{
- super.onCreate(savedInstanceState);
- setContentView(R.layout.share);
-
- File blaDirectory = new File("/sdcard/blaupload/");
- blaDirectory.mkdirs();
-
- Intent intent = getIntent();
- Bundle extras = intent.getExtras();
- String action = intent.getAction();
-
- text = (EditText) findViewById(R.id.filename);
- text.requestFocus();
- ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
- .showSoftInput(text, 0);
-// text.setOnFocusChangeListener(new View.OnFocusChangeListener() {
-//
-// public void onFocusChange(View v, boolean hasFocus) {
-// // TODO Auto-generated method stub
-// if (hasFocus)
-// {
-//
-// }
-// }
-// });
-// progressBar = (ProgressBar) findViewById(R.id.uploadprogress);
-
- alert = new AlertDialog.Builder(this).create();
- alert.setTitle("FTP Response");
- alert.setButton("OK", new DialogInterface.OnClickListener() {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.share);
+
+ //Temp files are stored in this folder
+ final File blaDirectory = new File("/sdcard/blaupload");
+ blaDirectory.mkdirs();
+
+ Intent intent = getIntent();
+ Bundle extras = intent.getExtras();
+ String action = intent.getAction();
+
+ //Set up filename input text box
+ text = (EditText) findViewById(R.id.filename);
+ text.requestFocus();
+ ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
+ .showSoftInput(text, 0);
+
+ //Set up alert box for any FTP error messages
+ alert = new AlertDialog.Builder(this).create();
+ alert.setTitle("FTP Response");
+ alert.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alert.dismiss();
}
});
- progressDialog = new ProgressDialog(this);
-
-
- progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- progressDialog.setMessage("Blauploading...");
- progressDialog.setCancelable(true);
- progressDialog.setProgress(0);
+
+ //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() {
- progressDialog.setButton(getText(R.string.cancel), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ // Cancel the upload!
+ progressDialog.dismiss();
+ thread.interrupt();
- public void onClick(DialogInterface dialog, int which) {
- // Cancel the upload!
- progressDialog.dismiss();
- thread.stop();
-
-
- }
- });
-
- preparing = new ProgressDialog(this);
- preparing.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- preparing.setMessage("Preparing to Blaupload...");
- preparing.setCancelable(true);
- preparing.setButton(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();
+ }
+ });
+
+ //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);
- pbHandle = new Handler(){
+ //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);
+ }
- @Override
- public void handleMessage(Message msg) {
+ int code = msg.getData().getInt("response");
- /* get the value from the Message */
+ //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;
- long progress = msg.getData().getLong("progress_update");
- System.out.println(progress+"/"+fileSize);
-
- float percent = (progress/fileSize)*100.0f;
- System.out.println(percent);
- Integer intProgress = Math.round(percent);
- System.out.println(intProgress);
- int kB = Math.round(progress / 1024);
- if(intProgress==100 || progress>(fileSize-1024)) {
- progressDialog.dismiss();
- }
- else {
- preparing.dismiss();
- progressDialog.show();
- progressDialog.setProgress(kB);
- }
+ }
+ }
+ };
+
+ //Handler for "Upload" button
+ //This is where the magic happens
+ final Button button = (Button) findViewById(R.id.uploadfile);
+ button.setOnClickListener(new View.OnClickListener() {
+
+ public void onClick(View v) {
+
+ //Show the preparing dialog while this is all happening
+ //TODO: There is lag between pressing upload and this happening. Why?
+ preparing.show();
- int code = msg.getData().getInt("response");
+ //Check box for resizing/reducing quality of image
+ CheckBox checkBox = (CheckBox)findViewById(R.id.resize);
+
+ boolean resizeImage = checkBox.isChecked();
+ fileName = text.getText().toString();
- switch (code) {
- case 0:
- break;
- case 600:
- alert.setMessage("File Already Exists! Please Rename");
- alert.show();
- progressDialog.dismiss();
- thread.interrupt();
- break;
- case 226:
- progressDialog.dismiss();
- SmsManager sms = SmsManager.getDefault();
- sms.sendTextMessage("07927278978", null, "New image blauploaded: http://www.blaupload.co.uk/"+fileName,null, null);
- 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;
-
-
- }
+ blaFile = new File(blaDirectory+"/"+fileName);
+
+ //Perform any image manipulation now (currently rotate and quality)
+ if (imgRotate != 0 || resizeImage) {
+
+ try {
+ rotateBitmap(file, blaFile, imgRotate, 80);
+
+ } catch (FileNotFoundException e) {
+ Log.e("blauploader", "File not found when rotating");
+ e.printStackTrace();
+ } catch (IOException e) {
+ Log.e("blauploader", "IOException when rotating");
+ e.printStackTrace();
+ }
+ } else {
+ try {
+ //Copy the file to our temp dir so we don't break the gallery by renaming
+ //Only do this if we're not using the rotate function, as that does it anyway
+ //TODO: Find a better way to handle this, allow renaming of existing file
+ copyFile(file, blaFile);
+ } catch (IOException e) {
+ Log.e("blauploader", "IOException when copying");
+ e.printStackTrace();
+ }
+ }
+
+ //Set the filesize again in case it was changed above
+ fileSize = blaFile.length();
+
+ //Start the upload
+ FileUpload uploader = new FileUpload(blaFile, pbHandle);
+ thread = new Thread(uploader);
+ thread.start();
+ progressDialog.setMax(Math.round(fileSize/1024));
+
+
}
- };
-
-
-
- final Button button = (Button) findViewById(R.id.uploadfile);
- button.setOnClickListener(new View.OnClickListener() {
+ });
+
+ //Rotate button handlers
+ final Button rLeft = (Button) findViewById(R.id.rotateleft);
+ rLeft.setOnClickListener(new View.OnClickListener() {
+
+ public void onClick(View v) {
- public void onClick(View v) {
-
-
+ //Rotate the thumbnail on the screen
+ RotateAnimation rotateAnimation = new RotateAnimation(imgRotate, imgRotate-90,
+ Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
+ rotateAnimation.setInterpolator(new LinearInterpolator());
+ rotateAnimation.setDuration(100);
+ rotateAnimation.setFillAfter(true);
+ thumbView.startAnimation(rotateAnimation);
+
+ //Just keep track of the total rotate, we'll do the rotating of the actual image later
+ if(imgRotate == -270) {
+ imgRotate = 0;
+ } else {
+ imgRotate -= 90;
+ }
- fileName = text.getText().toString();
- String path = file.getParent();
- System.out.println(path);
- System.out.println(fileName);
-
-
- File newName = new File(path+"/"+fileName);
- System.out.println(newName.getAbsolutePath());
- file.renameTo(newName);
- file = newName;
- System.out.println("a"+file.getAbsolutePath());
- FileUpload uploader = new FileUpload(file, pbHandle);
- thread = new Thread(uploader);
- thread.start();
- progressDialog.setMax(Math.round(fileSize/1024));
- preparing.show();
-
-
-
+ }
+ });
+
+ final Button rRight = (Button) findViewById(R.id.rotateright);
+ rRight.setOnClickListener(new View.OnClickListener() {
+
+ public void onClick(View v) {
-
-// Toast toast = Toast.makeText(getApplicationContext(), "Upload Complete!", 10);
-// toast.show();
+ //Rotate the thumbnail on the screen
+ RotateAnimation rotateAnimation = new RotateAnimation(imgRotate, imgRotate + 90,
+ Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
+ rotateAnimation.setInterpolator(new LinearInterpolator());
+ rotateAnimation.setDuration(100);
+ rotateAnimation.setFillAfter(true);
+ thumbView.startAnimation(rotateAnimation);
+
+ //Just keep track of the total rotate, we'll do the rotating of the actual image later
+ if (imgRotate == 270) {
+ imgRotate = 0;
+ } else {
+ imgRotate += 90;
}
- });
-
-
-
-
- // if this is from the share menu
- if (Intent.ACTION_SEND.equals(action))
+
+ }});
+
+ // if this is from the share menu
+ //TODO: Actually we want to do this for any image regardless of where it came from
+ if (Intent.ACTION_SEND.equals(action))
+ {
+ if (extras.containsKey(Intent.EXTRA_STREAM))
+ {
+ try
+ {
+ // Get resource path from intent callee
+ Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
+ // Query gallery for camera picture via
+ // Android ContentResolver interface
+ ContentResolver cr = getContentResolver();
+
+ String[] projection = { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.MIME_TYPE, MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.WIDTH, MediaStore.MediaColumns.HEIGHT};
+ Cursor cur = cr.query(uri, projection, null, null, null);
+ cur.moveToFirst();
+
+ fileName = cur.getString(3);
+ fileSize = cur.getLong(2);
+ int srcWidth = cur.getInt(4);
+ int srcHeight = cur.getInt(5);
+
+ cur.close();
+ String[] fileParts = fileName.split("/");
+ for (int i = 0; i < fileParts.length; i++) {
+ System.out.println(fileParts[i]);
+ }
+ text.setText(fileParts[fileParts.length-1]);
+ text.setSelection(0,fileParts[fileParts.length-1].indexOf("."));
+ file = new File(fileName);
+
+ //Get the screen size, so we can scale the thumbnail
+ Display display = getWindowManager().getDefaultDisplay();
+ int dspWidth = 0;
+ int dspHeight = 0;
+
+ //getWidth/Height are deprecated in 13, getSize is not supported pre-13
+ if(android.os.Build.VERSION.SDK_INT >= 13) {
+ Point size = new Point();
+ display.getSize(size);
+ dspWidth = size.x - 20;
+ dspHeight = size.y - 20;
+ } else {
+ dspWidth = display.getWidth();
+ dspHeight = display.getHeight();
+ }
+
+ float ratio = 0;
+
+ //Scale the thumbnail so neither dimension is bigger than the screen width
+ if(srcWidth > srcHeight) {
+ ratio = (float)dspWidth / (float)srcWidth;
+ dspHeight = Math.round(srcHeight * ratio);
+ } else {
+ ratio = (float)dspWidth / (float)srcHeight;
+ dspHeight = dspWidth;
+ dspWidth = Math.round(srcWidth * ratio);
+ }
+
+ //Get the thumbnail from the ether
+ Bitmap sourceImage= BitmapFactory.decodeFile(fileName);
+ Bitmap thumbnail = ThumbnailUtils.extractThumbnail(sourceImage, dspWidth, dspHeight);
+
+ thumbView = (ImageView)findViewById(R.id.thumbnail);
+ thumbView.setImageBitmap(thumbnail);
+
+ return;
+ } catch (Exception e)
+ {
+ Log.e(this.getClass().getName(), e.toString());
+ }
+
+ //TODO: I guess this was supposed to be some way to handle sharing text
+ //That should probably be in the texting screen which I lost
+ } else if (extras.containsKey(Intent.EXTRA_TEXT))
+ {
+ return;
+ }
+ }
+ }
+
+ //Code from http://bricolsoftconsulting.com/2012/12/07/handling-large-images-on-android
+ private boolean rotateBitmap(File inFile, File outFile, int angle, int quality)
+ throws FileNotFoundException, IOException
+ {
+
+
+ //TODO: Faster way for ICS+, uses OpenGL
+ //See package com.android.gallery3d.photoeditor.RendererUtils from AOSP/CM gallery to create a GL texture
+ /*if(android.os.Build.VERSION.SDK_INT >= 14) {
+ Bitmap bitmap = BitmapFactory.decodeFile(inFile.getAbsolutePath());
+
+ Texture texture = RendererUtils.
+ EffectContext context = EffectContext.createWithCurrentGlContext();
+ Effect rotate = context.getFactory().createEffect(EffectFactory.EFFECT_ROTATE);
+ rotate.setParameter("angle", (int) imgRotate);
+ }*/
+
+ // Declare
+ FileInputStream inStream = null;
+ FileOutputStream outStream = null;
+
+ // Create options
+ BitmapFactory.Options options = new BitmapFactory.Options();
+
+ // Create transform matrix
+ Matrix matrix = new Matrix();
+ matrix.postRotate(angle);
+
+ // Increment inSampleSize progressively to reduce image resolution and size. If
+ // the program is properly managing memory, and you don't have other large images
+ // loaded in memory, this loop will generally not need to go through more than 3
+ // iterations. To be safe though, we stop looping after a certain amount of tries
+ // to avoid infinite loops
+ for (options.inSampleSize = 1; options.inSampleSize <= 32; options.inSampleSize++)
+ {
+ try
{
- if (extras.containsKey(Intent.EXTRA_STREAM))
+ // Load the bitmap from file
+ inStream = new FileInputStream(inFile);
+ Bitmap originalBitmap = BitmapFactory.decodeStream(inStream, null, options);
+
+ // Rotate the bitmap
+ Bitmap rotatedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0, originalBitmap.getWidth(), originalBitmap.getHeight(), matrix, true);
+
+ // Save the rotated bitmap
+ outStream = new FileOutputStream(outFile);
+
+ rotatedBitmap.compress(CompressFormat.JPEG, quality, outStream);
+ outStream.close();
+
+ // Recycle the bitmaps to immediately free memory
+ originalBitmap.recycle();
+ originalBitmap = null;
+ rotatedBitmap.recycle();
+ rotatedBitmap = null;
+
+ // Return
+ return true;
+ }
+ catch (OutOfMemoryError e)
+ {
+ // If an OutOfMemoryError occurred, we continue with for loop and next inSampleSize value
+ }
+ finally
+ {
+ // Clean-up if we failed on save
+ if (outStream != null)
+ {
+ try
{
- try
- {
- // Get resource path from intent callee
- Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
-
- // Query gallery for camera picture via
- // Android ContentResolver interface
- ContentResolver cr = getContentResolver();
- is = cr.openInputStream(uri);
-
- String[] projection = { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.MIME_TYPE, MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.DATA };
- Cursor cur = cr.query(uri, projection, null, null, null);
- cur.moveToFirst();
-
- fileName = cur.getString(3);
- fileSize = cur.getLong(2);
- System.out.println(cur.getString(3));
- cur.close();
- String[] fileParts = fileName.split("/");
- for (int i = 0; i < fileParts.length; i++) {
- System.out.println(fileParts[i]);
- }
- text.setText(fileParts[fileParts.length-1]);
- text.setSelection(fileParts[fileParts.length-1].indexOf("."));
- file = new File(fileName);
-
-// text.setSelection(0, filename.indexOf("."));
-// text.requestFocus();
-
- InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- // only will trigger it if no physical keyboard is open
- mgr.showSoftInput(text, InputMethodManager.SHOW_FORCED);
-
-
- // Get binary bytes for encode
-// byte[] data = getBytesFromFile(is);
-// cr.
-//
-// // base 64 encode for text transmission (HTTP)
-// byte[] encoded_data = Base64.encodeBase64(data);
-// String data_string = new String(encoded_data); // convert to string
-//
-// SendRequest(data_string);
-
- return;
- } catch (Exception e)
- {
- Log.e(this.getClass().getName(), e.toString());
- }
-
- } else if (extras.containsKey(Intent.EXTRA_TEXT))
+ outStream.close();
+ }
+ catch (IOException e)
{
- return;
}
+ }
}
-
+ }
+
+
+
+ // Failed
+ return false;
}
+ //Copies a file from the source to dhe destination
+ //Currently used to create a temporary copy to upload
+ public static void copyFile(File source, File destination) throws IOException {
+ FileInputStream input = new FileInputStream(source);
+ OutputStream output = null;
+
+ //Read the input file into a buffer, and write it out to the new file
+ try {
+ output = new FileOutputStream(destination);
+ byte[] buffer = new byte[1024];
+ int bytesRead = input.read(buffer);
+ while (bytesRead >= 0) {
+ output.write(buffer, 0, bytesRead);
+ bytesRead = input.read(buffer);
+ }
+ } catch (Exception e) {
+ Log.e("blauploader", "Exception in copyFile");
+ e.printStackTrace();
+ } finally {
+ input.close();
+ output.close();
+ }
+ input = null;
+ output = null;
+ }
+
}
diff --git a/src/com/lc8n/blauploader/FileUpload.java b/src/com/lc8n/blauploader/FileUpload.java
index 18f7af8..1d41f8c 100644
--- a/src/com/lc8n/blauploader/FileUpload.java
+++ b/src/com/lc8n/blauploader/FileUpload.java
@@ -23,11 +23,11 @@ import java.io.BufferedInputStream;
import java.io.File;
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 java.net.SocketException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
@@ -105,6 +105,22 @@ public class FileUpload implements Runnable{
code = 804;
}
boolean exists = false;
+
+ //Add http file check
+ try {
+ if(fileExists(fileName)) {
+ exists = true;
+ code = 600;
+ }
+ } catch (MalformedURLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ //FTP file check no longer works on blaupload
for (int i = 0; i < curFiles.length; i++) {
if (curFiles[i].equals(fileName))
{
@@ -179,5 +195,17 @@ public class FileUpload implements Runnable{
ftpClient.abort();
file = null;
}
+
+ public boolean fileExists(String fileName) throws MalformedURLException, IOException {
+ URL blaURL = new URL("http://www.blaupload.co.uk/" + fileName);
+ HttpURLConnection connection = (HttpURLConnection) blaURL.openConnection();
+ connection.setRequestMethod("HEAD");
+ connection.connect();
+ if (connection.getResponseCode() == 404) {
+ return false;
+ } else {
+ return true;
+ }
+ }
}
diff --git a/src/com/lc8n/blauploader/SoundRecorder.java b/src/com/lc8n/blauploader/SoundRecorder.java
index e31fc9f..df4f6b2 100644
--- a/src/com/lc8n/blauploader/SoundRecorder.java
+++ b/src/com/lc8n/blauploader/SoundRecorder.java
@@ -34,9 +34,9 @@ public class SoundRecorder extends Activity{
recordButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- recordAudio();
Toast toast = Toast.makeText(getApplicationContext(), "Recording!", 10);
toast.show();
+ recordAudio();
}
});
@@ -44,9 +44,9 @@ public class SoundRecorder extends Activity{
stopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- stopAudio();
Toast toast = Toast.makeText(getApplicationContext(), "Stopping!", 10);
toast.show();
+ stopAudio();
}
});
@@ -91,14 +91,14 @@ public class SoundRecorder extends Activity{
{
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
- mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
+ mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
+ mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
ContentValues contentValues = new ContentValues(3);
contentValues.put(MediaStore.MediaColumns.TITLE, "Blauploaded from Android");
contentValues.put(MediaStore.MediaColumns.DATE_ADDED, System.currentTimeMillis());
// contentValues.put(MediaStore.MediaColumns.MIME_TYPE, mediaRecorder.)
- fileName = "/sdcard/blasound"+System.currentTimeMillis()+".3gp";
+ fileName = "/sdcard/blasound"+System.currentTimeMillis()+".mp4";
mediaRecorder.setOutputFile(fileName);
try {
mediaRecorder.prepare();