Skip to content

Commit

Permalink
Merge branch 'release/2.0.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Inigo Lopez de Heredia committed Nov 13, 2014
2 parents b383705 + b93026f commit 4c82f42
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 37 deletions.
8 changes: 7 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Akvo FLOW app
Last update 05 November 2014
Last update 12 November 2014

#ver 2.0.5.1

New and noteworthy
------------------
* Barcode questions allow batch scans, storing multiple, concatenated values in the same question response [#211]

#ver 2.0.5

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.akvo.flow"
android:versionCode="1"
android:versionName="2.0.5" >
android:versionName="2.0.5.1" >

<uses-sdk
android:minSdkVersion="10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ public void startElement(String uri, String localName, String name,
currentQuestion.setIsDoubleEntry(false);
}

// 'allowMultiple' flag can be found at the <question> and <options> scopes. In option
// questions, the latter will be used. For the rest, the flag will be set in <question>
currentQuestion.setAllowMultiple(Boolean.parseBoolean(attributes.getValue(ALLOW_MULT)));

currentQuestion.setType(attributes.getValue(TYPE));
currentQuestion.setId(attributes.getValue(ID));
String validation = attributes.getValue(VALIDATION_TYPE);
Expand Down
133 changes: 105 additions & 28 deletions app/src/main/java/org/akvo/flow/ui/view/BarcodeQuestionView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@
package org.akvo.flow.ui.view;

import android.content.Context;
import android.os.Build;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import org.akvo.flow.R;
import org.akvo.flow.domain.Question;
import org.akvo.flow.domain.QuestionResponse;
import org.akvo.flow.event.QuestionInteractionEvent;
import org.akvo.flow.event.SurveyListener;
import org.akvo.flow.util.ConstantUtil;
import org.akvo.flow.util.ViewUtil;

/**
* Question to handle scanning of a barcode. This question relies on the zxing
Expand All @@ -41,8 +45,11 @@
*/
public class BarcodeQuestionView extends QuestionView implements OnClickListener,
OnFocusChangeListener {
private Button mBarcodeButton;
private EditText mBarcodeText;
private EditText mInputText;
private ImageButton mAddBtn;
private Button mScanBtn;
private LinearLayout mInputContainer;
private boolean mMultiple;

public BarcodeQuestionView(Context context, Question q, SurveyListener surveyListener) {
super(context, q, surveyListener);
Expand All @@ -52,39 +59,82 @@ public BarcodeQuestionView(Context context, Question q, SurveyListener surveyLis
private void init() {
setQuestionView(R.layout.barcode_question_view);

mBarcodeButton = (Button)findViewById(R.id.scan_btn);
mBarcodeText = (EditText)findViewById(R.id.barcode_et);
mMultiple = getQuestion().isAllowMultiple();

mBarcodeText.setOnFocusChangeListener(this);
mBarcodeButton.setOnClickListener(this);
mInputContainer = (LinearLayout)findViewById(R.id.input_ll);
mScanBtn = (Button)findViewById(R.id.scan_btn);
mAddBtn = (ImageButton)findViewById(R.id.add_btn);
mInputText = (EditText)findViewById(R.id.input_text);

if (isReadOnly()) {
mBarcodeButton.setEnabled(false);
mBarcodeText.setEnabled(false);
if (isReadOnly() && mMultiple) {
mInputText.setVisibility(View.GONE);
}
if (isReadOnly() || !mMultiple) {
mAddBtn.setVisibility(View.GONE);
}
// Barcode scanning crashes API 7 app, at least on Emulator
// ECLAIR_MR1 has code 7, but as we build against 6, it does not know
// this name yet
if (Build.VERSION.SDK_INT <= 7) {
// Maybe change button text as well?
mBarcodeButton.setEnabled(false);
mScanBtn.setEnabled(!isReadOnly());
mInputText.setFocusable(!isReadOnly());

mInputText.setOnFocusChangeListener(this);
mScanBtn.setOnClickListener(this);
mAddBtn.setOnClickListener(this);
}

private void addValue(final String text) {
LayoutInflater inflater = LayoutInflater.from(getContext());
final View view = inflater.inflate(R.layout.barcode_item, mInputContainer, false);
((EditText)view.findViewById(R.id.input)).setText(text);
ImageButton btn = (ImageButton)view.findViewById(R.id.delete);
if (isReadOnly()) {
btn.setVisibility(View.GONE);
} else {
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ViewUtil.showConfirmDialog(R.string.deleteresponse, R.string.clear_value_msg,
getContext(), true, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mInputContainer.removeView(view);
captureResponse();
}
});
}
});
}

mInputContainer.addView(view);
captureResponse();
}

