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()));
}
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);
}
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());
}
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);
}
}
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);
}
Aggregations