Search in sources :

Example 6 with StoragePathProvider

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();
}
Also used : StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) Activity(android.app.Activity)

Example 7 with StoragePathProvider

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);
    }
}
Also used : StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Before(org.junit.Before)

Example 8 with StoragePathProvider

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()));
}
Also used : Bitmap(android.graphics.Bitmap) StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) FileOutputStream(java.io.FileOutputStream) Instrumentation(android.app.Instrumentation) File(java.io.File) Test(org.junit.Test)

Example 9 with StoragePathProvider

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");
}
Also used : StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) Test(org.junit.Test)

Example 10 with StoragePathProvider

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;
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) Form(org.odk.collect.forms.Form) UploadException(org.odk.collect.android.upload.UploadException) FormsRepositoryProvider(org.odk.collect.android.utilities.FormsRepositoryProvider) LocalizedApplicationKt.getLocalizedString(org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString) File(java.io.File) TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement)

Aggregations

StoragePathProvider (org.odk.collect.android.storage.StoragePathProvider)19 File (java.io.File)10 Test (org.junit.Test)5 FileOutputStream (java.io.FileOutputStream)3 Bitmap (android.graphics.Bitmap)2 Activity (android.app.Activity)1 Instrumentation (android.app.Instrumentation)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 Paint (android.graphics.Paint)1 Path (android.graphics.Path)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 View (android.view.View)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 OvershootInterpolator (android.view.animation.OvershootInterpolator)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 CardView (androidx.cardview.widget.CardView)1 FloatingActionButton (com.google.android.material.floatingactionbutton.FloatingActionButton)1