summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2010-10-28 00:23:59 +0100
committerJoe Robinson <joe@lc8n.com>2010-10-28 00:23:59 +0100
commita94be1ada1fab129049e6a8864545c2d7e4e9dee (patch)
tree399da26854b6da6c224d6d7c1cb4917071e1ed44 /src
parentfba62b1f4fbdb09e920591fd260fcfcd3adc52b8 (diff)
Added basic functionality for sound upload (.3gp format/AMR codec) and SMS of current location
Diffstat (limited to 'src')
-rw-r--r--src/com/lc8n/blauploader/SoundRecorder.java125
-rw-r--r--src/com/lc8n/blauploader/UploadLocation.java98
2 files changed, 223 insertions, 0 deletions
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);
+ }
+
+}