Commit 9c0003f7 authored by Jeffrey I. Schiller's avatar Jeffrey I. Schiller

Fix indentation on Camcorder.java

Change-Id: Ie79734f6ba20a8ef3676c262028514627a1e7879
parent 6008ee02
...@@ -26,125 +26,123 @@ import java.util.Date; ...@@ -26,125 +26,123 @@ import java.util.Date;
*/ */
@DesignerComponent(version = YaVersion.CAMCORDER_COMPONENT_VERSION, @DesignerComponent(version = YaVersion.CAMCORDER_COMPONENT_VERSION,
description = "A component to record a video using the device's camcorder." + description = "A component to record a video using the device's camcorder." +
"After the video is recorded, the name of the file on the phone " + "After the video is recorded, the name of the file on the phone " +
"containing the clip is available as an argument to the " + "containing the clip is available as an argument to the " +
"AfterRecording event. The file name can be used, for example, to set " + "AfterRecording event. The file name can be used, for example, to set " +
"the source property of a VideoPlayer component.", "the source property of a VideoPlayer component.",
category = ComponentCategory.MEDIA, category = ComponentCategory.MEDIA,
nonVisible = true, nonVisible = true,
iconName = "images/camcorder.png") iconName = "images/camcorder.png")
@SimpleObject @SimpleObject
public class Camcorder extends AndroidNonvisibleComponent public class Camcorder extends AndroidNonvisibleComponent
implements ActivityResultListener, Component { implements ActivityResultListener, Component {
private static final String CAMCORDER_INTENT = "android.media.action.VIDEO_CAPTURE"; private static final String CAMCORDER_INTENT = "android.media.action.VIDEO_CAPTURE";
private static final String CAMCORDER_OUTPUT = "output"; private static final String CAMCORDER_OUTPUT = "output";
private final ComponentContainer container; private final ComponentContainer container;
private Uri clipFile; private Uri clipFile;
/* Used to identify the call to startActivityForResult. Will be passed back /* Used to identify the call to startActivityForResult. Will be passed back
into the resultReturned() callback method. */ into the resultReturned() callback method. */
private int requestCode; private int requestCode;
/** /**
* Creates a Camcorder component. * Creates a Camcorder component.
* *
* @param container container, component will be placed in * @param container container, component will be placed in
*/ */
public Camcorder(ComponentContainer container) { public Camcorder(ComponentContainer container) {
super(container.$form()); super(container.$form());
this.container = container; this.container = container;
} }
/** /**
* Records a video, then raises the AfterRecoding event. * Records a video, then raises the AfterRecoding event.
*/ */
@SimpleFunction @SimpleFunction
public void RecordVideo() { public void RecordVideo() {
Date date = new Date(); Date date = new Date();
String state = Environment.getExternalStorageState(); String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) { if (Environment.MEDIA_MOUNTED.equals(state)) {
Log.i("CamcorderComponent", "External storage is available and writable"); Log.i("CamcorderComponent", "External storage is available and writable");
clipFile = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), clipFile = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
"/Video/app_inventor_" + date.getTime() "/Video/app_inventor_" + date.getTime()
+ ".3gp")); + ".3gp"));
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(MediaStore.Video.Media.DATA, clipFile.getPath()); values.put(MediaStore.Video.Media.DATA, clipFile.getPath());
values.put(MediaStore.Video.Media.MIME_TYPE, "clip/3gp"); values.put(MediaStore.Video.Media.MIME_TYPE, "clip/3gp");
values.put(MediaStore.Video.Media.TITLE, clipFile.getLastPathSegment()); values.put(MediaStore.Video.Media.TITLE, clipFile.getLastPathSegment());
if (requestCode == 0) { if (requestCode == 0) {
requestCode = form.registerForActivityResult(this); requestCode = form.registerForActivityResult(this);
} }
Uri clipUri = container.$context().getContentResolver().insert( Uri clipUri = container.$context().getContentResolver().insert(
MediaStore.Video.Media.INTERNAL_CONTENT_URI, values); MediaStore.Video.Media.INTERNAL_CONTENT_URI, values);
Intent intent = new Intent(CAMCORDER_INTENT); Intent intent = new Intent(CAMCORDER_INTENT);
intent.putExtra(CAMCORDER_OUTPUT, clipUri); intent.putExtra(CAMCORDER_OUTPUT, clipUri);
container.$context().startActivityForResult(intent, requestCode); container.$context().startActivityForResult(intent, requestCode);
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
form.dispatchErrorOccurredEvent(this, "RecordVideo", form.dispatchErrorOccurredEvent(this, "RecordVideo",
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_READONLY); ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_READONLY);
} else { } else {
form.dispatchErrorOccurredEvent(this, "RecordVideo", form.dispatchErrorOccurredEvent(this, "RecordVideo",
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_NOT_AVAILABLE); ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_NOT_AVAILABLE);
} }
} }
@Override @Override
public void resultReturned(int requestCode, int resultCode, Intent data) { public void resultReturned(int requestCode, int resultCode, Intent data) {
Log.i("CamcorderComponent", Log.i("CamcorderComponent",
"Returning result. Request code = " + requestCode + ", result code = " + resultCode); "Returning result. Request code = " + requestCode + ", result code = " + resultCode);
if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) { if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) {
File clip = new File(clipFile.getPath()); File clip = new File(clipFile.getPath());
if (clip.length() != 0) { if (clip.length() != 0) {
AfterRecording(clipFile.toString()); AfterRecording(clipFile.toString());
} else { } else {
deleteFile(clipFile); // delete empty file deleteFile(clipFile); // delete empty file
// see if something useful got returned in the data // see if something useful got returned in the data
if (data != null && data.getData() != null) { if (data != null && data.getData() != null) {
Uri tryClipUri = data.getData(); Uri tryClipUri = data.getData();
Log.i("CamcorderComponent", "Calling Camcorder.AfterPicture with clip path " Log.i("CamcorderComponent", "Calling Camcorder.AfterPicture with clip path "
+ tryClipUri.toString()); + tryClipUri.toString());
AfterRecording(tryClipUri.toString()); AfterRecording(tryClipUri.toString());
} else { } else {
Log.i("CamcorderComponent", "Couldn't find a clip file from the Camcorder result"); Log.i("CamcorderComponent", "Couldn't find a clip file from the Camcorder result");
form.dispatchErrorOccurredEvent(this, "TakeVideo", form.dispatchErrorOccurredEvent(this, "TakeVideo",
ErrorMessages.ERROR_CAMCORDER_NO_CLIP_RETURNED); ErrorMessages.ERROR_CAMCORDER_NO_CLIP_RETURNED);
} }
} }
} else { } else {
// delete empty file // delete empty file
deleteFile(clipFile); deleteFile(clipFile);
} }
} }
private void deleteFile(Uri fileUri) { private void deleteFile(Uri fileUri) {
File fileToDelete = new File(fileUri.getPath()); File fileToDelete = new File(fileUri.getPath());
try { try {
if (fileToDelete.delete()) { if (fileToDelete.delete()) {
Log.i("CamcorderComponent", "Deleted file " + fileUri.toString()); Log.i("CamcorderComponent", "Deleted file " + fileUri.toString());
} else { } else {
Log.i("CamcorderComponent", "Could not delete file " + fileUri.toString()); Log.i("CamcorderComponent", "Could not delete file " + fileUri.toString());
} }
} catch (SecurityException e) { } catch (SecurityException e) {
Log.i("CamcorderComponent", "Got security exception trying to delete file " Log.i("CamcorderComponent", "Got security exception trying to delete file "
+ fileUri.toString()); + fileUri.toString());
} }
} }
/** /**
* Indicates that a video was recorded with the camera and provides the path to * Indicates that a video was recorded with the camera and provides the path to
* the stored picture. * the stored picture.
*/ */
@SimpleEvent @SimpleEvent
public void AfterRecording(String clip) { public void AfterRecording(String clip) {
EventDispatcher.dispatchEvent(this, "AfterRecording", clip); EventDispatcher.dispatchEvent(this, "AfterRecording", clip);
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment