public static class ClipData extends JsonData {
	public Long session_id;
	public String lang; // Locale.getDefault().getLanguage()
	public String user;
	public Long user_id;
	public String created;
	public Integer duration;
	public Integer status;
	public String title;
	public String hash_key;
	public Long id;
	public Float latitude;
	public Float longitude;
	public String resource_uri;
	public String permalink;
	public String send_date;
	public String updated;
	public String image;
	public String thumbnail;
	public String sound;
	public String mp3_sound;
	public String ogg_sound;
	public Long score;
	public Boolean adult_content = false;
	public Boolean has_voted = false;
	public Integer votes = 0;
		
} public static class ClipDataChangeStatus extends JsonData {
	public String hash_key;
	public int status;
} public static class RestResult {
	public int httpCode = 0;
	public String payload = null;
	public Boolean ok = false;
} public class RestClient {
	//protected DefaultHttpClient mClient;
	protected String uri = null;
	protected String data = null;
	protected RestClientListener listener = null;
//	protected Context activity;
	protected Boolean useSSL = false;

	public RestClient(String uri){
		this.uri = uri;
	}

	public RestClient(String uri, String data) {
		this.uri = uri;
		this.data = data;
	}

	public void useSSL(Boolean ssl) {
		useSSL = ssl;
	}

	protected String getScheme() {
		// TODO: check which server
		if (useSSL && App.getInstance().getUseSSL()) {
			return "https://";
		} else return "http://";
	}

	protected String getSchemeServer() {
		return getScheme() + App.getInstance().getServer();
	}

	public void backgroundConnect(RestClientListener listener) {
		// Create a background thread
		this.listener = listener;
		new RestTask(this).execute();
	}

	public RestResult connect() {
		// Do all operations in the same thread
		return process();
	}

	protected void finished(RestResult result) {
		if (listener != null){
			try {
				listener.onRestFinished(result);
			} catch (Exception e) {
				Log.d("Rest Client", "Error " + e.getMessage());
			}
		}
	}

	protected void setupHttp(HttpMessage m) {
		if (App.getInstance().getKey() != null) {
			m.setHeader("Authorization", "ApiKey " + App.getInstance().getUsername() + ":" + App.getInstance().getKey());
		}
	}

	protected RestResult doGet() {
		HttpGet httpGet = new HttpGet(getSchemeServer()+this.uri);
		setupHttp(httpGet);
		try {
			httpGet.setHeader("Content-type", "application/json");
			HttpResponse httpResponse = HttpManager.execute(httpGet);
			return returnResponse(httpResponse);
		} catch (Exception e) {
			Log.d("RestClient", "Error doGet " + this.uri + ": " + e.toString());
			return errorResponse("Fatal error during GET: " + this.uri);
		}
	}

	protected RestResult doPost() {
		HttpPost httpPost = new HttpPost(getSchemeServer()+this.uri);
		setupHttp(httpPost);
		try {
			StringEntity data = new StringEntity(this.data, "UTF-8");
			data.setChunked(false);
			httpPost.setEntity(data);
			httpPost.setHeader("Content-type", "application/json");
			HttpResponse httpResponse = HttpManager.execute(httpPost);
			return returnResponse(httpResponse);
		} catch (Exception e) {
			Log.d("RestClient", "Error doPost " + e.toString());
			return errorResponse("Fatal error during POST");
		}
	}

	protected RestResult errorResponse(String message) {
		RestResult result = new RestResult();
		result.ok = false;
		result.httpCode = 0;
		result.payload = message;
		return result;
	}

	protected RestResult returnResponse(HttpResponse httpResponse) {
		try {
			//mClient.close();
			RestResult result = new RestResult();
			result.httpCode = httpResponse.getStatusLine().getStatusCode();
			if (httpResponse.getEntity() != null) {
				result.payload = EntityUtils.toString(httpResponse.getEntity(), HTTP.UTF_8);
				//Log.d("HTTP", "Got response: " + result.payload);
			}
			if (result.httpCode < 200 || result.httpCode > 299) {
				result.ok = false;
				if (result.payload == null || result.payload.length() == 0) {
					if (result.httpCode >= 400 && result.httpCode < 500) {
						result.payload = "Not found";
					} else {
						result.payload = "Server error";
					}
				}
				App.DEBUG("HTTP Status: " + result.httpCode + " Body: "+ result.payload.substring(0, Math.min(50, result.payload.length()) - 1 ));
				return result;
			} else {
				//App.DEBUG(result.payload);
				result.ok = true;
			}
			return result;
		} catch (Exception e) {
			Log.d("RestClient", "Error returnResponse " + e.toString());
			return errorResponse("Fatal error in response");
		}
	}

	protected RestResult process() {
		if (data != null) {
			return doPost();
		} else {
			return doGet();
		}
	}

	public static interface RestClientListener {
		void onRestFinished(RestResult result);
	}

	private class RestTask extends AsyncTask<Void, Void, RestResult> {
		RestClient rest = null;

		public RestTask(RestClient rest) {
			this.rest = rest;
		}

		@Override
		protected RestResult doInBackground(Void... params) {
			return process();
		}

		@Override
		protected void onPostExecute(RestResult result){
			try {
				rest.finished(result);
			} catch (Exception e) {
				Log.d("RestClient", "Error onPostExecute " + e.toString());
			}
		}
	}
} public static interface RestClientListener {
	void onRestFinished(RestResult result);
} public class RestClientDelete extends RestClient {
	
	public RestClientDelete(String uri) {
		super(uri);
	}
	
	@Override
	protected RestResult doGet() {
		HttpDelete httpDelete = new HttpDelete(getSchemeServer()+this.uri);
		setupHttp(httpDelete);
		try {
			HttpResponse httpResponse = HttpManager.execute(httpDelete);
			return returnResponse(httpResponse);
		} catch (Exception e) {
			Log.d("RestClientDelete", "Error doGet (delete) " + e.toString());
			return errorResponse("Fatal error during DELETE");
		}
	}
} public class RestClientPut extends RestClient {

	public RestClientPut(String uri, String data) {
		super(uri, data);
	}

	@Override
	protected RestResult doPost() {
		HttpPut httpPut = new HttpPut(getSchemeServer()+this.uri);
		setupHttp(httpPut);
		try {
			StringEntity data = new StringEntity(this.data, "UTF-8");
			data.setChunked(false);
			httpPut.setEntity(data);
			httpPut.setHeader("Content-type", "application/json");
			HttpResponse httpResponse = HttpManager.execute(httpPut);
			return returnResponse(httpResponse);
		} catch (Exception e) {
			Log.d("RestClientFilePUT", "Error doPost: " + e.toString());
			return errorResponse("Fatal error during PUT");
		}
	}

} public class ClipPlayer implements OnPreparedListener, MediaController.MediaPlayerControl{
	MediaPlayer mPlayer;
	MediaController mController;
	String audioFilename;
	Boolean mPrepared = false;
	
	public ClipPlayer(Activity activity) {
		mController = new MediaController(activity);
		mController.setMediaPlayer(this);

		mPlayer = new MediaPlayer();
		mPlayer.setOnPreparedListener(this);
	}

	public void setAudioSource(String audioFile) {
		
		try {
			FileInputStream fileInputStream = new FileInputStream(audioFile);
			mPlayer.setDataSource(fileInputStream.getFD());
			fileInputStream.close();
			audioFilename = audioFile;
		} catch (Exception e) {
			Log.d("ClipPlayer", "Error: " + e.getMessage());
		}
		
	}

	public void setAnchorView(View view) {
		mController.setAnchorView(view);
	}
	
	public void onPrepared(MediaPlayer mp) {
		mPrepared = true;
		Handler handler = new Handler();
		handler.post(new Runnable() {
			public void run() {
				show();
			}
		});
	}

	public void prepare() {
		try {
			mPlayer.prepare();
		} catch (Exception e) {
			Log.d("ClipPlayer", "Error: " + e.getMessage());
		}
	}

	public void start() {
		if (mPrepared) {
			mPlayer.start();
		}
	}

	public void seekTo(int pos) {
		if (mPrepared) {
			mPlayer.seekTo(pos);
		}
	}

	public void pause() {
		if (mPlayer.isPlaying()) {
			mPlayer.pause();
		}
	}

	public boolean isPlaying() {
		return mPlayer.isPlaying();
	}

	public int getDuration() {
		return mPlayer.getDuration();
	}

	public int getCurrentPosition() {
		return mPlayer.getCurrentPosition();
	}

	public int getBufferPercentage() {
		return 0;
	}

	public boolean canSeekForward() {
		return false;
	}

	public boolean canSeekBackward() {
		return false;
	}

	public boolean canPause() {
		return true;
	}

	public void show() {
		if (mPrepared) {
			mController.setEnabled(true);
			mController.show();
		}
	}

	public void showHide() {
		App.DEBUG("showHide()");
		if (mPrepared && ! mController.isShowing()) {
			mController.show();
		} else {
			mController.hide();
		}
	}

	public void stop() {
		if (isPlaying()) {
			mPlayer.stop();
		}
	}
	public void reset() {
		mPlayer.reset();
	}
	
	public void release() {
		mPrepared = false;
		mPlayer.release();
		if (mController.isShowing()) {
			mController.hide();
		}
	}
} public class ImageUtils {
	static int sequence = 0;
	static public String scale(String inFileName, String outDirName, Integer maxSize) {
		String outFileName = null;

		BitmapFactory.Options o = new BitmapFactory.Options();
		o.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(inFileName, o);

		Integer max = Math.max(o.outHeight, o.outWidth);
		double scale = (double) max/maxSize;

		int sample = (int) Math.max(1,  Math.floor(scale)); 

		FileInputStream inFileStream;

		try {
			inFileStream = new FileInputStream(inFileName);
		} catch (FileNotFoundException e) {
			return null;
		}

		//Decode with inSampleSize
		BitmapFactory.Options o2 = new BitmapFactory.Options();
		o2.inSampleSize=sample;

		Bitmap bitmap;
		try {
			bitmap = BitmapFactory.decodeStream(inFileStream, null, o2);
		} catch (OutOfMemoryError e) {
			return null;
		}

		if (bitmap != null) {
			Bitmap scaledBitmap = null;
			if (scale > 1 && sample * 1.2d < scale) {
				App.DEBUG("Rescaling, scale, sample: " + scale + ", " + sample);
				int tries = 0;
				while (scaledBitmap == null && tries < 2) {
					try {
						scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int) Math.round(o.outWidth/scale), (int) Math.round(o.outHeight/scale), true);
					} catch (OutOfMemoryError e) {
						scaledBitmap = null;
						if (tries < 1) {
							System.gc();
						} else {
							App.getInstance().onLowMemory();
						}
						try {
							Thread.sleep(500);
						} catch (InterruptedException e1) {}
					}
					tries++;
				}

				if (scaledBitmap != null) {
					bitmap.recycle();
					bitmap = scaledBitmap;
				}
			}
			bitmap = rotateByExif(bitmap, inFileName);
			sequence = (sequence + 1) % 5;
			outFileName = outDirName + "/"+sequence+"_scaled.jpg";
			try {
				bitmap.compress(CompressFormat.JPEG, 70, new FileOutputStream(outFileName));
			} catch (FileNotFoundException e) {
				outFileName = null;
			} finally {
				bitmap.recycle();
			}
		}
		return outFileName;
	}
	static public Bitmap thumb(String fileName, int maxSize) {
		return thumb(fileName, maxSize, null);
	}

	static public Bitmap cachedThumb(String fileName, int maxSize, File cacheDir) {
		Bitmap bitmap;
		File thumbNail = null;

		File original = new File(fileName);
		try {
			thumbNail = new File(cacheDir, "thumb_"+maxSize+"_"+original.getName());
			bitmap = BitmapFactory.decodeFile(thumbNail.getAbsolutePath());
			if (bitmap != null) {
				return bitmap;
			}
		} catch (Exception e) {}
		return null;
	}

	static public Bitmap thumb(String fileName, int maxSize, File cacheDir) {
		File thumbNail = null;
		File original;
		Bitmap bitmap;

		if (fileName == null) {
			App.DEBUG("LoadThumbnail: null fileName");
			return null;
		}

		original = new File(fileName);

		bitmap = cachedThumb(fileName, maxSize, cacheDir);
		if (bitmap != null) {
			return bitmap;
		}

		try {
			if (cacheDir != null) {
				thumbNail = new File(cacheDir, "thumb_"+maxSize+"_"+original.getName());
			}

			BitmapFactory.Options o = new BitmapFactory.Options();
			o.inJustDecodeBounds = true;
			BitmapFactory.decodeFile(fileName, o);

			Integer max = Math.max(o.outHeight, o.outWidth);
			double scale = (double) max/maxSize;

			int sample = (int) Math.max(1,  Math.floor(scale)); 

			//Decode with inSampleSize
			BitmapFactory.Options o2 = new BitmapFactory.Options();
			o2.inSampleSize=sample;
			// AppPreferences.DEBUG("Thumb scale " + fileName + " = " + scale + " w: " + o.outWidth + " h: "  + o.outHeight + " Max: " + maxSize);
			bitmap = BitmapFactory.decodeStream(new FileInputStream(fileName), null, o2);

			if (bitmap == null) return null;

			bitmap = rotateByExif(bitmap, fileName);
			if (thumbNail != null) {
				try {
					bitmap.compress(CompressFormat.JPEG, 85, new FileOutputStream(thumbNail));
				} catch (FileNotFoundException e) {
				}
			}
			return bitmap;
		} catch (FileNotFoundException e) {
			Log.d("thumbnail", "FileNotFoundException");
			return null;
		}
	}
	static public Bitmap rotate(Bitmap image, int rotation) {
		if (rotation == 0) return image;
		Matrix matrix = new Matrix();
		matrix.postRotate(rotation);
		return Bitmap.createBitmap(image, 0, 0, 
				image.getWidth(), image.getHeight(), 
				matrix, true);
	}

	static public Bitmap rotateByExif(Bitmap bitmap, String filename) {
		int rotation = getExifRotation(filename);
		return rotate(bitmap, rotation);
	}

	static public int getExifRotation(String fileName) {
		ExifInterface exif;
		try {
			exif = new ExifInterface(fileName);
		} catch (IOException e) {
			return 0;
		}
		int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
		switch (orientation) {
		case ExifInterface.ORIENTATION_ROTATE_90:
			return 90;
		case ExifInterface.ORIENTATION_ROTATE_180:
			return 180;
		case ExifInterface.ORIENTATION_ROTATE_270:
			return 270;
		default:
			return 0;
		}

	}

	static public String getFilenameFromUri(Uri uri) {
		String[] filePathColumn = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME };
		Cursor cursor = App.getInstance().getContentResolver().query(uri, filePathColumn, null, null, null);
		cursor.moveToFirst();

		String fileName = null;

		int columnIndex;
		columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
		if (columnIndex != -1 ) {
			fileName = cursor.getString(columnIndex);
		}
		cursor.close();

		if (fileName != null && new File(fileName).canRead()) {
			return fileName;
		}

		return null;
	}

	static ImageLoader imageLoader;

	static public ImageLoader getImageLoader() {
		if (imageLoader == null) {
			imageLoader = createImageLoader();
			App.DEBUG("Creating ImageLoader");
		}
		return imageLoader;
	}


	static public DisplayImageOptions getImageLoaderOptions(Boolean fromMemory, Boolean fromDisc) {
		if (fromMemory && fromDisc) {
			return new DisplayImageOptions.Builder()
			.cacheInMemory()
			.exifRotate()
			.imageScaleType(ImageScaleType.EXACT)
			.build();
		} else if (fromDisc) {
			return new DisplayImageOptions.Builder()
			.cacheOnDisc()
			.imageScaleType(ImageScaleType.EXACT)
			.build();
		} else if (fromMemory) {
			return new DisplayImageOptions.Builder()
			.cacheInMemory()
			.exifRotate() // Not cache from disc, so we assume is local and must be rotated
			.imageScaleType(ImageScaleType.EXACT)
			.build();
		} else {
			return new DisplayImageOptions.Builder()
			.exifRotate()
			.imageScaleType(ImageScaleType.EXACT)
			.build();
		}
	}

	static ImageLoader createImageLoader() {
		int width;
		int height;

		WindowManager wm = (WindowManager) App.getInstance().getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();

		width = display.getWidth();
		height = display.getHeight();

		if (height > width) {
			int tmp;
			tmp = width;
			width = height;
			height = tmp;
		}

		File dir =  new File(App.getInstance().getMyCacheDir().getAbsolutePath() + "/.universaldownloader");
		dir.mkdir();

		/** TODO: it doesn't work in API < 13
			Point size = new Point();
			display.getSize(size);
			width = size.x;
			height = size.y;
		 **/


		// Get singleton instance of ImageLoader
		ImageLoader imageLoader = ImageLoader.getInstance();
		DisplayImageOptions options = new DisplayImageOptions.Builder()
		.cacheInMemory()
		//.cacheOnDisc()
		//.decodingType(DecodingType.FAST)
		.imageScaleType(ImageScaleType.POWER_OF_2)
		.build();

		long memoryClass = ((ActivityManager) App.getInstance().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
		int megaBytes;

		if (memoryClass < 32) {
			megaBytes = 1;
		} else if (memoryClass <= 48) {
			megaBytes = 2;
		} else {
			megaBytes = 4;
		}
		App.DEBUG("Memory for images cache: " + megaBytes);

		// Create configuration for ImageLoader (all options are optional)
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(App.getInstance())
		.memoryCache(new LRULimitedMemoryCache(megaBytes * 1024 * 1024))
		.memoryCacheExtraOptions(Math.min((int) (width * 0.9), 800), Math.min((int) (height * 0.9), 800))
		//.discCacheExtraOptions(Math.min((int) (width * 0.9), 600), Math.min((int) (height * 0.9), 900), CompressFormat.JPEG, 85)
		.threadPoolSize(4)
		.threadPriority(Thread.MIN_PRIORITY + 2)
		.denyCacheImageMultipleSizesInMemory()
		.offOutOfMemoryHandling()
		.discCache(new FileCountLimitedDiscCache(dir, 2000)) // You can pass your own disc cache implementation
		.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
		.defaultDisplayImageOptions(options)
		.imageDownloader(new URLConnectionImageDownloader(10 * 1000, 20 * 1000))
		.build();

		// Initialize ImageLoader with created configuration. Do it once.
		imageLoader.init(config);

		return imageLoader;

	}

	static public void clearImageLoaderCache() {
		if (imageLoader != null) {
			imageLoader.clearMemoryCache();
			System.gc();
		}
	}

	static public void clearImageLoader() {
		if (imageLoader != null) {
			imageLoader.clearMemoryCache();
			imageLoader.stop();
			imageLoader = null;
			System.gc();
		}
	}

} public class LazyProgressDialog extends ProgressDialog {
	Activity mActivity;
	public LazyProgressDialog(Activity activity) {
		super(activity);
		mActivity = activity;
	}
	public static LazyProgressDialog show (Activity context, CharSequence title, CharSequence message, boolean indeterminate) {
		return show(context, title, message, indeterminate, false, null);
	}

	public static LazyProgressDialog show (Activity context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable) {
		return show(context, title, message, indeterminate, cancelable, null);
	}

	public static LazyProgressDialog show (Activity context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable, DialogInterface.OnCancelListener cancelListener) {
		LazyProgressDialog d = new LazyProgressDialog(context);
		d.setTitle(title);
		d.setMessage(message);
		d.setIndeterminate(indeterminate);
		d.setCancelable(cancelable);
		if (cancelListener != null) d.setOnCancelListener(cancelListener);
		d.show();
		return d;
	}
	
	
	public void onStart() {
		int orientation = App.getInstance().getResources().getConfiguration().orientation;
		if(orientation == Configuration.ORIENTATION_LANDSCAPE) {
			mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		} else if(orientation == Configuration.ORIENTATION_PORTRAIT) {
			mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		} else {
			mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
		}
	}

	protected void onStop() {
		mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
	}
	
	@Override
	public void dismiss() {
		try {
			super.dismiss();
		} catch (Exception e) {}
	}
}
import java.io.File;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.preference.PreferenceManager;
import android.speech.RecognizerIntent;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.ShareActionProvider;
import com.google.gson.Gson;
import com.spokenpic.net.JsonData.ClipData;
import com.spokenpic.net.JsonData.ClipDataChangeStatus;
import com.spokenpic.net.JsonData.RestResult;
import com.spokenpic.net.RestClient;
import com.spokenpic.net.RestClient.RestClientListener;
import com.spokenpic.net.RestClientDelete;
import com.spokenpic.net.RestClientPut;
import com.spokenpic.utils.ClipPlayer;
import com.spokenpic.utils.ImageUtils;
import com.spokenpic.utils.LazyProgressDialog;
/**
 * SpokenPic Java source code 
 * @author Ricardo Galli (gallir@gmail.com)
 * @copyright: Menéame & APSL, 2012
 * @license: GPL3
 */

