Wlo-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- 141 discussions
27 Mar '14
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;
}
}
1
0
r82 - in trunk: res/values res/values-fr src/fr/ifremer/wlo src/fr/ifremer/wlo/utils
by kmorin@users.forge.codelutin.com 18 Mar '14
by kmorin@users.forge.codelutin.com 18 Mar '14
18 Mar '14
Author: kmorin
Date: 2014-03-18 17:15:11 +0100 (Tue, 18 Mar 2014)
New Revision: 82
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/82
Log:
fixes #4742 [ERGO] ne pas afficher les "Non d?\195?\169fini - Non d?\195?\169fini - Non d?\195?\169fini" ou 'NA, NA"
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/fr/ifremer/wlo/WeightsActivity.java
trunk/src/fr/ifremer/wlo/utils/WloItemListViewBinder.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-03-17 18:25:25 UTC (rev 81)
+++ trunk/res/values/strings.xml 2014-03-18 16:15:11 UTC (rev 82)
@@ -232,7 +232,7 @@
<string name="commercial_species_total_unloaded_weight">Total unloaded weight</string>
<string name="scientific_species_sorted_weight">Sorted weight</string>
<string name="scientific_species_sample_weight">Sample weight</string>
- <string name="scientific_species_categories">Weights per category (gender / maturity / age)</string>
+ <string name="scientific_species_categories">Weights per category</string>
<!--File chooser-->
<string name="file_chooser_location">Location</string>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-03-17 18:25:25 UTC (rev 81)
+++ trunk/res/values-fr/strings.xml 2014-03-18 16:15:11 UTC (rev 82)
@@ -224,7 +224,7 @@
<string name="commercial_species_total_unloaded_weight">Poids total débarqué</string>
<string name="scientific_species_sorted_weight">Poids trié</string>
<string name="scientific_species_sample_weight">Poids d\'échantillon</string>
- <string name="scientific_species_categories">Poids par catégorie (Sexe / maturité / age)</string>
+ <string name="scientific_species_categories">Poids par catégorie</string>
<!--File chooser-->
<string name="file_chooser_location">Emplacement</string>
Modified: trunk/src/fr/ifremer/wlo/WeightsActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WeightsActivity.java 2014-03-17 18:25:25 UTC (rev 81)
+++ trunk/src/fr/ifremer/wlo/WeightsActivity.java 2014-03-18 16:15:11 UTC (rev 82)
@@ -102,17 +102,21 @@
commercialSpeciesModel = (CommercialSpeciesModel) getIntent().getSerializableExtra(INTENT_COMMERCIAL_SPECIES);
+ List<String> categoryLabels = new ArrayList<>();
CategoryModel category1 = commercialSpeciesModel.getCategory1();
if (category1 != null) {
valuesById.putAll(Maps.uniqueIndex(category1.getQualitativeValues(), BaseModel.GET_ID_FUNCTION));
+ categoryLabels.add(category1.getLabel());
}
CategoryModel category2 = commercialSpeciesModel.getCategory2();
if (category2 != null) {
valuesById.putAll(Maps.uniqueIndex(category2.getQualitativeValues(), BaseModel.GET_ID_FUNCTION));
+ categoryLabels.add(category2.getLabel());
}
CategoryModel category3 = commercialSpeciesModel.getCategory3();
if (category3 != null) {
valuesById.putAll(Maps.uniqueIndex(category3.getQualitativeValues(), BaseModel.GET_ID_FUNCTION));
+ categoryLabels.add(category3.getLabel());
}
getSupportActionBar().setSubtitle(commercialSpeciesModel.toString(this));
@@ -179,50 +183,68 @@
}
});
- // weight per category
- TextView weightByCategoryView = new TextView(this);
- weightByCategoryView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
- weightByCategoryView.setTextAppearance(this, android.R.style.TextAppearance_Medium);
- weightByCategoryView.setText(R.string.scientific_species_categories);
- container.addView(weightByCategoryView);
+ if (!categoryLabels.isEmpty()) {
+ // weight per category
+ TextView weightByCategoryView = new TextView(this);
+ weightByCategoryView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
+ weightByCategoryView.setTextAppearance(this, android.R.style.TextAppearance_Medium);
+ String weightByCategoryViewText = getString(R.string.scientific_species_categories)
+ + " (" + StringUtils.join(categoryLabels, " / ") + ")";
+ weightByCategoryView.setText(weightByCategoryViewText);
+ container.addView(weightByCategoryView);
- // get all the category weights
- Cursor categoryWeighs = woh.getAllCategoryWeigths(scientificSpecies.getId());
- categoryWeightModels = WloSqlOpenHelper.transformCursorIntoCollection(categoryWeighs,
- new Function<Cursor, CategoryWeightModel>() {
- @Override
- public CategoryWeightModel apply(Cursor input) {
- CategoryWeightModel result = new CategoryWeightModel(input);
- result.setParent(scientificSpecies);
- return result;
- }
- });
+ // get all the category weights
+ Cursor categoryWeighs = woh.getAllCategoryWeigths(scientificSpecies.getId());
+ categoryWeightModels = WloSqlOpenHelper.transformCursorIntoCollection(categoryWeighs,
+ new Function<Cursor, CategoryWeightModel>() {
+ @Override
+ public CategoryWeightModel apply(Cursor input) {
+ CategoryWeightModel result = new CategoryWeightModel(input);
+ result.setParent(scientificSpecies);
+ return result;
+ }
+ });
- for (final CategoryWeightModel categoryWeightModel : categoryWeightModels) {
- // create the weight field
- QualitativeValueModel category1Value = valuesById.get(categoryWeightModel.getCategory1());
- QualitativeValueModel category2Value = valuesById.get(categoryWeightModel.getCategory2());
- QualitativeValueModel category3Value = valuesById.get(categoryWeightModel.getCategory3());
+ for (final CategoryWeightModel categoryWeightModel : categoryWeightModels) {
+ // create the weight field
- String category1ValueLabel = category1Value != null ? category1Value.toString() : categoryWeightModel.getCategory1();
- String category2ValueLabel = category2Value != null ? category2Value.toString() : categoryWeightModel.getCategory2();
- String category3ValueLabel = category3Value != null ? category3Value.toString() : categoryWeightModel.getCategory3();
+ List<String> labels = new ArrayList<>();
- String label = (category1ValueLabel != null ? category1ValueLabel : "NA") + ", " +
- (category2ValueLabel != null ? category2ValueLabel : "NA") + ", " +
- (category3ValueLabel != null ? category3ValueLabel : "NA");
+ String categoryWeightModelCategory1 = categoryWeightModel.getCategory1();
+ if (categoryWeightModelCategory1 != null) {
+ QualitativeValueModel category1Value = valuesById.get(categoryWeightModelCategory1);
+ String category1ValueLabel = category1Value != null ? category1Value.toString() : categoryWeightModelCategory1;
+ labels.add(category1ValueLabel);
+ }
- // add label
- createWeightLabel(label);
+ String categoryWeightModelCategory2 = categoryWeightModel.getCategory2();
+ if (categoryWeightModelCategory2 != null) {
+ QualitativeValueModel category2Value = valuesById.get(categoryWeightModelCategory2);
+ String category2ValueLabel = category2Value != null ? category2Value.toString() : categoryWeightModelCategory2;
+ labels.add(category2ValueLabel);
+ }
- createEditText(categoryWeightModel.getWeight(), new Function<Integer, Void>() {
- @Override
- public Void apply(Integer input) {
- categoryWeightModel.setWeight(input);
- return null;
+ String categoryWeightModelCategory3 = categoryWeightModel.getCategory3();
+ if (categoryWeightModelCategory3 != null) {
+ QualitativeValueModel category3Value = valuesById.get(categoryWeightModelCategory3);
+ String category3ValueLabel = category3Value != null ? category3Value.toString() : categoryWeightModelCategory3;
+ labels.add(category3ValueLabel);
}
- });
+
+ String label = StringUtils.join(labels, " / ");
+
+ // add label
+ createWeightLabel(label);
+
+ createEditText(categoryWeightModel.getWeight(), new Function<Integer, Void>() {
+ @Override
+ public Void apply(Integer input) {
+ categoryWeightModel.setWeight(input);
+ return null;
+ }
+ });
+ }
}
}
woh.close();
Modified: trunk/src/fr/ifremer/wlo/utils/WloItemListViewBinder.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/WloItemListViewBinder.java 2014-03-17 18:25:25 UTC (rev 81)
+++ trunk/src/fr/ifremer/wlo/utils/WloItemListViewBinder.java 2014-03-18 16:15:11 UTC (rev 82)
@@ -120,7 +120,7 @@
break;
}
TextView textView = (TextView) view;
- textView.setText(UIUtils.getStringOrUndefined(ref, context));
+ textView.setText(ref != null ? ref.toString(context): "");
return true;
}
}
@@ -128,7 +128,7 @@
String value = cursor.getString(columnIndex);
if (value == null) {
TextView textView = (TextView) view;
- textView.setText(R.string.undefined);
+ textView.setText("");
return true;
}
1
0
Author: kmorin
Date: 2014-03-17 19:25:25 +0100 (Mon, 17 Mar 2014)
New Revision: 81
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/81
Log:
add missing signing parameters
Modified:
trunk/AndroidManifest.xml
trunk/pom.xml
Modified: trunk/AndroidManifest.xml
===================================================================
--- trunk/AndroidManifest.xml 2014-03-17 17:21:13 UTC (rev 80)
+++ trunk/AndroidManifest.xml 2014-03-17 18:25:25 UTC (rev 81)
@@ -15,8 +15,8 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.ifremer.wlo"
- android:versionCode="2"
- android:versionName="0.3">
+ android:versionCode="3"
+ android:versionName="0.4">
<uses-sdk android:minSdkVersion="15"
android:targetSdkVersion="15"/>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-17 17:21:13 UTC (rev 80)
+++ trunk/pom.xml 2014-03-17 18:25:25 UTC (rev 81)
@@ -283,7 +283,7 @@
${project.build.directory}/${project.artifactId}-${project.version}.apk
</inputApk>
<outputApk>
- ${project.build.directory}/${project.artifactId}-${project.version}-aligned.apk
+ ${project.build.directory}/${project.artifactId}-${project.version}.apk
</outputApk>
</zipalign>
</configuration>
@@ -368,6 +368,10 @@
<includes>
<include>target/*.apk</include>
</includes>
+ <arguments>
+ <argument>-sigalg</argument><argument>MD5withRSA</argument>
+ <argument>-digestalg</argument><argument>SHA1</argument>
+ </arguments>
</configuration>
</execution>
</executions>
1
0
Author: maven-release
Date: 2014-03-17 18:21:13 +0100 (Mon, 17 Mar 2014)
New Revision: 80
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/80
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-17 17:21:06 UTC (rev 79)
+++ trunk/pom.xml 2014-03-17 17:21:13 UTC (rev 80)
@@ -33,7 +33,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>wlo</artifactId>
- <version>0.3</version>
+ <version>0.4-SNAPSHOT</version>
<name>WLO</name>
<description>
@@ -76,12 +76,12 @@
</developers>
<scm>
- <url>https://svn.codelutin.com/wlo/tags/wlo-0.3</url>
+ <url>https://svn.codelutin.com/wlo/trunk</url>
<connection>
- scm:svn:https://svn.codelutin.com/wlo/tags/wlo-0.3
+ scm:svn:https://svn.codelutin.com/wlo/trunk
</connection>
<developerConnection>
- scm:svn:https://svn.codelutin.com/wlo/tags/wlo-0.3
+ scm:svn:https://svn.codelutin.com/wlo/trunk
</developerConnection>
</scm>
<distributionManagement>
1
0
Author: maven-release
Date: 2014-03-17 18:21:06 +0100 (Mon, 17 Mar 2014)
New Revision: 79
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/79
Log:
[maven-release-plugin] copy for tag wlo-0.3
Added:
tags/wlo-0.3/
1
0
Author: maven-release
Date: 2014-03-17 18:20:48 +0100 (Mon, 17 Mar 2014)
New Revision: 78
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/78
Log:
[maven-release-plugin] prepare release wlo-0.3
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-17 17:08:51 UTC (rev 77)
+++ trunk/pom.xml 2014-03-17 17:20:48 UTC (rev 78)
@@ -33,7 +33,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>wlo</artifactId>
- <version>0.3-SNAPSHOT</version>
+ <version>0.3</version>
<name>WLO</name>
<description>
@@ -76,12 +76,12 @@
</developers>
<scm>
- <url>https://svn.codelutin.com/wlo/trunk</url>
+ <url>https://svn.codelutin.com/wlo/tags/wlo-0.3</url>
<connection>
- scm:svn:https://svn.codelutin.com/wlo/trunk
+ scm:svn:https://svn.codelutin.com/wlo/tags/wlo-0.3
</connection>
<developerConnection>
- scm:svn:https://svn.codelutin.com/wlo/trunk
+ scm:svn:https://svn.codelutin.com/wlo/tags/wlo-0.3
</developerConnection>
</scm>
<distributionManagement>
1
0
17 Mar '14
Author: kmorin
Date: 2014-03-17 18:08:51 +0100 (Mon, 17 Mar 2014)
New Revision: 77
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/77
Log:
upgrade to mavenpom 5.0.1
Modified:
trunk/pom.xml
trunk/src/fr/ifremer/wlo/imports/WloAbstractImportExportModel.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-17 16:56:27 UTC (rev 76)
+++ trunk/pom.xml 2014-03-17 17:08:51 UTC (rev 77)
@@ -28,7 +28,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>5.0</version>
+ <version>5.0.1</version>
</parent>
<groupId>fr.ifremer</groupId>
@@ -387,15 +387,6 @@
</profile>
<profile>
- <id>check-release-profile</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- </profile>
- <profile>
<id>license-profile</id>
<activation>
<property>
Modified: trunk/src/fr/ifremer/wlo/imports/WloAbstractImportExportModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/WloAbstractImportExportModel.java 2014-03-17 16:56:27 UTC (rev 76)
+++ trunk/src/fr/ifremer/wlo/imports/WloAbstractImportExportModel.java 2014-03-17 17:08:51 UTC (rev 77)
@@ -1,5 +1,29 @@
package fr.ifremer.wlo.imports;
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
import fr.ifremer.wlo.models.BaseModel;
import org.nuiton.csv.ValueGetter;
import org.nuiton.csv.ValueGetterSetter;
1
0
r76 - in trunk: . res/values res/values-fr res/xml src/fr/ifremer/wlo src/fr/ifremer/wlo/imports src/fr/ifremer/wlo/models src/fr/ifremer/wlo/models/referentials src/fr/ifremer/wlo/preferences src/fr/ifremer/wlo/storage src/fr/ifremer/wlo/utils
by kmorin@users.forge.codelutin.com 17 Mar '14
by kmorin@users.forge.codelutin.com 17 Mar '14
17 Mar '14
Author: kmorin
Date: 2014-03-17 17:56:27 +0100 (Mon, 17 Mar 2014)
New Revision: 76
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/76
Log:
fixes #4230 Mettre ?\195?\160 jour les imports existants si l'id est le m?\195?\170me
fixes #4738 Exporter les r?\195?\169f?\195?\169rentiels
Added:
trunk/src/fr/ifremer/wlo/imports/WloAbstractImportExportModel.java
trunk/src/fr/ifremer/wlo/utils/ImportExportUtil.java
Removed:
trunk/src/fr/ifremer/wlo/utils/ImportUtil.java
Modified:
trunk/AndroidManifest.xml
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/res/xml/preferences.xml
trunk/src/fr/ifremer/wlo/MainActivity.java
trunk/src/fr/ifremer/wlo/WloApplication.java
trunk/src/fr/ifremer/wlo/imports/CalcifiedPartTakingRowModel.java
trunk/src/fr/ifremer/wlo/imports/CommercialSpeciesRowModel.java
trunk/src/fr/ifremer/wlo/imports/LocationRowModel.java
trunk/src/fr/ifremer/wlo/imports/MensurationRowModel.java
trunk/src/fr/ifremer/wlo/imports/MetierRowModel.java
trunk/src/fr/ifremer/wlo/imports/PresentationRowModel.java
trunk/src/fr/ifremer/wlo/imports/ScientificSpeciesRowModel.java
trunk/src/fr/ifremer/wlo/imports/StateRowModel.java
trunk/src/fr/ifremer/wlo/imports/VesselRowModel.java
trunk/src/fr/ifremer/wlo/models/BaseModel.java
trunk/src/fr/ifremer/wlo/models/referentials/CalcifiedPartTaking.java
trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java
trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java
Modified: trunk/AndroidManifest.xml
===================================================================
--- trunk/AndroidManifest.xml 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/AndroidManifest.xml 2014-03-17 16:56:27 UTC (rev 76)
@@ -124,7 +124,7 @@
android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".preferences.MultiSelectionActivity"
- android:label="@string/favaorite_selection_title"
+ android:label="@string/favorite_selection_title"
android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".utils.filechooser.FileDialog"
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/res/values/strings.xml 2014-03-17 16:56:27 UTC (rev 76)
@@ -26,6 +26,7 @@
<string name="delete">Delete</string>
<string name="edit">Edit</string>
<string name="form_comment">Comment</string>
+ <string name="error">Error</string>
<!-- BigFin communication service -->
<string name="bigfin_no_ichtyometer_connected_title">No ichtyometer connected</string>
@@ -91,6 +92,7 @@
<string name="preferences_ichtyometer">Ichtyometer</string>
<string name="preferences_referentials">Referentials</string>
<string name="preferences_imports">Imports</string>
+ <string name="preferences_exports">Exports</string>
<string name="preferences_imports">Favorites</string>
<string name="preferences_import_summary">%s items currently</string>
@@ -108,20 +110,51 @@
<string name="preferences_import_categories">Import categorizations</string>
<string name="preferences_import_no_external_storage_title">External storage unavailable</string>
- <string name="preferences_import_no_external_storage_message">No externat storage is available.\nWould you like to import the data without saving the source file?</string>
+ <string name="preferences_import_no_external_storage_message">No external storage is available.\nWould you like to import the data without saving the source file?</string>
<string name="preferences_importing_referential">Importing referential data</string>
+ <string name="export_element_number">%s new items imported</string>
+ <string name="export_error">An error occurred during the import.\nCheck that the header names of the file you chose are correct.</string>
+
+ <string name="preferences_export_summary">%s items</string>
+ <string name="preferences_export_commercial_species">Export commercial species</string>
+ <string name="preferences_export_locations">Export locations</string>
+ <string name="preferences_export_mensurations">Export mensurations</string>
+ <string name="preferences_export_metiers">Export metiers</string>
+ <string name="preferences_export_presentations">Export presentations</string>
+ <string name="preferences_export_scientific_species">Export scientific species</string>
+ <string name="preferences_export_states">Export states</string>
+ <string name="preferences_export_vessels">Export vessels</string>
+ <string name="preferences_export_categories">Export categorizations</string>
+ <string name="preferences_exporting_referential">Exporting referential data</string>
+
+ <string name="preferences_export_commercial_species_default_name">commercial_species</string>
+ <string name="preferences_export_locations_default_name">locations</string>
+ <string name="preferences_export_mensurations_default_name">mensurations</string>
+ <string name="preferences_export_metiers_default_name">metiers</string>
+ <string name="preferences_export_presentations_default_name">presentations</string>
+ <string name="preferences_export_scientific_species_default_name">scientific_species</string>
+ <string name="preferences_export_states_default_name">states</string>
+ <string name="preferences_export_vessels_default_name">vessels</string>
+
+ <string name="export_exported_element_number">%s items exported</string>
+ <string name="export_error">An error occurred during the export.</string>
+
<string name="preferences_favorites_commercial_species">Commercial species</string>
<string name="preferences_favorites_scientific_species">Scientific species</string>
- <string name="favaorite_selection_title">Favorites</string>
+ <string name="favorite_selection_title">Favorites</string>
<string name="select_new_favorite">Select a new favorite</string>
<string name="favorite_nb">%s favorites</string>
- <string name="import_new_element_number">%s new items imported</string>
- <string name="import_error">An error occurred during the import.\nCheck that the header names of the file you chose are correct.</string>
-
<string name="preferences_calcified_parts_takings">Calcified parts taking</string>
<string name="preferences_import_calcified_parts_takings">Import algorithm settings</string>
+ <string name="preferences_export_calcified_parts_takings">Export algorithm settings</string>
+ <string name="preferences_export_calcified_parts_takings_default_name">calcified_takings</string>
+ <string name="preferences_import_calcified_parts_takings_null_species">A species code is null or is not in the species referential.</string>
+ <string name="preferences_import_calcified_parts_takings_overlapping">The ranges must not overlap.</string>
+ <string name="preferences_import_calcified_parts_takings_value_out_of_ranges">The ranges must cover every value.</string>
+ <string name="preferences_import_calcified_parts_different_size_steps">The size steps must be equals for a single species.</string>
+ <string name="preferences_import_calcified_parts_no_size_step">At least one row must have a size step for each species.</string>
<string name="category_creation_title">New category</string>
<string name="category_label">Label</string>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/res/values-fr/strings.xml 2014-03-17 16:56:27 UTC (rev 76)
@@ -24,6 +24,7 @@
<string name="delete">Supprimer</string>
<string name="edit">Éditer</string>
<string name="form_comment">Commentaire</string>
+ <string name="error">Erreur</string>
<!-- BigFin communication service -->
<string name="bigfin_no_ichtyometer_connected_title">Aucun ichtyomètre connecté</string>
@@ -107,14 +108,45 @@
<string name="import_new_element_number">%s nouveaux éléments importés</string>
<string name="import_error">Une erreur s\'est produite durant l\'import.\nVérifiez que les entêtes du fichier que vous avez choisi sont corrects.</string>
+ <string name="preferences_export_summary">%s éléments</string>
+ <string name="preferences_export_commercial_species">Exporter les espèces commerciales</string>
+ <string name="preferences_export_locations">Exporter les lieux</string>
+ <string name="preferences_export_mensurations">Exporter les mensurations</string>
+ <string name="preferences_export_metiers">Exporter les métiers</string>
+ <string name="preferences_export_presentations">Exporter les présentations</string>
+ <string name="preferences_export_scientific_species">Exporter les espèces scientifiques</string>
+ <string name="preferences_export_states">Exporter les états</string>
+ <string name="preferences_export_vessels">Exporter les navires</string>
+ <string name="preferences_export_categories">Export des catégorisations</string>
+ <string name="preferences_exporting_referential">Export des données du référentiel en cours</string>
+
+ <string name="preferences_export_commercial_species_default_name">especes_commerciales</string>
+ <string name="preferences_export_locations_default_name">lieux</string>
+ <string name="preferences_export_mensurations_default_name">mensurations</string>
+ <string name="preferences_export_metiers_default_name">metiers</string>
+ <string name="preferences_export_presentations_default_name">presentations</string>
+ <string name="preferences_export_scientific_species_default_name">especes_scientifiques</string>
+ <string name="preferences_export_states_default_name">etats</string>
+ <string name="preferences_export_vessels_default_name">navires</string>
+
+ <string name="export_element_number">%s éléments exportés</string>
+ <string name="export_error">Une erreur s\'est produite durant l\'export.</string>
+
<string name="preferences_favorites_commercial_species">Espèces commerciales</string>
<string name="preferences_favorites_scientific_species">Espèces scientifiques</string>
- <string name="favaorite_selection_title">Favoris</string>
+ <string name="favorite_selection_title">Favoris</string>
<string name="select_new_favorite">Choisissez un nouveau favori</string>
<string name="favorite_nb">%s favoris</string>
<string name="preferences_calcified_parts_takings">Prélèvement des pièces calcifiées</string>
<string name="preferences_import_calcified_parts_takings">Import des paramètres de l\'algorithme</string>
+ <string name="preferences_export_calcified_parts_takings">Export des paramètres de l\'algorithmes</string>
+ <string name="preferences_export_calcified_parts_takings_default_name">prelevement_pieces_calcifiees</string>
+ <string name="preferences_import_calcified_parts_takings_null_species">Un code d\'espèce est nul ou ne correspond à aucune espèce dans le référentiel.</string>
+ <string name="preferences_import_calcified_parts_takings_overlapping">Les intervalles ne doivent pas se chevaucher.</string>
+ <string name="preferences_import_calcified_parts_takings_value_out_of_ranges">Les intervalles doivent couvrir toutes les valeurs.</string>
+ <string name="preferences_import_calcified_parts_different_size_steps">Les pas de classe de taille doivent être égaux pour chaque espèce.</string>
+ <string name="preferences_import_calcified_parts_no_size_step">Au moins une ligne pour chaque espèce doit avoir un pas de classe de taille.</string>
<string name="category_creation_title">Nouvelle catégorie</string>
<string name="category_label">Libellé</string>
Modified: trunk/res/xml/preferences.xml
===================================================================
--- trunk/res/xml/preferences.xml 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/res/xml/preferences.xml 2014-03-17 16:56:27 UTC (rev 76)
@@ -63,6 +63,30 @@
</PreferenceScreen>
<PreferenceScreen
+ android:key="preferences_exports"
+ android:title="@string/preferences_exports"
+ android:persistent="false">
+
+ <Preference android:title="@string/preferences_export_commercial_species"
+ android:key="export_commercial_species"/>
+ <Preference android:title="@string/preferences_export_scientific_species"
+ android:key="export_scientific_species"/>
+ <Preference android:title="@string/preferences_export_locations"
+ android:key="export_locations"/>
+ <Preference android:title="@string/preferences_export_vessels"
+ android:key="export_vessels"/>
+ <Preference android:title="@string/preferences_export_metiers"
+ android:key="export_metiers"/>
+ <Preference android:title="@string/preferences_export_presentations"
+ android:key="export_presentations"/>
+ <Preference android:title="@string/preferences_export_states"
+ android:key="export_states"/>
+ <Preference android:title="@string/preferences_export_mensurations"
+ android:key="export_mensurations"/>
+
+ </PreferenceScreen>
+
+ <PreferenceScreen
android:key="preferences_favorites"
android:title="@string/preferences_favorites">
@@ -83,6 +107,9 @@
<Preference android:title="@string/preferences_import_calcified_parts_takings"
android:key="import_calcified_parts_takings"/>
+ <Preference android:title="@string/preferences_export_calcified_parts_takings"
+ android:key="export_calcified_parts_takings"/>
+
</PreferenceCategory>
<PreferenceCategory
Modified: trunk/src/fr/ifremer/wlo/MainActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/MainActivity.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/MainActivity.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,7 +25,6 @@
*/
import android.app.Activity;
-import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
@@ -42,13 +41,12 @@
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
-import fr.ifremer.wlo.utils.ImportUtil;
+import fr.ifremer.wlo.utils.ImportExportUtil;
import fr.ifremer.wlo.models.categorization.CategoryModel;
import fr.ifremer.wlo.preferences.SettingsActivity;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.Exporter;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
-import fr.ifremer.wlo.utils.UIUtils;
import fr.ifremer.wlo.utils.UpdateCheckTask;
import fr.ifremer.wlo.utils.filechooser.FileDialog;
import fr.ifremer.wlo.utils.filechooser.SelectionMode;
@@ -308,42 +306,42 @@
try {
int i = 1;
if (DataCache.getAllCommercialSpecies(context).isEmpty()) {
- ImportUtil.importCommercialSpecies(context, getAssets().open("ref_import_commercial_species.csv"));
+ ImportExportUtil.importCommercialSpecies(context, getAssets().open("ref_import_commercial_species.csv"));
}
publishProgress(i++);
if (DataCache.getAllLocations(context).isEmpty()) {
- ImportUtil.importLocations(context, getAssets().open("ref_import_locations.csv"));
+ ImportExportUtil.importLocations(context, getAssets().open("ref_import_locations.csv"));
}
publishProgress(i++);
if (DataCache.getAllMensurations(context).isEmpty()) {
- ImportUtil.importMensurations(context, getAssets().open("ref_import_mensurations.csv"));
+ ImportExportUtil.importMensurations(context, getAssets().open("ref_import_mensurations.csv"));
}
publishProgress(i++);
if (DataCache.getAllMetiers(context).isEmpty()) {
- ImportUtil.importMetiers(context, getAssets().open("ref_import_metiers.csv"));
+ ImportExportUtil.importMetiers(context, getAssets().open("ref_import_metiers.csv"));
}
publishProgress(i++);
if (DataCache.getAllPresentations(context).isEmpty()) {
- ImportUtil.importPresentations(context, getAssets().open("ref_import_presentations.csv"));
+ ImportExportUtil.importPresentations(context, getAssets().open("ref_import_presentations.csv"));
}
publishProgress(i++);
if (DataCache.getAllScientificSpecies(context).isEmpty()) {
- ImportUtil.importScientificSpecies(context, getAssets().open("ref_import_scientific_species.csv"));
+ ImportExportUtil.importScientificSpecies(context, getAssets().open("ref_import_scientific_species.csv"));
}
publishProgress(i++);
if (DataCache.getAllStates(context).isEmpty()) {
- ImportUtil.importStates(context, getAssets().open("ref_import_states.csv"));
+ ImportExportUtil.importStates(context, getAssets().open("ref_import_states.csv"));
}
publishProgress(i++);
if (DataCache.getAllVessels(context).isEmpty()) {
- ImportUtil.importVessels(context, getAssets().open("ref_import_vessels.csv"));
+ ImportExportUtil.importVessels(context, getAssets().open("ref_import_vessels.csv"));
}
publishProgress(i++);
@@ -362,9 +360,9 @@
maturityCategory.setLabel(getString(R.string.maturity));
soh.saveData(maturityCategory);
- soh.saveData(ImportUtil.importQualitativeValues(ageCategory, getAssets().open("ref_import_ages.csv")));
- soh.saveData(ImportUtil.importQualitativeValues(genderCategory, getAssets().open("ref_import_genders.csv")));
- soh.saveData(ImportUtil.importQualitativeValues(maturityCategory, getAssets().open("ref_import_maturities.csv")));
+ soh.saveData(ImportExportUtil.importQualitativeValues(ageCategory, getAssets().open("ref_import_ages.csv")));
+ soh.saveData(ImportExportUtil.importQualitativeValues(genderCategory, getAssets().open("ref_import_genders.csv")));
+ soh.saveData(ImportExportUtil.importQualitativeValues(maturityCategory, getAssets().open("ref_import_maturities.csv")));
soh.close();
}
Modified: trunk/src/fr/ifremer/wlo/WloApplication.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloApplication.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/WloApplication.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,25 +25,10 @@
*/
import android.app.Application;
-import android.app.DownloadManager;
-import android.app.ProgressDialog;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.AsyncTask;
-import android.util.Log;
-import fr.ifremer.wlo.utils.ImportUtil;
-import fr.ifremer.wlo.models.categorization.CategoryModel;
-import fr.ifremer.wlo.storage.DataCache;
-import fr.ifremer.wlo.storage.WloSqlOpenHelper;
-import fr.ifremer.wlo.utils.UpdateCheckTask;
import org.acra.ACRA;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
/**
* @author Kevin Morin (Code Lutin)
* @since x.x
Modified: trunk/src/fr/ifremer/wlo/imports/CalcifiedPartTakingRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/CalcifiedPartTakingRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/CalcifiedPartTakingRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -29,6 +29,7 @@
import com.google.common.collect.Maps;
import fr.ifremer.wlo.models.referentials.CalcifiedPartTaking;
import fr.ifremer.wlo.models.referentials.ScientificSpecies;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -39,7 +40,7 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class CalcifiedPartTakingRowModel extends AbstractImportExportModel<CalcifiedPartTaking> {
+public class CalcifiedPartTakingRowModel extends WloAbstractImportExportModel<CalcifiedPartTaking> {
private static final String TAG = "CalcifiedPartTakingRowModel";
@@ -54,18 +55,22 @@
}
});
- newMandatoryColumn("Espece_scientifique", new ValueSetter<CalcifiedPartTaking, String>() {
+ newColumnForImportExport("Espece_scientifique", new ValueGetterSetter<CalcifiedPartTaking, String>() {
@Override
public void set(CalcifiedPartTaking object, String value) throws Exception {
- if (value == null) {
- throw new NullPointerException("L'espece scientifique ne peut etre nulle");
- }
+ Log.d(TAG, "code expece scientific " + value);
ScientificSpecies species = scientificSpeciesByCode.get(value);
+ Log.d(TAG, "expece scientific " + species);
object.setParent(species);
}
+
+ @Override
+ public String get(CalcifiedPartTaking object) throws Exception {
+ return object.getParentId();
+ }
});
- newMandatoryColumn("Classe_debut", new ValueSetter<CalcifiedPartTaking, String>() {
+ newColumnForImportExport("Classe_debut", new ValueGetterSetter<CalcifiedPartTaking, String>() {
@Override
public void set(CalcifiedPartTaking object, String value) throws Exception {
Integer size;
@@ -77,9 +82,14 @@
Log.d(TAG, object + "setStartSize " + size);
object.setStartSize(size);
}
+
+ @Override
+ public String get(CalcifiedPartTaking object) throws Exception {
+ return String.valueOf(object.getStartSize());
+ }
});
- newMandatoryColumn("Classe_fin", new ValueSetter<CalcifiedPartTaking, String>() {
+ newColumnForImportExport("Classe_fin", new ValueGetterSetter<CalcifiedPartTaking, String>() {
@Override
public void set(CalcifiedPartTaking object, String value) throws Exception {
Integer size;
@@ -91,27 +101,47 @@
Log.d(TAG, object + "setEndSize " + size);
object.setEndSize(size);
}
+
+ @Override
+ public String get(CalcifiedPartTaking object) throws Exception {
+ return String.valueOf(object.getEndSize());
+ }
});
- newMandatoryColumn("Pas_de_classe", new ValueSetter<CalcifiedPartTaking, String>() {
+ newColumnForImportExport("Pas_de_classe", new ValueGetterSetter<CalcifiedPartTaking, String>() {
@Override
public void set(CalcifiedPartTaking object, String value) throws Exception {
- Integer size = Integer.parseInt(value);
+ Integer size;
+ try {
+ size = Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ size = null;
+ }
Log.d(TAG, object + "setSizeStep " + size);
object.setSizeStep(size);
}
+
+ @Override
+ public String get(CalcifiedPartTaking object) throws Exception {
+ return String.valueOf(object.getSizeStep());
+ }
});
- newMandatoryColumn("Pas", new ValueSetter<CalcifiedPartTaking, String>() {
+ newColumnForImportExport("Pas", new ValueGetterSetter<CalcifiedPartTaking, String>() {
@Override
public void set(CalcifiedPartTaking object, String value) throws Exception {
Integer size = Integer.parseInt(value);
Log.d(TAG, object + "setStep " + size);
object.setStep(size);
}
+
+ @Override
+ public String get(CalcifiedPartTaking object) throws Exception {
+ return String.valueOf(object.getStep());
+ }
});
- newMandatoryColumn("Arret", new ValueSetter<CalcifiedPartTaking, String>() {
+ newColumnForImportExport("Arret", new ValueGetterSetter<CalcifiedPartTaking, String>() {
@Override
public void set(CalcifiedPartTaking object, String value) throws Exception {
Integer size;
@@ -123,6 +153,11 @@
Log.d(TAG, object + "setStop " + size);
object.setStop(size);
}
+
+ @Override
+ public String get(CalcifiedPartTaking object) throws Exception {
+ return String.valueOf(object.getStop());
+ }
});
}
Modified: trunk/src/fr/ifremer/wlo/imports/CommercialSpeciesRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/CommercialSpeciesRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/CommercialSpeciesRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.wlo.models.referentials.CommercialSpecies;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -32,55 +33,90 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class CommercialSpeciesRowModel extends AbstractImportExportModel<CommercialSpecies> {
+public class CommercialSpeciesRowModel extends WloAbstractImportExportModel<CommercialSpecies> {
public CommercialSpeciesRowModel(char separator) {
super(separator);
- newMandatoryColumn("ESPF_COD", new ValueSetter<CommercialSpecies, String>() {
+ newColumnForImportExport("ESPF_COD", new ValueGetterSetter<CommercialSpecies, String>() {
@Override
public void set(CommercialSpecies object, String value) throws Exception {
object.setCode(value);
}
+
+ @Override
+ public String get(CommercialSpecies object) throws Exception {
+ return object.getCode();
+ }
});
- newMandatoryColumn("ESPF_ISSCAP", new ValueSetter<CommercialSpecies, String>() {
+ newColumnForImportExport("ESPF_ISSCAP", new ValueGetterSetter<CommercialSpecies, String>() {
@Override
public void set(CommercialSpecies object, String value) throws Exception {
object.setIsscap(value);
}
+
+ @Override
+ public String get(CommercialSpecies object) throws Exception {
+ return object.getIsscap();
+ }
});
- newMandatoryColumn("ESPF_TAXON_COD", new ValueSetter<CommercialSpecies, String>() {
+ newColumnForImportExport("ESPF_TAXON_COD", new ValueGetterSetter<CommercialSpecies, String>() {
@Override
public void set(CommercialSpecies object, String value) throws Exception {
object.setTaxonCode(value);
}
+
+ @Override
+ public String get(CommercialSpecies object) throws Exception {
+ return object.getTaxonCode();
+ }
});
- newMandatoryColumn("ESPF_SCI_LIB", new ValueSetter<CommercialSpecies, String>() {
+ newColumnForImportExport("ESPF_SCI_LIB", new ValueGetterSetter<CommercialSpecies, String>() {
@Override
public void set(CommercialSpecies object, String value) throws Exception {
object.setScientificLabel(value);
}
+
+ @Override
+ public String get(CommercialSpecies object) throws Exception {
+ return object.getScientificLabel();
+ }
});
- newMandatoryColumn("ESPF_FRA_LIB", new ValueSetter<CommercialSpecies, String>() {
+ newColumnForImportExport("ESPF_FRA_LIB", new ValueGetterSetter<CommercialSpecies, String>() {
@Override
public void set(CommercialSpecies object, String value) throws Exception {
object.setFrenchLabel(value);
}
+
+ @Override
+ public String get(CommercialSpecies object) throws Exception {
+ return object.getFrenchLabel();
+ }
});
- newMandatoryColumn("ESPF_FAMILLE", new ValueSetter<CommercialSpecies, String>() {
+ newColumnForImportExport("ESPF_FAMILLE", new ValueGetterSetter<CommercialSpecies, String>() {
@Override
public void set(CommercialSpecies object, String value) throws Exception {
object.setFamily(value);
}
+
+ @Override
+ public String get(CommercialSpecies object) throws Exception {
+ return object.getFamily();
+ }
});
- newMandatoryColumn("ESPF_ORDRE", new ValueSetter<CommercialSpecies, String>() {
+ newColumnForImportExport("ESPF_ORDRE", new ValueGetterSetter<CommercialSpecies, String>() {
@Override
public void set(CommercialSpecies object, String value) throws Exception {
object.setSpeciesOrder(value);
}
+
+ @Override
+ public String get(CommercialSpecies object) throws Exception {
+ return object.getSpeciesOrder();
+ }
});
- newMandatoryColumn("ESPF_ACT", new ValueSetter<CommercialSpecies, String>() {
+ newColumnForImportExport("ESPF_ACT", new ValueGetterSetter<CommercialSpecies, String>() {
@Override
public void set(CommercialSpecies object, String value) throws Exception {
Integer iValue;
@@ -91,6 +127,11 @@
}
object.setActive(iValue);
}
+
+ @Override
+ public String get(CommercialSpecies object) throws Exception {
+ return String.valueOf(object.getActive());
+ }
});
}
Modified: trunk/src/fr/ifremer/wlo/imports/LocationRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/LocationRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/LocationRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.wlo.models.referentials.Location;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -32,29 +33,44 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class LocationRowModel extends AbstractImportExportModel<Location> {
+public class LocationRowModel extends WloAbstractImportExportModel<Location> {
public LocationRowModel(char separator) {
super(separator);
- newMandatoryColumn("TLIEU_LIB", new ValueSetter<Location, String>() {
+ newColumnForImportExport("TLIEU_LIB", new ValueGetterSetter<Location, String>() {
@Override
public void set(Location object, String value) throws Exception {
object.setTypeLabel(value);
}
+
+ @Override
+ public String get(Location object) throws Exception {
+ return object.getTypeLabel();
+ }
});
- newMandatoryColumn("LIEU_COD", new ValueSetter<Location, String>() {
+ newColumnForImportExport("LIEU_COD", new ValueGetterSetter<Location, String>() {
@Override
public void set(Location object, String value) throws Exception {
object.setCode(value);
}
+
+ @Override
+ public String get(Location object) throws Exception {
+ return object.getCode();
+ }
});
- newMandatoryColumn("LIEU_LIB", new ValueSetter<Location, String>() {
+ newColumnForImportExport("LIEU_LIB", new ValueGetterSetter<Location, String>() {
@Override
public void set(Location object, String value) throws Exception {
object.setLabel(value);
}
+
+ @Override
+ public String get(Location object) throws Exception {
+ return object.getLabel();
+ }
});
}
Modified: trunk/src/fr/ifremer/wlo/imports/MensurationRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/MensurationRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/MensurationRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.wlo.models.referentials.Mensuration;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -32,23 +33,35 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class MensurationRowModel extends AbstractImportExportModel<Mensuration> {
+public class MensurationRowModel extends WloAbstractImportExportModel<Mensuration> {
public MensurationRowModel(char separator) {
super(separator);
- newMandatoryColumn("Type_Longueur_cod", new ValueSetter<Mensuration, String>() {
+ newColumnForImportExport("Type_Longueur_cod", new ValueGetterSetter<Mensuration, String>() {
+
@Override
public void set(Mensuration object, String value) throws Exception {
object.setCode(value);
}
+
+ @Override
+ public String get(Mensuration object) throws Exception {
+ return object.getCode();
+ }
});
- newMandatoryColumn("Type_Longueur_lib", new ValueSetter<Mensuration, String>() {
+ newColumnForImportExport("Type_Longueur_lib", new ValueGetterSetter<Mensuration, String>() {
+
@Override
public void set(Mensuration object, String value) throws Exception {
object.setLabel(value);
}
+
+ @Override
+ public String get(Mensuration object) throws Exception {
+ return object.getLabel();
+ }
});
}
Modified: trunk/src/fr/ifremer/wlo/imports/MetierRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/MetierRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/MetierRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.wlo.models.referentials.Metier;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -32,55 +33,90 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class MetierRowModel extends AbstractImportExportModel<Metier> {
+public class MetierRowModel extends WloAbstractImportExportModel<Metier> {
public MetierRowModel(char separator) {
super(separator);
- newMandatoryColumn("MET_ID", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_ID", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
object.setMetierId(value);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return object.getMetierId();
+ }
});
- newMandatoryColumn("MET_COD", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_COD", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
object.setCode(value);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return object.getCode();
+ }
});
- newMandatoryColumn("MET_LIB", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_LIB", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
object.setLabel(value);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return object.getLabel();
+ }
});
- newMandatoryColumn("MET_ENGIN_COD", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_ENGIN_COD", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
object.setGearCode(value);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return object.getGearCode();
+ }
});
- newMandatoryColumn("MET_ENGIN_LIB", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_ENGIN_LIB", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
object.setGearLabel(value);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return object.getGearLabel();
+ }
});
- newMandatoryColumn("MET_ESPECE_COD", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_ESPECE_COD", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
object.setSpeciesCode(value);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return object.getSpeciesCode();
+ }
});
- newMandatoryColumn("MET_ESPECE_LIB", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_ESPECE_LIB", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
object.setSpeciesLabel(value);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return object.getSpeciesLabel();
+ }
});
- newMandatoryColumn("MET_PECHE", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_PECHE", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
Integer iValue;
@@ -91,8 +127,13 @@
}
object.setFishing(iValue);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return String.valueOf(object.getFishing());
+ }
});
- newMandatoryColumn("MET_ACT", new ValueSetter<Metier, String>() {
+ newColumnForImportExport("MET_ACT", new ValueGetterSetter<Metier, String>() {
@Override
public void set(Metier object, String value) throws Exception {
Integer iValue;
@@ -103,6 +144,11 @@
}
object.setActive(iValue);
}
+
+ @Override
+ public String get(Metier object) throws Exception {
+ return String.valueOf(object.getActive());
+ }
});
}
Modified: trunk/src/fr/ifremer/wlo/imports/PresentationRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/PresentationRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/PresentationRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.wlo.models.referentials.Presentation;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -32,23 +33,33 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class PresentationRowModel extends AbstractImportExportModel<Presentation> {
+public class PresentationRowModel extends WloAbstractImportExportModel<Presentation> {
public PresentationRowModel(char separator) {
super(separator);
- newMandatoryColumn("Presentation_cod", new ValueSetter<Presentation, String>() {
+ newColumnForImportExport("Presentation_cod", new ValueGetterSetter<Presentation, String>() {
@Override
public void set(Presentation object, String value) throws Exception {
object.setCode(value);
}
+
+ @Override
+ public String get(Presentation object) throws Exception {
+ return object.getCode();
+ }
});
- newMandatoryColumn("Presentation_lib", new ValueSetter<Presentation, String>() {
+ newColumnForImportExport("Presentation_lib", new ValueGetterSetter<Presentation, String>() {
@Override
public void set(Presentation object, String value) throws Exception {
object.setLabel(value);
}
+
+ @Override
+ public String get(Presentation object) throws Exception {
+ return object.getLabel();
+ }
});
}
Modified: trunk/src/fr/ifremer/wlo/imports/ScientificSpeciesRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/ScientificSpeciesRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/ScientificSpeciesRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.wlo.models.referentials.ScientificSpecies;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -32,29 +33,44 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class ScientificSpeciesRowModel extends AbstractImportExportModel<ScientificSpecies> {
+public class ScientificSpeciesRowModel extends WloAbstractImportExportModel<ScientificSpecies> {
public ScientificSpeciesRowModel(char separator) {
super(separator);
- newMandatoryColumn("C_Perm", new ValueSetter<ScientificSpecies, String>() {
+ newColumnForImportExport("C_Perm", new ValueGetterSetter<ScientificSpecies, String>() {
@Override
public void set(ScientificSpecies object, String value) throws Exception {
object.setPermCode(value);
}
+
+ @Override
+ public String get(ScientificSpecies object) throws Exception {
+ return object.getPermCode();
+ }
});
- newMandatoryColumn("C_VALIDE", new ValueSetter<ScientificSpecies, String>() {
+ newColumnForImportExport("C_VALIDE", new ValueGetterSetter<ScientificSpecies, String>() {
@Override
public void set(ScientificSpecies object, String value) throws Exception {
object.setCode(value);
}
+
+ @Override
+ public String get(ScientificSpecies object) throws Exception {
+ return object.getCode();
+ }
});
- newMandatoryColumn("L_VALIDE", new ValueSetter<ScientificSpecies, String>() {
+ newColumnForImportExport("L_VALIDE", new ValueGetterSetter<ScientificSpecies, String>() {
@Override
public void set(ScientificSpecies object, String value) throws Exception {
object.setLabel(value);
}
+
+ @Override
+ public String get(ScientificSpecies object) throws Exception {
+ return object.getLabel();
+ }
});
}
Modified: trunk/src/fr/ifremer/wlo/imports/StateRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/StateRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/StateRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.wlo.models.referentials.State;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -32,23 +33,33 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class StateRowModel extends AbstractImportExportModel<State> {
+public class StateRowModel extends WloAbstractImportExportModel<State> {
public StateRowModel(char separator) {
super(separator);
- newMandatoryColumn("Etat_cod", new ValueSetter<State, String>() {
+ newColumnForImportExport("Etat_cod", new ValueGetterSetter<State, String>() {
@Override
public void set(State object, String value) throws Exception {
object.setCode(value);
}
+
+ @Override
+ public String get(State object) throws Exception {
+ return object.getCode();
+ }
});
- newMandatoryColumn("Etat_lib", new ValueSetter<State, String>() {
+ newColumnForImportExport("Etat_lib", new ValueGetterSetter<State, String>() {
@Override
public void set(State object, String value) throws Exception {
object.setLabel(value);
}
+
+ @Override
+ public String get(State object) throws Exception {
+ return object.getLabel();
+ }
});
}
Modified: trunk/src/fr/ifremer/wlo/imports/VesselRowModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/VesselRowModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/imports/VesselRowModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -25,6 +25,7 @@
*/
import fr.ifremer.wlo.models.referentials.Vessel;
+import org.nuiton.csv.ValueGetterSetter;
import org.nuiton.csv.ValueSetter;
import org.nuiton.csv.ext.AbstractImportExportModel;
@@ -32,29 +33,44 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public class VesselRowModel extends AbstractImportExportModel<Vessel> {
+public class VesselRowModel extends WloAbstractImportExportModel<Vessel> {
public VesselRowModel(char separator) {
super(separator);
- newMandatoryColumn("NAVS_COD", new ValueSetter<Vessel, String>() {
+ newColumnForImportExport("NAVS_COD", new ValueGetterSetter<Vessel, String>() {
@Override
public void set(Vessel object, String value) throws Exception {
object.setCode(value);
}
+
+ @Override
+ public String get(Vessel object) throws Exception {
+ return object.getCode();
+ }
});
- newMandatoryColumn("CARN_NOM", new ValueSetter<Vessel, String>() {
+ newColumnForImportExport("CARN_NOM", new ValueGetterSetter<Vessel, String>() {
@Override
public void set(Vessel object, String value) throws Exception {
object.setName(value);
}
+
+ @Override
+ public String get(Vessel object) throws Exception {
+ return object.getName();
+ }
});
- newMandatoryColumn("QUARTIER_COD", new ValueSetter<Vessel, String>() {
+ newColumnForImportExport("QUARTIER_COD", new ValueGetterSetter<Vessel, String>() {
@Override
public void set(Vessel object, String value) throws Exception {
object.setQuarterCode(value);
}
+
+ @Override
+ public String get(Vessel object) throws Exception {
+ return object.getQuarterCode();
+ }
});
}
Added: trunk/src/fr/ifremer/wlo/imports/WloAbstractImportExportModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/imports/WloAbstractImportExportModel.java (rev 0)
+++ trunk/src/fr/ifremer/wlo/imports/WloAbstractImportExportModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -0,0 +1,32 @@
+package fr.ifremer.wlo.imports;
+
+import fr.ifremer.wlo.models.BaseModel;
+import org.nuiton.csv.ValueGetter;
+import org.nuiton.csv.ValueGetterSetter;
+import org.nuiton.csv.ValueSetter;
+import org.nuiton.csv.ext.AbstractImportExportModel;
+
+/**
+ * @author Kevin Morin (Code Lutin)
+ * @since x.x
+ */
+public abstract class WloAbstractImportExportModel<M extends BaseModel> extends AbstractImportExportModel<M> {
+
+ public WloAbstractImportExportModel(char separator) {
+ super(separator);
+
+ newOptionalColumn("id", new ValueSetter<M, String>() {
+ @Override
+ public void set(M object, String value) throws Exception {
+ object.setId(value);
+ }
+ });
+
+ newColumnForExport("id", new ValueGetter<M, String>() {
+ @Override
+ public String get(M object) throws Exception {
+ return object.getId();
+ }
+ });
+ }
+}
Modified: trunk/src/fr/ifremer/wlo/models/BaseModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/BaseModel.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/models/BaseModel.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -34,6 +34,7 @@
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -86,7 +87,7 @@
}
public boolean isNew() {
- return id == null;
+ return StringUtils.isBlank(id);
}
public boolean isModified() {
Modified: trunk/src/fr/ifremer/wlo/models/referentials/CalcifiedPartTaking.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/referentials/CalcifiedPartTaking.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/models/referentials/CalcifiedPartTaking.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -63,7 +63,7 @@
protected Integer startSize;
protected Integer endSize;
- protected int sizeStep;
+ protected Integer sizeStep;
protected int step;
protected Integer stop;
@@ -104,11 +104,11 @@
this.endSize = endSize;
}
- public int getSizeStep() {
+ public Integer getSizeStep() {
return sizeStep;
}
- public void setSizeStep(int sizeStep) {
+ public void setSizeStep(Integer sizeStep) {
this.sizeStep = sizeStep;
}
Modified: trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/preferences/CategoryCreationAcivity.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -34,7 +34,7 @@
import android.widget.TextView;
import fr.ifremer.wlo.R;
import fr.ifremer.wlo.WloBaseActivity;
-import fr.ifremer.wlo.utils.ImportUtil;
+import fr.ifremer.wlo.utils.ImportExportUtil;
import fr.ifremer.wlo.models.categorization.CategoryModel;
import fr.ifremer.wlo.models.categorization.QualitativeValueModel;
import fr.ifremer.wlo.storage.DataCache;
@@ -113,7 +113,7 @@
String path = data.getStringExtra(FileDialog.RESULT_PATH);
try {
Collection<QualitativeValueModel> qualitativeValueModels =
- ImportUtil.importQualitativeValues(model, path);
+ ImportExportUtil.importQualitativeValues(model, path);
model.setQualitativeValues(new ArrayList<>(qualitativeValueModels));
TextView textView = (TextView) findViewById(R.id.qualitative_values_nb_label);
Modified: trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -34,15 +34,11 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
-import android.preference.MultiSelectListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.util.Log;
import android.widget.Toast;
-import com.google.common.base.Functions;
-import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
-import com.google.common.collect.Collections2;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import fr.ifremer.wlo.MainActivity;
@@ -54,7 +50,7 @@
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.StorageUtils;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
-import fr.ifremer.wlo.utils.ImportUtil;
+import fr.ifremer.wlo.utils.ImportExportUtil;
import fr.ifremer.wlo.utils.UIUtils;
import fr.ifremer.wlo.utils.UpdateCheckTask;
import fr.ifremer.wlo.utils.filechooser.FileDialog;
@@ -65,10 +61,8 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -89,11 +83,21 @@
protected static final int REQUEST_IMPORT_STATES = 6;
protected static final int REQUEST_IMPORT_VESSELS = 7;
protected static final int REQUEST_IMPORT_CALCIFIED_PARTS_TAKINGS = 8;
- protected static final int REQUEST_CREATE_CATEGORY = 9;
- protected static final int REQUEST_FAVORITES_COMMERCIAL_SPECIES = 10;
- protected static final int REQUEST_FAVORITES_SCIENTIFIC_SPECIES = 11;
+ protected static final int REQUEST_EXPORT_COMMERCIAL_SPECIES = 10;
+ protected static final int REQUEST_EXPORT_LOCATIONS = 11;
+ protected static final int REQUEST_EXPORT_MENSURATIONS = 12;
+ protected static final int REQUEST_EXPORT_METIERS = 13;
+ protected static final int REQUEST_EXPORT_PRESENTATIONS = 14;
+ protected static final int REQUEST_EXPORT_SCIENTIFIC_SPECIES = 15;
+ protected static final int REQUEST_EXPORT_STATES = 16;
+ protected static final int REQUEST_EXPORT_VESSELS = 17;
+ protected static final int REQUEST_EXPORT_CALCIFIED_PARTS_TAKINGS = 18;
+ protected static final int REQUEST_CREATE_CATEGORY = 20;
+ protected static final int REQUEST_FAVORITES_COMMERCIAL_SPECIES = 21;
+ protected static final int REQUEST_FAVORITES_SCIENTIFIC_SPECIES = 22;
+
@Override
protected Integer getContentView() {
return null;
@@ -138,6 +142,16 @@
requestCodeByPrefKey.put("import_vessels", REQUEST_IMPORT_VESSELS);
requestCodeByPrefKey.put("import_calcified_parts_takings", REQUEST_IMPORT_CALCIFIED_PARTS_TAKINGS);
+ requestCodeByPrefKey.put("export_commercial_species", REQUEST_EXPORT_COMMERCIAL_SPECIES);
+ requestCodeByPrefKey.put("export_locations", REQUEST_EXPORT_LOCATIONS);
+ requestCodeByPrefKey.put("export_mensurations", REQUEST_EXPORT_MENSURATIONS);
+ requestCodeByPrefKey.put("export_metiers", REQUEST_EXPORT_METIERS);
+ requestCodeByPrefKey.put("export_presentations", REQUEST_EXPORT_PRESENTATIONS);
+ requestCodeByPrefKey.put("export_scientific_species", REQUEST_EXPORT_SCIENTIFIC_SPECIES);
+ requestCodeByPrefKey.put("export_states", REQUEST_EXPORT_STATES);
+ requestCodeByPrefKey.put("export_vessels", REQUEST_EXPORT_VESSELS);
+ requestCodeByPrefKey.put("export_calcified_parts_takings", REQUEST_EXPORT_CALCIFIED_PARTS_TAKINGS);
+
Map<String, Integer> nbElementsByPrefKey = Maps.newHashMap();
Context context = getActivity();
nbElementsByPrefKey.put("import_commercial_species", DataCache.getAllCommercialSpecies(context).size());
@@ -149,6 +163,15 @@
nbElementsByPrefKey.put("import_states", DataCache.getAllStates(context).size());
nbElementsByPrefKey.put("import_vessels", DataCache.getAllVessels(context).size());
+ nbElementsByPrefKey.put("export_commercial_species", DataCache.getAllCommercialSpecies(context).size());
+ nbElementsByPrefKey.put("export_locations", DataCache.getAllLocations(context).size());
+ nbElementsByPrefKey.put("export_mensurations", DataCache.getAllMensurations(context).size());
+ nbElementsByPrefKey.put("export_metiers", DataCache.getAllMetiers(context).size());
+ nbElementsByPrefKey.put("export_presentations", DataCache.getAllPresentations(context).size());
+ nbElementsByPrefKey.put("export_scientific_species", DataCache.getAllScientificSpecies(context).size());
+ nbElementsByPrefKey.put("export_states", DataCache.getAllStates(context).size());
+ nbElementsByPrefKey.put("export_vessels", DataCache.getAllVessels(context).size());
+
for (String key : requestCodeByPrefKey.keySet()) {
final Integer requestCode = requestCodeByPrefKey.get(key);
Preference filePicker = findPreference(key);
@@ -161,7 +184,7 @@
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(getActivity(), FileDialog.class); //Intent to start openIntents File Manager
intent.putExtra(FileDialog.START_PATH, "/sdcard");
- intent.putExtra(FileDialog.CAN_SELECT_DIR, false);
+ intent.putExtra(FileDialog.CAN_SELECT_DIR, requestCode >= REQUEST_EXPORT_COMMERCIAL_SPECIES);
intent.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
//alternatively you can set file filter
@@ -293,6 +316,11 @@
importData(requestCode, data, true);
}
+ } else if (requestCode >= REQUEST_EXPORT_COMMERCIAL_SPECIES
+ && requestCode <= REQUEST_EXPORT_CALCIFIED_PARTS_TAKINGS) {
+
+ exportData(requestCode, data);
+
} else if (requestCode == REQUEST_CREATE_CATEGORY) {
int nb = DataCache.getAllCategories(context).size();
Preference categoryPref = findPreference("import_categories");
@@ -311,11 +339,15 @@
}
protected void importData(final int requestCode, final Intent data, final boolean backupFile) {
- final Context context = getActivity();
String path = data.getStringExtra(FileDialog.RESULT_PATH);
new ImportAsyncTask().execute(path, requestCode, backupFile);
}
+ protected void exportData(final int requestCode, final Intent data) {
+ String path = data.getStringExtra(FileDialog.RESULT_PATH);
+ new ExportAsyncTask().execute(path, requestCode);
+ }
+
protected <M extends BaseModel> void initMultiSelectListPreference(String prefKey,
final Class clazz,
final int requestCode) {
@@ -361,6 +393,8 @@
protected ProgressDialog dialog;
+ protected String errorMessage;
+
@Override
protected void onPreExecute() {
super.onPreExecute();
@@ -388,42 +422,42 @@
try {
switch (requestCode) {
case REQUEST_IMPORT_COMMERCIAL_SPECIES:
- result[0] = ImportUtil.importCommercialSpecies(context, path);
+ result[0] = ImportExportUtil.importCommercialSpecies(context, path);
result[1] = DataCache.getAllCommercialSpecies(context).size();
break;
case REQUEST_IMPORT_LOCATIONS:
- result[0] = ImportUtil.importLocations(context, path);
+ result[0] = ImportExportUtil.importLocations(context, path);
result[1] = DataCache.getAllLocations(context).size();
break;
case REQUEST_IMPORT_MENSURATIONS:
- result[0] = ImportUtil.importMensurations(context, path);
+ result[0] = ImportExportUtil.importMensurations(context, path);
result[1] = DataCache.getAllMensurations(context).size();
break;
case REQUEST_IMPORT_METIERS:
- result[0] = ImportUtil.importMetiers(context, path);
+ result[0] = ImportExportUtil.importMetiers(context, path);
result[1] = DataCache.getAllMetiers(context).size();
break;
case REQUEST_IMPORT_PRESENTATIONS:
- result[0] = ImportUtil.importPresentations(context, path);
+ result[0] = ImportExportUtil.importPresentations(context, path);
result[1] = DataCache.getAllPresentations(context).size();
break;
case REQUEST_IMPORT_SCIENTIFIC_SPECIES:
- result[0] = ImportUtil.importScientificSpecies(context, path);
+ result[0] = ImportExportUtil.importScientificSpecies(context, path);
result[1] = DataCache.getAllScientificSpecies(context).size();
break;
case REQUEST_IMPORT_STATES:
- result[0] = ImportUtil.importStates(context, path);
+ result[0] = ImportExportUtil.importStates(context, path);
result[1] = DataCache.getAllStates(context).size();
break;
case REQUEST_IMPORT_VESSELS:
- result[0] = ImportUtil.importVessels(context, path);
+ result[0] = ImportExportUtil.importVessels(context, path);
result[1] = DataCache.getAllVessels(context).size();
break;
case REQUEST_IMPORT_CALCIFIED_PARTS_TAKINGS:
WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
soh.clearCalcifiedPartTakings();
soh.close();
- result[0] = ImportUtil.importCalcifiedPartTakings(context, path);
+ result[0] = ImportExportUtil.importCalcifiedPartTakings(context, path);
result[1] = null;
break;
default:
@@ -446,7 +480,14 @@
} catch (Exception e) {
// cf issue #4205
// nuiton-i18n provocks an error when trying to get the error message
- Log.e(TAG, "error during import", e);
+ Log.e(TAG, "error during import " + requestCode, e);
+
+ if (requestCode == REQUEST_IMPORT_CALCIFIED_PARTS_TAKINGS) {
+ errorMessage = e.getMessage();
+
+ } else {
+ errorMessage = getString(R.string.import_error);
+ }
result = null;
cancel(true);
@@ -468,13 +509,6 @@
}
Toast.makeText(getActivity(), getString(R.string.import_new_element_number, result[0]), Toast.LENGTH_LONG).show();
-
-// } else {
-// //error
-// new AlertDialog.Builder(getActivity())
-// .setMessage(R.string.import_error)
-// .setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
-// .create().show();
}
}
@@ -484,12 +518,111 @@
dialog.dismiss();
new AlertDialog.Builder(getActivity())
- .setMessage(R.string.import_error)
+ .setTitle(R.string.error)
+ .setMessage(errorMessage)
.setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
.create().show();
}
}
+
+ protected class ExportAsyncTask extends AsyncTask<Object, Integer, Integer> {
+
+ protected ProgressDialog dialog;
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+
+ dialog = new ProgressDialog(getActivity());
+ dialog.setCancelable(false);
+ dialog.setMessage(getString(R.string.preferences_exporting_referential));
+ dialog.show();
+ }
+
+ @Override
+ protected Integer doInBackground(Object... params) {
+ if (params.length != 2) {
+ return null;
+ }
+ Context context = getActivity();
+ String path = (String) params[0];
+ Integer requestCode = (Integer) params[1];
+ Log.d(TAG, path);
+
+ Integer result;
+
+ try {
+ switch (requestCode) {
+ case REQUEST_EXPORT_COMMERCIAL_SPECIES:
+ result = ImportExportUtil.exportCommercialSpecies(context, path);
+ break;
+ case REQUEST_EXPORT_LOCATIONS:
+ result = ImportExportUtil.exportLocations(context, path);
+ break;
+ case REQUEST_EXPORT_MENSURATIONS:
+ result = ImportExportUtil.exportMensurations(context, path);
+ break;
+ case REQUEST_EXPORT_METIERS:
+ result = ImportExportUtil.exportMetiers(context, path);
+ break;
+ case REQUEST_EXPORT_PRESENTATIONS:
+ result = ImportExportUtil.exportPresentations(context, path);
+ break;
+ case REQUEST_EXPORT_SCIENTIFIC_SPECIES:
+ result = ImportExportUtil.exportScientificSpecies(context, path);
+ break;
+ case REQUEST_EXPORT_STATES:
+ result = ImportExportUtil.exportStates(context, path);
+ break;
+ case REQUEST_EXPORT_VESSELS:
+ result = ImportExportUtil.exportVessels(context, path);
+ break;
+ case REQUEST_EXPORT_CALCIFIED_PARTS_TAKINGS:
+ WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
+ soh.clearCalcifiedPartTakings();
+ soh.close();
+ result = ImportExportUtil.exportCalcifiedPartTakings(context, path);
+ break;
+ default:
+ result = null;
+ }
+
+ } catch (Exception e) {
+ // cf issue #4205
+ // nuiton-i18n provocks an error when trying to get the error message
+ Log.e(TAG, "error during import", e);
+ result = null;
+ cancel(true);
+
+ }
+ return result;
+ }
+
+ @Override
+ protected void onPostExecute(Integer result) {
+ super.onPostExecute(result);
+
+ dialog.dismiss();
+
+ if (result != null) {
+ Toast.makeText(getActivity(), getString(R.string.export_element_number, result), Toast.LENGTH_LONG).show();
+ }
+ }
+
+ @Override
+ protected void onCancelled(Integer integer) {
+ super.onCancelled(integer);
+ dialog.dismiss();
+
+ new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.error)
+ .setMessage(R.string.export_error)
+ .setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
+ .create().show();
+ }
+
+ }
}
}
\ No newline at end of file
Modified: trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java
===================================================================
--- trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -28,6 +28,7 @@
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -570,6 +571,13 @@
// CALCIFIED PART TAKING
+ public Cursor getAllCalcifiedPartTakings() {
+ SQLiteDatabase db = getReadableDatabase();
+ Cursor cursor = db.query(CalcifiedPartTaking.TABLE_NAME, CalcifiedPartTaking.ALL_COLUMNS,
+ null, null, null, null, null);
+ return cursor;
+ }
+
public Cursor getAllCalcifiedPartTakings(String scientificSpeciesId) {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(CalcifiedPartTaking.TABLE_NAME, CalcifiedPartTaking.ALL_COLUMNS,
@@ -687,9 +695,11 @@
ContentValues values = model.convertIntoContentValues();
if (newSession) {
+ Log.d(TAG, "create " + values);
db.insert(tableName, null, values);
} else {
+ Log.d(TAG, "update " + values);
db.update(tableName, values, BaseModel._ID + " = ?", new String[]{ model.getId() });
}
model.setModified(false);
Copied: trunk/src/fr/ifremer/wlo/utils/ImportExportUtil.java (from rev 69, trunk/src/fr/ifremer/wlo/utils/ImportUtil.java)
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/ImportExportUtil.java (rev 0)
+++ trunk/src/fr/ifremer/wlo/utils/ImportExportUtil.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -0,0 +1,497 @@
+package fr.ifremer.wlo.utils;
+
+/*
+ * #%L
+ * WLO
+ * $Id:$
+ * $HeadURL:$
+ * %%
+ * Copyright (C) 2013 - 2014 Ifremer
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+import android.content.Context;
+import android.database.Cursor;
+import android.os.AsyncTask;
+import android.util.Log;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import fr.ifremer.wlo.R;
+import fr.ifremer.wlo.imports.CalcifiedPartTakingRowModel;
+import fr.ifremer.wlo.imports.CommercialSpeciesRowModel;
+import fr.ifremer.wlo.imports.LocationRowModel;
+import fr.ifremer.wlo.imports.MensurationRowModel;
+import fr.ifremer.wlo.imports.MetierRowModel;
+import fr.ifremer.wlo.imports.PresentationRowModel;
+import fr.ifremer.wlo.imports.QualitativeValueRowModel;
+import fr.ifremer.wlo.imports.ScientificSpeciesRowModel;
+import fr.ifremer.wlo.imports.StateRowModel;
+import fr.ifremer.wlo.imports.VesselRowModel;
+import fr.ifremer.wlo.models.BaseModel;
+import fr.ifremer.wlo.models.categorization.CategoryModel;
+import fr.ifremer.wlo.models.categorization.QualitativeValueModel;
+import fr.ifremer.wlo.models.referentials.CalcifiedPartTaking;
+import fr.ifremer.wlo.models.referentials.HasCode;
+import fr.ifremer.wlo.storage.DataCache;
+import fr.ifremer.wlo.storage.WloSqlOpenHelper;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.ComparatorUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.Range;
+import org.nuiton.csv.Export;
+import org.nuiton.csv.ExportModel;
+import org.nuiton.csv.Import;
+import org.nuiton.csv.ImportModel;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * @author kmorin <kmorin(a)codelutin.com>
+ * @since 0.1
+ */
+public class ImportExportUtil {
+
+ private static final String TAG = "ImportExportUtil";
+
+ public static final char CSV_SEPARATOR = ';';
+
+ public static int importCommercialSpecies(Context context, String path) {
+ try {
+ return importCommercialSpecies(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importCommercialSpecies(Context context, InputStream inputStream) {
+ CommercialSpeciesRowModel commercialSpeciesRowModel = new CommercialSpeciesRowModel(CSV_SEPARATOR);
+ int result = importData(context, commercialSpeciesRowModel, inputStream);
+ DataCache.invalidateCommercialSpecies();
+ return result;
+ }
+
+ public static int exportCommercialSpecies(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ CommercialSpeciesRowModel commercialSpeciesRowModel = new CommercialSpeciesRowModel(CSV_SEPARATOR);
+ int result = exportData(context,
+ commercialSpeciesRowModel,
+ DataCache.getAllCommercialSpecies(context),
+ path,
+ R.string.preferences_export_commercial_species_default_name);
+ return result;
+ }
+
+ public static int importLocations(Context context, String path) {
+ try {
+ return importLocations(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importLocations(Context context, InputStream inputStream) {
+ LocationRowModel locationRowModel = new LocationRowModel(CSV_SEPARATOR);
+ int result = importData(context, locationRowModel, inputStream);
+ DataCache.invalidateLocations();
+ return result;
+ }
+
+ public static int exportLocations(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ LocationRowModel locationRowModel = new LocationRowModel(CSV_SEPARATOR);
+ int result = exportData(context,
+ locationRowModel,
+ DataCache.getAllLocations(context),
+ path,
+ R.string.preferences_export_locations_default_name);
+ return result;
+ }
+
+ public static int importMensurations(Context context, String path) {
+ try {
+ return importMensurations(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importMensurations(Context context, InputStream inputStream) {
+ MensurationRowModel mensurationRowModel = new MensurationRowModel(CSV_SEPARATOR);
+ int result = importData(context, mensurationRowModel, inputStream);
+ DataCache.invalidateMensurations();
+ return result;
+ }
+
+ public static int exportMensurations(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ MensurationRowModel mensurationRowModel = new MensurationRowModel(CSV_SEPARATOR);
+ int result = exportData(context,
+ mensurationRowModel,
+ DataCache.getAllMensurations(context),
+ path,
+ R.string.preferences_export_mensurations_default_name);
+ return result;
+ }
+
+ public static int importMetiers(Context context, String path) {
+ try {
+ return importMetiers(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importMetiers(Context context, InputStream inputStream) {
+ MetierRowModel metierRowModel = new MetierRowModel(CSV_SEPARATOR);
+ int result = importData(context, metierRowModel, inputStream);
+ DataCache.invalidateMetiers();
+ return result;
+ }
+
+
+ public static int exportMetiers(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ MetierRowModel metierRowModel = new MetierRowModel(CSV_SEPARATOR);
+ int result = exportData(context,
+ metierRowModel,
+ DataCache.getAllMetiers(context),
+ path,
+ R.string.preferences_export_metiers_default_name);
+ return result;
+ }
+
+ public static int importPresentations(Context context, String path) {
+ try {
+ return importPresentations(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importPresentations(Context context, InputStream inputStream) {
+ PresentationRowModel presentationRowModel = new PresentationRowModel(CSV_SEPARATOR);
+ int result = importData(context, presentationRowModel, inputStream);
+ DataCache.invalidatePresentations();
+ return result;
+ }
+
+
+ public static int exportPresentations(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ PresentationRowModel presentationRowModel = new PresentationRowModel(CSV_SEPARATOR);
+ int result = exportData(context,
+ presentationRowModel,
+ DataCache.getAllPresentations(context),
+ path,
+ R.string.preferences_export_presentations_default_name);
+ return result;
+ }
+
+ public static int importScientificSpecies(Context context, String path) {
+ try {
+ return importScientificSpecies(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importScientificSpecies(Context context, InputStream inputStream) {
+ ScientificSpeciesRowModel scientificSpeciesRowModel = new ScientificSpeciesRowModel(CSV_SEPARATOR);
+ int result = importData(context, scientificSpeciesRowModel, inputStream);
+ DataCache.invalidateScientificSpecies();
+ return result;
+ }
+
+ public static int exportScientificSpecies(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ ScientificSpeciesRowModel scientificSpeciesRowModel = new ScientificSpeciesRowModel(CSV_SEPARATOR);
+ int result = exportData(context,
+ scientificSpeciesRowModel,
+ DataCache.getAllScientificSpecies(context),
+ path,
+ R.string.preferences_export_scientific_species_default_name);
+ return result;
+ }
+
+ public static int importStates(Context context, String path) {
+ try {
+ return importStates(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importStates(Context context, InputStream inputStream) {
+ StateRowModel stateRowModel = new StateRowModel(CSV_SEPARATOR);
+ int result = importData(context, stateRowModel, inputStream);
+ DataCache.invalidateStates();
+ return result;
+ }
+
+ public static int exportStates(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ StateRowModel stateRowModel = new StateRowModel(CSV_SEPARATOR);
+ int result = exportData(context,
+ stateRowModel,
+ DataCache.getAllStates(context),
+ path,
+ R.string.preferences_export_states_default_name);
+ return result;
+ }
+
+ public static int importVessels(Context context, String path) {
+ try {
+ return importVessels(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importVessels(Context context, InputStream inputStream) {
+ VesselRowModel vesselRowModel = new VesselRowModel(CSV_SEPARATOR);
+ int result = importData(context, vesselRowModel, inputStream);
+ DataCache.invalidateVessels();
+ return result;
+ }
+
+ public static int exportVessels(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ VesselRowModel vesselRowModel = new VesselRowModel(CSV_SEPARATOR);
+ int result = exportData(context,
+ vesselRowModel,
+ DataCache.getAllVessels(context),
+ path,
+ R.string.preferences_export_vessels_default_name);
+ return result;
+ }
+
+ public static int importCalcifiedPartTakings(Context context, String path) throws Exception {
+ try {
+ return importCalcifiedPartTakings(context, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return 0;
+ }
+
+ public static int importCalcifiedPartTakings(Context context, InputStream inputStream) {
+ CalcifiedPartTakingRowModel calcifiedPartTakingRowModel = new CalcifiedPartTakingRowModel(CSV_SEPARATOR, DataCache.getAllScientificSpecies(context));
+ Collection<CalcifiedPartTaking> data = importData(calcifiedPartTakingRowModel, inputStream);
+
+ Multimap<String, Range<Integer>> ranges = HashMultimap.create();
+ Map<String, Integer> sizeSteps = new HashMap<>();
+
+ for (CalcifiedPartTaking taking : data) {
+ // check if the species exists
+ if (taking.getParent() == null) {
+ throw new NullPointerException(context.getString(R.string.preferences_import_calcified_parts_takings_null_species));
+ }
+
+ String parentId = taking.getParentId();
+
+ // check if the steps are the same for the species (at least one step must be defined for each species)
+ Integer speciesSizeStep = sizeSteps.get(parentId);
+ Integer sizeStep = taking.getSizeStep();
+ if (speciesSizeStep != null && sizeStep != null && !speciesSizeStep.equals(sizeStep)) {
+ throw new RuntimeException(context.getString(R.string.preferences_import_calcified_parts_different_size_steps));
+ }
+ if (sizeStep != null) {
+ sizeSteps.put(parentId, sizeStep);
+ }
+
+ // check if the intervals are not overlapping
+ Integer startSize = taking.getStartSize();
+ if (startSize == null) {
+ startSize = 0;
+ }
+ Integer endSize = taking.getEndSize();
+ if (endSize == null) {
+ endSize = Integer.MAX_VALUE;
+ }
+ Range<Integer> currentRange = Range.between(startSize, endSize);
+ for (Range<Integer> range : ranges.get(parentId)) {
+ if (range.isOverlappedBy(currentRange)) {
+ throw new RuntimeException(context.getString(R.string.preferences_import_calcified_parts_takings_overlapping));
+ }
+ }
+
+ ranges.put(parentId, currentRange);
+ }
+
+ // check if every species has a size step
+ if (sizeSteps.containsValue(null)) {
+ throw new RuntimeException(context.getString(R.string.preferences_import_calcified_parts_no_size_step));
+ }
+
+ // check if there is no interval out of the ranges
+ Set<Range<Integer>> rangesForSpecies = new TreeSet<>(new Comparator<Range<Integer>>() {
+
+ @Override
+ public int compare(Range<Integer> lhs, Range<Integer> rhs) {
+ return ObjectUtils.compare(lhs.getMinimum(), rhs.getMinimum());
+ }
+ });
+ for (String speciesId : ranges.keySet()) {
+ int sizeStep = sizeSteps.get(speciesId);
+ rangesForSpecies.clear();
+ rangesForSpecies.addAll(ranges.get(speciesId));
+ int n = 0;
+ for (Range<Integer> range : rangesForSpecies) {
+ if (range.getMinimum() - sizeStep > n) {
+ throw new RuntimeException(context.getString(R.string.preferences_import_calcified_parts_takings_value_out_of_ranges));
+ }
+ n = range.getMaximum();
+ }
+ if (n < Integer.MAX_VALUE) {
+ throw new RuntimeException(context.getString(R.string.preferences_import_calcified_parts_takings_value_out_of_ranges));
+ }
+ }
+
+ WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
+ soh.saveData(data);
+ soh.close();
+
+ int result = data.size();
+ return result;
+ }
+
+ public static int exportCalcifiedPartTakings(Context context, String path) throws Exception {
+ Preconditions.checkNotNull(path);
+ CalcifiedPartTakingRowModel calcifiedPartTakingRowModel = new CalcifiedPartTakingRowModel(CSV_SEPARATOR, DataCache.getAllScientificSpecies(context));
+ WloSqlOpenHelper wloSqlOpenHelper = new WloSqlOpenHelper(context);
+ int result = exportData(context,
+ calcifiedPartTakingRowModel,
+ WloSqlOpenHelper.transformCursorIntoCollection(wloSqlOpenHelper.getAllCalcifiedPartTakings(),
+ new Function<Cursor, CalcifiedPartTaking>() {
+ @Override
+ public CalcifiedPartTaking apply(Cursor input) {
+ return new CalcifiedPartTaking(input);
+ }
+ }),
+ path,
+ R.string.preferences_export_calcified_parts_takings_default_name);
+ wloSqlOpenHelper.close();
+ return result;
+ }
+
+ public static Collection<QualitativeValueModel> importQualitativeValues(CategoryModel categoryModel, String path) {
+ try {
+ return importQualitativeValues(categoryModel, new FileInputStream(path));
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File " + path + " not found", e);
+ }
+ return null;
+ }
+
+ public static Collection<QualitativeValueModel> importQualitativeValues(CategoryModel categoryModel, InputStream inputStream) {
+ QualitativeValueRowModel qualitativeValueRowModel = new QualitativeValueRowModel(CSV_SEPARATOR, categoryModel);
+ Collection<QualitativeValueModel> result = importData(qualitativeValueRowModel, inputStream);
+ return result;
+ }
+
+ protected static <M extends BaseModel> int importData(Context context, ImportModel<M> importModel,
+ InputStream inputStream) {
+
+ Collection<M> models = importData(importModel, inputStream);
+
+ if (CollectionUtils.isNotEmpty(models)) {
+ WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
+ soh.saveData(models);
+ soh.close();
+ }
+
+ return models.size();
+ }
+
+ protected static <M extends BaseModel> Collection<M> importData(ImportModel<M> importModel, InputStream inputStream) {
+ Import<M> importer = null;
+ Collection<M> models = null;
+
+ try {
+ importer = Import.newImport(importModel, inputStream);
+ models = Lists.newArrayList(importer.iterator());
+
+ } catch (ClassCastException e) {
+ // cf issue #4205
+ // nuiton-i18n provocks an error when trying to get the error message
+ Log.e(TAG, "error during import", e);
+ throw e;
+
+ } finally {
+ if (importer != null) {
+ importer.close();
+ }
+ }
+ return models;
+ }
+
+ protected static <M extends BaseModel> int exportData(Context context,
+ ExportModel<M> exportModel,
+ Collection<M> data,
+ String path,
+ int defaultFileName) throws Exception {
+
+ int result = 0;
+
+ File targetFile = new File(path);
+ if (targetFile.isDirectory()) {
+ String fileName = context.getString(defaultFileName)
+ + String.format("-%1$tY%1$tm%1$td-%1$tH%1$tM%1$tS", new Date()) + ".csv";
+ targetFile = new File(targetFile, fileName);
+ }
+
+ try {
+ Export<M> exporter = Export.newExport(exportModel, data);
+ exporter.write(targetFile);
+ result = data.size();
+
+ } catch (Exception e) {
+ // cf issue #4205
+ // nuiton-i18n provocks an error when trying to get the error message
+ Log.e(TAG, "error during import", e);
+ throw e;
+ }
+ return result;
+ }
+}
Deleted: trunk/src/fr/ifremer/wlo/utils/ImportUtil.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/ImportUtil.java 2014-03-11 17:30:27 UTC (rev 75)
+++ trunk/src/fr/ifremer/wlo/utils/ImportUtil.java 2014-03-17 16:56:27 UTC (rev 76)
@@ -1,295 +0,0 @@
-package fr.ifremer.wlo.utils;
-
-/*
- * #%L
- * WLO
- * $Id:$
- * $HeadURL:$
- * %%
- * Copyright (C) 2013 - 2014 Ifremer
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-import android.content.Context;
-import android.os.AsyncTask;
-import android.util.Log;
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import fr.ifremer.wlo.imports.CalcifiedPartTakingRowModel;
-import fr.ifremer.wlo.imports.CommercialSpeciesRowModel;
-import fr.ifremer.wlo.imports.LocationRowModel;
-import fr.ifremer.wlo.imports.MensurationRowModel;
-import fr.ifremer.wlo.imports.MetierRowModel;
-import fr.ifremer.wlo.imports.PresentationRowModel;
-import fr.ifremer.wlo.imports.QualitativeValueRowModel;
-import fr.ifremer.wlo.imports.ScientificSpeciesRowModel;
-import fr.ifremer.wlo.imports.StateRowModel;
-import fr.ifremer.wlo.imports.VesselRowModel;
-import fr.ifremer.wlo.models.BaseModel;
-import fr.ifremer.wlo.models.categorization.CategoryModel;
-import fr.ifremer.wlo.models.categorization.QualitativeValueModel;
-import fr.ifremer.wlo.models.referentials.CalcifiedPartTaking;
-import fr.ifremer.wlo.models.referentials.HasCode;
-import fr.ifremer.wlo.storage.DataCache;
-import fr.ifremer.wlo.storage.WloSqlOpenHelper;
-import org.apache.commons.collections.CollectionUtils;
-import org.nuiton.csv.Import;
-import org.nuiton.csv.ImportModel;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * @author kmorin <kmorin(a)codelutin.com>
- * @since 0.1
- */
-public class ImportUtil {
-
- private static final String TAG = "ImportUtil";
-
- public static final char CSV_SEPARATOR = ';';
-
- public static int importCommercialSpecies(Context context, String path) {
- try {
- return importCommercialSpecies(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importCommercialSpecies(Context context, InputStream inputStream) {
- CommercialSpeciesRowModel commercialSpeciesRowModel = new CommercialSpeciesRowModel(CSV_SEPARATOR);
- int result = importData(context, commercialSpeciesRowModel, inputStream, DataCache.getAllCommercialSpecies(context));
- DataCache.invalidateCommercialSpecies();
- return result;
- }
-
- public static int importLocations(Context context, String path) {
- try {
- return importLocations(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importLocations(Context context, InputStream inputStream) {
- LocationRowModel locationRowModel = new LocationRowModel(CSV_SEPARATOR);
- int result = importData(context, locationRowModel, inputStream, DataCache.getAllLocations(context));
- DataCache.invalidateLocations();
- return result;
- }
-
- public static int importMensurations(Context context, String path) {
- try {
- return importMensurations(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importMensurations(Context context, InputStream inputStream) {
- MensurationRowModel mensurationRowModel = new MensurationRowModel(CSV_SEPARATOR);
- int result = importData(context, mensurationRowModel, inputStream, DataCache.getAllMensurations(context));
- DataCache.invalidateMensurations();
- return result;
- }
-
- public static int importMetiers(Context context, String path) {
- try {
- return importMetiers(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importMetiers(Context context, InputStream inputStream) {
- MetierRowModel metierRowModel = new MetierRowModel(CSV_SEPARATOR);
- int result = importData(context, metierRowModel, inputStream, DataCache.getAllMetiers(context));
- DataCache.invalidateMetiers();
- return result;
- }
-
- public static int importPresentations(Context context, String path) {
- try {
- return importPresentations(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importPresentations(Context context, InputStream inputStream) {
- PresentationRowModel presentationRowModel = new PresentationRowModel(CSV_SEPARATOR);
- int result = importData(context, presentationRowModel, inputStream, DataCache.getAllPresentations(context));
- DataCache.invalidatePresentations();
- return result;
- }
-
- public static int importScientificSpecies(Context context, String path) {
- try {
- return importScientificSpecies(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importScientificSpecies(Context context, InputStream inputStream) {
- ScientificSpeciesRowModel scientificSpeciesRowModel = new ScientificSpeciesRowModel(CSV_SEPARATOR);
- int result = importData(context, scientificSpeciesRowModel, inputStream, DataCache.getAllScientificSpecies(context));
- DataCache.invalidateScientificSpecies();
- return result;
- }
-
- public static int importStates(Context context, String path) {
- try {
- return importStates(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importStates(Context context, InputStream inputStream) {
- StateRowModel stateRowModel = new StateRowModel(CSV_SEPARATOR);
- int result = importData(context, stateRowModel, inputStream, DataCache.getAllStates(context));
- DataCache.invalidateStates();
- return result;
- }
-
- public static int importVessels(Context context, String path) {
- try {
- return importVessels(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importVessels(Context context, InputStream inputStream) {
- VesselRowModel vesselRowModel = new VesselRowModel(CSV_SEPARATOR);
- int result = importData(context, vesselRowModel, inputStream, DataCache.getAllVessels(context));
- DataCache.invalidateVessels();
- return result;
- }
-
- public static int importCalcifiedPartTakings(Context context, String path) {
- try {
- return importCalcifiedPartTakings(context, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return 0;
- }
-
- public static int importCalcifiedPartTakings(Context context, InputStream inputStream) {
- CalcifiedPartTakingRowModel calcifiedPartTakingRowModel = new CalcifiedPartTakingRowModel(CSV_SEPARATOR, DataCache.getAllScientificSpecies(context));
- int result = importData(context, calcifiedPartTakingRowModel, inputStream, new ArrayList<CalcifiedPartTaking>());
- return result;
- }
-
- public static Collection<QualitativeValueModel> importQualitativeValues(CategoryModel categoryModel, String path) {
- try {
- return importQualitativeValues(categoryModel, new FileInputStream(path));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File " + path + " not found", e);
- }
- return null;
- }
-
- public static Collection<QualitativeValueModel> importQualitativeValues(CategoryModel categoryModel, InputStream inputStream) {
- QualitativeValueRowModel qualitativeValueRowModel = new QualitativeValueRowModel(CSV_SEPARATOR, categoryModel);
- Collection<QualitativeValueModel> result = importData(qualitativeValueRowModel, inputStream, new ArrayList<QualitativeValueModel>());
- return result;
- }
-
- protected static <M extends BaseModel> int importData(Context context, ImportModel<M> importModel,
- InputStream inputStream, final Collection<M> actualReferential) {
-
- Collection<M> models = importData(importModel, inputStream, actualReferential);
-
- if (CollectionUtils.isNotEmpty(models)) {
- Predicate<M> filter;
- //if the models have a code attribute, check
- M first = models.iterator().next();
- if (HasCode.class.isAssignableFrom(first.getClass())) {
- Collection<HasCode> hasCodes = Collections2.transform(actualReferential, new Function<M, HasCode>() {
- @Override
- public HasCode apply(M m) {
- return (HasCode) m;
- }
- });
- final Collection<String> codes = Collections2.transform(hasCodes, HasCode.GET_CODE_FUNCTION);
- filter = new Predicate<M>() {
- @Override
- public boolean apply(M model) {
- HasCode hasCode = (HasCode) model;
- return !codes.contains(hasCode.getCode());
- }
- };
- } else {
- filter = new Predicate<M>() {
- @Override
- public boolean apply(M m) {
- return !actualReferential.contains(m);
- }
- };
- }
-
- models = Collections2.filter(models, filter);
- WloSqlOpenHelper soh = new WloSqlOpenHelper(context);
- soh.saveData(models);
- soh.close();
- }
-
- return models.size();
- }
-
- protected static <M extends BaseModel> Collection<M> importData(ImportModel<M> importModel, InputStream inputStream,
- Collection<M> actualReferential) {
- Preconditions.checkNotNull(actualReferential);
- Import<M> importer = null;
- Collection<M> models = null;
-
- try {
- importer = Import.newImport(importModel, inputStream);
- models = Lists.newArrayList(importer.iterator());
-
- } catch (ClassCastException e) {
- // cf issue #4205
- // nuiton-i18n provocks an error when trying to get the error message
- Log.e(TAG, "error during import", e);
- throw e;
-
- } finally {
- if (importer != null) {
- importer.close();
- }
- }
- return models;
- }
-}
1
0
Author: kmorin
Date: 2014-03-11 18:30:27 +0100 (Tue, 11 Mar 2014)
New Revision: 75
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/75
Log:
fix bluetooth connexion once failed
Modified:
trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java
Modified: trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java
===================================================================
--- trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java 2014-03-11 17:18:53 UTC (rev 74)
+++ trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java 2014-03-11 17:30:27 UTC (rev 75)
@@ -378,7 +378,7 @@
*/
protected class AcceptThread extends Thread {
// The local server socket
- private final BluetoothServerSocket mmServerSocket;
+ private BluetoothServerSocket mmServerSocket;
public AcceptThread() {
BluetoothServerSocket tmp = null;
@@ -400,7 +400,7 @@
BluetoothSocket socket = null;
// Listen to the server socket if we're not connected
- while (mState != STATE_CONNECTED) {
+ while (mState != STATE_CONNECTED && mmServerSocket != null) {
try {
// This is a blocking call and will only return on a
// successful connection or an exception
@@ -440,6 +440,7 @@
Log.d(TAG, "Socket cancel " + this);
try {
mmServerSocket.close();
+ mmServerSocket = null;
} catch (IOException e) {
Log.e(TAG, "Socket close() of server failed", e);
}
@@ -546,7 +547,7 @@
int bytes;
// Keep listening to the InputStream while connected
- while (true) {
+ while (!stop) {
try {
// Read from the InputStream
// bytes = mmInStream.read(buffer);
@@ -559,9 +560,6 @@
boolean complete = false;
while (!complete) {
while (mmInStream.available() > 0) {
- if (stop) {
- break;
- }
int c = mmInStream.read();
if (c == '@') {
complete = true;
1
0
r74 - in trunk: res/values res/values-fr src/fr/ifremer/wlo src/fr/ifremer/wlo/measurement
by kmorin@users.forge.codelutin.com 11 Mar '14
by kmorin@users.forge.codelutin.com 11 Mar '14
11 Mar '14
Author: kmorin
Date: 2014-03-11 18:18:53 +0100 (Tue, 11 Mar 2014)
New Revision: 74
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/74
Log:
fixes #4679 [OBSERVATIONS] Les mesures sont dites autant de fois qu'on est arriv?\195?\169 sur l'?\195?\169cran
fixes #4680 [OBSERVATIONS] Quand on change d'esp?\195?\168ce, les mesures ne sont pas mises ?\195?\160 jour
fixes #4686 [OBSERVATIONS] Les modifications de l'esp?\195?\168ce ne sont pas prises en compte quand on revient sur l'?\195?\169cran
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java
trunk/src/fr/ifremer/wlo/DeviceListActivity.java
trunk/src/fr/ifremer/wlo/MainActivity.java
trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java
trunk/src/fr/ifremer/wlo/WloBaseActivity.java
trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/res/values/strings.xml 2014-03-11 17:18:53 UTC (rev 74)
@@ -38,6 +38,8 @@
<string name="devices_none_paired">No devices have been paired</string>
<string name="devices_title_paired_devices">Paired Devices</string>
<string name="bt_not_enabled">Bluetooth is off. No ichtyometer can be connected.</string>
+ <string name="connecting_device">Connecting. Please wait...</string>
+ <string name="connected_to_device">Connected to %s</string>
<!-- Measurement -->
<string name="measurement_title">Measurement</string>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/res/values-fr/strings.xml 2014-03-11 17:18:53 UTC (rev 74)
@@ -36,6 +36,8 @@
<string name="devices_none_paired">Aucun appareil n\'a été appairé.</string>
<string name="devices_title_paired_devices">Appareils appairés</string>
<string name="bt_not_enabled">Le bluetooth est désactivé, connexion d\'un ichtyomètre impossible.</string>
+ <string name="connecting_device">Connexion en cours. Veuillez patienter...</string>
+ <string name="connected_to_device">Connecté à %s</string>
<!-- Measurement -->
<string name="measurement_title">Observations</string>
Modified: trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java
===================================================================
--- trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java 2014-03-11 17:18:53 UTC (rev 74)
@@ -167,18 +167,10 @@
} else {
title = R.string.bigfin_no_ichtyometer_connected_title;
text = R.string.bigfin_no_ichtyometer_connected_text;
-// stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
}
- // Gets a PendingIntent containing the entire back stack
-// PendingIntent pendingIntent =
-// stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
-
-// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-
notificationBuilder.setContentTitle(getText(title))
.setContentText(getText(text));
-// .setContentIntent(pendingIntent);
if (connected) {
startForeground(NOIFICATION_ID, notificationBuilder.build());
@@ -414,7 +406,7 @@
// successful connection or an exception
socket = mmServerSocket.accept();
} catch (IOException e) {
- Log.e(TAG, "Socket accept() failed", e);
+ Log.e(TAG, "Socket accept() failed");
break;
}
@@ -526,6 +518,7 @@
protected final BluetoothSocket mmSocket;
protected final InputStream mmInStream;
protected final OutputStream mmOutStream;
+ protected boolean stop;
public ConnectedThread(BluetoothSocket socket) {
Log.d(TAG, "create ConnectedThread");
@@ -543,6 +536,8 @@
mmInStream = tmpIn;
mmOutStream = tmpOut;
+
+ stop = false;
}
public void run() {
@@ -564,9 +559,9 @@
boolean complete = false;
while (!complete) {
while (mmInStream.available() > 0) {
-// if (stop) {
-// break;
-// }
+ if (stop) {
+ break;
+ }
int c = mmInStream.read();
if (c == '@') {
complete = true;
@@ -594,7 +589,7 @@
sendMessage(MESSAGE_READ, -1, -1, readerRecord);
} catch (IOException e) {
- Log.e(TAG, "disconnected", e);
+ Log.e(TAG, "disconnected");
connectionLost();
}
}
@@ -622,6 +617,7 @@
} catch (IOException e) {
Log.e(TAG, "close() of connect socket failed", e);
}
+ stop = true;
}
}
Modified: trunk/src/fr/ifremer/wlo/DeviceListActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/DeviceListActivity.java 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/src/fr/ifremer/wlo/DeviceListActivity.java 2014-03-11 17:18:53 UTC (rev 74)
@@ -77,9 +77,6 @@
// Debugging
private static final String TAG = "DeviceListActivity";
- // Return Intent extra
- public static final String EXTRA_DEVICE_ADDRESS = "device_address";
-
// Member fields
protected BluetoothAdapter mBtAdapter;
protected ArrayAdapter<String> mPairedDevicesArrayAdapter;
@@ -220,13 +217,14 @@
sendDataToDevice("b");
dialog.dismiss();
+ setResult(RESULT_OK);
finish();
break;
case BigFinCommunicationService.STATE_CONNECTING:
dialog = ProgressDialog.show(DeviceListActivity.this, "",
- "Connecting. Please wait...", true);
+ getString(R.string.connecting_device), true);
break;
}
@@ -248,8 +246,9 @@
case BigFinCommunicationService.MESSAGE_DEVICE_NAME:
// save the connected device's name
String mConnectedDeviceName = msg.getData().getString(BigFinCommunicationService.DEVICE_NAME);
- Toast.makeText(getApplicationContext(), "Connected to "
- + mConnectedDeviceName, Toast.LENGTH_SHORT).show();
+ Toast.makeText(getApplicationContext(),
+ getString(R.string.connected_to_device, mConnectedDeviceName),
+ Toast.LENGTH_SHORT).show();
break;
case BigFinCommunicationService.MESSAGE_CONNECTION_FAILED:
Modified: trunk/src/fr/ifremer/wlo/MainActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/MainActivity.java 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/src/fr/ifremer/wlo/MainActivity.java 2014-03-11 17:18:53 UTC (rev 74)
@@ -85,6 +85,29 @@
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "create");
+ super.onCreate(savedInstanceState);
+
+ new InitializationTask().execute();
+ new UpdateCheckTask(this).execute();
+
+ mainPanel = (LinearLayout) findViewById(R.id.main_panel);
+ logoPanel = (LinearLayout) findViewById(R.id.logo_panel);
+ buttonPanel = (LinearLayout) findViewById(R.id.button_panel);
+
+ // Get local Bluetooth adapter
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+
+ // If the adapter is null, then Bluetooth is not supported
+ if (mBluetoothAdapter == null) {
+ findViewById(R.id.main_connect_ichtyometer_button).setEnabled(false);
+ }
+
+ connectButton = (Button) findViewById(R.id.main_connect_ichtyometer_button);
+ disconnectButton = (Button) findViewById(R.id.main_disconnect_ichtyometer_button);
+
+ Configuration config = getResources().getConfiguration();
+ setOrientation(config.orientation);
+
mMessenger = new Messenger(new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -109,30 +132,7 @@
}
}
});
-
- super.onCreate(savedInstanceState);
-
- new InitializationTask().execute();
- new UpdateCheckTask(this).execute();
-
- mainPanel = (LinearLayout) findViewById(R.id.main_panel);
- logoPanel = (LinearLayout) findViewById(R.id.logo_panel);
- buttonPanel = (LinearLayout) findViewById(R.id.button_panel);
-
- // Get local Bluetooth adapter
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
-
- // If the adapter is null, then Bluetooth is not supported
- if (mBluetoothAdapter == null) {
- findViewById(R.id.main_connect_ichtyometer_button).setEnabled(false);
- }
-
- connectButton = (Button) findViewById(R.id.main_connect_ichtyometer_button);
- disconnectButton = (Button) findViewById(R.id.main_disconnect_ichtyometer_button);
bigfinDisconnected();
-
- Configuration config = getResources().getConfiguration();
- setOrientation(config.orientation);
}
protected void bigfinConnected() {
@@ -208,9 +208,11 @@
switch (requestCode) {
case REQUEST_CONNECT_ICHTYOMETER:
// When DeviceListActivity returns with a device to connect
-// if (resultCode == Activity.RESULT_OK) {
-// connectDevice(data);
-// }
+ if (resultCode == Activity.RESULT_OK) {
+ bigfinConnected();
+ } else {
+ bigfinDisconnected();
+ }
break;
case REQUEST_ENABLE_BT:
Modified: trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-03-11 17:18:53 UTC (rev 74)
@@ -118,21 +118,10 @@
}
@Override
- public void validate(View view) {
- boolean newModel = model.isNew();
-
- WloSqlOpenHelper woh = new WloSqlOpenHelper(this);
- woh.saveData(model);
- woh.close();
-
- if (newModel) {
- Intent intent = new Intent(this, MeasurementActivity.class);
- intent.putExtra(MeasurementActivity.INTENT_EXTRA_SCIENTIFIC_SPECIES, model);
- startActivity(intent);
-
- } else {
- finish();
- }
+ public void gotoNextActivity() {
+ Intent intent = new Intent(this, MeasurementActivity.class);
+ intent.putExtra(MeasurementActivity.INTENT_EXTRA_SCIENTIFIC_SPECIES, model);
+ startActivity(intent);
}
}
Modified: trunk/src/fr/ifremer/wlo/WloBaseActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloBaseActivity.java 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/src/fr/ifremer/wlo/WloBaseActivity.java 2014-03-11 17:18:53 UTC (rev 74)
@@ -107,7 +107,11 @@
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(getUpActivity() != null);
+ }
+ @Override
+ protected void onStart() {
+ super.onStart();
bindService(new Intent(this, BigFinCommunicationService.class), this, Context.BIND_AUTO_CREATE);
}
@@ -120,19 +124,20 @@
@Override
protected void onPause() {
+ Log.d(TAG, "pause");
super.onPause();
unregisterReceiver(downloadReceiver);
}
@Override
- protected void onDestroy() {
- Log.d(TAG, "destroy");
- super.onDestroy();
+ protected void onStop() {
+ Log.d(TAG, "stop");
+ super.onStop();
doUnbindService();
}
protected void doUnbindService() {
- Log.d(TAG, "doUnbindService");
+ Log.d(TAG, "doUnbindService " + this);
// If we have received the service, and hence registered with it, then now is the time to unregister.
if (mServiceMessenger != null && mMessenger != null) {
try {
@@ -150,6 +155,7 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
+ Log.d(TAG, "onServiceConnected " + this);
mServiceMessenger = new Messenger(service);
Log.d(TAG, "mMessenger " + mMessenger);
if (mMessenger != null) {
@@ -166,7 +172,7 @@
@Override
public void onServiceDisconnected(ComponentName name) {
- Log.d(TAG, "onServiceDisconnected");
+ Log.d(TAG, "onServiceDisconnected " + this);
mServiceMessenger = null;
}
Modified: trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-03-11 17:18:53 UTC (rev 74)
@@ -167,10 +167,7 @@
saveModel();
if (newModel) {
-// Intent intent = new Intent(this, getNextEditionActivity());
- Intent intent = new Intent(this, getNextListActivity());
- intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_PARENT_MODEL, model);
- startActivity(intent);
+ gotoNextActivity();
} else {
Intent intent = new Intent();
@@ -202,6 +199,12 @@
}
}
+ protected void gotoNextActivity() {
+ Intent intent = new Intent(this, getNextListActivity());
+ intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_PARENT_MODEL, model);
+ startActivity(intent);
+ }
+
/* Protected methods */
protected void saveModel() {
Modified: trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-03-11 12:59:38 UTC (rev 73)
+++ trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-03-11 17:18:53 UTC (rev 74)
@@ -152,6 +152,8 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ Log.d(TAG, "on create");
+
measurements = (MeasurementsModel) getIntent().getSerializableExtra(INTENT_EXTRA_MEASUREMENTS);
if (measurements != null) {
scientificSpecies = measurements.getScientificSpecies();
@@ -206,48 +208,71 @@
validateButton = (Button) findViewById(R.id.measurement_add_button);
- sizeText = (EditText) findViewById(R.id.size);
- int inputType = InputType.TYPE_CLASS_NUMBER;
- if (measurements.getPrecision().isDecimal()) {
- inputType |= InputType.TYPE_NUMBER_FLAG_DECIMAL;
- }
- sizeText.setRawInputType(inputType);
- sizeText.addTextChangedListener(new BaseTextWatcher() {
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- sizeText.setSelection(start + count);
- }
+ initSizeText();
+ observedNumberText = (TextView) findViewById(R.id.observed_number);
+ observedNumberText.setText(String.valueOf(measurements.getMeasurements().size()));
+
+ initCategories();
+
+ initFishMeasurement(10 * measurements.getPrecision().getUnitDivider(), null, null, null);
+
+ initDrawer();
+
+ initActionBar();
+
+ mMessenger = new Messenger(new Handler() {
@Override
- public void afterTextChanged(Editable s) {
- if (s.toString().isEmpty()) {
- measurement.setSize(null);
+ public void handleMessage(Message msg) {
+ if (!MeasurementActivity.this.isFinishing()) {
+ switch (msg.what) {
+ case BigFinCommunicationService.MESSAGE_READ:
+ BigFinFeedReaderRecord record = (BigFinFeedReaderRecord) msg.obj;
- } else {
- Mensuration.Precision precision = measurements.getPrecision();
- int multiplier = precision.getUnitDivider();
- try {
- NumberFormat format = NumberFormat.getInstance(Locale.US);
- Number number = format.parse(s.toString());
- double d = number.doubleValue();
- int size = (int)(d * multiplier);
- measurement.setSize(size);
+ if (record != null && record.getLength() != null) {
- } catch (ParseException e) {
- Log.e(TAG, "ParseException " + e.getMessage());
- measurement.setSize(null);
+ int size = (int) Math.floor(record.getLength());
+ measurement.setSize(size);
+ MeasurementModel savedMeasurement = addMeasurement();
+
+ if (useTextToSpeech) {
+ String formattedSize = UIUtils.getFormattedSize(savedMeasurement.getSize(), measurements.getPrecision());
+ textToSpeech.speak(formattedSize, TextToSpeech.QUEUE_ADD, null);
+
+ } else {
+ ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, ToneGenerator.MAX_VOLUME);
+ tg.startTone(ToneGenerator.TONE_PROP_BEEP);
+ }
+
+ // Get instance of Vibrator from current Context
+ Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
+ // Vibrate for 300 milliseconds
+ v.vibrate(300);
+ }
+ break;
}
}
}
});
- observedNumberText = (TextView) findViewById(R.id.observed_number);
- observedNumberText.setText(String.valueOf(measurements.getMeasurements().size()));
+ Intent checkIntent = new Intent();
+ checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
+ startActivityForResult(checkIntent, CHECK_TTS_REQUEST_CODE);
+ }
- initCategories();
+ protected void initActionBar() {
+ ActionBar actionBar = getActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setHomeButtonEnabled(true);
+ actionBar.setTitle(commercialSpecies.toString(this) + " / " +
+ scientificSpecies.toString(this) + " / " +
+ commercialSpecies.getMeasurementMethod().toString(this) + " / " +
+ commercialSpecies.getPrecision());
+ actionBar.setSubtitle(vessel.toString(this) + " / " +
+ metier.toString(this));
+ }
- initFishMeasurement(10 * measurements.getPrecision().getUnitDivider(), null, null, null);
-
+ protected void initDrawer() {
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
@@ -279,52 +304,43 @@
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
+ }
- ActionBar actionBar = getActionBar();
- actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setHomeButtonEnabled(true);
- actionBar.setTitle(commercialSpecies.toString(this) + " / " +
- scientificSpecies.toString(this) + " / " +
- commercialSpecies.getMeasurementMethod().toString(this) + " / " +
- commercialSpecies.getPrecision());
- actionBar.setSubtitle(vessel.toString(this) + " / " +
- metier.toString(this));
+ protected void initSizeText() {
+ sizeText = (EditText) findViewById(R.id.size);
+ int inputType = InputType.TYPE_CLASS_NUMBER;
+ if (measurements.getPrecision().isDecimal()) {
+ inputType |= InputType.TYPE_NUMBER_FLAG_DECIMAL;
+ }
+ sizeText.setRawInputType(inputType);
+ sizeText.addTextChangedListener(new BaseTextWatcher() {
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ sizeText.setSelection(start + count);
+ }
- mMessenger = new Messenger(new Handler() {
@Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case BigFinCommunicationService.MESSAGE_READ:
- BigFinFeedReaderRecord record = (BigFinFeedReaderRecord) msg.obj;
+ public void afterTextChanged(Editable s) {
+ if (s.toString().isEmpty()) {
+ measurement.setSize(null);
- if (record != null && record.getLength() != null) {
+ } else {
+ Mensuration.Precision precision = measurements.getPrecision();
+ int multiplier = precision.getUnitDivider();
+ try {
+ NumberFormat format = NumberFormat.getInstance(Locale.US);
+ Number number = format.parse(s.toString());
+ double d = number.doubleValue();
+ int size = (int)(d * multiplier);
+ measurement.setSize(size);
- int size = (int) Math.floor(record.getLength());
- measurement.setSize(size);
- MeasurementModel savedMeasurement = addMeasurement();
-
- if (useTextToSpeech) {
- String formattedSize = UIUtils.getFormattedSize(savedMeasurement.getSize(), measurements.getPrecision());
- textToSpeech.speak(formattedSize, TextToSpeech.QUEUE_ADD, null);
-
- } else {
- ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, ToneGenerator.MAX_VOLUME);
- tg.startTone(ToneGenerator.TONE_PROP_BEEP);
- }
-
- // Get instance of Vibrator from current Context
- Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
- // Vibrate for 300 milliseconds
- v.vibrate(300);
- }
- break;
+ } catch (ParseException e) {
+ Log.e(TAG, "ParseException " + e.getMessage());
+ measurement.setSize(null);
+ }
}
}
});
-
- Intent checkIntent = new Intent();
- checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
- startActivityForResult(checkIntent, CHECK_TTS_REQUEST_CODE);
}
protected void initCategories() {
@@ -402,8 +418,6 @@
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
-
if (requestCode == CHECK_TTS_REQUEST_CODE && resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// Succès, au moins un moteur de TTS à été trouvé, on l'instancie
textToSpeech = new TextToSpeech(this, this);
@@ -412,6 +426,7 @@
}
} else if (resultCode == RESULT_OK) {
+ Log.d(TAG, "requestCode " + requestCode);
switch (requestCode) {
case 1:
vessel = (VesselModel) data.getSerializableExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL);
@@ -430,6 +445,9 @@
break;
}
setDrawerListAdapter();
+
+ } else {
+ super.onActivityResult(requestCode, resultCode, data);
}
}
@@ -644,15 +662,16 @@
}
protected void setDrawerListAdapter() {
+ Log.d(TAG, scientificSpecies.toString(this));
mDrawerList.setAdapter(new ArrayAdapter<>(this,
- android.R.layout.simple_list_item_1,
- new String[]{
- getString(R.string.home_title),
- vessel.toString(this),
- metier.toString(this),
- commercialSpecies.toString(this),
- scientificSpecies.toString(this)
- }));
+ android.R.layout.simple_list_item_1,
+ new String[]{
+ getString(R.string.home_title),
+ vessel.toString(this),
+ metier.toString(this),
+ commercialSpecies.toString(this),
+ scientificSpecies.toString(this)
+ }));
}
protected void fetchCalcifiedPartTakings() {
@@ -670,7 +689,6 @@
}
}
- /** Swaps fragments in the main content view */
protected void editItem(int position) {
Class clazz;
BaseModel modelToEdit;
@@ -702,6 +720,7 @@
if (clazz != null) {
Intent intent = new Intent(this, clazz);
intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL, modelToEdit);
+ Log.d(TAG, "startActivityForResult " + position);
startActivityForResult(intent, position);
}
}
1
0