/**
* handle the action button click
*/
public void onClick(View v) {
notifyQuestionListeners(QuestionInteractionEvent.SCAN_BARCODE_EVENT);
switch (v.getId()) {
case R.id.scan_btn:
notifyQuestionListeners(QuestionInteractionEvent.SCAN_BARCODE_EVENT);
break;
case R.id.add_btn:
final String value = mInputText.getText().toString();
if (!TextUtils.isEmpty(value)) {
addValue(value);
mInputText.setText("");
}
break;
}
}

@Override
public void questionComplete(Bundle barcodeData) {
if (barcodeData != null) {
mBarcodeText.setText(barcodeData.getString(ConstantUtil.BARCODE_CONTENT));
setResponse(new QuestionResponse(
barcodeData.getString(ConstantUtil.BARCODE_CONTENT),
ConstantUtil.VALUE_RESPONSE_TYPE, getQuestion().getId()));
String value = barcodeData.getString(ConstantUtil.BARCODE_CONTENT);
if (mMultiple) {
addValue(value);
} else {
mInputText.setText(value);
}
captureResponse();
}
}

Expand All @@ -95,8 +145,18 @@ public void questionComplete(Bundle barcodeData) {
@Override
public void rehydrate(QuestionResponse resp) {
super.rehydrate(resp);
if (resp != null && resp.getValue() != null) {
mBarcodeText.setText(resp.getValue());
mInputContainer.removeAllViews();
mInputText.setText("");
String answer = resp != null ? resp.getValue() : null;
if (!TextUtils.isEmpty(answer)) {
if (mMultiple) {
String[] values = answer.split("\\|", -1);
for (String value : values) {
addValue(value);
}
} else {
mInputText.setText(answer);
}
}
}

Expand All @@ -106,7 +166,8 @@ public void rehydrate(QuestionResponse resp) {
@Override
public void resetQuestion(boolean fireEvent) {
super.resetQuestion(fireEvent);
mBarcodeText.setText("");
mInputContainer.removeAllViews();
mInputText.setText("");
}

/**
Expand All @@ -126,9 +187,25 @@ public void onFocusChange(View view, boolean hasFocus) {
* possibly suppressing listeners
*/
public void captureResponse(boolean suppressListeners) {
setResponse(new QuestionResponse(mBarcodeText.getText().toString(),
ConstantUtil.VALUE_RESPONSE_TYPE, getQuestion().getId()),
suppressListeners);
StringBuilder builder = new StringBuilder();
if (mMultiple) {
for (int i=0; i<mInputContainer.getChildCount(); i++) {
View v = mInputContainer.getChildAt(i);
String value = ((EditText)v.findViewById(R.id.input)).getText().toString();
if (!TextUtils.isEmpty(value)) {
builder.append(value);
if (i < mInputContainer.getChildCount() - 1) {
builder.append("|");
}
}
}
}
String value = mInputText.getText().toString();
if (!TextUtils.isEmpty(value)) {
builder.append(value);
}
setResponse(new QuestionResponse(builder.toString(), ConstantUtil.VALUE_RESPONSE_TYPE,
getQuestion().getId()), suppressListeners);
}

}
Binary file added app/src/main/res/drawable-hdpi/ic_add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions app/src/main/res/layout/barcode_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<EditText
android:id="@+id/input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:focusable="false"
android:singleLine="true"
android:layout_weight="1"/>

<ImageButton
android:id="@+id/delete"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ic_trash"/>

</LinearLayout>
51 changes: 44 additions & 7 deletions app/src/main/res/layout/barcode_question_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,53 @@

<include layout="@layout/question_header" />

<Button
android:id="@+id/scan_btn"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/input_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/scanbarcode" />
android:orientation="vertical">
</LinearLayout>

<EditText
android:id="@+id/barcode_et"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ImageButton
android:id="@+id/add_btn"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:src="@drawable/ic_add" />

<EditText
android:id="@+id/input_text"
android:layout_toLeftOf="@id/add_btn"
android:layout_toStartOf="@id/add_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:hint="@string/type_code"
android:imeOptions="actionDone" />

</RelativeLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone" />
android:gravity="center"
android:text="@string/or"
android:textSize="12sp"
android:textColor="@color/black_diabled" />

<Button
android:id="@+id/scan_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/scanbarcode" />

</merge>
8 changes: 8 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ Version</string>
<string name="reg_form_warning_title">Encuestra de registro</string>
<string name="reg_form_warning_text">El Punto de Datos ya contiene una respuesta para este formulario. Si se crea una nueva respuesta se usarán esos valores como los más recientes. ¿Desea continuar?</string>
<string name="error_img_preview">La imagen no pude ser cargada</string>
<string name="use_external_source">Utilizar aplicación externa</string>
<string name="error_empty_form">Un formulario sin respuestas no puede ser enviado. Por favor, responda a las preguntas antes de enviar.</string>
<string name="clear_value_msg">¿Está seguro de que quiere borrar este valor?</string>
<string name="type_code">introducir código</string>
<string name="or">o</string>
<!--RecordList Activity-->
<string name="create_data_point">CREAR NUEVO PUNTO DE DATOS</string>
<string name="stats_title">Estadísticas del proyecto.</string>
Expand Down Expand Up @@ -193,6 +197,10 @@ Version</string>
<string name="updatedownloaded">La nueva versión de FLOW ha sido descargada</string>
<string name="clicktoinstall">La nueva versión de FLOW está descargada. ¿Quiere instalarla ahora?</string>
<string name="apk_upgrade_error">Error descargando la actualización de FLOW</string>
<!--Time check-->
<string name="time_check_activity">Fecha y hora</string>
<string name="time_warning">¡La hora de su dispositivo no es correcta! Ajuste la hora y vuelta a intentar. La hora local de su dispositivo es:</string>
<string name="adjust_date">Ajustar hora</string>
<!--Misc-->
<string name="okbutton">OK</string>
<string name="cancelbutton">Cancelar</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@
<string name="reg_form_warning_title">Questionnaire d\'enregistrement</string>
<string name="reg_form_warning_text">Ce point contient déjà une réponse pour ce formulaire. Toute nouvelle réponse sera considérée comme la plus récente. Voulez-vous continuer?</string>
<string name="error_img_preview">Impossible de charger l\'image</string>
<string name="use_external_source">Utiliser source externe</string>
<string name="error_empty_form">Les formulaires vides ne peuvent être envoyés. Veuillez répondre aux questions.</string>
<string name="clear_value_msg">Voulez-vous supprimer cette valeur?</string>
<string name="type_code">entrez code</string>
<string name="or">ou</string>
<!--RecordList Activity-->
<string name="create_data_point">CRÉER UN NOUVEAU POINT</string>
<string name="stats_title">Statistiques du projet</string>
Expand Down Expand Up @@ -190,6 +194,10 @@
<string name="updatedownloaded">La mise à jour de FLOW a été téléchargé</string>
<string name="clicktoinstall">La mise à jour est téléchargée. Voulez vous l\'installer maintenant?</string>
<string name="apk_upgrade_error">Erreur lors du téléchargement de la mise à jour de FLOW.</string>
<!--Time check-->
<string name="time_check_activity">Date et heure</string>
<string name="time_warning">Votre date de téléphone est inexacte! Réglez votre horloge et essayer à nouveau. Votre date et l\'heure téléphone est le:</string>
<string name="adjust_date">Ajuster heure</string>
<!--Misc-->
<string name="okbutton">OK</string>
<string name="cancelbutton">Annuler</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
<string name="error_img_preview">Can\'t load image preview</string>
<string name="use_external_source">Use External Source</string>
<string name="error_empty_form">Empty forms cannot be submitted. Please, add the corresponding responses first.</string>
<string name="clear_value_msg">Do you want to delete this value?</string>
<string name="type_code">type code</string>
<string name="or">or</string>
<!-- RecordList Activity -->
<string name="create_data_point">CREATE NEW DATA POINT</string>
<string name="stats_title">Project Stats</string>
Expand Down

0 comments on commit 4c82f42

Please sign in to comment.