diff options
Diffstat (limited to 'src/com/lc8n')
| -rw-r--r-- | src/com/lc8n/blauploader/FileBrowser.java | 476 | ||||
| -rw-r--r-- | src/com/lc8n/blauploader/FileShare.java | 298 | ||||
| -rw-r--r-- | src/com/lc8n/blauploader/FileUpload.java | 259 | ||||
| -rw-r--r-- | src/com/lc8n/blauploader/HomeScreen.java | 106 | ||||
| -rw-r--r-- | src/com/lc8n/blauploader/ProgressInputStream.java | 192 | ||||
| -rw-r--r-- | src/com/lc8n/blauploader/SoundRecorder.java | 326 | ||||
| -rw-r--r-- | src/com/lc8n/blauploader/UploadLocation.java | 259 | 
7 files changed, 1164 insertions, 752 deletions
diff --git a/src/com/lc8n/blauploader/FileBrowser.java b/src/com/lc8n/blauploader/FileBrowser.java index 18d2214..279ed2c 100644 --- a/src/com/lc8n/blauploader/FileBrowser.java +++ b/src/com/lc8n/blauploader/FileBrowser.java @@ -1,239 +1,239 @@ -/* -    This program is free software: you can redistribute it and/or modify -    it under the terms of the GNU General Public License as published by -    the Free Software Foundation, either version 3 of the License, or -    (at your option) any later version. - -    This program is distributed in the hope that it will be useful, -    but WITHOUT ANY WARRANTY; without even the implied warranty of -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -    GNU General Public License for more details. - -    You should have received a copy of the GNU General Public License -    along with this program.  If not, see <http://www.gnu.org/licenses/>. -*/ - -/* -    Copyright 2010 Joe Robinson <joe@lc8n.com> -*/ - -package com.lc8n.blauploader; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import android.app.ListActivity; -import android.app.ProgressDialog; -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.telephony.SmsManager; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.ListView; - -public class FileBrowser extends ListActivity { -    /** Called when the activity is first created. */ -	 -	private List<String> directoryEntries = new ArrayList<String>(); -    private File currentDirectory = new File("/"); -    private float fileSize = 0; -    private Handler pbHandle = null; -    private ProgressDialog progressDialog; -     -    @Override -    public void onCreate(Bundle savedInstanceState) { -        super.onCreate(savedInstanceState); -         -         -        directoryEntries.clear(); -         -        File[] files = currentDirectory.listFiles(); -        directoryEntries.add("Directory:"+currentDirectory.getAbsolutePath()); -        directoryEntries.add("Up One Level"); -        if (files != null) -        { -        for (File file: files) -        { -        	directoryEntries.add(file.getPath()); -//        	System.out.println(file.getPath()); -        } -        } -        ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.filerow, this.directoryEntries); -         -        this.setListAdapter(directoryList); -         -        progressDialog = new ProgressDialog(this); -		 -		 -		progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); -		progressDialog.setMessage("Blauploading..."); -		progressDialog.setCancelable(true); -		progressDialog.setProgress(0); - - -//		 -//		 - -		 -		 -		pbHandle = new Handler(){ -		 -        @Override					 -		public void handleMessage(Message msg) { -		 -			/* get the value from the Message */ -			 -			long progress = msg.getData().getLong("progress_update"); -			System.out.println(progress+"/"+fileSize); -			if(progress>(fileSize-10240)) -			{ -				progressDialog.dismiss(); -			} -			float percent = (progress/fileSize)*100; -			Integer intProgress = Math.round(percent); -			if(intProgress==100) -			{ -				progressDialog.dismiss(); -			} -			else -			{ -				progressDialog.show(); -				progressDialog.setProgress(intProgress); -			} -		} -		}; -         -    } -     -    public void browseTo(File dir) -    { -        directoryEntries.clear(); -         -        File[] files = dir.listFiles(); -        directoryEntries.add("Current Directory:"+currentDirectory.getAbsolutePath()); -        directoryEntries.add("Up One Level"); -         -//        System.out.println(files.length); -        if(files != null) -        { -        for (File file: files) -        { -        	directoryEntries.add(file.getPath()); -        	System.out.println(file.getPath()); -        } -        } -        ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.filerow, this.directoryEntries); -         -        this.setListAdapter(directoryList); -    } -     -     -    @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, "wjoe 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(); -				} -	    		 -	    	} -	     -    	} -    	 -    	 -    	 -    } -     -	@Override -	public boolean onCreateOptionsMenu(Menu menu) { -	    MenuInflater inflater = getMenuInflater(); -	    inflater.inflate(R.menu.menu, menu); -	    return true; -	} -	 -	@Override -	public boolean onOptionsItemSelected(MenuItem item) { -	    // Handle item selection -	    switch (item.getItemId()) { -	    case R.id.menuBrowse: -//	    	Intent browse = new Intent(this, FileBrowser.class); -//            startActivityForResult(browse, 0);; -	        return true; -	    case R.id.menuRecord: -	    	Intent record = new Intent(this, SoundRecorder.class); -            startActivityForResult(record, 0); -	        return true; -	    case R.id.menuLocate: -	    	Intent locate = new Intent(this, UploadLocation.class); -            startActivityForResult(locate, 0);; -	        return true;     -	    case R.id.menuExit: -	    	this.finish(); -	    	break;  -	    default: -	        return super.onOptionsItemSelected(item); -	         -	    } -	    return true; - -	} -     - -  +/*
 +    This program is free software: you can redistribute it and/or modify
 +    it under the terms of the GNU General Public License as published by
 +    the Free Software Foundation, either version 3 of the License, or
 +    (at your option) any later version.
 +
 +    This program is distributed in the hope that it will be useful,
 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +    GNU General Public License for more details.
 +
 +    You should have received a copy of the GNU General Public License
 +    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +*/
 +
 +/*
 +    Copyright 2010 Joe Robinson <joe@lc8n.com>
 +*/
 +
 +package com.lc8n.blauploader;
 +
 +import java.io.File;
 +import java.util.ArrayList;
 +import java.util.List;
 +
 +import android.app.ListActivity;
 +import android.app.ProgressDialog;
 +import android.content.Intent;
 +import android.os.Bundle;
 +import android.os.Handler;
 +import android.os.Message;
 +import android.telephony.SmsManager;
 +import android.view.Menu;
 +import android.view.MenuInflater;
 +import android.view.MenuItem;
 +import android.view.View;
 +import android.widget.ArrayAdapter;
 +import android.widget.ListView;
 +
 +public class FileBrowser extends ListActivity {
 +    /** Called when the activity is first created. */
 +	
 +	private List<String> directoryEntries = new ArrayList<String>();
 +    private File currentDirectory = new File("/");
 +    private float fileSize = 0;
 +    private Handler pbHandle = null;
 +    private ProgressDialog progressDialog;
 +    
 +    @Override
 +    public void onCreate(Bundle savedInstanceState) {
 +        super.onCreate(savedInstanceState);
 +        
 +        
 +        directoryEntries.clear();
 +        
 +        File[] files = currentDirectory.listFiles();
 +        directoryEntries.add("Directory:"+currentDirectory.getAbsolutePath());
 +        directoryEntries.add("Up One Level");
 +        if (files != null)
 +        {
 +        for (File file: files)
 +        {
 +        	directoryEntries.add(file.getPath());
 +//        	System.out.println(file.getPath());
 +        }
 +        }
 +        ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.filerow, this.directoryEntries);
 +        
 +        this.setListAdapter(directoryList);
 +        
 +        progressDialog = new ProgressDialog(this);
 +		
 +		
 +		progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
 +		progressDialog.setMessage("Blauploading...");
 +		progressDialog.setCancelable(true);
 +		progressDialog.setProgress(0);
 +
 +
 +//		
 +//		
 +
 +		
 +		
 +		pbHandle = new Handler(){
 +		
 +        @Override					
 +		public void handleMessage(Message msg) {
 +		
 +			/* get the value from the Message */
 +			
 +			long progress = msg.getData().getLong("progress_update");
 +			System.out.println(progress+"/"+fileSize);
 +			if(progress>(fileSize-10240))
 +			{
 +				progressDialog.dismiss();
 +			}
 +			float percent = (progress/fileSize)*100;
 +			Integer intProgress = Math.round(percent);
 +			if(intProgress==100)
 +			{
 +				progressDialog.dismiss();
 +			}
 +			else
 +			{
 +				progressDialog.show();
 +				progressDialog.setProgress(intProgress);
 +			}
 +		}
 +		};
 +        
 +    }
 +    
 +    public void browseTo(File dir)
 +    {
 +        directoryEntries.clear();
 +        
 +        File[] files = dir.listFiles();
 +        directoryEntries.add("Current Directory:"+currentDirectory.getAbsolutePath());
 +        directoryEntries.add("Up One Level");
 +        
 +//        System.out.println(files.length);
 +        if(files != null)
 +        {
 +        for (File file: files)
 +        {
 +        	directoryEntries.add(file.getPath());
 +        	System.out.println(file.getPath());
 +        }
 +        }
 +        ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this, R.layout.filerow, this.directoryEntries);
 +        
 +        this.setListAdapter(directoryList);
 +    }
 +    
 +    
 +    @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();
 +				}
 +	    		
 +	    	}
 +	    
 +    	}
 +    	
 +    	
 +    	
 +    }
 +    
 +	@Override
 +	public boolean onCreateOptionsMenu(Menu menu) {
 +	    MenuInflater inflater = getMenuInflater();
 +	    inflater.inflate(R.menu.menu, menu);
 +	    return true;
 +	}
 +	
 +	@Override
 +	public boolean onOptionsItemSelected(MenuItem item) {
 +	    // Handle item selection
 +	    switch (item.getItemId()) {
 +	    case R.id.menuBrowse:
 +//	    	Intent browse = new Intent(this, FileBrowser.class);
 +//            startActivityForResult(browse, 0);;
 +	        return true;
 +	    case R.id.menuRecord:
 +	    	Intent record = new Intent(this, SoundRecorder.class);
 +            startActivityForResult(record, 0);
 +	        return true;
 +	    case R.id.menuLocate:
 +	    	Intent locate = new Intent(this, UploadLocation.class);
 +            startActivityForResult(locate, 0);;
 +	        return true;    
 +	    case R.id.menuExit:
 +	    	this.finish();
 +	    	break; 
 +	    default:
 +	        return super.onOptionsItemSelected(item);
 +	        
 +	    }
 +	    return true;
 +
 +	}
 +    
 +
 + 
  }
