2012-07-13 18:06:24 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-08-02 17:33:44 +00:00
|
|
|
import org.mozilla.gecko.util.ActivityResultHandler;
|
|
|
|
|
2012-07-13 18:06:24 +00:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.provider.MediaStore;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2013-05-10 01:48:00 +00:00
|
|
|
import java.util.Queue;
|
2012-07-28 00:53:54 +00:00
|
|
|
|
2012-07-13 18:06:24 +00:00
|
|
|
class CameraVideoResultHandler implements ActivityResultHandler {
|
|
|
|
private static final String LOGTAG = "GeckoCameraVideoResultHandler";
|
|
|
|
|
2013-05-10 01:48:00 +00:00
|
|
|
private final Queue<String> mFilePickerResult;
|
2013-05-29 15:08:55 +00:00
|
|
|
private final ActivityHandlerHelper.FileResultHandler mHandler;
|
2012-07-13 18:06:24 +00:00
|
|
|
|
2013-05-10 01:48:00 +00:00
|
|
|
CameraVideoResultHandler(Queue<String> resultQueue) {
|
2012-07-13 18:06:24 +00:00
|
|
|
mFilePickerResult = resultQueue;
|
2013-05-29 15:08:55 +00:00
|
|
|
mHandler = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use this constructor to asynchronously listen for results */
|
|
|
|
public CameraVideoResultHandler(ActivityHandlerHelper.FileResultHandler handler) {
|
|
|
|
mFilePickerResult = null;
|
|
|
|
mHandler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendResult(String res) {
|
|
|
|
if (mFilePickerResult != null)
|
|
|
|
mFilePickerResult.offer(res);
|
|
|
|
|
|
|
|
if (mHandler != null)
|
|
|
|
mHandler.gotFile(res);
|
2012-07-13 18:06:24 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-07-13 18:06:24 +00:00
|
|
|
public void onActivityResult(int resultCode, Intent data) {
|
2013-05-10 01:48:00 +00:00
|
|
|
if (data == null || resultCode != Activity.RESULT_OK) {
|
2013-05-29 15:08:55 +00:00
|
|
|
sendResult("");
|
2013-05-10 01:48:00 +00:00
|
|
|
return;
|
2012-07-13 18:06:24 +00:00
|
|
|
}
|
2013-05-10 01:48:00 +00:00
|
|
|
|
2013-05-24 16:21:01 +00:00
|
|
|
Cursor cursor = GeckoAppShell.getGeckoInterface().getActivity().managedQuery(data.getData(),
|
2013-05-10 01:48:00 +00:00
|
|
|
new String[] { MediaStore.Video.Media.DATA },
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
cursor.moveToFirst();
|
2013-05-29 15:08:55 +00:00
|
|
|
|
|
|
|
sendResult(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)));
|
2012-07-13 18:06:24 +00:00
|
|
|
}
|
|
|
|
}
|