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) { Toast toast = Toast.makeText(getApplicationContext(), "Recording!", 10); toast.show(); recordAudio(); } }); final Button stopButton = (Button) findViewById(R.id.Stop); stopButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast toast = Toast.makeText(getApplicationContext(), "Stopping!", 10); toast.show(); stopAudio(); } }); 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.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()+".mp4"; 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; } }