From 1ef18f5f47ee2d6df3c0ef044b4973ee558eb1e1 Mon Sep 17 00:00:00 2001 From: Telmo Barros Date: Thu, 8 Dec 2016 15:52:59 +0000 Subject: [PATCH] capture video and upload directly on app --- .../ui/activity/BrowserActivity.java | 46 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 2 files changed, 48 insertions(+) diff --git a/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java index 726a95eda..ab5d7e52b 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java @@ -1077,6 +1077,8 @@ else if (which == 2) // upload file pickFile(); else if (which == 3) // take a photo CameraTakePhoto(); + else if (which == 4) // capture a video + CameraCaptureVideo(); } }).show(); } @@ -1153,6 +1155,26 @@ private void CameraTakePhoto() { } } + private File captureCameraVideoTempFile; + + private void CameraCaptureVideo() { + Intent videoCaptureIntent = new Intent("android.media.action.VIDEO_CAPTURE"); + + try { + File VideoDir = DataManager.createTempDir(); + + String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".mp4"; + captureCameraVideoTempFile = new File(VideoDir, fileName); + + Uri video = Uri.fromFile(captureCameraVideoTempFile); + videoCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, video); + startActivityForResult(videoCaptureIntent, CAPTURE_VIDEO_REQUEST); + + } catch (IOException e) { + showShortToast(BrowserActivity.this, R.string.unknow_error); + } + } + public void enableUpButton() { getSupportActionBar().setDisplayHomeAsUpEnabled(true); setSupportActionBar(getActionBarToolbar()); @@ -1219,6 +1241,7 @@ private void refreshViewOnSlideTabs(int position) { public static final int TAKE_PHOTO_REQUEST = 4; public static final int CHOOSE_COPY_MOVE_DEST_REQUEST = 5; public static final int DOWNLOAD_FILE_REQUEST = 6; + public static final int CAPTURE_VIDEO_REQUEST = 7; public boolean hasRepoWritePermission() { if (navContext == null) { @@ -1359,6 +1382,29 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } break; + case CAPTURE_VIDEO_REQUEST: + if (resultCode == RESULT_OK) { + showShortToast(this, getString(R.string.capture_video_successfully)); + if (!Utils.isNetworkOn()) { + showShortToast(this, R.string.network_down); + return; + } + + if(captureCameraVideoTempFile == null) { + showShortToast(this, getString(R.string.saf_upload_path_not_available)); + Log.i(DEBUG_TAG, "Pick file request did not return a path"); + return; + } + showShortToast(this, getString(R.string.added_to_upload_tasks)); + final SeafRepo repo = dataManager.getCachedRepoByID(navContext.getRepoID()); + if (repo != null && repo.canLocalDecrypt()) { + addUploadBlocksTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), captureCameraVideoTempFile.getAbsolutePath(), repo.encVersion); + } else { + addUploadTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), captureCameraVideoTempFile.getAbsolutePath()); + } + + } + break; case DOWNLOAD_FILE_REQUEST: if (resultCode == RESULT_OK) { File file = new File(data.getStringExtra("path")); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 546fee598..44baa8090 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -148,6 +148,7 @@ Create folder Upload file Take a photo + Capture a video Create a new library Successfully created library %s @@ -186,6 +187,7 @@ Uploading started Photo uploading started Take photo successfully + Capture video successfully Libraries Activities Starred