Search in sources :

Example 11 with StoragePathProvider

use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.

the class FormUtils method setupReferenceManagerForForm.

/**
 * Configures the given reference manager to resolve jr:// URIs to a folder in the root ODK forms
 * directory with name matching the name of the directory represented by {@code formMediaDir}.
 * <p>
 * E.g. if /foo/bar/baz is passed in as {@code formMediaDir}, jr:// URIs will be resolved to
 * projectRoot/forms/baz.
 */
public static void setupReferenceManagerForForm(ReferenceManager referenceManager, File formMediaDir) {
    referenceManager.reset();
    // Always build URIs against the project root, regardless of the absolute path of formMediaDir
    referenceManager.addReferenceFactory(new FileReferenceFactory(new StoragePathProvider().getProjectRootDirPath()));
    addSessionRootTranslators(referenceManager, buildSessionRootTranslators(formMediaDir.getName(), enumerateHostStrings()));
}
Also used : StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) FileReferenceFactory(org.odk.collect.android.logic.FileReferenceFactory)

Example 12 with StoragePathProvider

use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.

the class DrawView method setupView.

public void setupView(boolean isSignature) {
    this.isSignature = isSignature;
    bitmapPaint = new Paint(Paint.DITHER_FLAG);
    currentPath = new Path();
    offscreenPath = new Path();
    backgroundBitmapFile = new File(new StoragePathProvider().getTmpImageFilePath());
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setColor(currentColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeWidth(10);
    pointPaint = new Paint();
    pointPaint.setAntiAlias(true);
    pointPaint.setDither(true);
    pointPaint.setColor(currentColor);
    pointPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    pointPaint.setStrokeWidth(10);
}
Also used : Path(android.graphics.Path) StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) Paint(android.graphics.Paint) File(java.io.File)

Example 13 with StoragePathProvider

use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.

the class FormIndexSavepointTest method saveAndReadFormIndexTest.

@Test
public void saveAndReadFormIndexTest() {
    String instanceName = "test.xml";
    // for loadFormIndexFromFile
    File instancePath = new File(new StoragePathProvider().getOdkDirPath(StorageSubdirectory.INSTANCES) + File.separator + instanceName);
    when(formController.getInstanceFile()).thenReturn(instancePath);
    Collect.getInstance().setFormController(formController);
    FormIndex originalFormIndex = FormIndex.createBeginningOfFormIndex();
    File indexFile = SaveFormToDisk.getFormIndexFile(instanceName);
    SaveFormIndexTask.exportFormIndexToFile(originalFormIndex, indexFile);
    FormIndex readFormIndex = SaveFormIndexTask.loadFormIndexFromFile();
    assertEquals(originalFormIndex, readFormIndex);
    assertNotNull(readFormIndex);
    assertEquals(originalFormIndex.getReference(), readFormIndex.getReference());
}
Also used : StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) FormIndex(org.javarosa.core.model.FormIndex) File(java.io.File) Test(org.junit.Test)

Example 14 with StoragePathProvider

use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.

the class FormUtilsTest method sessionRootTranslatorOrderDoesNotMatter.

/* Verify that each host string matches only a single root translator, allowing for them to
     be defined in any order. See: https://github.com/getodk/collect/issues/3334
    */
@Test
public void sessionRootTranslatorOrderDoesNotMatter() throws Exception {
    final String formPath = new StoragePathProvider().getOdkDirPath(StorageSubdirectory.FORMS) + File.separator + BASIC_FORM;
    // Load the form in order to populate the ReferenceManager
    FormLoaderTask formLoaderTask = new FormLoaderTask(formPath, null, null);
    formLoaderTask.execute(formPath).get();
    final File formXml = new File(formPath);
    final File formMediaDir = FileUtils.getFormMediaDir(formXml);
    List<RootTranslator> rootTranslators = FormUtils.buildSessionRootTranslators(formMediaDir.getName(), FormUtils.enumerateHostStrings());
    // Check each type of host string to determine that only one match is resolved.
    for (String hostString : FormUtils.enumerateHostStrings()) {
        String uri = String.format("jr://%s/test", hostString);
        int matchCount = 0;
        for (RootTranslator rootTranslator : rootTranslators) {
            if (rootTranslator.derives(uri)) {
                matchCount++;
            }
        }
        Assert.assertEquals("Expected only a single match for URI: " + uri, 1, matchCount);
    }
}
Also used : StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) File(java.io.File) RootTranslator(org.javarosa.core.reference.RootTranslator) FormLoaderTask(org.odk.collect.android.tasks.FormLoaderTask) Test(org.junit.Test)

Example 15 with StoragePathProvider

use of org.odk.collect.android.storage.StoragePathProvider in project collect by opendatakit.

the class ItemsetDbAdapter method dropTable.

public void dropTable(String pathHash, String path) {
    // drop the table
    db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE + pathHash);
    // and remove the entry from the itemsets table
    String where = KEY_PATH + "=?";
    String[] whereArgs = { PathUtils.getRelativeFilePath(new StoragePathProvider().getOdkDirPath(StorageSubdirectory.FORMS), path) };
    db.delete(ITEMSET_TABLE, where, whereArgs);
}
Also used : StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider)

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