From a94be1ada1fab129049e6a8864545c2d7e4e9dee Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 28 Oct 2010 00:23:59 +0100 Subject: Added basic functionality for sound upload (.3gp format/AMR codec) and SMS of current location --- src/com/lc8n/blauploader/SoundRecorder.java | 125 +++++++++++++++++++++++++++ src/com/lc8n/blauploader/UploadLocation.java | 98 +++++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 src/com/lc8n/blauploader/SoundRecorder.java create mode 100644 src/com/lc8n/blauploader/UploadLocation.java (limited to 'src/com/lc8n') diff --git a/src/com/lc8n/blauploader/SoundRecorder.java b/src/com/lc8n/blauploader/SoundRecorder.java new file mode 100644 index 0000000..dba3873 --- /dev/null +++ b/src/com/lc8n/blauploader/SoundRecorder.java @@ -0,0 +1,125 @@ +package com.lc8n.blauploader; + +import java.io.File; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.ContentValues; +import android.media.MediaRecorder; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.provider.MediaStore; +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.MPEG_4); + 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()+".mp3"; + 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(); + } + +} diff --git a/src/com/lc8n/blauploader/UploadLocation.java b/src/com/lc8n/blauploader/UploadLocation.java new file mode 100644 index 0000000..8b211d6 --- /dev/null +++ b/src/com/lc8n/blauploader/UploadLocation.java @@ -0,0 +1,98 @@ +package com.lc8n.blauploader; + +import android.app.Activity; +import android.app.PendingIntent; +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.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; + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.uploadlocation); + + + + textLocation = (TextView) findViewById(R.id.location); + + final Button getLoc = (Button) findViewById(R.id.getlocation); + getLoc.setOnClickListener(new View.OnClickListener() { + + public void onClick(View v) { + LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); + Criteria criteria = new Criteria(); + criteria.setAccuracy(Criteria.ACCURACY_FINE); + criteria.setAltitudeRequired(true); + criteria.setBearingRequired(true); + String provider = lm.getBestProvider(criteria, true); + + MyLocationListener 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) { + + sendSms("07927278978","wjoe blauploaded his location: http://maps.google.com/maps?q="+lat+","+lon); + + } + }); + } + + 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 + + } + } + + private void sendSms(String number, String message) + { + SmsManager sms = SmsManager.getDefault(); + PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, UploadLocation.class), 0); + + sms.sendTextMessage(number, null, message, intent, null); + } + +} -- cgit v1.2.3