Skip to content

Commit

Permalink
Add documentation and replace deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Feb 12, 2020
1 parent 3bab0f9 commit ad14148
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ View setUpNoButtonsView(int index) {
String errorMsg = null;
if (imageURI != null) {
try {
final File imageFile = new File(ReferenceManager.instance().DeriveReference(imageURI).getLocalURI());
final File imageFile = new File(ReferenceManager.instance().deriveReference(imageURI).getLocalURI());
if (imageFile.exists()) {
Bitmap bitmap = FileUtils.getBitmap(imageFile.getPath(), new BitmapFactory.Options());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void onImageClick() {

private void openImage() {
try {
File bigImage = new File(referenceManager.DeriveReference(bigImageURI).getLocalURI());
File bigImage = new File(referenceManager.deriveReference(bigImageURI).getLocalURI());
Intent intent = new Intent("android.intent.action.VIEW");
Uri uri =
FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider", bigImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ private FormUtils() {

}

/**
* 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}.
*
* E.g. if /foo/bar/baz is passed in as {@code formMediaDir}, jr:// URIs will be resolved to
* /odk/root/forms/baz.
*/
public static void setupReferenceManagerForForm(ReferenceManager referenceManager, File formMediaDir) {

// Remove previous forms
// Clear mappings to the media dir for the previous form that was configured
referenceManager.clearSession();

// This should get moved to the Application Class
if (referenceManager.getFactories().length == 0) {
// this is /sdcard/odk
// Always build URIs against the ODK root, regardless of the absolute path of formMediaDir
referenceManager.addReferenceFactory(new FileReferenceFactory(new StoragePathProvider().getDirPath(StorageSubdirectory.ODK)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ private String processOneForm(int total, int count, FormDetails fd) throws TaskC
final long start = System.currentTimeMillis();
Timber.w("Parsing document %s", fileResult.file.getAbsolutePath());

// Add a stub last-saved instance to the tmp media directory so it will be resolved
// when parsing a form definition with last-saved reference
File tmpLastSaved = new File(tempMediaPath, LAST_SAVED_FILENAME);
write(tmpLastSaved, STUB_XML.getBytes(Charset.forName("UTF-8")));
ReferenceManager.instance().reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private View setUpNoButtonsItem(int index) {
String errorMsg = null;
if (imageURI != null) {
try {
final File imageFile = new File(ReferenceManager.instance().DeriveReference(imageURI).getLocalURI());
final File imageFile = new File(ReferenceManager.instance().deriveReference(imageURI).getLocalURI());
if (imageFile.exists()) {
Bitmap b = FileUtils.getBitmapScaledToDisplay(imageFile, ScreenUtils.getScreenHeight(), ScreenUtils.getScreenWidth());
if (b != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void addItems(Context context, QuestionDetails questionDetails) {
if (imageURI != null) {
try {
String imageFilename =
ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
ReferenceManager.instance().deriveReference(imageURI).getLocalURI();
final File imageFile = new File(imageFilename);
if (imageFile.exists()) {
Bitmap b = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.odk.collect.android.widgets;

import java.io.File;
import java.util.HashMap;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
Expand All @@ -11,9 +8,9 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

Expand All @@ -32,6 +29,9 @@
import org.odk.collect.android.utilities.FileUtils;
import org.odk.collect.android.utilities.ViewIds;

import java.io.File;
import java.util.HashMap;

import timber.log.Timber;

import static android.widget.RelativeLayout.CENTER_HORIZONTAL;
Expand Down Expand Up @@ -288,7 +288,7 @@ public String setImageFromOtherSource(String imageURI, ImageView imageView) {
String errorMsg = null;
try {
String imageFilename =
ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
ReferenceManager.instance().deriveReference(imageURI).getLocalURI();
final File imageFile = new File(imageFilename);
if (imageFile.exists()) {
Bitmap b = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (imageURI != null) {
try {
String imageFilename =
ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
ReferenceManager.instance().deriveReference(imageURI).getLocalURI();
final File imageFile = new File(imageFilename);
if (imageFile.exists()) {
Bitmap b = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public ListWidget(Context context, QuestionDetails questionDetails, boolean disp
if (imageURI != null) {
try {
String imageFilename =
ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
ReferenceManager.instance().deriveReference(imageURI).getLocalURI();
final File imageFile = new File(imageFilename);
if (imageFile.exists()) {
Bitmap b = null;
Expand Down

0 comments on commit ad14148

Please sign in to comment.