\ No newline at end of file diff --git a/src/com/lc8n/blauploader/FileShare.java b/src/com/lc8n/blauploader/FileShare.java new file mode 100644 index 0000000..6b474a5 --- /dev/null +++ b/src/com/lc8n/blauploader/FileShare.java @@ -0,0 +1,298 @@ +package com.lc8n.blauploader;
 +
 +import java.io.File;
 +import java.io.InputStream;
 +
 +import android.app.Activity;
 +import android.app.AlertDialog;
 +import android.app.ProgressDialog;
 +import android.content.ContentResolver;
 +import android.content.Context;
 +import android.content.DialogInterface;
 +import android.content.Intent;
 +import android.database.Cursor;
 +import android.net.Uri;
 +import android.os.Bundle;
 +import android.os.Handler;
 +import android.os.Message;
 +import android.provider.MediaStore;
 +import android.telephony.SmsManager;
 +import android.util.Log;
 +import android.view.View;
 +import android.view.inputmethod.InputMethodManager;
 +import android.widget.Button;
 +import android.widget.EditText;
 +
 +public class FileShare extends Activity {
 +	private EditText text;
 +	private float fileSize;
 +	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;
 +	
 +	
 +	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() {
 +				
 +				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);
 +			
 +			progressDialog.setButton(getText(R.string.cancel), new DialogInterface.OnClickListener() {
 +				
 +				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();
 +					
 +					
 +				}
 +			});
 +			
 +
 +
 +			
 +			
 +			pbHandle = new Handler(){
 +			
 +	        @Override					
 +			public void handleMessage(Message msg) {
 +			
 +				/* get the value from the Message */
 +				
 +				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);
 +				}
 +				
 +				int code = msg.getData().getInt("response");
 +				
 +				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;
 +					
 +					
 +				}
 +			}
 +			};
 +	        
 +	    
 +	        
 +	        final Button button = (Button) findViewById(R.id.uploadfile);
 +	        button.setOnClickListener(new View.OnClickListener() {
 +				
 +				public void onClick(View v) {
 +					
 +					
 +
 +							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();
 +
 +						
 +						
 +
 +					
 +//					Toast toast = Toast.makeText(getApplicationContext(), "Upload Complete!", 10);
 +//					toast.show();
 +				}
 +			});
 +	        
 +	        
 +	        
 +	        
 +	        // if this is from the share menu
 +	        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();
 +	                                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))
 +	                {
 +	                        return;
 +	                }
 +	        }
 +	        
 +	}
 +	
 +
 +}
 diff --git a/src/com/lc8n/blauploader/FileUpload.java b/src/com/lc8n/blauploader/FileUpload.java index b81ec2d..18f7af8 100644 --- a/src/com/lc8n/blauploader/FileUpload.java +++ b/src/com/lc8n/blauploader/FileUpload.java @@ -1,76 +1,183 @@ -/* -    This program is free software: you can redistribute it and/or modify -    it under the terms of the GNU General Public License as published by -    the Free Software Foundation, either version 3 of the License, or -    (at your option) any later version. - -    This program is distributed in the hope that it will be useful, -    but WITHOUT ANY WARRANTY; without even the implied warranty of -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -    GNU General Public License for more details. - -    You should have received a copy of the GNU General Public License -    along with this program.  If not, see <http://www.gnu.org/licenses/>. -*/ - -/* -    Copyright 2010 Joe Robinson <joe@lc8n.com> -*/ - -package com.lc8n.blauploader; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.SocketException; - -import org.apache.commons.net.ftp.FTP; -import org.apache.commons.net.ftp.FTPClient; - -import android.os.Handler; - -public class FileUpload implements Runnable{ -	 -	private File file; -	private Handler pbHandle; -	public FileUpload(File file, Handler pbHandle) -	{ -		this.file = file; -		this.pbHandle = pbHandle; -	} - -    public void uploadFile(File file, Handler pbHandle) throws SocketException, IOException -    { -    	 - -		FileInputStream fis = new FileInputStream(file); -		BufferedInputStream bis = new BufferedInputStream(fis); -		ProgressInputStream pis = new ProgressInputStream(bis,pbHandle); -		String fileName = file.getName(); -		FTPClient ftpClient = new FTPClient(); -		 -		ftpClient.connect("tghost.co.uk"); -		ftpClient.login("blaupload", "lemons"); -		ftpClient.setFileType(FTP.BINARY_FILE_TYPE); -		ftpClient.enterLocalPassiveMode(); -		ftpClient.changeWorkingDirectory("/"); -		ftpClient.storeFile(fileName, pis); -		bis.close(); -		pis.close(); -        ftpClient.logout(); -        ftpClient.disconnect(); - -    } -	public void run() { -		try { -			uploadFile(file, pbHandle); -		} catch (Exception e) { - -			// TODO Auto-generated catch block -			e.printStackTrace(); -		} -		 -	} - -} +/*
 +    This program is free software: you can redistribute it and/or modify
 +    it under the terms of the GNU General Public License as published by
 +    the Free Software Foundation, either version 3 of the License, or
 +    (at your option) any later version.
 +
 +    This program is distributed in the hope that it will be useful,
 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +    GNU General Public License for more details.
 +
 +    You should have received a copy of the GNU General Public License
 +    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +*/
 +
 +/*
 +    Copyright 2010 Joe Robinson <joe@lc8n.com>
 +*/
 +
 +package com.lc8n.blauploader;
 +
 +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 org.apache.commons.net.ftp.FTP;
 +import org.apache.commons.net.ftp.FTPClient;
 +
 +import android.os.Bundle;
 +import android.os.Handler;
 +import android.os.Message;
 +
 +public class FileUpload implements Runnable{
 +	
 +	private File file = null;
 +	private Handler pbHandle;
 +	private InputStream is;
 +	private String fileName;
 +	private FTPClient ftpClient;
 +	
 +	public FileUpload(File file, Handler pbHandle)
 +	{
 +		this.file = file;
 +		this.pbHandle = pbHandle;
 +	}
 +	
 +	public FileUpload(InputStream is, Handler pbHandle, String fileName)
 +	{
 +		this.is = is;
 +		this.pbHandle = pbHandle;
 +		this.fileName = fileName;
 +		
 +		
 +	}
 +
 +    public void uploadFile(File file, Handler pbHandle)
 +    {
 +    	
 +
 +    	int code = 0;
 +		FileInputStream fis = null;
 +		try {
 +			fis = new FileInputStream(file);
 +		} catch (FileNotFoundException e) {
 +			code = 700;
 +		}
 +		BufferedInputStream bis = new BufferedInputStream(fis);
 +		ProgressInputStream pis = new ProgressInputStream(bis,pbHandle);
 +		String fileName = file.getName();
 +		ftpClient = new FTPClient();
 +		
 +		try {
 +			ftpClient.connect("tghost.co.uk");
 +		} catch (Exception e) {
 +			code = 800;
 +			e.printStackTrace();
 +		}
 +		try {
 +			ftpClient.login("blaupload", "lemons");
 +		} catch (IOException e) {
 +			code = 801;
 +			e.printStackTrace();
 +		}
 +		try {
 +			ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
 +		} catch (IOException e) {
 +			code = 802;
 +		}
 +		ftpClient.enterLocalPassiveMode();
 +		try {
 +			ftpClient.changeWorkingDirectory("blaupload");
 +		} catch (IOException e) {
 +			code = 803;
 +		}
 +		String[] curFiles = null;
 +		try {
 +			curFiles = ftpClient.listNames();
 +		} catch (IOException e) {
 +			code = 804;
 +		}
 +		boolean exists = false;
 +		for (int i = 0; i < curFiles.length; i++) {
 +			if (curFiles[i].equals(fileName))
 +			{
 +				exists = true;
 +				code = 600;
 +			}
 +		}
 +		if (!exists) {
 +			try {
 +				ftpClient.storeFile(fileName, pis);
 +			} catch (IOException e) {
 +				code = 805;
 +			}
 +			try {
 +				code = ftpClient.getReply();
 +			} catch (IOException e) {
 +				code = 806;
 +			}
 +    	}
 +		try {
 +			bis.close();
 +			pis.close();
 +		} catch (IOException e) {
 +			code = 999;
 +		}
 +
 +        try {
 +			ftpClient.logout();
 +			ftpClient.disconnect();
 +		} catch (IOException e) {
 +			code = 807;
 +		}
 +        
 +        
 +        Bundle data = new Bundle();
 +        data.putInt("response", code);
 +        Message message = Message.obtain();
 +        message.setData(data);
 +        pbHandle.sendMessage(message);
 +
 +    }
 +    
 +
 +	public void run() {
 +		try {
 +			
 +//			if(file == null && is != null) {
 +//				file = new File("/sdcard/blaupload/"+fileName);
 +//		        OutputStream out = new FileOutputStream(file);
 +//		        
 +//				int read=0;
 +//				byte[] bytes = new byte[1024];
 +//		 
 +//				while((read = is.read(bytes))!= -1){
 +//					out.write(bytes, 0, read);
 +//				}
 +//		 
 +//				is.close();
 +//				out.flush();
 +//				out.close();
 +//			}
 +			
 +			uploadFile(file, pbHandle);
 +		} catch (Exception e) {
 +
 +			// TODO Auto-generated catch block
 +			e.printStackTrace();
 +		}
 +		
 +	}
 +	public void interrupt() throws IOException {
 +		ftpClient.abort();
 +		file = null;
 +	}
 +
 +}
 diff --git a/src/com/lc8n/blauploader/HomeScreen.java b/src/com/lc8n/blauploader/HomeScreen.java index 98de7f8..37343f3 100644 --- a/src/com/lc8n/blauploader/HomeScreen.java +++ b/src/com/lc8n/blauploader/HomeScreen.java @@ -1,49 +1,57 @@ -package com.lc8n.blauploader; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; - -public class HomeScreen extends Activity{ -	 - -	public void onCreate(Bundle savedInstanceState) { -        super.onCreate(savedInstanceState); -        setContentView(R.layout.home); - -        final Button browse = (Button) findViewById(R.id.browse); -        browse.setOnClickListener(new View.OnClickListener() { -			 -			public void onClick(View v) { -				Intent myIntent = new Intent(v.getContext(), FileBrowser.class); -                startActivityForResult(myIntent, 0); - -				 -			} -		}); -         -        final Button audio = (Button) findViewById(R.id.audio); -        audio.setOnClickListener(new View.OnClickListener() { -			 -			public void onClick(View v) { -				Intent myIntent = new Intent(v.getContext(), SoundRecorder.class); -                startActivityForResult(myIntent, 0); -				 -			} -		}); -         -        final Button locate = (Button) findViewById(R.id.locate); -        locate	 .setOnClickListener(new View.OnClickListener() { -			 -			public void onClick(View v) { -				Intent myIntent = new Intent(v.getContext(), UploadLocation.class); -                startActivityForResult(myIntent, 0); -				 -			} -		}); -         -         -	} -} +package com.lc8n.blauploader;
 +
 +import java.io.File;
 +
 +import android.app.Activity;
 +import android.content.Intent;
 +import android.os.Bundle;
 +import android.view.View;
 +import android.widget.Button;
 +
 +public class HomeScreen extends Activity{
 +	
 +
 +	public void onCreate(Bundle savedInstanceState) {
 +        super.onCreate(savedInstanceState);
 +        setContentView(R.layout.home);
 +
 +        File blaDirectory = new File("/sdcard/blaupload/");
 +        blaDirectory.mkdirs();
 +
 +        
 +
 +        
 +        final Button browse = (Button) findViewById(R.id.browse);
 +        browse.setOnClickListener(new View.OnClickListener() {
 +			
 +			public void onClick(View v) {
 +				Intent myIntent = new Intent(v.getContext(), FileBrowser.class);
 +                startActivityForResult(myIntent, 0);
 +                
 +				
 +			}
 +		});
 +        
 +        final Button audio = (Button) findViewById(R.id.audio);
 +        audio.setOnClickListener(new View.OnClickListener() {
 +			
 +			public void onClick(View v) {
 +				Intent myIntent = new Intent(v.getContext(), SoundRecorder.class);
 +                startActivityForResult(myIntent, 0);
 +				
 +			}
 +		});
 +        
 +        final Button locate = (Button) findViewById(R.id.locate);
 +        locate	 .setOnClickListener(new View.OnClickListener() {
 +			
 +			public void onClick(View v) {
 +				Intent myIntent = new Intent(v.getContext(), UploadLocation.class);
 +                startActivityForResult(myIntent, 0);
 +				
 +			}
 +		});
 +        
 +        
 +	}
 +}
 diff --git a/src/com/lc8n/blauploader/ProgressInputStream.java b/src/com/lc8n/blauploader/ProgressInputStream.java index bda5980..9404633 100644 --- a/src/com/lc8n/blauploader/ProgressInputStream.java +++ b/src/com/lc8n/blauploader/ProgressInputStream.java @@ -1,97 +1,97 @@ -/* -    This program is free software: you can redistribute it and/or modify -    it under the terms of the GNU General Public License as published by -    the Free Software Foundation, either version 3 of the License, or -    (at your option) any later version. - -    This program is distributed in the hope that it will be useful, -    but WITHOUT ANY WARRANTY; without even the implied warranty of -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -    GNU General Public License for more details. - -    You should have received a copy of the GNU General Public License -    along with this program.  If not, see <http://www.gnu.org/licenses/>. -*/ - -/* -    Copyright 2010 Joe Robinson <joe@lc8n.com> -*/ - -package com.lc8n.blauploader; - -import java.io.IOException; -import java.io.InputStream; -  -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -  -public class ProgressInputStream extends InputStream { -  -    /* Key to retrieve progress value from message bundle passed to handler */ -    public static final String PROGRESS_UPDATE = "progress_update"; -  -    private static final int TEN_KILOBYTES = 1024 * 10; -  -    private InputStream inputStream; -    private Handler handler; -  -    private long progress; -    private long lastUpdate; -  -    private boolean closed; -  -    public ProgressInputStream(InputStream inputStream, Handler handler) { -        this.inputStream = inputStream; -        this.handler = handler; -  -        this.progress = 0; -        this.lastUpdate = 0; -  -        this.closed = false; -    } -  -    @Override -        public int read() throws IOException { -            int count = inputStream.read(); -            return incrementCounterAndUpdateDisplay(count); -        } -  -    @Override -        public int read(byte[] b, int off, int len) throws IOException { -            int count = inputStream.read(b, off, len); -            return incrementCounterAndUpdateDisplay(count); -        } -  -    @Override -        public void close() throws IOException { -            super.close(); -            if (closed) -                throw new IOException("already closed"); -            closed = true; -        } -  -    private int incrementCounterAndUpdateDisplay(int count) { -        if (count > 0) -            progress += count; -        lastUpdate = maybeUpdateDisplay(progress, lastUpdate); -        return count; -    } -  -    private long maybeUpdateDisplay(long progress, long lastUpdate) { -        if (progress - lastUpdate > TEN_KILOBYTES) { -            lastUpdate = progress; -            sendLong(PROGRESS_UPDATE, progress); -        } -        return lastUpdate; -    } -  -    public void sendLong(String key, long value) { -        Bundle data = new Bundle(); -        data.putLong(key, value); -      -        Message message = Message.obtain(); -        message.setData(data); -        handler.sendMessage(message); -    } +/*
 +    This program is free software: you can redistribute it and/or modify
 +    it under the terms of the GNU General Public License as published by
 +    the Free Software Foundation, either version 3 of the License, or
 +    (at your option) any later version.
 +
 +    This program is distributed in the hope that it will be useful,
 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +    GNU General Public License for more details.
 +
 +    You should have received a copy of the GNU General Public License
 +    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +*/
 +
 +/*
 +    Copyright 2010 Joe Robinson <joe@lc8n.com>
 +*/
 +
 +package com.lc8n.blauploader;
 +
 +import java.io.IOException;
 +import java.io.InputStream;
 + 
 +import android.os.Bundle;
 +import android.os.Handler;
 +import android.os.Message;
 + 
 +public class ProgressInputStream extends InputStream {
 + 
 +    /* Key to retrieve progress value from message bundle passed to handler */
 +    public static final String PROGRESS_UPDATE = "progress_update";
 + 
 +    private static final int TEN_KILOBYTES = 1024 * 10;
 + 
 +    private InputStream inputStream;
 +    private Handler handler;
 + 
 +    private long progress;
 +    private long lastUpdate;
 + 
 +    private boolean closed;
 + 
 +    public ProgressInputStream(InputStream inputStream, Handler handler) {
 +        this.inputStream = inputStream;
 +        this.handler = handler;
 + 
 +        this.progress = 0;
 +        this.lastUpdate = 0;
 + 
 +        this.closed = false;
 +    }
 + 
 +    @Override
 +        public int read() throws IOException {
 +            int count = inputStream.read();
 +            return incrementCounterAndUpdateDisplay(count);
 +        }
 + 
 +    @Override
 +        public int read(byte[] b, int off, int len) throws IOException {
 +            int count = inputStream.read(b, off, len);
 +            return incrementCounterAndUpdateDisplay(count);
 +        }
 + 
 +    @Override
 +        public void close() throws IOException {
 +            super.close();
 +            if (closed)
 +                throw new IOException("already closed");
 +            closed = true;
 +        }
 + 
 +    private int incrementCounterAndUpdateDisplay(int count) {
 +        if (count > 0)
 +            progress += count;
 +        lastUpdate = maybeUpdateDisplay(progress, lastUpdate);
 +        return count;
 +    }
 + 
 +    private long maybeUpdateDisplay(long progress, long lastUpdate) {
 +        if (progress - lastUpdate > TEN_KILOBYTES) {
 +            lastUpdate = progress;
 +            sendLong(PROGRESS_UPDATE, progress);
 +        }
 +        return lastUpdate;
 +    }
 + 
 +    public void sendLong(String key, long value) {
 +        Bundle data = new Bundle();
 +        data.putLong(key, value);
 +     
 +        Message message = Message.obtain();
 +        message.setData(data);
 +        handler.sendMessage(message);
 +    }
  }
\ No newline at end of file diff --git a/src/com/lc8n/blauploader/SoundRecorder.java b/src/com/lc8n/blauploader/SoundRecorder.java index 8e6e7bd..e31fc9f 100644 --- a/src/com/lc8n/blauploader/SoundRecorder.java +++ b/src/com/lc8n/blauploader/SoundRecorder.java @@ -1,163 +1,163 @@ -package com.lc8n.blauploader; - -import java.io.File; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.content.ContentValues; -import android.content.Intent; -import android.media.MediaRecorder; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.provider.MediaStore; -import android.telephony.SmsManager; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.Toast; - -public class SoundRecorder extends Activity{ - -	private MediaRecorder mediaRecorder;  -	private String fileName; -	private ProgressDialog progressDialog; -	private long fileSize; -	private Handler pbHandle = null; -	public void onCreate(Bundle savedInstanceState) { -        super.onCreate(savedInstanceState); -        setContentView(R.layout.soundrecorder); - -        final Button recordButton = (Button) findViewById(R.id.Record); -        recordButton.setOnClickListener(new View.OnClickListener() { -			 -			public void onClick(View v) { -				recordAudio(); -				Toast toast = Toast.makeText(getApplicationContext(), "Recording!", 10); -				toast.show(); -			} -		}); -         -        final Button stopButton = (Button) findViewById(R.id.Stop); -        stopButton.setOnClickListener(new View.OnClickListener() { -			 -			public void onClick(View v) { -				stopAudio(); -				Toast toast = Toast.makeText(getApplicationContext(), "Stopping!", 10); -				toast.show(); -			} -		}); -         -        progressDialog = new ProgressDialog(this); -		 -		 -		progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); -		progressDialog.setMessage("Blauploading..."); -		progressDialog.setCancelable(true); -		progressDialog.setProgress(0); -		 -		pbHandle = new Handler(){ -			 -	        @Override					 -			public void handleMessage(Message msg) { -			 -				/* get the value from the Message */ -				 -				long progress = msg.getData().getLong("progress_update"); -				System.out.println(progress+"/"+fileSize); -				if(progress>(fileSize-10240)) -				{ -					progressDialog.dismiss(); -				} -				float percent = (progress/fileSize)*100; -				Integer intProgress = Math.round(percent); -				if(intProgress==100) -				{ -					progressDialog.dismiss(); -				} -				else -				{ -					progressDialog.show(); -					progressDialog.setProgress(intProgress); -				} -			} -			}; -         -	} -	 -	public void recordAudio() -	{ -		mediaRecorder = new MediaRecorder(); -		mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); -		mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); -		mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); -		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"; -		mediaRecorder.setOutputFile(fileName); -		try { -			mediaRecorder.prepare(); -		} catch (Exception e) { -			// TODO Auto-generated catch block -			e.printStackTrace(); -		} -		mediaRecorder.start(); -	} -	 -	public void stopAudio() -	{ -		mediaRecorder.stop(); -		mediaRecorder.release(); -		File recordedSound = new File(fileName); -		fileSize = recordedSound.length(); - -		 -		FileUpload fu = new FileUpload(recordedSound,pbHandle); -		Thread thread = new Thread(fu); -		 -		thread.start(); -		 -		SmsManager sms = SmsManager.getDefault(); -		sms.sendTextMessage("07927278978", null, "wjoe blauploaded a recording: http://www.blaupload.co.uk/"+recordedSound.getName(), null, null); -	} -	 -	@Override -	public boolean onCreateOptionsMenu(Menu menu) { -	    MenuInflater inflater = getMenuInflater(); -	    inflater.inflate(R.menu.menu, menu); -	    return true; -	} -	 -	@Override -	public boolean onOptionsItemSelected(MenuItem item) { -	    // Handle item selection -	    switch (item.getItemId()) { -	    case R.id.menuBrowse: -	    	Intent browse = new Intent(this, FileBrowser.class); -            startActivityForResult(browse, 0); -	        return true; -	    case R.id.menuRecord: -//	    	Intent record = new Intent(this, SoundRecorder.class); -//            startActivityForResult(record, 0); -	        return true; -	    case R.id.menuLocate: -	    	Intent locate = new Intent(this, UploadLocation.class); -            startActivityForResult(locate, 0); -	        return true;     -	    case R.id.menuExit: -	    	this.finish(); -	    	break;  -	    default: -	        return super.onOptionsItemSelected(item); -	         -	    } -	    return true; - -	} -	 -} +package com.lc8n.blauploader;
 +
 +import java.io.File;
 +
 +import android.app.Activity;
 +import android.app.ProgressDialog;
 +import android.content.ContentValues;
 +import android.content.Intent;
 +import android.media.MediaRecorder;
 +import android.os.Bundle;
 +import android.os.Handler;
 +import android.os.Message;
 +import android.provider.MediaStore;
 +import android.telephony.SmsManager;
 +import android.view.Menu;
 +import android.view.MenuInflater;
 +import android.view.MenuItem;
 +import android.view.View;
 +import android.widget.Button;
 +import android.widget.Toast;
 +
 +public class SoundRecorder extends Activity{
 +
 +	private MediaRecorder mediaRecorder; 
 +	private String fileName;
 +	private ProgressDialog progressDialog;
 +	private long fileSize;
 +	private Handler pbHandle = null;
 +	public void onCreate(Bundle savedInstanceState) {
 +        super.onCreate(savedInstanceState);
 +        setContentView(R.layout.soundrecorder);
 +
 +        final Button recordButton = (Button) findViewById(R.id.Record);
 +        recordButton.setOnClickListener(new View.OnClickListener() {
 +			
 +			public void onClick(View v) {
 +				recordAudio();
 +				Toast toast = Toast.makeText(getApplicationContext(), "Recording!", 10);
 +				toast.show();
 +			}
 +		});
 +        
 +        final Button stopButton = (Button) findViewById(R.id.Stop);
 +        stopButton.setOnClickListener(new View.OnClickListener() {
 +			
 +			public void onClick(View v) {
 +				stopAudio();
 +				Toast toast = Toast.makeText(getApplicationContext(), "Stopping!", 10);
 +				toast.show();
 +			}
 +		});
 +        
 +        progressDialog = new ProgressDialog(this);
 +		
 +		
 +		progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
 +		progressDialog.setMessage("Blauploading...");
 +		progressDialog.setCancelable(true);
 +		progressDialog.setProgress(0);
 +		
 +		pbHandle = new Handler(){
 +			
 +	        @Override					
 +			public void handleMessage(Message msg) {
 +			
 +				/* get the value from the Message */
 +				
 +				long progress = msg.getData().getLong("progress_update");
 +				System.out.println(progress+"/"+fileSize);
 +				if(progress>(fileSize-10240))
 +				{
 +					progressDialog.dismiss();
 +				}
 +				float percent = (progress/fileSize)*100;
 +				Integer intProgress = Math.round(percent);
 +				if(intProgress==100)
 +				{
 +					progressDialog.dismiss();
 +				}
 +				else
 +				{
 +					progressDialog.show();
 +					progressDialog.setProgress(intProgress);
 +				}
 +			}
 +			};
 +        
 +	}
 +	
 +	public void recordAudio()
 +	{
 +		mediaRecorder = new MediaRecorder();
 +		mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 +		mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 +		mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 +		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";
 +		mediaRecorder.setOutputFile(fileName);
 +		try {
 +			mediaRecorder.prepare();
 +		} catch (Exception e) {
 +			// TODO Auto-generated catch block
 +			e.printStackTrace();
 +		}
 +		mediaRecorder.start();
 +	}
 +	
 +	public void stopAudio()
 +	{
 +		mediaRecorder.stop();
 +		mediaRecorder.release();
 +		File recordedSound = new File(fileName);
 +		fileSize = recordedSound.length();
 +
 +		
 +		FileUpload fu = new FileUpload(recordedSound,pbHandle);
 +		Thread thread = new Thread(fu);
 +		
 +		thread.start();
 +		
 +		SmsManager sms = SmsManager.getDefault();
 +		sms.sendTextMessage("07927278978", null, "New sound recording blauploaded: http://www.blaupload.co.uk/"+recordedSound.getName(), null, null);
 +	}
 +	
 +	@Override
 +	public boolean onCreateOptionsMenu(Menu menu) {
 +	    MenuInflater inflater = getMenuInflater();
 +	    inflater.inflate(R.menu.menu, menu);
 +	    return true;
 +	}
 +	
 +	@Override
 +	public boolean onOptionsItemSelected(MenuItem item) {
 +	    // Handle item selection
 +	    switch (item.getItemId()) {
 +	    case R.id.menuBrowse:
 +	    	Intent browse = new Intent(this, FileBrowser.class);
 +            startActivityForResult(browse, 0);
 +	        return true;
 +	    case R.id.menuRecord:
 +//	    	Intent record = new Intent(this, SoundRecorder.class);
 +//            startActivityForResult(record, 0);
 +	        return true;
 +	    case R.id.menuLocate:
 +	    	Intent locate = new Intent(this, UploadLocation.class);
 +            startActivityForResult(locate, 0);
 +	        return true;    
 +	    case R.id.menuExit:
 +	    	this.finish();
 +	    	break; 
 +	    default:
 +	        return super.onOptionsItemSelected(item);
 +	        
 +	    }
 +	    return true;
 +
 +	}
 +	
 +}
 diff --git a/src/com/lc8n/blauploader/UploadLocation.java b/src/com/lc8n/blauploader/UploadLocation.java index 99f1a08..3db3974 100644 --- a/src/com/lc8n/blauploader/UploadLocation.java +++ b/src/com/lc8n/blauploader/UploadLocation.java @@ -1,130 +1,129 @@ -package com.lc8n.blauploader; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.location.Criteria; -import android.location.Location; -import android.location.LocationListener; -import android.location.LocationManager; -import android.os.Bundle; -import android.telephony.SmsManager; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; - -public class UploadLocation extends Activity { -	 -	private TextView textLocation; -	private double lat = 0; -	private double lon = 0; -	private MyLocationListener ll; -	private LocationManager lm; -	public void onCreate(Bundle savedInstanceState) { -        super.onCreate(savedInstanceState); -        setContentView(R.layout.uploadlocation); - - -         -        textLocation = (TextView) findViewById(R.id.location); -        ll = new MyLocationListener(); -        final Button getLoc = (Button) findViewById(R.id.getlocation); -        getLoc.setOnClickListener(new View.OnClickListener() { -			 -			public void onClick(View v) { -		        lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); -		        Criteria criteria = new Criteria(); -		        criteria.setAccuracy(Criteria.ACCURACY_FINE); -		        criteria.setAltitudeRequired(false); -		        criteria.setBearingRequired(false); -		        String provider = lm.getBestProvider(criteria, true); -		         -		        ll = new MyLocationListener(); -		        lm.requestLocationUpdates(provider, 10000, 0, ll); -				 -			} -		}); -         -        final Button uploadLoc = (Button) findViewById(R.id.uploadlocation); -        uploadLoc.setOnClickListener(new View.OnClickListener() { -			 -			public void onClick(View v) { -				 -		    	SmsManager sms = SmsManager.getDefault(); -				sms.sendTextMessage("07927278978", null, "wjoe blauploaded his location: http://maps.google.com/maps?q="+lat+","+lon, null, null); -				lm.removeUpdates(ll); -			} -		}); -	} -	 -    private class MyLocationListener implements LocationListener -    { - -    public void onLocationChanged(Location loc) { -    if (loc != null) { - - -    lat = (loc.getLatitude()); -    lon = (loc.getLongitude()); -    textLocation.setText(lat+", "+lon); - -         - -    } -    } - -	public void onProviderDisabled(String provider) { -		// TODO Auto-generated method stub -		 -	} - -	public void onProviderEnabled(String provider) { -		// TODO Auto-generated method stub -		 -	} - -	public void onStatusChanged(String provider, int status, Bundle extras) { -		// TODO Auto-generated method stub -		 -	} -    } -     -	@Override -	public boolean onCreateOptionsMenu(Menu menu) { -	    MenuInflater inflater = getMenuInflater(); -	    inflater.inflate(R.menu.menu, menu); -	    return true; -	} -	 -	@Override -	public boolean onOptionsItemSelected(MenuItem item) { -	    // Handle item selection -	    switch (item.getItemId()) { -	    case R.id.menuBrowse: -	    	Intent browse = new Intent(this, FileBrowser.class); -            startActivityForResult(browse, 0);; -	        return true; -	    case R.id.menuRecord: -	    	Intent record = new Intent(this, SoundRecorder.class); -            startActivityForResult(record, 0); -	        return true; -	    case R.id.menuLocate: -//	    	Intent locate = new Intent(this, UploadLocation.class); -//            startActivityForResult(locate, 0);; -	        return true;     -	    case R.id.menuExit: -	    	this.finish(); -	    	break;  -	    default: -	        return super.onOptionsItemSelected(item); -	         -	    } -	    return true; - -	} -     - -} +package com.lc8n.blauploader;
 +
 +import android.app.Activity;
 +import android.content.Context;
 +import android.content.Intent;
 +import android.location.Criteria;
 +import android.location.Location;
 +import android.location.LocationListener;
 +import android.location.LocationManager;
 +import android.os.Bundle;
 +import android.telephony.SmsManager;
 +import android.view.Menu;
 +import android.view.MenuInflater;
 +import android.view.MenuItem;
 +import android.view.View;
 +import android.widget.Button;
 +import android.widget.TextView;
 +
 +public class UploadLocation extends Activity {
 +	
 +	private TextView textLocation;
 +	private double lat = 0;
 +	private double lon = 0;
 +	private MyLocationListener ll;
 +	private LocationManager lm;
 +	public void onCreate(Bundle savedInstanceState) {
 +        super.onCreate(savedInstanceState);
 +        setContentView(R.layout.uploadlocation);
 +
 +
 +        
 +        textLocation = (TextView) findViewById(R.id.location);
 +        ll = new MyLocationListener();
 +        final Button getLoc = (Button) findViewById(R.id.getlocation);
 +        getLoc.setOnClickListener(new View.OnClickListener() {
 +			
 +			public void onClick(View v) {
 +		        lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
 +		        Criteria criteria = new Criteria();
 +		        criteria.setAltitudeRequired(false);
 +		        criteria.setBearingRequired(false);
 +		        String provider = lm.getBestProvider(criteria, true);
 +		        
 +		        ll = new MyLocationListener();
 +		        lm.requestLocationUpdates(provider, 10000, 0, ll);
 +				
 +			}
 +		});
 +        
 +        final Button uploadLoc = (Button) findViewById(R.id.uploadlocation);
 +        uploadLoc.setOnClickListener(new View.OnClickListener() {
 +			
 +			public void onClick(View v) {
 +				
 +		    	SmsManager sms = SmsManager.getDefault();
 +				sms.sendTextMessage("07927278978", null, "Current location: http://maps.google.com/maps?q="+lat+","+lon, null, null);
 +				lm.removeUpdates(ll);
 +			}
 +		});
 +	}
 +	
 +    private class MyLocationListener implements LocationListener
 +    {
 +
 +    public void onLocationChanged(Location loc) {
 +    if (loc != null) {
 +
 +
 +    lat = (loc.getLatitude());
 +    lon = (loc.getLongitude());
 +    textLocation.setText(lat+", "+lon);
 +
 +        
 +
 +    }
 +    }
 +
 +	public void onProviderDisabled(String provider) {
 +		// TODO Auto-generated method stub
 +		
 +	}
 +
 +	public void onProviderEnabled(String provider) {
 +		// TODO Auto-generated method stub
 +		
 +	}
 +
 +	public void onStatusChanged(String provider, int status, Bundle extras) {
 +		// TODO Auto-generated method stub
 +		
 +	}
 +    }
 +    
 +	@Override
 +	public boolean onCreateOptionsMenu(Menu menu) {
 +	    MenuInflater inflater = getMenuInflater();
 +	    inflater.inflate(R.menu.menu, menu);
 +	    return true;
 +	}
 +	
 +	@Override
 +	public boolean onOptionsItemSelected(MenuItem item) {
 +	    // Handle item selection
 +	    switch (item.getItemId()) {
 +	    case R.id.menuBrowse:
 +	    	Intent browse = new Intent(this, FileBrowser.class);
 +            startActivityForResult(browse, 0);;
 +	        return true;
 +	    case R.id.menuRecord:
 +	    	Intent record = new Intent(this, SoundRecorder.class);
 +            startActivityForResult(record, 0);
 +	        return true;
 +	    case R.id.menuLocate:
 +//	    	Intent locate = new Intent(this, UploadLocation.class);
 +//            startActivityForResult(locate, 0);;
 +	        return true;    
 +	    case R.id.menuExit:
 +	    	this.finish();
 +	    	break; 
 +	    default:
 +	        return super.onOptionsItemSelected(item);
 +	        
 +	    }
 +	    return true;
 +
 +	}
 +    
 +
 +}
  | 
