Skip to content

Commit

Permalink
Hide buttons if a question is readonly (getodk#2563)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 authored and lognaturel committed Oct 9, 2018
1 parent 9a227b6 commit 2f9c0d2
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public boolean isNullAnswer() {

private void createDateButton() {
dateButton = getSimpleButton(getContext().getString(R.string.select_date));
dateButton.setEnabled(!getFormEntryPrompt().isReadOnly());
}

private void addViews() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,13 @@ protected void setUpLayout() {
}

captureButton = getSimpleButton(getContext().getString(R.string.capture_image), R.id.capture_image);
captureButton.setEnabled(!getFormEntryPrompt().isReadOnly());

chooseButton = getSimpleButton(getContext().getString(R.string.choose_image), R.id.choose_image);
chooseButton.setEnabled(!getFormEntryPrompt().isReadOnly());

answerLayout.addView(captureButton);
answerLayout.addView(chooseButton);
answerLayout.addView(errorTextView);

// and hide the capture and choose button if read-only
if (getFormEntryPrompt().isReadOnly()) {
captureButton.setVisibility(View.GONE);
chooseButton.setVisibility(View.GONE);
}
errorTextView.setVisibility(View.GONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,14 @@ public AnnotateWidget(Context context, FormEntryPrompt prompt) {
protected void setUpLayout() {
super.setUpLayout();
captureButton = getSimpleButton(getContext().getString(R.string.capture_image), R.id.capture_image);
captureButton.setEnabled(!getFormEntryPrompt().isReadOnly());

chooseButton = getSimpleButton(getContext().getString(R.string.choose_image), R.id.choose_image);
chooseButton.setEnabled(!getFormEntryPrompt().isReadOnly());

annotateButton = getSimpleButton(getContext().getString(R.string.markup_image), R.id.markup_image);
annotateButton.setEnabled(!(binaryName == null || getFormEntryPrompt().isReadOnly()));
annotateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageClickHandler.clickImage("annotateButton");
}
});
if (binaryName == null) {
annotateButton.setEnabled(false);
}
annotateButton.setOnClickListener(v -> imageClickHandler.clickImage("annotateButton"));

answerLayout.addView(captureButton);
answerLayout.addView(chooseButton);
Expand All @@ -100,9 +95,7 @@ public Intent addExtrasToIntent(Intent intent) {
@Override
public void clearAnswer() {
super.clearAnswer();
if (!getFormEntryPrompt().isReadOnly()) {
annotateButton.setEnabled(false);
}
annotateButton.setEnabled(false);

// reset buttons
captureButton.setText(getContext().getString(R.string.capture_image));
Expand Down Expand Up @@ -146,11 +139,7 @@ public void denied() {
}

private void hideButtonsIfNeeded() {
if (getFormEntryPrompt().isReadOnly()) {
captureButton.setVisibility(View.GONE);
chooseButton.setVisibility(View.GONE);
annotateButton.setVisibility(View.GONE);
} else if (getFormEntryPrompt().getAppearanceHint() != null
if (getFormEntryPrompt().getAppearanceHint() != null
&& getFormEntryPrompt().getAppearanceHint().toLowerCase(Locale.ENGLISH).contains("new")) {
chooseButton.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ public AudioWidget(Context context, FormEntryPrompt prompt) {
this.audioController = audioController;

captureButton = getSimpleButton(getContext().getString(R.string.capture_audio), R.id.capture_audio);
captureButton.setEnabled(!prompt.isReadOnly());

chooseButton = getSimpleButton(getContext().getString(R.string.choose_sound), R.id.choose_sound);
chooseButton.setEnabled(!prompt.isReadOnly());

audioController.init(context, getPlayer(), getFormEntryPrompt());

Expand Down Expand Up @@ -197,10 +195,7 @@ public void setBinaryData(Object object) {
}

private void hideButtonsIfNeeded() {
if (getFormEntryPrompt().isReadOnly()) {
captureButton.setVisibility(View.GONE);
chooseButton.setVisibility(View.GONE);
} else if (getFormEntryPrompt().getAppearanceHint() != null
if (getFormEntryPrompt().getAppearanceHint() != null
&& getFormEntryPrompt().getAppearanceHint().toLowerCase(Locale.ENGLISH).contains("new")) {
chooseButton.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public BarcodeWidget(Context context, FormEntryPrompt prompt) {
super(context, prompt);

getBarcodeButton = getSimpleButton(getContext().getString(R.string.get_barcode));
getBarcodeButton.setEnabled(!prompt.isReadOnly());

stringAnswer = getCenteredAnswerTextView();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.text.InputType;
import android.text.method.DigitsKeyListener;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -66,10 +65,6 @@ public BearingWidget(Context context, FormEntryPrompt prompt) {
answer.setBackground(null);

getBearingButton = getSimpleButton(getContext().getString(R.string.get_bearing));
getBearingButton.setEnabled(!prompt.isReadOnly());
if (prompt.isReadOnly()) {
getBearingButton.setVisibility(View.GONE);
}

answerLayout.addView(getBearingButton);
answerLayout.addView(answer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@ public DrawWidget(Context context, FormEntryPrompt prompt) {
protected void setUpLayout() {
super.setUpLayout();
drawButton = getSimpleButton(getContext().getString(R.string.draw_image));
drawButton.setEnabled(!getFormEntryPrompt().isReadOnly());

answerLayout.addView(drawButton);
answerLayout.addView(errorTextView);

if (getFormEntryPrompt().isReadOnly()) {
drawButton.setVisibility(View.GONE);
}
errorTextView.setVisibility(View.GONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ public ExPrinterWidget(Context context, FormEntryPrompt prompt) {
String buttonText = (v != null) ? v : context.getString(R.string.launch_printer);
launchIntentButton = getSimpleButton(buttonText);

if (prompt.isReadOnly()) {
launchIntentButton.setEnabled(false);
}

// finish complex layout
LinearLayout printLayout = new LinearLayout(getContext());
printLayout.setOrientation(LinearLayout.VERTICAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public ExStringWidget(Context context, FormEntryPrompt prompt) {
String buttonText = (v != null) ? v : context.getString(R.string.launch_app);

launchIntentButton = getSimpleButton(buttonText);
launchIntentButton.setEnabled(!getFormEntryPrompt().isReadOnly());

// finish complex layout
LinearLayout answerLayout = new LinearLayout(getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public GeoPointWidget(Context context, FormEntryPrompt prompt) {
viewButton = getSimpleButton(getContext().getString(R.string.get_point), R.id.get_point);

getLocationButton = getSimpleButton(R.id.get_location);
getLocationButton.setEnabled(!prompt.isReadOnly());

// finish complex layout
// control what gets shown with setVisibility(View.GONE)
Expand All @@ -138,8 +137,6 @@ private void updateButtonLabelsAndVisibility(boolean dataAvailable) {
// for maps, we show the view button.

if (useMapsV2 && useMaps) {
// show the GetLocation button
getLocationButton.setVisibility(View.VISIBLE);
// hide the view button
viewButton.setVisibility(View.GONE);
if (readOnly) {
Expand All @@ -155,11 +152,7 @@ private void updateButtonLabelsAndVisibility(boolean dataAvailable) {
}
}
} else {
// if it is read-only, hide the get-location button...
if (readOnly) {
getLocationButton.setVisibility(View.GONE);
} else {
getLocationButton.setVisibility(View.VISIBLE);
if (!readOnly) {
getLocationButton.setText(getContext().getString(
dataAvailable ? R.string.change_location : R.string.get_point));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ public GeoShapeWidget(Context context, FormEntryPrompt prompt) {

createShapeButton = getSimpleButton(getContext().getString(R.string.get_shape));

if (prompt.isReadOnly()) {
createShapeButton.setEnabled(false);
}

LinearLayout answerLayout = new LinearLayout(getContext());
answerLayout.setOrientation(LinearLayout.VERTICAL);
answerLayout.addView(createShapeButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ public GeoTraceWidget(Context context, FormEntryPrompt prompt) {

createTraceButton = getSimpleButton(getContext().getString(R.string.get_trace));

if (prompt.isReadOnly()) {
createTraceButton.setEnabled(false);
}

LinearLayout answerLayout = new LinearLayout(getContext());
answerLayout.setOrientation(LinearLayout.VERTICAL);
answerLayout.addView(createTraceButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ public ImageWebViewWidget(Context context, FormEntryPrompt prompt) {
errorTextView.setText(R.string.selected_invalid_image);

captureButton = getSimpleButton(getContext().getString(R.string.capture_image), R.id.capture_image);
captureButton.setEnabled(!prompt.isReadOnly());

chooseButton = getSimpleButton(getContext().getString(R.string.choose_image), R.id.choose_image);
chooseButton.setEnabled(!prompt.isReadOnly());

// finish complex layout
LinearLayout answerLayout = new LinearLayout(getContext());
Expand All @@ -99,11 +97,6 @@ public ImageWebViewWidget(Context context, FormEntryPrompt prompt) {
answerLayout.addView(chooseButton);
answerLayout.addView(errorTextView);

// and hide the capture and choose button if read-only
if (prompt.isReadOnly()) {
captureButton.setVisibility(View.GONE);
chooseButton.setVisibility(View.GONE);
}
errorTextView.setVisibility(View.GONE);

// retrieve answer from data model and update ui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ protected void setUpLayout() {
|| appearance.equalsIgnoreCase("new-front"));

captureButton = getSimpleButton(getContext().getString(R.string.capture_image), R.id.capture_image);
captureButton.setEnabled(!getFormEntryPrompt().isReadOnly());

chooseButton = getSimpleButton(getContext().getString(R.string.choose_image), R.id.choose_image);
chooseButton.setEnabled(!getFormEntryPrompt().isReadOnly());

answerLayout.addView(captureButton);
answerLayout.addView(chooseButton);
Expand Down Expand Up @@ -137,10 +135,7 @@ public void denied() {
}

private void hideButtonsIfNeeded(String appearance) {
if (getFormEntryPrompt().isReadOnly()) {
captureButton.setVisibility(View.GONE);
chooseButton.setVisibility(View.GONE);
} else if (selfie || ((appearance != null
if (selfie || ((appearance != null
&& appearance.toLowerCase(Locale.ENGLISH).contains("new")))) {
chooseButton.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public OSMWidget(Context context, FormEntryPrompt prompt) {
} else {
launchOpenMapKitButton.setText(getContext().getString(R.string.capture_osm));
}
launchOpenMapKitButton.setEnabled(!prompt.isReadOnly());

osmFileNameHeaderTextView = new TextView(context);
osmFileNameHeaderTextView.setId(ViewIds.generateViewId());
Expand Down Expand Up @@ -133,10 +132,6 @@ public OSMWidget(Context context, FormEntryPrompt prompt) {
answerLayout.addView(osmFileNameTextView);
addAnswerView(answerLayout);

// Hide Launch button if read-only
if (prompt.isReadOnly()) {
launchOpenMapKitButton.setVisibility(View.GONE);
}
errorTextView.setVisibility(View.GONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,27 +514,28 @@ public void stopAudio() {
}

protected Button getSimpleButton(String text, @IdRes final int withId) {
final QuestionWidget questionWidget = this;
final Button button = new Button(getContext());

button.setId(withId);
button.setText(text);
button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, getAnswerFontSize());
button.setPadding(20, 20, 20, 20);
if (getFormEntryPrompt().isReadOnly()) {
button.setVisibility(GONE);
} else {
button.setId(withId);
button.setText(text);
button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, getAnswerFontSize());
button.setPadding(20, 20, 20, 20);

TableLayout.LayoutParams params = new TableLayout.LayoutParams();
params.setMargins(7, 5, 7, 5);
TableLayout.LayoutParams params = new TableLayout.LayoutParams();
params.setMargins(7, 5, 7, 5);

button.setLayoutParams(params);
button.setLayoutParams(params);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
button.setOnClickListener(v -> {
if (Collect.allowClick()) {
((ButtonWidget) questionWidget).onButtonClick(withId);
((ButtonWidget) this).onButtonClick(withId);
}
}
});
});
}

return button;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,8 @@ public RangeWidget(Context context, FormEntryPrompt prompt) {
setUpWidgetParameters();
setUpAppearance();

if (prompt.isReadOnly()) {
if (isPickerAppearance) {
pickerButton.setEnabled(false);
} else {
seekBar.setEnabled(false);
}
if (prompt.isReadOnly() && !isPickerAppearance) {
seekBar.setEnabled(false);
}

addAnswerView(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ public SignatureWidget(Context context, FormEntryPrompt prompt) {
protected void setUpLayout() {
super.setUpLayout();
signButton = getSimpleButton(getContext().getString(R.string.sign_button));
signButton.setEnabled(!getFormEntryPrompt().isReadOnly());

answerLayout.addView(signButton);
answerLayout.addView(errorTextView);

// and hide the sign button if read-only
if (getFormEntryPrompt().isReadOnly()) {
signButton.setVisibility(View.GONE);
}
errorTextView.setVisibility(View.GONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ public SpinnerMultiWidget(final Context context, FormEntryPrompt prompt) {
selectionText = getAnswerTextView();
selectionText.setVisibility(View.GONE);

if (prompt.isReadOnly()) {
button.setEnabled(false);
}

// Fill in previous answers
List<Selection> ve = new ArrayList<>();
if (prompt.getAnswerValue() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public void cancelLongPress() {

private void createTimeButton() {
timeButton = getSimpleButton(getContext().getString(R.string.select_time));
timeButton.setEnabled(!getFormEntryPrompt().isReadOnly());
}

private void addViews() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public UrlWidget(Context context, FormEntryPrompt prompt) {
super(context, prompt);

openUrlButton = getSimpleButton(context.getString(R.string.open_url));
openUrlButton.setEnabled(!prompt.isReadOnly());

stringAnswer = getCenteredAnswerTextView();

Expand Down
Loading

0 comments on commit 2f9c0d2

Please sign in to comment.