r83 - in trunk: assets src/fr/ifremer/wlo/utils
Author: kmorin Date: 2014-03-27 11:20:09 +0100 (Thu, 27 Mar 2014) New Revision: 83 Url: http://forge.codelutin.com/projects/wlo/repository/revisions/83 Log: fixes #4805 les mesures au cm inf?\195?\169rieur : 25.8 s'enregistre 26 au lieu de 25 Modified: trunk/assets/ref_import_calcified_part_takings.csv trunk/src/fr/ifremer/wlo/utils/UIUtils.java trunk/src/fr/ifremer/wlo/utils/WloItemListViewBinder.java Modified: trunk/assets/ref_import_calcified_part_takings.csv =================================================================== --- trunk/assets/ref_import_calcified_part_takings.csv 2014-03-18 16:15:11 UTC (rev 82) +++ trunk/assets/ref_import_calcified_part_takings.csv 2014-03-27 10:20:09 UTC (rev 83) @@ -1,6 +1,6 @@ Espece_scientifique;Classe_debut;Classe_fin;Pas_de_classe;Pas;Arret -AAPT;10;200;1;5;Inf -AAPT;201;400;1;2;Inf -AAPT;401;Inf;1;1;Inf +AAPT;10;200;10;5;Inf +AAPT;201;400;10;2;Inf +AAPT;401;Inf;10;1;Inf AAPTAAP;5;Inf;5;2;5 ABAL;10;Inf;10;5;2 \ No newline at end of file Modified: trunk/src/fr/ifremer/wlo/utils/UIUtils.java =================================================================== --- trunk/src/fr/ifremer/wlo/utils/UIUtils.java 2014-03-18 16:15:11 UTC (rev 82) +++ trunk/src/fr/ifremer/wlo/utils/UIUtils.java 2014-03-27 10:20:09 UTC (rev 83) @@ -29,6 +29,7 @@ import android.content.SharedPreferences; import android.database.Cursor; import android.preference.PreferenceManager; +import android.util.Log; import com.google.common.base.Preconditions; import fr.ifremer.wlo.R; import fr.ifremer.wlo.models.BaseModel; @@ -137,9 +138,17 @@ public static String getFormattedSize(int size, Mensuration.Precision precision) { Preconditions.checkNotNull(precision); + + // round the size down, otherwise, the string.format method will round it up (eg 25.8 -> 26) + // cf http://forge.codelutin.com/issues/4805 + int precisionValue = precision.getValue(); + int roundedSize = (size / precisionValue) * precisionValue; + String format = getSizeFormat(precision); int divider = precision.getUnitDivider(); - double dSize = (double) size / divider; - return String.format(Locale.US, format, dSize); + double dSize = (double) roundedSize / divider; + + String result = String.format(Locale.US, format, dSize); + return result; } } Modified: trunk/src/fr/ifremer/wlo/utils/WloItemListViewBinder.java =================================================================== --- trunk/src/fr/ifremer/wlo/utils/WloItemListViewBinder.java 2014-03-18 16:15:11 UTC (rev 82) +++ trunk/src/fr/ifremer/wlo/utils/WloItemListViewBinder.java 2014-03-27 10:20:09 UTC (rev 83) @@ -79,20 +79,18 @@ DataType dataType = dataTypes.get(columnIndex); Log.d(TAG, "dataType for " + columnIndex + " : " + dataType); - if (DataType.DATE.equals(dataType) || DataType.DATETIME.equals(dataType)) { - if (cursor.getType(columnIndex) != Cursor.FIELD_TYPE_NULL) { - long time = cursor.getLong(columnIndex); - Date date = new Date(time); - String format = DataType.DATE.equals(dataType) ? dateFormat : dateTimeFormat; - String formattedDate = String.format(format, date); - TextView textView = (TextView) view; - textView.setText(formattedDate); - return true; - } - } - + TextView textView = (TextView) view; if (dataType != null) { if (cursor.getType(columnIndex) != Cursor.FIELD_TYPE_NULL) { + if (DataType.DATE.equals(dataType) || DataType.DATETIME.equals(dataType)) { + long time = cursor.getLong(columnIndex); + Date date = new Date(time); + String format = DataType.DATE.equals(dataType) ? dateFormat : dateTimeFormat; + String formattedDate = String.format(format, date); + textView.setText(formattedDate); + return true; + } + Context context = view.getContext(); String id = cursor.getString(columnIndex); BaseModel ref = null; @@ -119,19 +117,16 @@ ref = DataCache.getScientificSpeciesById(context, id); break; } - TextView textView = (TextView) view; textView.setText(ref != null ? ref.toString(context): ""); return true; } + if (DataType.SCIENTIFIC_SPECIES.equals(dataType)) { + textView.setText( + context.getString(R.string.undefined)); + return true; + } } - String value = cursor.getString(columnIndex); - if (value == null) { - TextView textView = (TextView) view; - textView.setText(""); - return true; - } - return false; } }
participants (1)
-
kmorin@users.forge.codelutin.com