diff --git a/android/src/main/java/org/openforis/collect/android/gui/input/ImageFileAttributeComponent.java b/android/src/main/java/org/openforis/collect/android/gui/input/ImageFileAttributeComponent.java index bcaaf0d..7a14316 100644 --- a/android/src/main/java/org/openforis/collect/android/gui/input/ImageFileAttributeComponent.java +++ b/android/src/main/java/org/openforis/collect/android/gui/input/ImageFileAttributeComponent.java @@ -115,55 +115,50 @@ private void rotateImage() { private void setupCaptureButton() { captureButton = inputView.findViewById(R.id.file_attribute_capture); - if (canCapture()) { - captureButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - Runnable captureImageRunnable = new Runnable() { - public void run() { - capture(); - } - }; - if (file != null && file.exists()) { - Dialogs.confirm(context, R.string.warning, R.string.file_attribute_captured_file_overwrite_confirm_message, - captureImageRunnable, null, R.string.overwrite_label, android.R.string.cancel); - } else { - captureImageRunnable.run(); + captureButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Runnable captureImageRunnable = new Runnable() { + public void run() { + capture(); } + }; + if (file != null && file.exists()) { + Dialogs.confirm(context, R.string.warning, R.string.file_attribute_captured_file_overwrite_confirm_message, + captureImageRunnable, null, R.string.overwrite_label, android.R.string.cancel); + } else { + captureImageRunnable.run(); } - }); - } else { - captureButton.setVisibility(View.GONE); - } - } - - protected boolean canCapture() { - Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - return takePictureIntent.resolveActivity(context.getPackageManager()) != null; + } + }); } protected void capture() { - Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - if (takePictureIntent.resolveActivity(context.getPackageManager()) != null && - Permissions.checkCameraPermissionOrRequestIt(context)) { - ((SurveyNodeActivity) context).setImageChangedListener(this); - Uri imageUri; - if (AndroidVersion.greaterThan20()) { - // Create temp file and store image there - File imageFile = createTempImageFile(); - if (imageFile == null) { - Toast.makeText(context, R.string.file_attribute_capture_image_error_creating_temp_file, Toast.LENGTH_SHORT).show(); - return; + try { + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + if (Permissions.checkCameraPermissionOrRequestIt(context)) { + ((SurveyNodeActivity) context).setImageChangedListener(this); + Uri imageUri; + if (AndroidVersion.greaterThan20()) { + // Create temp file and store image there + File imageFile = createTempImageFile(); + if (imageFile == null) { + Toast.makeText(context, R.string.file_attribute_capture_image_error_creating_temp_file, Toast.LENGTH_SHORT).show(); + return; + } + imageUri = AndroidFiles.getUriForFile(context, imageFile); + } else { + // Store image directly to "file" + //TODO find nicer solution to prevent FileUriExposedException + StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); + StrictMode.setVmPolicy(builder.build()); + imageUri = Uri.fromFile(file); } - imageUri = AndroidFiles.getUriForFile(context, imageFile); - } else { - // Store image directly to "file" - //TODO find nicer solution to prevent FileUriExposedException - StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); - StrictMode.setVmPolicy(builder.build()); - imageUri = Uri.fromFile(file); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); + context.startActivityForResult(takePictureIntent, SurveyNodeActivity.IMAGE_CAPTURE_REQUEST_CODE); } - takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); - context.startActivityForResult(takePictureIntent, SurveyNodeActivity.IMAGE_CAPTURE_REQUEST_CODE); + } catch (Exception e) { + String errorMessage = context.getString(R.string.file_attribute_capture_image_error, e.getMessage()); + Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show(); } } diff --git a/android/src/main/java/org/openforis/collect/android/gui/input/VideoFileAttributeComponent.java b/android/src/main/java/org/openforis/collect/android/gui/input/VideoFileAttributeComponent.java index 195c033..174b68c 100644 --- a/android/src/main/java/org/openforis/collect/android/gui/input/VideoFileAttributeComponent.java +++ b/android/src/main/java/org/openforis/collect/android/gui/input/VideoFileAttributeComponent.java @@ -23,12 +23,6 @@ public VideoFileAttributeComponent(UiFileAttribute attribute, SurveyService surv super(attribute, surveyService, context); } - @Override - protected boolean canCapture() { - Intent takePictureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); - return takePictureIntent.resolveActivity(context.getPackageManager()) != null; - } - @Override protected void capture() { if (Permissions.checkCameraPermissionOrRequestIt(context)) { diff --git a/android/src/main/java/org/openforis/collect/android/gui/list/EntityListAdapter.java b/android/src/main/java/org/openforis/collect/android/gui/list/EntityListAdapter.java index b960072..b4225b5 100644 --- a/android/src/main/java/org/openforis/collect/android/gui/list/EntityListAdapter.java +++ b/android/src/main/java/org/openforis/collect/android/gui/list/EntityListAdapter.java @@ -107,6 +107,14 @@ public View getView(int position, View convertView, ViewGroup parent) { return row; } + @Override + public void setSelectionEnabled(boolean selectionEnabled) { + super.setSelectionEnabled(selectionEnabled); + if (!selectionEnabled && actionMode != null) { + actionMode.finish(); + } + } + public List getSummaryAttributes(UiNode node) { return UiNodes.getSummaryAttributes(node); } @@ -152,9 +160,9 @@ protected int layoutResourceId() { } protected void onPrepareView(final UiNode node, View row) { - final CheckBox checkbox = (CheckBox) row.findViewById(R.id.nodeSelectedForAction); + final CheckBox checkbox = row.findViewById(R.id.nodeSelectedForAction); Definition parentDef = node.getParent().getDefinition(); - if (!isSelectionEnabled() || + if ((!(node instanceof UiRecord.Placeholder) && !isSelectionEnabled()) || (parentDef instanceof UiEntityCollectionDefinition && ((UiEntityCollectionDefinition) parentDef).isEnumerated()) ) {