2012-07-13 11:06:24 -07: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 10:33:44 -07:00
|
|
|
import org.mozilla.gecko.util.ActivityResultHandler;
|
|
|
|
|
2012-07-13 11:06:24 -07:00
|
|
|
import android.app.Activity;
|
2013-11-01 12:21:35 -07:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
|
|
|
import android.support.v4.app.LoaderManager;
|
|
|
|
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
|
|
|
import android.support.v4.content.CursorLoader;
|
|
|
|
import android.support.v4.content.Loader;
|
2012-07-13 11:06:24 -07:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.database.Cursor;
|
2013-11-01 12:21:35 -07:00
|
|
|
import android.os.Bundle;
|
2012-07-13 11:06:24 -07:00
|
|
|
import android.provider.MediaStore;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2013-05-09 18:48:00 -07:00
|
|
|
import java.util.Queue;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2012-07-13 11:06:24 -07:00
|
|
|
class CameraVideoResultHandler implements ActivityResultHandler {
|
|
|
|
private static final String LOGTAG = "GeckoCameraVideoResultHandler";
|
|
|
|
|
2013-05-09 18:48:00 -07:00
|
|
|
private final Queue<String> mFilePickerResult;
|
2013-05-29 08:08:55 -07:00
|
|
|
private final ActivityHandlerHelper.FileResultHandler mHandler;
|
2012-07-13 11:06:24 -07:00
|
|
|
|
2013-05-09 18:48:00 -07:00
|
|
|
CameraVideoResultHandler(Queue<String> resultQueue) {
|
2012-07-13 11:06:24 -07:00
|
|
|
mFilePickerResult = resultQueue;
|
2013-05-29 08:08:55 -07: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 11:06:24 -07:00
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-11-01 12:21:35 -07:00
|
|
|
public void onActivityResult(int resultCode, final Intent data) {
|
2013-11-01 12:21:33 -07:00
|
|
|
// Intent.getData() can return null. Avoid a crash. See bug 904551.
|
|
|
|
if (data == null || data.getData() == null || resultCode != Activity.RESULT_OK) {
|
2013-05-29 08:08:55 -07:00
|
|
|
sendResult("");
|
2013-05-09 18:48:00 -07:00
|
|
|
return;
|
2012-07-13 11:06:24 -07:00
|
|
|
}
|
2013-05-09 18:48:00 -07:00
|
|
|
|
2013-11-01 12:21:35 -07:00
|
|
|
final FragmentActivity fa = (FragmentActivity) GeckoAppShell.getGeckoInterface().getActivity();
|
|
|
|
final LoaderManager lm = fa.getSupportLoaderManager();
|
|
|
|
lm.initLoader(data.hashCode(), null, new LoaderCallbacks<Cursor>() {
|
|
|
|
@Override
|
|
|
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
|
|
|
return new CursorLoader(fa,
|
|
|
|
data.getData(),
|
|
|
|
new String[] { MediaStore.Video.Media.DATA },
|
|
|
|
null, // selection
|
|
|
|
null, // selectionArgs
|
|
|
|
null); // sortOrder
|
|
|
|
}
|
2013-05-29 08:08:55 -07:00
|
|
|
|
2013-11-01 12:21:35 -07:00
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
sendResult(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)));
|
|
|
|
} else {
|
|
|
|
sendResult("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> loader) { }
|
|
|
|
});
|
2012-07-13 11:06:24 -07:00
|
|
|
}
|
|
|
|
}
|