forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CameraImageResultHandler.java
54 lines (42 loc) · 1.7 KB
/
CameraImageResultHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* 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;
import org.mozilla.gecko.util.ActivityResultHandler;
import android.app.Activity;
import android.content.Intent;
import android.os.Environment;
import android.text.format.Time;
import android.util.Log;
import java.io.File;
import java.util.concurrent.SynchronousQueue;
class CameraImageResultHandler implements ActivityResultHandler {
private static final String LOGTAG = "GeckoCameraImageResultHandler";
private final SynchronousQueue<String> mFilePickerResult;
CameraImageResultHandler(SynchronousQueue<String> resultQueue) {
mFilePickerResult = resultQueue;
}
@Override
public void onActivityResult(int resultCode, Intent data) {
try {
if (resultCode != Activity.RESULT_OK) {
mFilePickerResult.put("");
return;
}
File file = new File(Environment.getExternalStorageDirectory(), sImageName);
sImageName = "";
mFilePickerResult.put(file.getAbsolutePath());
} catch (InterruptedException e) {
Log.i(LOGTAG, "error returning file picker result", e);
}
}
// this code is really hacky and doesn't belong anywhere so I'm putting it here for now
// until I can come up with a better solution.
private static String sImageName = "";
static String generateImageName() {
Time now = new Time();
now.setToNow();
sImageName = now.format("%Y-%m-%d %H.%M.%S") + ".jpg";
return sImageName;
}
}