use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.
the class Camera2VideoFragment method setUpMediaRecorder.
private void setUpMediaRecorder() throws IOException {
final Activity activity = getActivity();
if (null == activity) {
return;
}
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
if (nextVideoAbsolutePath == null || nextVideoAbsolutePath.isEmpty()) {
nextVideoAbsolutePath = new StoragePathProvider().getTmpVideoFilePath();
}
mediaRecorder.setOutputFile(nextVideoAbsolutePath);
mediaRecorder.setVideoEncodingBitRate(10000000);
mediaRecorder.setVideoFrameRate(30);
mediaRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
switch(sensorOrientation) {
case SENSOR_ORIENTATION_DEFAULT_DEGREES:
mediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
break;
case SENSOR_ORIENTATION_INVERSE_DEGREES:
mediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
break;
}
mediaRecorder.prepare();
}
use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.
the class ExternalDataReaderTest method setUp.
@Before
public void setUp() throws IOException {
CollectHelpers.setupDemoProject();
File formFile = new File(new StoragePathProvider().getOdkDirPath(StorageSubdirectory.FORMS) + File.separator + SIMPLE_SEARCH_EXTERNAL_CSV_FORM_FILENAME);
File mediaDir = FileUtils.getFormMediaDir(formFile);
mediaDir.mkdir();
csvFile = new File(mediaDir + File.separator + SIMPLE_SEARCH_EXTERNAL_CSV_FILENAME);
dbFile = new File(mediaDir + File.separator + SIMPLE_SEARCH_EXTERNAL_DB_FILENAME);
formDefToCsvMedia = makeExternalDataMap();
try (InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("forms" + File.separator + SIMPLE_SEARCH_EXTERNAL_CSV_FORM_FILENAME);
OutputStream output = new FileOutputStream(formFile)) {
IOUtils.copy(input, output);
}
try (InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("media" + File.separator + SIMPLE_SEARCH_EXTERNAL_CSV_FILENAME);
OutputStream output = new FileOutputStream(csvFile)) {
IOUtils.copy(input, output);
}
}
use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.
the class FieldListUpdateTest method questionsAppearingBeforeCurrentBinaryQuestion_ShouldNotChangeFocus.
@Test
public void questionsAppearingBeforeCurrentBinaryQuestion_ShouldNotChangeFocus() throws IOException {
jumpToGroupWithText("Push off screen binary");
onView(withText(startsWith("Source10"))).perform(click());
onView(withText("Target10-15")).check(doesNotExist());
// FormEntryActivity expects an image at a fixed path so copy the app logo there
Bitmap icon = BitmapFactory.decodeResource(ApplicationProvider.getApplicationContext().getResources(), R.drawable.notes);
File tmpJpg = new File(new StoragePathProvider().getTmpImageFilePath());
tmpJpg.createNewFile();
FileOutputStream fos = new FileOutputStream(tmpJpg);
icon.compress(Bitmap.CompressFormat.JPEG, 90, fos);
intending(not(isInternal())).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, null));
onView(withId(R.id.capture_image)).perform(click());
onView(withText("Target10-15")).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
onView(withId(R.id.capture_image)).check(matches(isCompletelyDisplayed()));
}
use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.
the class ExternalDataFileNotFoundTest method questionsThatUseExternalFiles_ShouldDisplayFriendlyMessageWhenFilesAreMissing.
@Test
public void questionsThatUseExternalFiles_ShouldDisplayFriendlyMessageWhenFilesAreMissing() {
String formsDirPath = new StoragePathProvider().getOdkDirPath(StorageSubdirectory.FORMS);
activityTestRule.startInFormEntry().assertText(R.string.file_missing, formsDirPath + "/external_data_questions-media/fruits.csv").swipeToNextQuestion("External csv").assertText(R.string.file_missing, formsDirPath + "/external_data_questions-media/itemsets.csv");
}
use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.
the class InstanceGoogleSheetsUploader method uploadOneSubmission.
@Override
public String uploadOneSubmission(Instance instance, String spreadsheetUrl) throws UploadException {
File instanceFile = new File(instance.getInstanceFilePath());
if (!instanceFile.exists()) {
throw new UploadException(FAIL + "instance XML file does not exist!");
}
// Get corresponding blank form and verify there is exactly 1
List<Form> forms = new FormsRepositoryProvider(Collect.getInstance()).get().getAllByFormIdAndVersion(instance.getFormId(), instance.getFormVersion());
try {
if (forms.size() != 1) {
throw new UploadException(getLocalizedString(Collect.getInstance(), R.string.not_exactly_one_blank_form_for_this_form_id));
}
Form form = forms.get(0);
if (form.getBASE64RSAPublicKey() != null) {
submissionComplete(instance, false);
throw new UploadException(getLocalizedString(Collect.getInstance(), R.string.google_sheets_encrypted_message));
}
String formFilePath = PathUtils.getAbsoluteFilePath(new StoragePathProvider().getOdkDirPath(StorageSubdirectory.FORMS), form.getFormFilePath());
TreeElement instanceElement = getInstanceElement(formFilePath, instanceFile);
setUpSpreadsheet(spreadsheetUrl);
sheetsHelper.updateSpreadsheetLocaleForNewSpreadsheet(spreadsheet.getSpreadsheetId(), spreadsheet.getSheets().get(0).getProperties().getTitle());
if (hasRepeatableGroups(instanceElement)) {
createSheetsIfNeeded(instanceElement);
}
String key = getInstanceID(getChildElements(instanceElement, false));
if (key == null) {
key = PropertyUtils.genUUID();
}
insertRows(instance, instanceElement, null, key, instanceFile, spreadsheet.getSheets().get(0).getProperties().getTitle());
} catch (UploadException e) {
submissionComplete(instance, false);
throw e;
} catch (GoogleJsonResponseException e) {
submissionComplete(instance, false);
throw new UploadException(getErrorMessageFromGoogleJsonResponseException(e));
}
submissionComplete(instance, true);
// Google Sheets can't provide a custom success message
return null;
}
Aggregations