package com.spokenpic;




/**
 * @author gallir
 *
 */
public class ViewClip extends SherlockActivity {
	final int VOICE_RECOGNITION = 100;

	static final String TAG = "ViewImage";
	private ImageView mImageView;
	private MenuItem mWebButton;
	private MenuItem mUploadButton;
	private MenuItem mPrivateButton;
	private MenuItem mShareButton;
	private EditText mTitleEdit;
	private ImageView mSpeechButtton;
	private ImageView mCancelButtton;
	private ClipPlayer mPlayer;
	private Model mModel;
	private String imageFileName = null;
	private String audioFileName = null;
	private long mSessionId;
	private ShareActionProvider mShareActionProvider;
	private boolean mReturnToCreator = false;
	private String mPreviousTitle = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.view_image);

		//App.getInstance().loadPreferences();

		getSupportActionBar().setHomeButtonEnabled(true);
		//getSupportActionBar().setDisplayShowTitleEnabled(false);

		Bundle intentExtras = getIntent().getExtras();

		mImageView = (ImageView) findViewById(R.id.imageView);
		mImageView.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if (mTitleEdit.hasFocus()) {
					mTitleEdit.clearFocus();
					// hide virtual keyboard
					InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.hideSoftInputFromWindow(mTitleEdit.getWindowToken(), 0);
				} else {
					if (mPlayer != null) {
						mPlayer.showHide();
					}
				}
			}
		});

		mTitleEdit = (EditText) findViewById(R.id.editTitle);
		mSpeechButtton = (ImageView) findViewById(R.id.micButton);
		mCancelButtton = (ImageView) findViewById(R.id.cancelButton);
		mCancelButtton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				String tmp;
				tmp = mTitleEdit.getText().toString();
				if (mModel.mTitle != null && ! mModel.mTitle.equals(tmp)) {
					mTitleEdit.setText(mModel.mTitle);

				} else if (mPreviousTitle != null && ! mPreviousTitle.equals(tmp)){
					mTitleEdit.setText(mPreviousTitle);
				}
				mPreviousTitle = tmp;
			}
		});


		if (intentExtras != null) {
			mSessionId = intentExtras.getLong("id");
			if (mSessionId <= 0) {
				finish();
				return;
			}

			mModel = new Model(mSessionId);
			if (mModel.mId <= 0) { // Not found
				finish();
				return;
			}

			imageFileName = mModel.getImage();
			audioFileName = mModel.getAudio();

			if (imageFileName == null || ! (new File(imageFileName)).canRead()) {
				// Bad clip, delete it and finish
				mModel.delete();
				finish();
			}

			if (intentExtras.getLong("new") > 0) {
				// It a new clip, do a ping
				RestClient c = new RestClient("/ping/");