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
January 2014
- 3 participants
- 33 discussions
r43 - in trunk: . res/layout src/fr/ifremer/wlo src/fr/ifremer/wlo/measurement src/fr/ifremer/wlo/models src/fr/ifremer/wlo/models/referentials/imports
by kmorin@users.forge.codelutin.com 30 Jan '14
by kmorin@users.forge.codelutin.com 30 Jan '14
30 Jan '14
Author: kmorin
Date: 2014-01-30 18:54:19 +0100 (Thu, 30 Jan 2014)
New Revision: 43
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/43
Log:
fixes #4240 plantage si je veux saisir une taille via le clavier num?\195?\169rique (et pas avec les + et-)
Removed:
trunk/src/fr/ifremer/wlo/Home.java
Modified:
trunk/AndroidManifest.xml
trunk/res/layout/measurement.xml
trunk/src/fr/ifremer/wlo/MainActivity.java
trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
trunk/src/fr/ifremer/wlo/models/BaseModel.java
trunk/src/fr/ifremer/wlo/models/MeasurementModel.java
trunk/src/fr/ifremer/wlo/models/referentials/imports/ImportUtil.java
Modified: trunk/AndroidManifest.xml
===================================================================
--- trunk/AndroidManifest.xml 2014-01-30 13:59:11 UTC (rev 42)
+++ trunk/AndroidManifest.xml 2014-01-30 17:54:19 UTC (rev 43)
@@ -33,7 +33,7 @@
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboardHidden"
- android:launchMode="singleInstance">
+ android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Modified: trunk/res/layout/measurement.xml
===================================================================
--- trunk/res/layout/measurement.xml 2014-01-30 13:59:11 UTC (rev 42)
+++ trunk/res/layout/measurement.xml 2014-01-30 17:54:19 UTC (rev 43)
@@ -73,7 +73,8 @@
</LinearLayout>
- <Button android:text="@android:string/ok"
+ <Button android:id="@+id/measurement_add_button"
+ android:text="@android:string/ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="addMeasurement"/>
Deleted: trunk/src/fr/ifremer/wlo/Home.java
===================================================================
--- trunk/src/fr/ifremer/wlo/Home.java 2014-01-30 13:59:11 UTC (rev 42)
+++ trunk/src/fr/ifremer/wlo/Home.java 2014-01-30 17:54:19 UTC (rev 43)
@@ -1,342 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package fr.ifremer.wlo;
-
-/*
- * #%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.app.ActionBar;
-import android.app.Activity;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.speech.tts.TextToSpeech;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-import android.widget.Toast;
-import fr.ifremer.wlo.measurement.MeasurementActivity;
-
-/**
- * This is the main Activity that displays the current chat location.
- */
-public class Home extends Activity implements TextToSpeech.OnInitListener {
-
- // Debugging
- private static final String TAG = "Home";
-
- // Message types sent from the BluetoothChatService Handler
- public static final int MESSAGE_STATE_CHANGE = 1;
- public static final int MESSAGE_READ = 2;
- public static final int MESSAGE_WRITE = 3;
- public static final int MESSAGE_DEVICE_NAME = 4;
- public static final int MESSAGE_TOAST = 5;
-
- // Key names received from the BluetoothChatService Handler
- public static final String DEVICE_NAME = "device_name";
- public static final String TOAST = "toast";
-
- // Intent request codes
- protected static final int REQUEST_CONNECT_DEVICE = 1;
- protected static final int REQUEST_ENABLE_BT = 2;
- protected static final int REQUEST_CHECK_TTS = 3;
-
- // Layout Views
- protected ListView mConversationView;
-
- // Name of the connected device
- protected String mConnectedDeviceName = null;
- // Array adapter for the conversation thread
- protected ArrayAdapter<String> mConversationArrayAdapter;
- // Local Bluetooth adapter
- protected BluetoothAdapter mBluetoothAdapter = null;
- // Member object for the chat services
- protected BigFinCommunicationService mBFCommunicationService = null;
-
-// protected TextToSpeech mTts;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Set up the window layout
-// setContentView(R.layout.home);
-
- // Get local Bluetooth adapter
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
-
- // If the adapter is null, then Bluetooth is not supported
- if (mBluetoothAdapter == null) {
- Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
- finish();
- return;
- }
- }
-
- @Override
- public void onStart() {
- super.onStart();
-
- // If BT is not on, request that it be enabled.
- // setupChat() will then be called during onActivityResult
- if (!mBluetoothAdapter.isEnabled()) {
- Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
- startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
-
- // Otherwise, setup the chat location
- } else {
-// Intent checkIntent = new Intent();
-// checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
-// startActivityForResult(checkIntent, REQUEST_CHECK_TTS);
- setupChat();
- }
- }
-
- @Override
- public synchronized void onResume() {
- super.onResume();
-
- // Performing this check in onResume() covers the case in which BT was
- // not enabled during onStart(), so we were paused to enable it...
- // onResume() will be called when ACTION_REQUEST_ENABLE activity returns.
- if (mBFCommunicationService != null) {
- // Only if the state is STATE_NONE, do we know that we haven't started already
-// if (mBFCommunicationService.getState() == BigFinCommunicationService.STATE_NONE) {
- // Start the Bluetooth chat services
-// mBFCommunicationService.start();
- selectDevice();
-// }
- }
- }
-
- protected void selectDevice() {
- // Launch the DeviceListActivity to see devices and do scan
- Intent serverIntent = new Intent(this, DeviceListActivity.class);
- startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
- }
-
- private void setupChat() {
- Log.d(TAG, "setupChat()");
-
- // Initialize the array adapter for the conversation thread
- mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
-// mConversationView = (ListView) findViewById(R.id.in);
- mConversationView.setAdapter(mConversationArrayAdapter);
-
- // Initialize the BluetoothChatService to perform bluetooth connections
-// mBFCommunicationService = new BigFinCommunicationService(this, mHandler);
-
- }
-
- @Override
- public void onStop() {
- super.onStop();
-// mTts.shutdown();
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- // Stop the Bluetooth chat services
-// if (mBFCommunicationService != null) mBFCommunicationService.stop();
- }
-
- protected final void setStatus(int resId) {
- final ActionBar actionBar = getActionBar();
- if (actionBar != null) {
- actionBar.setSubtitle(resId);
- }
- }
-
- protected final void setStatus(CharSequence subTitle) {
- final ActionBar actionBar = getActionBar();
- if (actionBar != null) {
- actionBar.setSubtitle(subTitle);
- }
- }
-
- // The Handler that gets information back from the BluetoothChatService
- protected final Handler mHandler = new Handler() {
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MESSAGE_STATE_CHANGE:
- Log.d(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
- switch (msg.arg1) {
- case BigFinCommunicationService.STATE_CONNECTED:
-// setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
- mConversationArrayAdapter.clear();
- mBFCommunicationService.write("a".getBytes());
- mBFCommunicationService.write("b".getBytes());
-
- Intent intent = new Intent(Home.this, MeasurementActivity.class);
- startActivity(intent);
-
- break;
-
- case BigFinCommunicationService.STATE_CONNECTING:
-// setStatus(R.string.title_connecting);
-
- break;
-
- case BigFinCommunicationService.STATE_LISTEN:
- case BigFinCommunicationService.STATE_NONE:
-// setStatus(R.string.title_not_connected);
- break;
- }
- break;
-
- case MESSAGE_WRITE:
- byte[] writeBuf = (byte[]) msg.obj;
- // construct a string from the buffer
- String writeMessage = new String(writeBuf);
-// mConversationArrayAdapter.add("Me: " + writeMessage);
- break;
-
- case MESSAGE_READ:
- byte[] readBuf = (byte[]) msg.obj;
- // construct a string from the valid bytes in the buffer
- String readMessage = new String(readBuf, 0, msg.arg1);
- mConversationArrayAdapter.add(readMessage);
-// mTts.speak(readMessage, TextToSpeech.QUEUE_ADD, null);
- break;
-
- case MESSAGE_DEVICE_NAME:
- // save the connected device's name
- mConnectedDeviceName = msg.getData().getString(DEVICE_NAME);
- Toast.makeText(getApplicationContext(), "Connected to "
- + mConnectedDeviceName, Toast.LENGTH_SHORT).show();
- break;
-
- case MESSAGE_TOAST:
- Toast.makeText(getApplicationContext(), msg.getData().getString(TOAST),
- Toast.LENGTH_SHORT).show();
- break;
- }
- }
- };
-
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
-
- switch (requestCode) {
- case REQUEST_CONNECT_DEVICE:
- // When DeviceListActivity returns with a device to connect
- if (resultCode == Activity.RESULT_OK) {
- connectDevice(data);
- }
- break;
-
- case REQUEST_ENABLE_BT:
- // When the request to enable Bluetooth returns
- if (resultCode == Activity.RESULT_OK) {
- // Bluetooth is now enabled, so set up a chat location
- setupChat();
-
- } else {
- // User did not enable Bluetooth or an error occurred
- Log.d(TAG, "BT not enabled");
-// Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();
- finish();
- }
- break;
-
- case REQUEST_CHECK_TTS:
- if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
- // Succès, au moins un moteur de TTS à été trouvé, on l'instancie
-// mTts = new TextToSpeech(this, this);
-
- } else {
- // Echec, aucun moteur n'a été trouvé, on propose à l'utilisateur d'en installer un depuis le Market
- Intent installIntent = new Intent();
- installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
- startActivity(installIntent);
- }
- break;
- }
-
- }
-
- protected void connectDevice(Intent data) {
- // Get the device MAC address
- String address = data.getExtras()
- .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
- // Get the BluetoothDevice object
- BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
- // Attempt to connect to the device
- mBFCommunicationService.connect(device);
-
- Intent intent = new Intent(this, MeasurementActivity.class);
- startActivity(intent);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
-// inflater.inflate(R.menu.option_menu, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
-// switch (item.getItemId()) {
-// case R.id.connect_scan:
-// selectDevice();
-// return true;
-// case R.id.disconnect:
-//// mBFCommunicationService.start();
-// return true;
-// }
- return false;
- }
-
- @Override
- public void onInit(int status) {
- if (status == TextToSpeech.SUCCESS) {
-// if (mTts.isLanguageAvailable(Locale.FRANCE) == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
-// mTts.setLanguage(Locale.FRANCE);
-// }
- }
- }
-}
Modified: trunk/src/fr/ifremer/wlo/MainActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/MainActivity.java 2014-01-30 13:59:11 UTC (rev 42)
+++ trunk/src/fr/ifremer/wlo/MainActivity.java 2014-01-30 17:54:19 UTC (rev 43)
@@ -3,8 +3,8 @@
/*
* #%L
* WLO
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2013 - 2014 Ifremer
* %%
@@ -162,7 +162,8 @@
}
dialog.setProgress(11);
- } catch (IOException e) {
+ } catch (IOException | RuntimeException e) {
+ //TODO kmorin 20140130 show error to the user
Log.e(TAG, "error on initial import", e);
} finally {
Modified: trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-01-30 13:59:11 UTC (rev 42)
+++ trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-01-30 17:54:19 UTC (rev 43)
@@ -39,6 +39,7 @@
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
+import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
@@ -102,6 +103,7 @@
protected EditText sizeText;
protected ActionBarDrawerToggle mDrawerToggle;
protected TextView observedNumberText;
+ protected Button validateButton;
protected MeasurementModel measurement;
protected MeasurementsModel measurements;
@@ -111,7 +113,7 @@
protected MetierModel metier;
protected VesselModel vessel;
- ListView mDrawerList;
+ protected ListView mDrawerList;
@Override
protected Integer getContentView() {
@@ -178,6 +180,8 @@
setupTab(R.id.table, TABLE_TAB, R.string.table_tab);
setupTab(R.id.logs, LOGS_TAB, R.string.logs_tab);
+ validateButton = (Button) findViewById(R.id.measurement_add_button);
+
sizeText = (EditText) findViewById(R.id.size);
int inputType = InputType.TYPE_CLASS_NUMBER;
if (measurements.getPrecision().isDecimal()) {
@@ -192,18 +196,23 @@
@Override
public void afterTextChanged(Editable s) {
- 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 (s.toString().isEmpty()) {
+ measurement.setSize(null);
- } catch (ParseException e) {
- Log.e(TAG, "ParseException ", e);
- measurement.setSize(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);
+
+ } catch (ParseException e) {
+ Log.e(TAG, "ParseException " + e.getMessage());
+ measurement.setSize(null);
+ }
}
}
});
@@ -377,6 +386,9 @@
String text = null;
if (newValue != null) {
text = UIUtils.getFormattedSize((Integer) newValue, measurements.getPrecision());
+ validateButton.setEnabled(true);
+ } else {
+ validateButton.setEnabled(false);
}
sizeText.setText(text);
break;
Modified: trunk/src/fr/ifremer/wlo/models/BaseModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/BaseModel.java 2014-01-30 13:59:11 UTC (rev 42)
+++ trunk/src/fr/ifremer/wlo/models/BaseModel.java 2014-01-30 17:54:19 UTC (rev 43)
@@ -118,9 +118,9 @@
}
public void firePropertyChange(String property, Object oldValue, Object newValue) {
- Log.d(TAG, "fire " + property + " " + oldValue + " " + newValue);
- Log.d(TAG, "equals ? " + ObjectUtils.equals(oldValue, newValue));
- changeSupport.firePropertyChange(property, oldValue, newValue);
+ if (ObjectUtils.notEqual(oldValue, newValue)) {
+ changeSupport.firePropertyChange(property, oldValue, newValue);
+ }
}
public Set<String> getRequiredFields() {
Modified: trunk/src/fr/ifremer/wlo/models/MeasurementModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/MeasurementModel.java 2014-01-30 13:59:11 UTC (rev 42)
+++ trunk/src/fr/ifremer/wlo/models/MeasurementModel.java 2014-01-30 17:54:19 UTC (rev 43)
@@ -35,6 +35,7 @@
import fr.ifremer.wlo.models.referentials.Mensuration;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.utils.UIUtils;
+import org.apache.commons.lang3.ObjectUtils;
import java.util.Calendar;
@@ -93,7 +94,6 @@
public void setSize(Integer size) {
Integer oldValue = this.size;
this.size = size;
- Log.d(TAG, size + " " + oldValue + " " + size.equals(oldValue));
firePropertyChange(COLUMN_SIZE, oldValue, size);
}
Modified: trunk/src/fr/ifremer/wlo/models/referentials/imports/ImportUtil.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/referentials/imports/ImportUtil.java 2014-01-30 13:59:11 UTC (rev 42)
+++ trunk/src/fr/ifremer/wlo/models/referentials/imports/ImportUtil.java 2014-01-30 17:54:19 UTC (rev 43)
@@ -27,6 +27,7 @@
import android.app.AlertDialog;
import android.content.Context;
import android.util.Log;
+import com.csvreader.CsvReader;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
@@ -38,12 +39,16 @@
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.IOUtils;
import org.nuiton.csv.Import;
import org.nuiton.csv.ImportModel;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
import java.util.Collection;
/**
@@ -235,8 +240,8 @@
protected static <M extends BaseModel> int importData(Context context, ImportModel<M> importModel,
InputStream inputStream, final Collection<M> actualReferential) {
Preconditions.checkNotNull(actualReferential);
- Import<M> importer = Import.newImport(importModel, inputStream);
- Collection<M> models = Lists.newArrayList(importer.iterator());
+ Import<M> importer = null;
+ Collection<M> models = null;
try {
importer = Import.newImport(importModel, inputStream);
1
0
Author: kmorin
Date: 2014-01-30 14:59:11 +0100 (Thu, 30 Jan 2014)
New Revision: 42
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/42
Log:
fixes #4206 G?\195?\169rer le changement d'orientation
Modified:
trunk/AndroidManifest.xml
trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java
trunk/src/fr/ifremer/wlo/WloBaseListActivity.java
Modified: trunk/AndroidManifest.xml
===================================================================
--- trunk/AndroidManifest.xml 2014-01-30 10:34:36 UTC (rev 41)
+++ trunk/AndroidManifest.xml 2014-01-30 13:59:11 UTC (rev 42)
@@ -30,28 +30,9 @@
<service android:name=".BigFinCommunicationService" />
- <!--<activity android:name=".Home"-->
- <!--android:label="@string/app_name"-->
- <!--android:configChanges="orientation|keyboardHidden">-->
- <!--<intent-filter>-->
- <!--<action android:name="android.intent.action.MAIN" />-->
- <!--<category android:name="android.intent.category.LAUNCHER" />-->
- <!--</intent-filter>-->
- <!--</activity>-->
-
- <activity android:name=".measurement.MeasurementActivity"
- android:label="@string/measurement_title"
- android:configChanges="orientation|keyboardHidden"
- android:screenOrientation="landscape"/>
-
- <activity android:name=".measurement.GraphActivity"
- android:label="@string/app_name"
- android:configChanges="orientation|keyboardHidden"
- android:screenOrientation="landscape"/>
-
<activity android:name=".MainActivity"
android:label="@string/app_name"
- android:configChanges="orientation|keyboardHidden"
+ android:configChanges="orientation|screenSize|keyboardHidden"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@@ -59,70 +40,80 @@
</intent-filter>
</activity>
+ <activity android:name=".measurement.MeasurementActivity"
+ android:label="@string/measurement_title"
+ android:configChanges="orientation|screenSize|keyboardHidden"
+ android:screenOrientation="landscape"/>
+
+ <activity android:name=".measurement.GraphActivity"
+ android:label="@string/app_name"
+ android:configChanges="orientation|screenSize|keyboardHidden"
+ android:screenOrientation="landscape"/>
+
<activity android:name=".DeviceListActivity"
android:label="@string/devices_title"
- android:configChanges="orientation|keyboardHidden" />
+ android:configChanges="orientation|screenSize|keyboardHidden" />
<activity android:name=".ContextsActivity"
android:label="@string/contexts_title"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".ContextFormActivity"
android:label="@string/new_context_title"
android:noHistory="true"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".LocationsActivity"
android:label="@string/locations_title"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".LocationFormActivity"
android:label="@string/new_location_title"
android:noHistory="true"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".VesselsActivity"
android:label="@string/vessels_title"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".VesselFormActivity"
android:label="@string/new_vessel_title"
android:noHistory="true"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".MetiersActivity"
android:label="@string/metiers_title"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".MetierFormActivity"
android:label="@string/new_metier_title"
android:noHistory="true"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".CommercialSpeciesActivity"
android:label="@string/commercial_species_title"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".CommercialSpeciesFormActivity"
android:label="@string/new_commercial_species_title"
android:noHistory="true"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".ScientificSpeciesActivity"
android:label="@string/scientific_species_title"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".ScientificSpeciesFormActivity"
android:label="@string/new_scientific_species_title"
android:noHistory="true"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".preferences.SettingsActivity"
android:label="@string/main_settings"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".utils.filechooser.FileDialog"
- android:configChanges="orientation|keyboardHidden"/>
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
</application>
</manifest>
Modified: trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java 2014-01-30 10:34:36 UTC (rev 41)
+++ trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java 2014-01-30 13:59:11 UTC (rev 42)
@@ -58,8 +58,7 @@
@Override
public boolean onCreateOptionsMenu(Menu menu) {
CommercialSpeciesModel parent = (CommercialSpeciesModel) parentModel;
- //TODO handle npe
- if (parent == null || parent.isSpeciesMix() || adapter.getCount() == 0) {
+ if (parent.isSpeciesMix() || adapter.getCount() == 0) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.model_list_menu, menu);
}
Modified: trunk/src/fr/ifremer/wlo/WloBaseListActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloBaseListActivity.java 2014-01-30 10:34:36 UTC (rev 41)
+++ trunk/src/fr/ifremer/wlo/WloBaseListActivity.java 2014-01-30 13:59:11 UTC (rev 42)
@@ -42,6 +42,7 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.res.Configuration;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
@@ -310,7 +311,8 @@
@Override
public Intent getSupportParentActivityIntent() {
Intent intent = super.getSupportParentActivityIntent();
- if (intent != null && parentModel != null && HierarchicalModel.class.isAssignableFrom(parentModel.getClass())) {
+ if (intent != null && parentModel != null
+ && HierarchicalModel.class.isAssignableFrom(parentModel.getClass())) {
HierarchicalModel hParentModel = (HierarchicalModel) parentModel;
intent.putExtra(WloBaseListActivity.INTENT_EXTRA_PARENT_MODEL, hParentModel.getParent());
}
1
0
r41 - in trunk: res/layout src/fr/ifremer/wlo src/fr/ifremer/wlo/utils
by kmorin@users.forge.codelutin.com 30 Jan '14
by kmorin@users.forge.codelutin.com 30 Jan '14
30 Jan '14
Author: kmorin
Date: 2014-01-30 11:34:36 +0100 (Thu, 30 Jan 2014)
New Revision: 41
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/41
Log:
fixes #4183 Liste de favoris
Modified:
trunk/res/layout/autocomplete_text_view_with_favorites.xml
trunk/res/layout/commercial_species_form.xml
trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java
trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java
trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextView.java
trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextViewWithFavorites.java
Modified: trunk/res/layout/autocomplete_text_view_with_favorites.xml
===================================================================
--- trunk/res/layout/autocomplete_text_view_with_favorites.xml 2014-01-29 18:51:33 UTC (rev 40)
+++ trunk/res/layout/autocomplete_text_view_with_favorites.xml 2014-01-30 10:34:36 UTC (rev 41)
@@ -14,8 +14,9 @@
android:hint="@string/undefined"/>
<ToggleButton android:id="@+id/favorite_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_width="32dp"
+ android:layout_height="32dp"
+ android:paddingRight="2dp"
android:background="@drawable/favorite_toggle"
android:textOff=""
android:textOn=""/>
Modified: trunk/res/layout/commercial_species_form.xml
===================================================================
--- trunk/res/layout/commercial_species_form.xml 2014-01-29 18:51:33 UTC (rev 40)
+++ trunk/res/layout/commercial_species_form.xml 2014-01-30 10:34:36 UTC (rev 41)
@@ -18,12 +18,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
- <fr.ifremer.wlo.utils.WloAutoCompleteTextView
+ <fr.ifremer.wlo.utils.WloAutoCompleteTextViewWithFavorites
android:id="@+id/commercial_species_form_fao_code"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:hint="@string/undefined"/>
+ android:layout_height="wrap_content"/>
<TextView android:text="@string/commercial_species_form_measurement_method"
android:layout_width="match_parent"
Modified: trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java 2014-01-29 18:51:33 UTC (rev 40)
+++ trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java 2014-01-30 10:34:36 UTC (rev 41)
@@ -24,8 +24,10 @@
* #L%
*/
+import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
@@ -34,15 +36,21 @@
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Spinner;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import fr.ifremer.wlo.models.CommercialSpeciesModel;
import fr.ifremer.wlo.models.referentials.CommercialSpecies;
import fr.ifremer.wlo.models.referentials.Mensuration;
import fr.ifremer.wlo.models.referentials.Presentation;
import fr.ifremer.wlo.models.referentials.State;
+import fr.ifremer.wlo.preferences.MultiSelectItemPreference;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
+import fr.ifremer.wlo.utils.WloAutoCompleteTextViewWithFavorites;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -83,8 +91,20 @@
// init editors
List<CommercialSpecies> commercialSpecies = Lists.newArrayList(DataCache.getAllCommercialSpecies(this));
- initAutoCompleteTextView(R.id.commercial_species_form_fao_code, CommercialSpeciesModel.COLUMN_FAO_CODE, commercialSpecies);
+ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
+ final Set<String> favoriteIds = sharedPref.getStringSet(MultiSelectItemPreference.COMMERCIAL_SPECIES_FAVORITES.getKey(),
+ Sets.<String>newHashSet());
+ Collection<CommercialSpecies> favorites = Collections2.filter(commercialSpecies, new Predicate<CommercialSpecies>() {
+ @Override
+ public boolean apply(CommercialSpecies input) {
+ return favoriteIds.contains(input.getId());
+ }
+ });
+ WloAutoCompleteTextViewWithFavorites actvwf = (WloAutoCompleteTextViewWithFavorites) findViewById(R.id.commercial_species_form_fao_code);
+ initAutoCompleteTextView(actvwf.getAutoCompleteTextView(), CommercialSpeciesModel.COLUMN_FAO_CODE, commercialSpecies, favorites);
+ actvwf.useFavorites(!favorites.isEmpty());
+
if (model.getMeasurementMethod() == null) {
Mensuration defaultMensuration = DataCache.getDefaultMensuration(this);
model.setMeasurementMethod(defaultMensuration);
Modified: trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-01-29 18:51:33 UTC (rev 40)
+++ trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-01-30 10:34:36 UTC (rev 41)
@@ -98,6 +98,7 @@
WloAutoCompleteTextViewWithFavorites actvwf = (WloAutoCompleteTextViewWithFavorites) findViewById(R.id.scientific_species_form_name);
initAutoCompleteTextView(actvwf.getAutoCompleteTextView(), ScientificSpeciesModel.COLUMN_NAME, scientificSpecies, favorites);
+ actvwf.useFavorites(!favorites.isEmpty());
CheckBox takingActivationEditor = (CheckBox) findViewById(R.id.scientific_species_form_takingActivation);
takingActivationEditor.setChecked(model.isTakingActivation());
Modified: trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextView.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextView.java 2014-01-29 18:51:33 UTC (rev 40)
+++ trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextView.java 2014-01-30 10:34:36 UTC (rev 41)
@@ -26,7 +26,9 @@
import android.content.Context;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.View;
+import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
/**
@@ -35,8 +37,12 @@
*/
public class WloAutoCompleteTextView extends AutoCompleteTextView {
- private int myThreshold;
+ private static final String TAG = "WloAutoCompleteTextView";
+ protected int myThreshold;
+
+ protected boolean popupShown;
+
public WloAutoCompleteTextView(Context context) {
super(context);
init();
@@ -53,27 +59,42 @@
}
protected void init() {
-// setOnFocusChangeListener(new OnFocusChangeListener() {
-// @Override
-// public void onFocusChange(View v, boolean hasFocus) {
-// if (hasFocus) {
-// showDropDown();
-// } else {
-// dismissDropDown();
-// }
-// }
-// });
+ setOnFocusChangeListener(new OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (!hasFocus) {
+ popupShown = false;
+ }
+ }
+ });
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- if (getAdapter() != null && !getAdapter().isEmpty()) {
+ Log.d(TAG, "onClick " + isPopupShowing());
+ if (getAdapter() != null && !getAdapter().isEmpty() && !popupShown) {
showDropDown();
+ popupShown = true;
+ } else {
+ dismissDropDown();
+ popupShown = false;
}
}
});
}
@Override
+ public void setOnItemClickListener(final AdapterView.OnItemClickListener l) {
+ AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ l.onItemClick(parent, view, position, id);
+ popupShown = false;
+ }
+ };
+ super.setOnItemClickListener(listener);
+ }
+
+ @Override
public void setThreshold(int threshold) {
if (threshold < 0) {
threshold = 0;
Modified: trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextViewWithFavorites.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextViewWithFavorites.java 2014-01-29 18:51:33 UTC (rev 40)
+++ trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextViewWithFavorites.java 2014-01-30 10:34:36 UTC (rev 41)
@@ -50,11 +50,14 @@
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d(TAG, "onCheckedChanged " + isChecked);
+ String s = autoCompleteTextView.getText().toString();
+ autoCompleteTextView.setText(null);
Adapter adapter = autoCompleteTextView.getAdapter();
if (FavoriteAdapter.class.isAssignableFrom(adapter.getClass())) {
FavoriteAdapter favoriteAdapter = (FavoriteAdapter) autoCompleteTextView.getAdapter();
favoriteAdapter.useFavorites(isChecked);
}
+ autoCompleteTextView.setText(s);
}
});
}
@@ -63,6 +66,10 @@
return autoCompleteTextView;
}
+ public void useFavorites(boolean useFavorites) {
+ toggleButton.setChecked(useFavorites);
+ }
+
public static class FavoriteAdapter<M> extends ArrayAdapter<M> {
protected Collection<M> allData;
@@ -76,7 +83,7 @@
}
}
- public void useFavorites(boolean favorites) {
+ protected void useFavorites(boolean favorites) {
if (CollectionUtils.isNotEmpty(favoriteData)) {
Log.d(TAG, "useFavorites " + favorites);
clear();
1
0
r40 - in trunk: . res/drawable res/layout res/values res/values-fr res/xml src src/fr/ifremer/wlo src/fr/ifremer/wlo/preferences src/fr/ifremer/wlo/storage src/fr/ifremer/wlo/utils
by kmorin@users.forge.codelutin.com 29 Jan '14
by kmorin@users.forge.codelutin.com 29 Jan '14
29 Jan '14
Author: kmorin
Date: 2014-01-29 19:51:33 +0100 (Wed, 29 Jan 2014)
New Revision: 40
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/40
Log:
refs #4183 Liste de favoris
Added:
trunk/res/drawable/favorite_toggle.xml
trunk/res/layout/autocomplete_text_view_with_favorites.xml
trunk/src/android/
trunk/src/fr/ifremer/wlo/preferences/MultiSelectItemPreference.java
trunk/src/fr/ifremer/wlo/preferences/WloMultiSelectListPreference.java
trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextViewWithFavorites.java
Modified:
trunk/AndroidManifest.xml
trunk/res/layout/scientific_species_form.xml
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/res/xml/preferences.xml
trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java
trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java
trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
trunk/src/fr/ifremer/wlo/storage/DataCache.java
Modified: trunk/AndroidManifest.xml
===================================================================
--- trunk/AndroidManifest.xml 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/AndroidManifest.xml 2014-01-29 18:51:33 UTC (rev 40)
@@ -18,7 +18,7 @@
android:versionCode="1"
android:versionName="1.0">
- <uses-sdk minSdkVersion="7"
+ <uses-sdk minSdkVersion="15"
android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Added: trunk/res/drawable/favorite_toggle.xml
===================================================================
--- trunk/res/drawable/favorite_toggle.xml (rev 0)
+++ trunk/res/drawable/favorite_toggle.xml 2014-01-29 18:51:33 UTC (rev 40)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- When selected, use grey -->
+ <item android:drawable="@android:drawable/btn_star_big_on"
+ android:state_checked="true" />
+ <!-- When not selected, use white-->
+ <item android:drawable="@android:drawable/btn_star_big_off"
+ android:state_checked="false"/>
+
+</selector>
\ No newline at end of file
Added: trunk/res/layout/autocomplete_text_view_with_favorites.xml
===================================================================
--- trunk/res/layout/autocomplete_text_view_with_favorites.xml (rev 0)
+++ trunk/res/layout/autocomplete_text_view_with_favorites.xml 2014-01-29 18:51:33 UTC (rev 40)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <fr.ifremer.wlo.utils.WloAutoCompleteTextView
+ android:id="@+id/autocomplete_text_view"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:singleLine="true"
+ android:hint="@string/undefined"/>
+
+ <ToggleButton android:id="@+id/favorite_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/favorite_toggle"
+ android:textOff=""
+ android:textOn=""/>
+</LinearLayout>
\ No newline at end of file
Modified: trunk/res/layout/scientific_species_form.xml
===================================================================
--- trunk/res/layout/scientific_species_form.xml 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/res/layout/scientific_species_form.xml 2014-01-29 18:51:33 UTC (rev 40)
@@ -19,12 +19,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
- <fr.ifremer.wlo.utils.WloAutoCompleteTextView
+ <fr.ifremer.wlo.utils.WloAutoCompleteTextViewWithFavorites
android:id="@+id/scientific_species_form_name"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:hint="@string/undefined"/>
+ android:layout_height="wrap_content"/>
<CheckBox android:id="@+id/scientific_species_form_takingActivation"
android:text="@string/scientific_species_form_taking_activation"
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/res/values/strings.xml 2014-01-29 18:51:33 UTC (rev 40)
@@ -85,6 +85,7 @@
<string name="preferences_ichtyometer">Ichtyometer</string>
<string name="preferences_referentials">Referentials</string>
<string name="preferences_imports">Imports</string>
+ <string name="preferences_imports">Favorites</string>
<string name="preferences_import_summary">%s items currently</string>
<string name="preferences_import_ages">Import ages</string>
@@ -102,6 +103,9 @@
<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_importing_referential">Importing referential data</string>
+ <string name="preferences_favorites_commercial_species">Commercial species</string>
+ <string name="preferences_favorites_scientific_species">Scientific species</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>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/res/values-fr/strings.xml 2014-01-29 18:51:33 UTC (rev 40)
@@ -80,6 +80,7 @@
<string name="preferences_use_place">Lieu d\'utilisation</string>
<string name="preferences_referentials">Référentiels</string>
<string name="preferences_imports">Imports</string>
+ <string name="preferences_favorites">Favoris</string>
<string name="preferences_import_summary">%s éléments actuellement</string>
<string name="preferences_import_ages">Importer des âges</string>
@@ -100,6 +101,9 @@
<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_favorites_commercial_species">Espèces commerciales</string>
+ <string name="preferences_favorites_scientific_species">Espèces scientifiques</string>
+
<!-- Contexts -->
<string name="add_context">Créer un nouveau contexte</string>
<string name="contexts_title">Contextes</string>
Modified: trunk/res/xml/preferences.xml
===================================================================
--- trunk/res/xml/preferences.xml 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/res/xml/preferences.xml 2014-01-29 18:51:33 UTC (rev 40)
@@ -66,6 +66,20 @@
</PreferenceScreen>
+ <PreferenceScreen
+ android:key="preferences_favorites"
+ android:title="@string/preferences_favorites">
+
+ <fr.ifremer.wlo.preferences.WloMultiSelectListPreference
+ android:key="preferences_favorites_commercial_species"
+ android:title="@string/preferences_favorites_commercial_species"/>
+
+ <fr.ifremer.wlo.preferences.WloMultiSelectListPreference
+ android:key="preferences_favorites_scientific_species"
+ android:title="@string/preferences_favorites_scientific_species"/>
+
+ </PreferenceScreen>
+
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
Modified: trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java
===================================================================
--- trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java 2014-01-29 18:51:33 UTC (rev 40)
@@ -19,8 +19,8 @@
/*
* #%L
* WLO
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2013 - 2014 Ifremer
* %%
@@ -554,7 +554,9 @@
// Read from the InputStream
bytes = mmInStream.read(buffer);
+ Log.d(TAG, "received " + new String(buffer, 0, bytes));
// Send the obtained bytes to the UI Activity
+
sendMessage(MESSAGE_READ, bytes, -1, buffer);
} catch (IOException e) {
Modified: trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-01-29 18:51:33 UTC (rev 40)
@@ -25,19 +25,28 @@
*/
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import fr.ifremer.wlo.measurement.MeasurementActivity;
import fr.ifremer.wlo.models.ScientificSpeciesModel;
import fr.ifremer.wlo.models.referentials.ScientificSpecies;
+import fr.ifremer.wlo.preferences.MultiSelectItemPreference;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
+import fr.ifremer.wlo.utils.WloAutoCompleteTextViewWithFavorites;
+import java.util.Collection;
import java.util.List;
+import java.util.Set;
/**
* @author kmorin <kmorin(a)codelutin.com>
@@ -76,8 +85,20 @@
// init editors
List<ScientificSpecies> scientificSpecies = Lists.newArrayList(DataCache.getAllScientificSpecies(this));
- initAutoCompleteTextView(R.id.scientific_species_form_name, ScientificSpeciesModel.COLUMN_NAME, scientificSpecies);
+ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
+ final Set<String> favoriteIds = sharedPref.getStringSet(MultiSelectItemPreference.SCIENTIFIC_SPECIES_FAVORITES.getKey(),
+ Sets.<String>newHashSet());
+ Collection<ScientificSpecies> favorites = Collections2.filter(scientificSpecies, new Predicate<ScientificSpecies>() {
+ @Override
+ public boolean apply(ScientificSpecies input) {
+ return favoriteIds.contains(input.getId());
+ }
+ });
+
+ WloAutoCompleteTextViewWithFavorites actvwf = (WloAutoCompleteTextViewWithFavorites) findViewById(R.id.scientific_species_form_name);
+ initAutoCompleteTextView(actvwf.getAutoCompleteTextView(), ScientificSpeciesModel.COLUMN_NAME, scientificSpecies, favorites);
+
CheckBox takingActivationEditor = (CheckBox) findViewById(R.id.scientific_species_form_takingActivation);
takingActivationEditor.setChecked(model.isTakingActivation());
takingActivationEditor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
Modified: trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-29 18:51:33 UTC (rev 40)
@@ -46,6 +46,7 @@
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
import fr.ifremer.wlo.utils.BaseTextWatcher;
import fr.ifremer.wlo.utils.UIUtils;
+import fr.ifremer.wlo.utils.WloAutoCompleteTextViewWithFavorites;
import org.apache.commons.lang3.ObjectUtils;
import java.beans.PropertyChangeEvent;
@@ -246,18 +247,28 @@
}
protected <R> AutoCompleteTextView initAutoCompleteTextView(int autoCompleteTextViewId, final String attribute, Collection<R> data) {
+ return initAutoCompleteTextView(autoCompleteTextViewId, attribute, data, null);
+ }
+
+ protected <R> AutoCompleteTextView initAutoCompleteTextView(int autoCompleteTextViewId, final String attribute,
+ Collection<R> data, Collection<R> favorites) {
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(autoCompleteTextViewId);
- initAutoCompleteTextView(autoCompleteTextView, attribute, data);
+ initAutoCompleteTextView(autoCompleteTextView, attribute, data, favorites);
return autoCompleteTextView;
}
protected <R> void initAutoCompleteTextView(final AutoCompleteTextView autoCompleteTextView, final String attribute, Collection<R> data) {
+ initAutoCompleteTextView(autoCompleteTextView, attribute, data, null);
+ }
+
+ protected <R> void initAutoCompleteTextView(final AutoCompleteTextView autoCompleteTextView, final String attribute,
+ Collection<R> data, Collection<R> favorites) {
final Class clazz = model.getClass();
final String firtsLetterUpperCaseAttribute =
attribute.substring(0, 1).toUpperCase() + attribute.substring(1);
if (!data.isEmpty()) {
- ArrayAdapter<R> adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, Lists.newArrayList(data));
+ ArrayAdapter<R> adapter = new WloAutoCompleteTextViewWithFavorites.FavoriteAdapter<R>(this, data, favorites);
autoCompleteTextView.setAdapter(adapter);
}
Copied: trunk/src/fr/ifremer/wlo/preferences/MultiSelectItemPreference.java (from rev 29, trunk/src/fr/ifremer/wlo/preferences/StringPreference.java)
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/MultiSelectItemPreference.java (rev 0)
+++ trunk/src/fr/ifremer/wlo/preferences/MultiSelectItemPreference.java 2014-01-29 18:51:33 UTC (rev 40)
@@ -0,0 +1,46 @@
+package fr.ifremer.wlo.preferences;
+
+/*
+ * #%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%
+ */
+
+/**
+ * @author kmorin <kmorin(a)codelutin.com>
+ * @since 0.1
+ */
+public enum MultiSelectItemPreference {
+
+ COMMERCIAL_SPECIES_FAVORITES("preferences_favorites_commercial_species"),
+ SCIENTIFIC_SPECIES_FAVORITES("preferences_favorites_scientific_species");
+
+ private String key;
+
+ private MultiSelectItemPreference(String key) {
+ this.key = key;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+}
Modified: trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-01-29 18:51:33 UTC (rev 40)
@@ -32,17 +32,24 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
+import android.preference.MultiSelectListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.text.format.DateFormat;
import android.util.Log;
import android.widget.Toast;
+import com.google.common.base.Functions;
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 com.google.common.collect.Sets;
import fr.ifremer.wlo.MainActivity;
import fr.ifremer.wlo.R;
import fr.ifremer.wlo.WloBaseActivity;
+import fr.ifremer.wlo.models.BaseModel;
+import fr.ifremer.wlo.models.referentials.CommercialSpecies;
+import fr.ifremer.wlo.models.referentials.ScientificSpecies;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.StorageUtils;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
@@ -55,8 +62,12 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
/**
* @author kmorin <kmorin(a)codelutin.com>
@@ -157,12 +168,14 @@
}
});
}
+
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ Log.d(TAG, "onSharedPreferenceChanged " + key);
- Preference connectionPref = findPreference(key);
+ Preference preference = findPreference(key);
String summary = null;
ListItemPreference pref = ListItemPreference.getListItemPreference(key);
@@ -171,10 +184,14 @@
summary = pref.getEntryForValue(getActivity(), entry);
} else {
- summary = sharedPreferences.getString(key, "");
+ try {
+ summary = sharedPreferences.getString(key, "");
+ } catch (ClassCastException e) {
+ // ok, that's normal, it is a list so we do not want to have a summary
+ }
}
// Set summary to be the user-description for the selected value
- connectionPref.setSummary(summary);
+ preference.setSummary(summary);
}
@Override
@@ -184,24 +201,32 @@
for (StringPreference pref : StringPreference.values()) {
String key = pref.getKey();
- Preference connectionPref = findPreference(key);
- connectionPref.setSummary(sharedPreferences.getString(key, ""));
+ Preference preference = findPreference(key);
+ preference.setSummary(sharedPreferences.getString(key, ""));
}
for (ListItemPreference pref : ListItemPreference.values()) {
String key = pref.getKey();
- Preference connectionPref = findPreference(key);
+ Preference preference = findPreference(key);
String entry = sharedPreferences.getString(key, "");
String summary = pref.getEntryForValue(getActivity(), entry);
- connectionPref.setSummary(summary);
+ preference.setSummary(summary);
}
+ Collection<CommercialSpecies> commercialSpecies = DataCache.getAllCommercialSpecies(getActivity());
+ initMultiSelectListPreference(MultiSelectItemPreference.COMMERCIAL_SPECIES_FAVORITES, commercialSpecies);
+
+ Collection<ScientificSpecies> scientificSpecies = DataCache.getAllScientificSpecies(getActivity());
+ initMultiSelectListPreference(MultiSelectItemPreference.SCIENTIFIC_SPECIES_FAVORITES, scientificSpecies);
+
+ Log.d(TAG, "registerOnSharedPreferenceChangeListener");
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
super.onPause();
+ Log.d(TAG, "unregisterOnSharedPreferenceChangeListener");
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@@ -346,6 +371,24 @@
}
}).start();
}
+
+ protected <M extends BaseModel> void initMultiSelectListPreference(MultiSelectItemPreference pref, Collection<M> refData) {
+ Log.d(TAG, "initMultiSelectListPreference " + pref.getKey());
+
+ SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
+ Set<String> data = sharedPreferences.getStringSet(pref.getKey(), new HashSet<String>());
+ Log.d(TAG, "data " + data);
+
+ MultiSelectListPreference preference =
+ (MultiSelectListPreference) findPreference(pref.getKey());
+ Collection<String> entries = Collections2.transform(refData, Functions.toStringFunction());
+ preference.setEntries(entries.toArray(new CharSequence[entries.size()]));
+ Collection<String> entryValues = Collections2.transform(refData, BaseModel.GET_ID_FUNCTION);
+ preference.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
+
+ preference.setValues(data);
+
+ }
}
}
\ No newline at end of file
Added: trunk/src/fr/ifremer/wlo/preferences/WloMultiSelectListPreference.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/WloMultiSelectListPreference.java (rev 0)
+++ trunk/src/fr/ifremer/wlo/preferences/WloMultiSelectListPreference.java 2014-01-29 18:51:33 UTC (rev 40)
@@ -0,0 +1,59 @@
+package fr.ifremer.wlo.preferences;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.preference.MultiSelectListPreference;
+import android.util.AttributeSet;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A {@link Preference} that displays a list of entries as
+ * a dialog.
+ * <p>
+ * This preference will store a set of strings into the SharedPreferences.
+ * This set will contain one or more values from the
+ * {@link #setEntryValues(CharSequence[])} array.
+ *
+ * @attr ref android.R.styleable#MultiSelectListPreference_entries
+ * @attr ref android.R.styleable#MultiSelectListPreference_entryValues
+ * @since 0.2
+ */
+public class WloMultiSelectListPreference extends MultiSelectListPreference {
+
+ public WloMultiSelectListPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public WloMultiSelectListPreference(Context context) {
+ this(context, null);
+ }
+
+ /**
+ * Sets the value of the key. This should contain entries in
+ * {@link #getEntryValues()}.
+ *
+ * @param values The values to set for the key.
+ */
+ public void setValues(Set<String> values) {
+ Set<String> mValues = getValues();
+ mValues.clear();
+ mValues.addAll(values);
+
+ SharedPreferences.Editor editor = getPreferenceManager().getSharedPreferences().edit();
+ editor.putStringSet(getKey(), mValues);
+
+ try {
+ editor.apply();
+
+ } catch (AbstractMethodError unused) {
+ // The app injected its own pre-Gingerbread
+ // SharedPreferences.Editor implementation without
+ // an apply method.
+ editor.commit();
+ }
+
+ }
+
+}
Modified: trunk/src/fr/ifremer/wlo/storage/DataCache.java
===================================================================
--- trunk/src/fr/ifremer/wlo/storage/DataCache.java 2014-01-29 13:38:23 UTC (rev 39)
+++ trunk/src/fr/ifremer/wlo/storage/DataCache.java 2014-01-29 18:51:33 UTC (rev 40)
@@ -92,7 +92,9 @@
public static Collection<CommercialSpecies> getAllCommercialSpecies(Context context) {
initCommercialSpecies(context);
- return commercialSpecies.values();
+ List<CommercialSpecies> result = Lists.newArrayList(commercialSpecies.values());
+ Collections.sort(result, HasCode.GET_CODE_COMPARATOR);
+ return result;
}
public static CommercialSpecies getCommercialSpeciesById(Context context, String id) {
Added: trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextViewWithFavorites.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextViewWithFavorites.java (rev 0)
+++ trunk/src/fr/ifremer/wlo/utils/WloAutoCompleteTextViewWithFavorites.java 2014-01-29 18:51:33 UTC (rev 40)
@@ -0,0 +1,92 @@
+package fr.ifremer.wlo.utils;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.widget.Adapter;
+import android.widget.ArrayAdapter;
+import android.widget.CompoundButton;
+import android.widget.FrameLayout;
+import android.widget.ToggleButton;
+import com.google.common.collect.Lists;
+import fr.ifremer.wlo.R;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * @author kmorin <kmorin(a)codelutin.com>
+ * @since 0.2
+ */
+public class WloAutoCompleteTextViewWithFavorites extends FrameLayout {
+
+ private static final String TAG = "WloAutoCompleteTextViewWithFavorites";
+
+ protected WloAutoCompleteTextView autoCompleteTextView;
+ protected ToggleButton toggleButton;
+
+ public WloAutoCompleteTextViewWithFavorites(Context context) {
+ super(context);
+ init(context);
+ }
+
+ public WloAutoCompleteTextViewWithFavorites(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context);
+ }
+
+ public WloAutoCompleteTextViewWithFavorites(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(context);
+ }
+
+ protected void init(Context context) {
+ inflate(context, R.layout.autocomplete_text_view_with_favorites, this);
+ autoCompleteTextView = (WloAutoCompleteTextView) findViewById(R.id.autocomplete_text_view);
+ toggleButton = (ToggleButton) findViewById(R.id.favorite_button);
+ toggleButton.setChecked(false);
+ toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ Log.d(TAG, "onCheckedChanged " + isChecked);
+ Adapter adapter = autoCompleteTextView.getAdapter();
+ if (FavoriteAdapter.class.isAssignableFrom(adapter.getClass())) {
+ FavoriteAdapter favoriteAdapter = (FavoriteAdapter) autoCompleteTextView.getAdapter();
+ favoriteAdapter.useFavorites(isChecked);
+ }
+ }
+ });
+ }
+
+ public WloAutoCompleteTextView getAutoCompleteTextView() {
+ return autoCompleteTextView;
+ }
+
+ public static class FavoriteAdapter<M> extends ArrayAdapter<M> {
+
+ protected Collection<M> allData;
+ protected Collection<M> favoriteData;
+
+ public FavoriteAdapter(Context context, Collection<M> allData, Collection<M> favoriteData) {
+ super(context, android.R.layout.simple_dropdown_item_1line, Lists.newArrayList(allData));
+ this.allData = Lists.newArrayList(allData);
+ if (favoriteData != null) {
+ this.favoriteData = Lists.newArrayList(favoriteData);
+ }
+ }
+
+ public void useFavorites(boolean favorites) {
+ if (CollectionUtils.isNotEmpty(favoriteData)) {
+ Log.d(TAG, "useFavorites " + favorites);
+ clear();
+ if (favorites) {
+ addAll(favoriteData);
+ } else {
+ addAll(allData);
+ }
+ notifyDataSetInvalidated();
+ }
+ }
+ }
+}
1
0
Author: kmorin
Date: 2014-01-29 14:38:23 +0100 (Wed, 29 Jan 2014)
New Revision: 39
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/39
Log:
fixes #4252 D?\195?\169sactiver la case coch?\195?\169e "m?\195?\169lange d'esp?\195?\168ces" si il existe au moins deux fils enregistr?\195?\169s
Modified:
trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java
Modified: trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java 2014-01-28 21:37:56 UTC (rev 38)
+++ trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java 2014-01-29 13:38:23 UTC (rev 39)
@@ -24,6 +24,7 @@
* #L%
*/
+import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@@ -125,6 +126,14 @@
model.setSpeciesMix(b);
}
});
+ boolean speciesMixEnabled = model.isNew() || !model.isSpeciesMix();
+ if (!speciesMixEnabled) {
+ WloSqlOpenHelper soh = new WloSqlOpenHelper(this);
+ Cursor cursor = soh.getAllScientificSpecies(model.getId());
+ int scientificSpeciesNb = cursor.getCount();
+ speciesMixEnabled = scientificSpeciesNb < 2;
+ }
+ speciesMixEditor.setEnabled(speciesMixEnabled);
initEditText(R.id.form_comment, CommercialSpeciesModel.COLUMN_COMMENT);
1
0
r38 - in trunk: . res/layout res/values res/values-fr src/fr/ifremer/wlo src/fr/ifremer/wlo/measurement
by kmorin@users.forge.codelutin.com 28 Jan '14
by kmorin@users.forge.codelutin.com 28 Jan '14
28 Jan '14
Author: kmorin
Date: 2014-01-28 22:37:56 +0100 (Tue, 28 Jan 2014)
New Revision: 38
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/38
Log:
fixes #4241 ?\195?\169cran des tailles, ajouter le nombre total d'individus mesur?\195?\169
Modified:
trunk/AndroidManifest.xml
trunk/res/layout/measurement.xml
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
Modified: trunk/AndroidManifest.xml
===================================================================
--- trunk/AndroidManifest.xml 2014-01-28 21:06:06 UTC (rev 37)
+++ trunk/AndroidManifest.xml 2014-01-28 21:37:56 UTC (rev 38)
@@ -51,7 +51,8 @@
<activity android:name=".MainActivity"
android:label="@string/app_name"
- android:configChanges="orientation|keyboardHidden">
+ android:configChanges="orientation|keyboardHidden"
+ android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Modified: trunk/res/layout/measurement.xml
===================================================================
--- trunk/res/layout/measurement.xml 2014-01-28 21:06:06 UTC (rev 37)
+++ trunk/res/layout/measurement.xml 2014-01-28 21:37:56 UTC (rev 38)
@@ -126,6 +126,31 @@
</FrameLayout>
+ <View android:layout_width="match_parent"
+ android:layout_height="2px"
+ android:background="@android:color/holo_blue_light"/>
+
+ <LinearLayout android:id="@+id/fragment_placeholder"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:padding="2dp">
+
+ <TextView android:text="@string/observed_number"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textStyle="italic"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"/>
+
+ <TextView android:id="@+id/observed_number"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textStyle="bold"
+ android:text='0'/>
+
+ </LinearLayout>
+
</LinearLayout>
</TabHost>
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-01-28 21:06:06 UTC (rev 37)
+++ trunk/res/values/strings.xml 2014-01-28 21:37:56 UTC (rev 38)
@@ -65,6 +65,8 @@
<string name="undefined">Undefined</string>
+ <string name="observed_number">Number of individuals observed:</string>
+
<!-- Home screen -->
<string name="main_open_contexts">Watch/Input data</string>
<string name="main_export_data">Export data</string>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-01-28 21:06:06 UTC (rev 37)
+++ trunk/res/values-fr/strings.xml 2014-01-28 21:37:56 UTC (rev 38)
@@ -61,6 +61,8 @@
<string name="undefined">Non défini</string>
+ <string name="observed_number">Nombre d\'individus observés :</string>
+
<!-- Home screen -->
<string name="main_open_contexts">Voir / saisir des données</string>
<string name="main_export_data">Export des données</string>
Modified: trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-28 21:06:06 UTC (rev 37)
+++ trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-28 21:37:56 UTC (rev 38)
@@ -160,6 +160,7 @@
saveModel();
if (newModel) {
+
Intent intent = new Intent(this, getNextEditionActivity());
intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_PARENT_MODEL, model);
startActivity(intent);
Modified: trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-01-28 21:06:06 UTC (rev 37)
+++ trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-01-28 21:37:56 UTC (rev 38)
@@ -101,6 +101,7 @@
protected TabHost tabs;
protected EditText sizeText;
protected ActionBarDrawerToggle mDrawerToggle;
+ protected TextView observedNumberText;
protected MeasurementModel measurement;
protected MeasurementsModel measurements;
@@ -152,11 +153,15 @@
measurements.addMeasurementsListener(new MeasurementsModel.MeasurementsListener() {
@Override
public void onMeasurementAdded(MeasurementsModel source, MeasurementModel measurement) {
+ int size = source.getMeasurements().size();
+ observedNumberText.setText(String.valueOf(size));
}
@Override
public void onMeasurementRemoved(MeasurementsModel source, MeasurementModel measurement) {
soh.deleteMeasurement(measurement);
+ int size = source.getMeasurements().size();
+ observedNumberText.setText(String.valueOf(size));
}
});
@@ -203,21 +208,27 @@
}
});
+ observedNumberText = (TextView) findViewById(R.id.observed_number);
+ observedNumberText.setText(String.valueOf(measurements.getMeasurements().size()));
+
Spinner genderSpinner = (Spinner) findViewById(R.id.gender_spinner);
genderSpinner.setOnItemSelectedListener(this);
List<Gender> genders = Lists.newArrayList(DataCache.getAllGenders(this));
+ genders.add(0, null);
ArrayAdapter<Gender> gendersAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, genders);
genderSpinner.setAdapter(gendersAdapter);
Spinner maturitySpinner = (Spinner) findViewById(R.id.maturity_spinner);
maturitySpinner.setOnItemSelectedListener(this);
List<Maturity> maturities = Lists.newArrayList(DataCache.getAllMaturities(this));
+ maturities.add(0, null);
ArrayAdapter<Maturity> maturitiesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, maturities);
maturitySpinner.setAdapter(maturitiesAdapter);
Spinner ageSpinner = (Spinner) findViewById(R.id.age_spinner);
ageSpinner.setOnItemSelectedListener(this);
List<Age> ages = Lists.newArrayList(DataCache.getAllAges(this));
+ ages.add(0, null);
ArrayAdapter<Age> agesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, ages);
ageSpinner.setAdapter(agesAdapter);
@@ -310,15 +321,16 @@
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
BaseModel selected = (BaseModel) adapterView.getItemAtPosition(i);
+ String id = selected != null ? selected.getId() : null;
switch(adapterView.getId()) {
case R.id.gender_spinner:
- measurement.setCategory1(selected.getId());
+ measurement.setCategory1(id);
break;
case R.id.maturity_spinner:
- measurement.setCategory2(selected.getId());
+ measurement.setCategory2(id);
break;
case R.id.age_spinner:
- measurement.setCategory3(selected.getId());
+ measurement.setCategory3(id);
break;
}
}
1
0
r37 - in trunk: res/values res/values-fr src/fr/ifremer/wlo/models/referentials/imports src/fr/ifremer/wlo/preferences
by kmorin@users.forge.codelutin.com 28 Jan '14
by kmorin@users.forge.codelutin.com 28 Jan '14
28 Jan '14
Author: kmorin
Date: 2014-01-28 22:06:06 +0100 (Tue, 28 Jan 2014)
New Revision: 37
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/37
Log:
fixes #4205 G?\195?\169rer les erreurs lors des imports de r?\195?\169f?\195?\169rentiels
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/fr/ifremer/wlo/models/referentials/imports/ImportUtil.java
trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-01-28 18:42:42 UTC (rev 36)
+++ trunk/res/values/strings.xml 2014-01-28 21:06:06 UTC (rev 37)
@@ -101,6 +101,7 @@
<string name="preferences_importing_referential">Importing referential data</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>
<!-- Contexts -->
<string name="add_context">Create a new context</string>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-01-28 18:42:42 UTC (rev 36)
+++ trunk/res/values-fr/strings.xml 2014-01-28 21:06:06 UTC (rev 37)
@@ -96,6 +96,7 @@
<string name="preferences_importing_referential">Import des données du référentiel en cours</string>
<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>
<!-- Contexts -->
<string name="add_context">Créer un nouveau contexte</string>
Modified: trunk/src/fr/ifremer/wlo/models/referentials/imports/ImportUtil.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/referentials/imports/ImportUtil.java 2014-01-28 18:42:42 UTC (rev 36)
+++ trunk/src/fr/ifremer/wlo/models/referentials/imports/ImportUtil.java 2014-01-28 21:06:06 UTC (rev 37)
@@ -24,19 +24,20 @@
* #L%
*/
+import android.app.AlertDialog;
import android.content.Context;
import android.util.Log;
-import android.widget.Toast;
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.R;
+import fr.ifremer.wlo.models.BaseModel;
import fr.ifremer.wlo.models.referentials.HasCode;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
-import fr.ifremer.wlo.models.BaseModel;
+import org.apache.commons.collections.CollectionUtils;
import org.nuiton.csv.Import;
import org.nuiton.csv.ImportModel;
@@ -44,7 +45,6 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Collection;
-import java.util.List;
/**
* @author kmorin <kmorin(a)codelutin.com>
@@ -238,7 +238,23 @@
Import<M> importer = Import.newImport(importModel, inputStream);
Collection<M> models = Lists.newArrayList(importer.iterator());
- if (!models.isEmpty()) {
+ 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();
+ }
+ }
+
+ if (CollectionUtils.isNotEmpty(models)) {
Predicate<M> filter;
//if the models have a code attribute, check
M first = models.iterator().next();
@@ -272,7 +288,6 @@
soh.close();
}
- importer.close();
return models.size();
}
}
Modified: trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-01-28 18:42:42 UTC (rev 36)
+++ trunk/src/fr/ifremer/wlo/preferences/SettingsActivity.java 2014-01-28 21:06:06 UTC (rev 37)
@@ -250,80 +250,99 @@
Log.d(TAG, path);
final int updatedNb;
final int newNb;
- switch (requestCode) {
- case REQUEST_IMPORT_AGES:
- newNb = ImportUtil.importAges(context, path);
- updatedNb = DataCache.getAllAges(context).size();
- break;
- case REQUEST_IMPORT_COMMERCIAL_SPECIES:
- newNb = ImportUtil.importCommercialSpecies(context, path);
- updatedNb = DataCache.getAllCommercialSpecies(context).size();
- break;
- case REQUEST_IMPORT_GENDERS:
- newNb = ImportUtil.importGenders(context, path);
- updatedNb = DataCache.getAllGenders(context).size();
- break;
- case REQUEST_IMPORT_LOCATIONS:
- newNb = ImportUtil.importLocations(context, path);
- updatedNb = DataCache.getAllLocations(context).size();
- break;
- case REQUEST_IMPORT_MATURITIES:
- newNb = ImportUtil.importMaturities(context, path);
- updatedNb = DataCache.getAllMaturities(context).size();
- break;
- case REQUEST_IMPORT_MENSURATIONS:
- newNb = ImportUtil.importMensurations(context, path);
- updatedNb = DataCache.getAllMensurations(context).size();
- break;
- case REQUEST_IMPORT_METIERS:
- newNb = ImportUtil.importMetiers(context, path);
- updatedNb = DataCache.getAllMetiers(context).size();
- break;
- case REQUEST_IMPORT_PRESENTATIONS:
- newNb = ImportUtil.importPresentations(context, path);
- updatedNb = DataCache.getAllPresentations(context).size();
- break;
- case REQUEST_IMPORT_SCIENTIFIC_SPECIES:
- newNb = ImportUtil.importScientificSpecies(context, path);
- updatedNb = DataCache.getAllScientificSpecies(context).size();
- break;
- case REQUEST_IMPORT_STATES:
- newNb = ImportUtil.importStates(context, path);
- updatedNb = DataCache.getAllStates(context).size();
- break;
- case REQUEST_IMPORT_VESSELS:
- newNb = ImportUtil.importVessels(context, path);
- updatedNb = DataCache.getAllVessels(context).size();
- break;
- default:
- newNb = 0;
- updatedNb = 0;
- }
- dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- String key = requestCodeByPrefKey.inverse().get(requestCode);
- Preference filePicker = findPreference(key);
- filePicker.setSummary(getString(R.string.preferences_import_summary, updatedNb));
+ try {
+ switch (requestCode) {
+ case REQUEST_IMPORT_AGES:
+ newNb = ImportUtil.importAges(context, path);
+ updatedNb = DataCache.getAllAges(context).size();
+ break;
+ case REQUEST_IMPORT_COMMERCIAL_SPECIES:
+ newNb = ImportUtil.importCommercialSpecies(context, path);
+ updatedNb = DataCache.getAllCommercialSpecies(context).size();
+ break;
+ case REQUEST_IMPORT_GENDERS:
+ newNb = ImportUtil.importGenders(context, path);
+ updatedNb = DataCache.getAllGenders(context).size();
+ break;
+ case REQUEST_IMPORT_LOCATIONS:
+ newNb = ImportUtil.importLocations(context, path);
+ updatedNb = DataCache.getAllLocations(context).size();
+ break;
+ case REQUEST_IMPORT_MATURITIES:
+ newNb = ImportUtil.importMaturities(context, path);
+ updatedNb = DataCache.getAllMaturities(context).size();
+ break;
+ case REQUEST_IMPORT_MENSURATIONS:
+ newNb = ImportUtil.importMensurations(context, path);
+ updatedNb = DataCache.getAllMensurations(context).size();
+ break;
+ case REQUEST_IMPORT_METIERS:
+ newNb = ImportUtil.importMetiers(context, path);
+ updatedNb = DataCache.getAllMetiers(context).size();
+ break;
+ case REQUEST_IMPORT_PRESENTATIONS:
+ newNb = ImportUtil.importPresentations(context, path);
+ updatedNb = DataCache.getAllPresentations(context).size();
+ break;
+ case REQUEST_IMPORT_SCIENTIFIC_SPECIES:
+ newNb = ImportUtil.importScientificSpecies(context, path);
+ updatedNb = DataCache.getAllScientificSpecies(context).size();
+ break;
+ case REQUEST_IMPORT_STATES:
+ newNb = ImportUtil.importStates(context, path);
+ updatedNb = DataCache.getAllStates(context).size();
+ break;
+ case REQUEST_IMPORT_VESSELS:
+ newNb = ImportUtil.importVessels(context, path);
+ updatedNb = DataCache.getAllVessels(context).size();
+ break;
+ default:
+ newNb = 0;
+ updatedNb = 0;
+ }
- Toast.makeText(context, context.getString(R.string.import_new_element_number, newNb), Toast.LENGTH_SHORT).show();
+ if (backupFile) {
+ File importedFile = new File(path);
+ String copyFileName = String.format("%1$tY%1$tm%1$td-%1$tH%1$tM%1$tS-", new Date()) + importedFile.getName();
+ File dir = Environment.getExternalStoragePublicDirectory(".wlo");
+ File file = new File(dir, copyFileName);
+ try {
+ FileUtils.copyInputStreamToFile(new FileInputStream(path), file);
+ } catch (IOException e) {
+ Log.e(TAG, "Error while copying the file", e);
+ }
}
- });
- if (backupFile) {
- File importedFile = new File(path);
- String copyFileName = String.format("%1$tY%1$tm%1$td-%1$tH%1$tM%1$tS-", new Date()) + importedFile.getName();
- File dir = Environment.getExternalStoragePublicDirectory(".wlo");
- File file = new File(dir, copyFileName);
- try {
- FileUtils.copyInputStreamToFile(new FileInputStream(path), file);
- } catch (IOException e) {
- Log.e(TAG, "Error while copying the file", e);
- }
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ dialog.dismiss();
+ String key = requestCodeByPrefKey.inverse().get(requestCode);
+ Preference filePicker = findPreference(key);
+ filePicker.setSummary(getString(R.string.preferences_import_summary, updatedNb));
+
+ Toast.makeText(context, context.getString(R.string.import_new_element_number, newNb), Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ } 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);
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ dialog.dismiss();
+ new AlertDialog.Builder(context)
+ .setMessage(R.string.import_error)
+ .setNeutralButton(android.R.string.ok, UIUtils.getCancelClickListener())
+ .create().show();
+ }
+ });
+
}
- dialog.dismiss();
}
}).start();
}
1
0
r36 - in trunk: res/layout res/values res/values-fr src/fr/ifremer/wlo src/fr/ifremer/wlo/measurement src/fr/ifremer/wlo/models src/fr/ifremer/wlo/storage
by kmorin@users.forge.codelutin.com 28 Jan '14
by kmorin@users.forge.codelutin.com 28 Jan '14
28 Jan '14
Author: kmorin
Date: 2014-01-28 19:42:42 +0100 (Tue, 28 Jan 2014)
New Revision: 36
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/36
Log:
fixes #4248 Ajouter un champ commentaire ?\195?\160 chaque ?\195?\169tape
Modified:
trunk/res/layout/commercial_species_form.xml
trunk/res/layout/context_form.xml
trunk/res/layout/location_form.xml
trunk/res/layout/metier_form.xml
trunk/res/layout/scientific_species_form.xml
trunk/res/layout/vessel_form.xml
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java
trunk/src/fr/ifremer/wlo/ContextFormActivity.java
trunk/src/fr/ifremer/wlo/LocationFormActivity.java
trunk/src/fr/ifremer/wlo/MetierFormActivity.java
trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java
trunk/src/fr/ifremer/wlo/VesselFormActivity.java
trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
trunk/src/fr/ifremer/wlo/models/CommercialSpeciesModel.java
trunk/src/fr/ifremer/wlo/models/ContextModel.java
trunk/src/fr/ifremer/wlo/models/LocationModel.java
trunk/src/fr/ifremer/wlo/models/MetierModel.java
trunk/src/fr/ifremer/wlo/models/ScientificSpeciesModel.java
trunk/src/fr/ifremer/wlo/models/VesselModel.java
trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java
Modified: trunk/res/layout/commercial_species_form.xml
===================================================================
--- trunk/res/layout/commercial_species_form.xml 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/res/layout/commercial_species_form.xml 2014-01-28 18:42:42 UTC (rev 36)
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
@@ -85,6 +84,16 @@
android:singleLine="true"
android:hint="@string/undefined"/>
+ <TextView android:text="@string/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <EditText android:id="@+id/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:minLines="5"/>
+
</LinearLayout>
</ScrollView>
Modified: trunk/res/layout/context_form.xml
===================================================================
--- trunk/res/layout/context_form.xml 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/res/layout/context_form.xml 2014-01-28 18:42:42 UTC (rev 36)
@@ -1,44 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fillViewport="true">
-
- <LinearLayout android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView android:text="@string/context_form_name"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
+ android:layout_height="match_parent">
- <EditText android:id="@+id/context_form_name"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:singleLine="true"
- android:hint="@string/undefined"/>
+ <ScrollView android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:fillViewport="true">
- <LinearLayout android:orientation="horizontal"
+ <LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:gravity="bottom">
+ android:layout_height="wrap_content">
- <Button android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="@android:string/cancel"
- android:onClick="cancel" />
+ <TextView android:text="@string/context_form_name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
- <Button android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="@android:string/ok"
- android:onClick="validate" />
+ <EditText android:id="@+id/context_form_name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:hint="@string/undefined"/>
+ <TextView android:text="@string/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <EditText android:id="@+id/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:minLines="5"/>
+
</LinearLayout>
+ </ScrollView>
+
+ <LinearLayout android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:gravity="bottom">
+
+ <Button android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@android:string/cancel"
+ android:onClick="cancel" />
+
+ <Button android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@android:string/ok"
+ android:onClick="validate" />
+
</LinearLayout>
-</ScrollView>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
Modified: trunk/res/layout/location_form.xml
===================================================================
--- trunk/res/layout/location_form.xml 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/res/layout/location_form.xml 2014-01-28 18:42:42 UTC (rev 36)
@@ -87,6 +87,16 @@
android:singleLine="true"
android:hint="@string/undefined"/>
+ <TextView android:text="@string/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <EditText android:id="@+id/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:minLines="5"/>
+
</LinearLayout>
</ScrollView>
Modified: trunk/res/layout/metier_form.xml
===================================================================
--- trunk/res/layout/metier_form.xml 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/res/layout/metier_form.xml 2014-01-28 18:42:42 UTC (rev 36)
@@ -46,6 +46,16 @@
android:layout_height="wrap_content"
android:singleLine="true"/>
+ <TextView android:text="@string/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <EditText android:id="@+id/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:minLines="5"/>
+
</LinearLayout>
</ScrollView>
Modified: trunk/res/layout/scientific_species_form.xml
===================================================================
--- trunk/res/layout/scientific_species_form.xml 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/res/layout/scientific_species_form.xml 2014-01-28 18:42:42 UTC (rev 36)
@@ -31,6 +31,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
+ <TextView android:text="@string/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <EditText android:id="@+id/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:minLines="5"/>
+
</LinearLayout>
</ScrollView>
Modified: trunk/res/layout/vessel_form.xml
===================================================================
--- trunk/res/layout/vessel_form.xml 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/res/layout/vessel_form.xml 2014-01-28 18:42:42 UTC (rev 36)
@@ -59,6 +59,16 @@
android:layout_height="wrap_content"
android:singleLine="true"/>
+ <TextView android:text="@string/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <EditText android:id="@+id/form_comment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:minLines="5"/>
+
</LinearLayout>
</ScrollView>
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/res/values/strings.xml 2014-01-28 18:42:42 UTC (rev 36)
@@ -24,6 +24,7 @@
<string name="one_required_field_error_message">At least one these fields is required</string>
<string name="delete">Delete</string>
<string name="edit">Edit</string>
+ <string name="form_comment">Comment</string>
<!-- BigFin communication service -->
<string name="bigfin_no_ichtyometer_connected_title">No ichtyometer connected</string>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/res/values-fr/strings.xml 2014-01-28 18:42:42 UTC (rev 36)
@@ -24,6 +24,7 @@
<string name="one_required_field_error_message">Au moins un de ces champs doit être saisi</string>
<string name="delete">Supprimer</string>
<string name="edit">Éditer</string>
+ <string name="form_comment">Commentaire</string>
<!-- BigFin communication service -->
<string name="bigfin_no_ichtyometer_connected_title">Aucun ichtyomètre connecté</string>
Modified: trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -126,6 +126,8 @@
}
});
+ initEditText(R.id.form_comment, CommercialSpeciesModel.COLUMN_COMMENT);
+
}
@Override
Modified: trunk/src/fr/ifremer/wlo/ContextFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/ContextFormActivity.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/ContextFormActivity.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -62,6 +62,7 @@
super.onCreate(savedInstanceState);
initEditText(R.id.context_form_name, ContextModel.COLUMN_NAME);
+ initEditText(R.id.form_comment, ContextModel.COLUMN_COMMENT);
}
Modified: trunk/src/fr/ifremer/wlo/LocationFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/LocationFormActivity.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/LocationFormActivity.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -107,6 +107,7 @@
endTimeTextView.setText(getString(R.string.time_format, endDate.getTime()));
}
+ initEditText(R.id.form_comment, LocationModel.COLUMN_COMMENT);
}
public void pickDate(View v) {
Modified: trunk/src/fr/ifremer/wlo/MetierFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/MetierFormActivity.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/MetierFormActivity.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -75,6 +75,7 @@
initEditText(R.id.metier_form_zone, MetierModel.COLUMN_ZONE);
initEditText(R.id.metier_form_sample_row_code, MetierModel.COLUMN_SAMPLE_ROW_CODE);
+ initEditText(R.id.form_comment, MetierModel.COLUMN_COMMENT);
}
}
Modified: trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -86,6 +86,8 @@
model.setTakingActivation(b);
}
});
+
+ initEditText(R.id.form_comment, ScientificSpeciesModel.COLUMN_COMMENT);
}
@Override
Modified: trunk/src/fr/ifremer/wlo/VesselFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/VesselFormActivity.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/VesselFormActivity.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -98,6 +98,8 @@
String dateFormat = UIUtils.getDateFormat(this);
landingDateEditor.setText(String.format(dateFormat, landingDate.getTime()));
}
+
+ initEditText(R.id.form_comment, VesselModel.COLUMN_COMMENT);
}
/* Method called by the view */
Modified: trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -235,13 +235,10 @@
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
Log.e(TAG, "Error on set" + firtsLetterUpperCaseAttribute + " for class " + clazz, e);
}
+ editText.setError(null);
+ editText.setSelection(start + count);
}
- @Override
- public void afterTextChanged(Editable s) {
- editText.setError(null);
- editText.setSelection(s.length());
- }
});
addModelPropertyChangeListener(editText, attribute, true);
@@ -253,7 +250,7 @@
return autoCompleteTextView;
}
- protected <R> void initAutoCompleteTextView(AutoCompleteTextView autoCompleteTextView, final String attribute, Collection<R> data) {
+ protected <R> void initAutoCompleteTextView(final AutoCompleteTextView autoCompleteTextView, final String attribute, Collection<R> data) {
final Class clazz = model.getClass();
final String firtsLetterUpperCaseAttribute =
attribute.substring(0, 1).toUpperCase() + attribute.substring(1);
@@ -265,14 +262,19 @@
autoCompleteTextView.setThreshold(0);
autoCompleteTextView.setTag(attribute);
+ autoCompleteTextView.addTextChangedListener(new BaseTextWatcher() {
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ autoCompleteTextView.setError(null);
+ autoCompleteTextView.setSelection(start + count);
+ }
+ });
try {
R value = (R) clazz.getMethod("get" + firtsLetterUpperCaseAttribute).invoke(model);
if (value != null) {
String text = value.toString();
autoCompleteTextView.setText(text);
- autoCompleteTextView.setSelection(text.length());
- autoCompleteTextView.setError(null);
autoCompleteTextView.dismissDropDown();
}
@@ -305,7 +307,6 @@
Object newValue = event.getNewValue();
String text = newValue != null ? newValue.toString() : getString(fr.ifremer.wlo.R.string.undefined);
editText.setText(text);
- editText.setSelection(text.length());
}
}
});
Modified: trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -182,6 +182,11 @@
sizeText.addTextChangedListener(new BaseTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
+ sizeText.setSelection(start + count);
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
Mensuration.Precision precision = measurements.getPrecision();
int multiplier = precision.getUnitDivider();
try {
@@ -196,11 +201,6 @@
measurement.setSize(null);
}
}
-
- @Override
- public void afterTextChanged(Editable s) {
- sizeText.setSelection(s.length());
- }
});
Spinner genderSpinner = (Spinner) findViewById(R.id.gender_spinner);
Modified: trunk/src/fr/ifremer/wlo/models/CommercialSpeciesModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/CommercialSpeciesModel.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/models/CommercialSpeciesModel.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -53,6 +53,7 @@
public static final String COLUMN_SORT_CATEGORY = "sortCategory";
public static final String COLUMN_STATE = "state";
public static final String COLUMN_PRESENTATION = "presentation";
+ public static final String COLUMN_COMMENT = "comment";
public static final String COLUMN_METIER_ID = "metierId";
public static final String[] ALL_COLUMNS = new String[] {
_ID,
@@ -63,6 +64,7 @@
COLUMN_SORT_CATEGORY,
COLUMN_STATE,
COLUMN_PRESENTATION,
+ COLUMN_COMMENT,
COLUMN_METIER_ID
};
@@ -73,6 +75,7 @@
protected String sortCategory;
protected State state;
protected Presentation presentation;
+ protected String comment;
public CommercialSpeciesModel() {
}
@@ -92,6 +95,7 @@
state = DataCache.getStateById(context, stateId);
String presentationId = cursor.getString(7);
presentation = DataCache.getPresentationById(context, presentationId);
+ comment = cursor.getString(8);
}
public CommercialSpecies getFaoCode() {
@@ -165,6 +169,16 @@
firePropertyChange(_ID, oldValue, id);
}
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ Object oldValue = this.comment;
+ this.comment = comment;
+ firePropertyChange(COLUMN_COMMENT, oldValue, comment);
+ }
+
@Override
public String getTableName() {
return TABLE_NAME;
@@ -185,6 +199,7 @@
putValue(value, COLUMN_SORT_CATEGORY, sortCategory);
putValue(value, COLUMN_STATE, state != null ? state.getId() : null);
putValue(value, COLUMN_PRESENTATION, presentation != null ? presentation.getId() : null);
+ putValue(value, COLUMN_COMMENT, comment);
putValue(value, COLUMN_METIER_ID, getParentId());
return value;
}
Modified: trunk/src/fr/ifremer/wlo/models/ContextModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/ContextModel.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/models/ContextModel.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -41,12 +41,15 @@
public static final String TABLE_NAME = "contexts";
public static final String COLUMN_NAME = "name";
+ public static final String COLUMN_COMMENT = "comment";
public static final String[] ALL_COLUMNS = new String[] {
_ID,
- COLUMN_NAME
+ COLUMN_NAME,
+ COLUMN_COMMENT
};
protected String name;
+ protected String comment;
public ContextModel() {
}
@@ -54,6 +57,7 @@
public ContextModel(Cursor cursor) {
super(cursor);
name = cursor.getString(1);
+ comment = cursor.getString(2);
}
public String getName() {
@@ -66,6 +70,16 @@
firePropertyChange(COLUMN_NAME, oldValue, name);
}
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ Object oldValue = this.comment;
+ this.comment = comment;
+ firePropertyChange(COLUMN_COMMENT, oldValue, comment);
+ }
+
@Override
public String getTableName() {
return TABLE_NAME;
@@ -80,6 +94,7 @@
public ContentValues convertIntoContentValues() {
ContentValues value = super.convertIntoContentValues();
putValue(value, COLUMN_NAME, name);
+ putValue(value, COLUMN_COMMENT, comment);
return value;
}
Modified: trunk/src/fr/ifremer/wlo/models/LocationModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/LocationModel.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/models/LocationModel.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -47,6 +47,7 @@
public static final String COLUMN_START_DATE = "startDate";
public static final String COLUMN_END_DATE = "endDate";
public static final String COLUMN_LOCATION = "location";
+ public static final String COLUMN_COMMENT = "comment";
public static final String COLUMN_CONTEXT_ID = "contextId";
public static final String[] ALL_COLUMNS = new String[] {
_ID,
@@ -54,6 +55,7 @@
COLUMN_START_DATE,
COLUMN_END_DATE,
COLUMN_LOCATION,
+ COLUMN_COMMENT,
COLUMN_CONTEXT_ID
};
@@ -61,6 +63,7 @@
protected Calendar startDate;
protected Calendar endDate;
protected Location location;
+ protected String comment;
public LocationModel() {
}
@@ -72,6 +75,7 @@
endDate = UIUtils.getCalendarFromCursor(cursor, 3);
String locationId = cursor.getString(4);
location = DataCache.getLocationById(context, locationId);
+ comment = cursor.getString(5);
}
public String getOperator() {
@@ -114,6 +118,16 @@
firePropertyChange(COLUMN_LOCATION, oldValue, location);
}
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ Object oldValue = this.comment;
+ this.comment = comment;
+ firePropertyChange(COLUMN_COMMENT, oldValue, comment);
+ }
+
@Override
public String getTableName() {
return TABLE_NAME;
@@ -131,6 +145,7 @@
putValue(value, COLUMN_START_DATE, startDate != null ? startDate.getTimeInMillis() : null);
putValue(value, COLUMN_END_DATE, endDate != null ? endDate.getTimeInMillis() : null);
putValue(value, COLUMN_LOCATION, location != null ? location.getId() : null);
+ putValue(value, COLUMN_COMMENT, comment);
putValue(value, COLUMN_CONTEXT_ID, getParentId());
return value;
}
Modified: trunk/src/fr/ifremer/wlo/models/MetierModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/MetierModel.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/models/MetierModel.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -43,18 +43,21 @@
public static final String COLUMN_GEAR_SPECIES = "gearSpecies";
public static final String COLUMN_ZONE = "zone";
public static final String COLUMN_SAMPLE_ROW_CODE = "sampleRowCode";
+ public static final String COLUMN_COMMENT = "comment";
public static final String COLUMN_VESSEL_ID = "vesselId";
public static final String[] ALL_COLUMNS = new String[] {
_ID,
COLUMN_GEAR_SPECIES,
COLUMN_ZONE,
COLUMN_SAMPLE_ROW_CODE,
+ COLUMN_COMMENT,
COLUMN_VESSEL_ID
};
protected Metier gearSpecies;
protected String zone;
protected String sampleRowCode;
+ protected String comment;
public MetierModel() {
}
@@ -65,6 +68,7 @@
gearSpecies = DataCache.getMetierById(context, gearSpeciesId);
zone = cursor.getString(2);
sampleRowCode = cursor.getString(3);
+ comment = cursor.getString(4);
}
public Metier getGearSpecies() {
@@ -97,6 +101,16 @@
firePropertyChange(COLUMN_SAMPLE_ROW_CODE, oldValue, sampleRowCode);
}
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ Object oldValue = this.comment;
+ this.comment = comment;
+ firePropertyChange(COLUMN_COMMENT, oldValue, comment);
+ }
+
@Override
public String getTableName() {
return TABLE_NAME;
@@ -113,6 +127,7 @@
putValue(value, COLUMN_GEAR_SPECIES, gearSpecies != null ? gearSpecies.getId() : null);
putValue(value, COLUMN_ZONE, zone);
putValue(value, COLUMN_SAMPLE_ROW_CODE, sampleRowCode);
+ putValue(value, COLUMN_COMMENT, comment);
putValue(value, COLUMN_VESSEL_ID, getParentId());
return value;
}
Modified: trunk/src/fr/ifremer/wlo/models/ScientificSpeciesModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/ScientificSpeciesModel.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/models/ScientificSpeciesModel.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -43,16 +43,19 @@
public static final String TABLE_NAME = "scientific_species";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_TAKING_ACTIVATION = "takingActivation";
+ public static final String COLUMN_COMMENT = "comment";
public static final String COLUMN_COMMERCIAL_SPECIES_ID = "commercialSpeciesId";
public static final String[] ALL_COLUMNS = new String[] {
_ID,
COLUMN_NAME,
COLUMN_TAKING_ACTIVATION,
+ COLUMN_COMMENT,
COLUMN_COMMERCIAL_SPECIES_ID
};
protected ScientificSpecies name;
protected boolean takingActivation;
+ protected String comment;
public ScientificSpeciesModel() {
}
@@ -62,6 +65,7 @@
String nameId = cursor.getString(1);
name = DataCache.getScientificSpeciesById(context, nameId);
takingActivation = cursor.getShort(2) > 0;
+ comment = cursor.getString(3);
}
public ScientificSpecies getName() {
@@ -84,6 +88,16 @@
firePropertyChange(COLUMN_TAKING_ACTIVATION, oldValue, takingActivation);
}
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ Object oldValue = this.comment;
+ this.comment = comment;
+ firePropertyChange(COLUMN_COMMENT, oldValue, comment);
+ }
+
@Override
public String getTableName() {
return TABLE_NAME;
@@ -99,6 +113,7 @@
ContentValues value = super.convertIntoContentValues();
putValue(value, COLUMN_NAME, name != null ? name.getId() : null);
putValue(value, COLUMN_TAKING_ACTIVATION, takingActivation ? 1 : 0);
+ putValue(value, COLUMN_COMMENT, comment);
putValue(value, COLUMN_COMMERCIAL_SPECIES_ID, getParentId());
return value;
}
Modified: trunk/src/fr/ifremer/wlo/models/VesselModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/VesselModel.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/models/VesselModel.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -51,6 +51,7 @@
public static final String COLUMN_NAME = "name";
public static final String COLUMN_LANDING_DATE = "landingDate";
public static final String COLUMN_LANDING_LOCATION = "landingLocation";
+ public static final String COLUMN_COMMENT = "comment";
public static final String COLUMN_LOCATION_ID = "location_id";
public static final String[] ALL_COLUMNS = new String[] {
_ID,
@@ -58,6 +59,7 @@
COLUMN_NAME,
COLUMN_LANDING_DATE,
COLUMN_LANDING_LOCATION,
+ COLUMN_COMMENT,
COLUMN_LOCATION_ID
};
@@ -65,6 +67,7 @@
protected String name;
protected Calendar landingDate;
protected Location landingLocation;
+ protected String comment;
public VesselModel() {
}
@@ -76,6 +79,7 @@
landingDate = UIUtils.getCalendarFromCursor(cursor, 3);
String landingLocationId = cursor.getString(4);
landingLocation = DataCache.getLocationById(context, landingLocationId);
+ comment = cursor.getString(5);
}
public String getRegistrationNumber() {
@@ -130,6 +134,16 @@
firePropertyChange(COLUMN_LANDING_LOCATION, oldValue, landingLocation);
}
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ Object oldValue = this.comment;
+ this.comment = comment;
+ firePropertyChange(COLUMN_COMMENT, oldValue, comment);
+ }
+
@Override
public String getTableName() {
return TABLE_NAME;
@@ -148,6 +162,7 @@
putValue(value, COLUMN_NAME, name);
putValue(value, COLUMN_LANDING_DATE, landingDate != null ? landingDate.getTimeInMillis() : null);
putValue(value, COLUMN_LANDING_LOCATION, landingLocation != null ? landingLocation.getId() : null);
+ putValue(value, COLUMN_COMMENT, comment);
putValue(value, COLUMN_LOCATION_ID, getParentId());
return value;
}
Modified: trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java
===================================================================
--- trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java 2014-01-28 17:58:49 UTC (rev 35)
+++ trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java 2014-01-28 18:42:42 UTC (rev 36)
@@ -66,7 +66,7 @@
private static final String TAG = "WloOpenHelper";
public static final String DATABASE_NAME = "wlo.db";
- public static final int DATABASE_VERSION = 13;
+ public static final int DATABASE_VERSION = 14;
public static final String TEXT_TYPE = " TEXT";
public static final String BIGINT_TYPE = " BIGINT";
@@ -78,7 +78,8 @@
protected static final String SQL_CREATE_CONTEXTS =
"CREATE TABLE " + ContextModel.TABLE_NAME + " (" +
ContextModel._ID + TEXT_TYPE + " PRIMARY KEY" + COMMA_SEP +
- ContextModel.COLUMN_NAME + TEXT_TYPE + NOT_NULL +
+ ContextModel.COLUMN_NAME + TEXT_TYPE + NOT_NULL + COMMA_SEP +
+ ContextModel.COLUMN_COMMENT + TEXT_TYPE +
" )";
protected static final String SQL_DELETE_CONTEXTS =
@@ -93,6 +94,7 @@
LocationModel.COLUMN_START_DATE + BIGINT_TYPE + COMMA_SEP +
LocationModel.COLUMN_END_DATE + BIGINT_TYPE + COMMA_SEP +
LocationModel.COLUMN_LOCATION + TEXT_TYPE + NOT_NULL + COMMA_SEP +
+ LocationModel.COLUMN_COMMENT + TEXT_TYPE + COMMA_SEP +
LocationModel.COLUMN_CONTEXT_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + LocationModel.COLUMN_CONTEXT_ID + ") REFERENCES " +
ContextModel.TABLE_NAME + "(" + ContextModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
@@ -111,6 +113,7 @@
VesselModel.COLUMN_NAME + TEXT_TYPE + COMMA_SEP +
VesselModel.COLUMN_LANDING_DATE + BIGINT_TYPE + COMMA_SEP +
VesselModel.COLUMN_LANDING_LOCATION + TEXT_TYPE + COMMA_SEP +
+ VesselModel.COLUMN_COMMENT + TEXT_TYPE + COMMA_SEP +
VesselModel.COLUMN_LOCATION_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + VesselModel.COLUMN_LOCATION_ID + ") REFERENCES " +
LocationModel.TABLE_NAME + "(" + LocationModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
@@ -128,6 +131,7 @@
MetierModel.COLUMN_GEAR_SPECIES + TEXT_TYPE + COMMA_SEP +
MetierModel.COLUMN_ZONE + TEXT_TYPE + COMMA_SEP +
MetierModel.COLUMN_SAMPLE_ROW_CODE + TEXT_TYPE + COMMA_SEP +
+ MetierModel.COLUMN_COMMENT + TEXT_TYPE + COMMA_SEP +
MetierModel.COLUMN_VESSEL_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + MetierModel.COLUMN_VESSEL_ID + ") REFERENCES " +
VesselModel.TABLE_NAME + "(" + VesselModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
@@ -149,6 +153,7 @@
CommercialSpeciesModel.COLUMN_SORT_CATEGORY + TEXT_TYPE + COMMA_SEP +
CommercialSpeciesModel.COLUMN_STATE + TEXT_TYPE + COMMA_SEP +
CommercialSpeciesModel.COLUMN_PRESENTATION + TEXT_TYPE + COMMA_SEP +
+ CommercialSpeciesModel.COLUMN_COMMENT + TEXT_TYPE + COMMA_SEP +
CommercialSpeciesModel.COLUMN_METIER_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_METIER_ID + ") REFERENCES " +
MetierModel.TABLE_NAME + "(" + MetierModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
@@ -171,6 +176,7 @@
ScientificSpeciesModel._ID + TEXT_TYPE + " PRIMARY KEY" + COMMA_SEP +
ScientificSpeciesModel.COLUMN_NAME + TEXT_TYPE + COMMA_SEP +
ScientificSpeciesModel.COLUMN_TAKING_ACTIVATION + BYTE_TYPE + COMMA_SEP +
+ ScientificSpeciesModel.COLUMN_COMMENT + TEXT_TYPE + COMMA_SEP +
ScientificSpeciesModel.COLUMN_COMMERCIAL_SPECIES_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + ScientificSpeciesModel.COLUMN_COMMERCIAL_SPECIES_ID + ") REFERENCES " +
CommercialSpeciesModel.TABLE_NAME + "(" + CommercialSpeciesModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
1
0
r35 - in trunk/src/fr/ifremer/wlo: . measurement models models/referentials utils
by kmorin@users.forge.codelutin.com 28 Jan '14
by kmorin@users.forge.codelutin.com 28 Jan '14
28 Jan '14
Author: kmorin
Date: 2014-01-28 18:58:49 +0100 (Tue, 28 Jan 2014)
New Revision: 35
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/35
Log:
fixes #4238 NAVIRE : proposer la recherche par l'immatriculation ou nom bref combiner les deux champs
Modified:
trunk/src/fr/ifremer/wlo/VesselFormActivity.java
trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
trunk/src/fr/ifremer/wlo/models/VesselModel.java
trunk/src/fr/ifremer/wlo/models/referentials/Vessel.java
trunk/src/fr/ifremer/wlo/utils/BaseTextWatcher.java
Modified: trunk/src/fr/ifremer/wlo/VesselFormActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/VesselFormActivity.java 2014-01-28 16:18:29 UTC (rev 34)
+++ trunk/src/fr/ifremer/wlo/VesselFormActivity.java 2014-01-28 17:58:49 UTC (rev 35)
@@ -84,9 +84,7 @@
// init editors
Collection<Vessel> vessels = DataCache.getAllVessels(this);
- List<String> vesselCodes = Lists.newArrayList(Collections2.transform(vessels, HasCode.GET_CODE_FUNCTION));
- final Map<String, Vessel> vesselsByCode = Maps.uniqueIndex(vessels, HasCode.GET_CODE_FUNCTION);
- initAutoCompleteTextView(R.id.vessel_form_registration_number, VesselModel.COLUMN_REGISTRATION_NUMBER, vesselCodes);
+ initAutoCompleteTextView(R.id.vessel_form_registration_number, VesselModel.COLUMN_REGISTRATION_NUMBER, vessels);
initEditText(R.id.vessel_form_name, VesselModel.COLUMN_NAME);
@@ -100,21 +98,6 @@
String dateFormat = UIUtils.getDateFormat(this);
landingDateEditor.setText(String.format(dateFormat, landingDate.getTime()));
}
-
- model.addPropertyChangeListener(VesselModel.COLUMN_REGISTRATION_NUMBER, new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent event) {
- Log.d(TAG, "registration number changed ! " + event.getNewValue());
- VesselModel vesselModel = (VesselModel) event.getSource();
- Log.d(TAG, "name " + vesselModel.getName());
- if (StringUtils.isEmpty(vesselModel.getName())) {
- String newCode = (String) event.getNewValue();
- Vessel vessel = vesselsByCode.get(newCode);
- vesselModel.setName(vessel != null ? vessel.getName() : getString(R.string.undefined));
- }
- }
- });
-
}
/* Method called by the view */
Modified: trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-28 16:18:29 UTC (rev 34)
+++ trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-28 17:58:49 UTC (rev 35)
@@ -28,6 +28,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
+import android.text.Editable;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -234,20 +235,16 @@
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
Log.e(TAG, "Error on set" + firtsLetterUpperCaseAttribute + " for class " + clazz, e);
}
- editText.setError(null);
}
- });
- model.addPropertyChangeListener(attribute, new PropertyChangeListener() {
@Override
- public void propertyChange(PropertyChangeEvent event) {
- Object newValue = event.getNewValue();
- if (!editText.isFocused()) {
- editText.setText(newValue != null ? newValue.toString() : getString(R.string.undefined));
- editText.setError(null);
- }
+ public void afterTextChanged(Editable s) {
+ editText.setError(null);
+ editText.setSelection(s.length());
}
});
+
+ addModelPropertyChangeListener(editText, attribute, true);
}
protected <R> AutoCompleteTextView initAutoCompleteTextView(int autoCompleteTextViewId, final String attribute, Collection<R> data) {
@@ -272,8 +269,11 @@
try {
R value = (R) clazz.getMethod("get" + firtsLetterUpperCaseAttribute).invoke(model);
if (value != null) {
- autoCompleteTextView.setText(value.toString());
+ String text = value.toString();
+ autoCompleteTextView.setText(text);
+ autoCompleteTextView.setSelection(text.length());
autoCompleteTextView.setError(null);
+ autoCompleteTextView.dismissDropDown();
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
@@ -284,6 +284,7 @@
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
R selectedData = (R) parent.getItemAtPosition(position);
+ Log.d(TAG, "selectedData.getClass() " + selectedData.getClass());
try {
clazz.getMethod("set" + firtsLetterUpperCaseAttribute, selectedData.getClass()).invoke(model, selectedData);
@@ -293,8 +294,23 @@
}
});
+ addModelPropertyChangeListener(autoCompleteTextView, attribute, false);
}
+ protected void addModelPropertyChangeListener(final EditText editText, String property, final boolean checkFocus) {
+ model.addPropertyChangeListener(property, new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (!checkFocus || !editText.isFocused()) {
+ Object newValue = event.getNewValue();
+ String text = newValue != null ? newValue.toString() : getString(fr.ifremer.wlo.R.string.undefined);
+ editText.setText(text);
+ editText.setSelection(text.length());
+ }
+ }
+ });
+ }
+
protected void openNewModelEdition() {
Intent intent = new Intent(WloModelEditionActivity.this, WloModelEditionActivity.this.getClass());
if (HierarchicalModel.class.isAssignableFrom(model.getClass())) {
Modified: trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-01-28 16:18:29 UTC (rev 34)
+++ trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-01-28 17:58:49 UTC (rev 35)
@@ -3,8 +3,8 @@
/*
* #%L
* WLO
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2013 - 2014 Ifremer
* %%
@@ -31,6 +31,7 @@
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
+import android.text.Editable;
import android.text.InputType;
import android.util.Log;
import android.view.LayoutInflater;
@@ -180,11 +181,6 @@
sizeText.setRawInputType(inputType);
sizeText.addTextChangedListener(new BaseTextWatcher() {
@Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- Log.d(TAG, "beforetextchnage " + s);
- }
-
- @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Mensuration.Precision precision = measurements.getPrecision();
int multiplier = precision.getUnitDivider();
@@ -200,6 +196,11 @@
measurement.setSize(null);
}
}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ sizeText.setSelection(s.length());
+ }
});
Spinner genderSpinner = (Spinner) findViewById(R.id.gender_spinner);
Modified: trunk/src/fr/ifremer/wlo/models/VesselModel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/VesselModel.java 2014-01-28 16:18:29 UTC (rev 34)
+++ trunk/src/fr/ifremer/wlo/models/VesselModel.java 2014-01-28 17:58:49 UTC (rev 35)
@@ -30,8 +30,10 @@
import android.util.Log;
import com.google.common.collect.Sets;
import fr.ifremer.wlo.models.referentials.Location;
+import fr.ifremer.wlo.models.referentials.Vessel;
import fr.ifremer.wlo.storage.DataCache;
import fr.ifremer.wlo.utils.UIUtils;
+import org.apache.commons.lang3.StringUtils;
import java.util.Calendar;
import java.util.Set;
@@ -81,16 +83,28 @@
}
public void setRegistrationNumber(String registrationNumber) {
+ Log.d(TAG, "setRegistrationNumber string " + registrationNumber);
Object oldValue = this.registrationNumber;
this.registrationNumber = registrationNumber;
firePropertyChange(COLUMN_REGISTRATION_NUMBER, oldValue, registrationNumber);
}
+ public void setRegistrationNumber(Vessel vessel) {
+ Log.d(TAG, "setRegistrationNumber vessel " + vessel.getCode());
+ if (vessel != null) {
+ setRegistrationNumber(vessel.getCode());
+ if (StringUtils.isEmpty(name)) {
+ setName(vessel.getName());
+ }
+ }
+ }
+
public String getName() {
return name;
}
public void setName(String name) {
+ Log.d(TAG, "setName " + name);
Object oldValue = this.name;
this.name = name;
firePropertyChange(COLUMN_NAME, oldValue, name);
Modified: trunk/src/fr/ifremer/wlo/models/referentials/Vessel.java
===================================================================
--- trunk/src/fr/ifremer/wlo/models/referentials/Vessel.java 2014-01-28 16:18:29 UTC (rev 34)
+++ trunk/src/fr/ifremer/wlo/models/referentials/Vessel.java 2014-01-28 17:58:49 UTC (rev 35)
@@ -25,6 +25,7 @@
*/
import android.content.ContentValues;
+import android.content.Context;
import android.database.Cursor;
import fr.ifremer.wlo.models.BaseModel;
import fr.ifremer.wlo.utils.UIUtils;
@@ -92,7 +93,12 @@
}
@Override
- public String toString(android.content.Context context) {
+ public String toString() {
+ return code + " - " + name;
+ }
+
+ @Override
+ public String toString(Context context) {
return UIUtils.getStringOrUndefined(code, context) + " - " +
UIUtils.getStringOrUndefined(name, context);
}
Modified: trunk/src/fr/ifremer/wlo/utils/BaseTextWatcher.java
===================================================================
--- trunk/src/fr/ifremer/wlo/utils/BaseTextWatcher.java 2014-01-28 16:18:29 UTC (rev 34)
+++ trunk/src/fr/ifremer/wlo/utils/BaseTextWatcher.java 2014-01-28 17:58:49 UTC (rev 35)
@@ -43,5 +43,6 @@
@Override
public void afterTextChanged(Editable s) {
+
}
}
1
0
r34 - in trunk: res/values res/values-fr src/fr/ifremer/wlo src/fr/ifremer/wlo/measurement src/fr/ifremer/wlo/storage
by kmorin@users.forge.codelutin.com 28 Jan '14
by kmorin@users.forge.codelutin.com 28 Jan '14
28 Jan '14
Author: kmorin
Date: 2014-01-28 17:18:29 +0100 (Tue, 28 Jan 2014)
New Revision: 34
Url: http://forge.codelutin.com/projects/wlo/repository/revisions/34
Log:
fixes #4251 Pouvoir supprimer une ?\195?\169tape et ses fils de fait
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/fr/ifremer/wlo/WloBaseListActivity.java
trunk/src/fr/ifremer/wlo/measurement/LogsFragment.java
trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-01-28 15:00:21 UTC (rev 33)
+++ trunk/res/values/strings.xml 2014-01-28 16:18:29 UTC (rev 34)
@@ -22,6 +22,8 @@
<string name="no">No</string>
<string name="required_field_error_message">Required field</string>
<string name="one_required_field_error_message">At least one these fields is required</string>
+ <string name="delete">Delete</string>
+ <string name="edit">Edit</string>
<!-- BigFin communication service -->
<string name="bigfin_no_ichtyometer_connected_title">No ichtyometer connected</string>
@@ -52,9 +54,10 @@
<string name="measurement_graph_title">Observations</string>
- <string name="delete">Delete</string>
- <string name="deletion_confirmation_title">Delete an input</string>
- <string name="deletion_confirmation_message">Êtes vous sûr de vouloir\nsupprimer la saisie\n%s ?</string>
+ <string name="deletion">Delete</string>
+ <string name="input_deletion_confirmation_title">Delete an input</string>
+ <string name="input_deletion_confirmation_message">Are you sure you want\nto delete the input\n%s ?</string>
+ <string name="item_deletion_confirmation_message">Are you sure you want\nto delete the item\n%s ?</string>
<string name="fulltime_format">%1$tH:%1$tM:%1$tS</string>
<string name="time_format">%1$tH:%1$tM</string>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-01-28 15:00:21 UTC (rev 33)
+++ trunk/res/values-fr/strings.xml 2014-01-28 16:18:29 UTC (rev 34)
@@ -22,6 +22,8 @@
<string name="no">Non</string>
<string name="required_field_error_message">Champs obligatoire</string>
<string name="one_required_field_error_message">Au moins un de ces champs doit être saisi</string>
+ <string name="delete">Supprimer</string>
+ <string name="edit">Éditer</string>
<!-- BigFin communication service -->
<string name="bigfin_no_ichtyometer_connected_title">Aucun ichtyomètre connecté</string>
@@ -51,9 +53,10 @@
<string name="measurement_graph_title">Observations</string>
- <string name="delete">Suppression</string>
- <string name="deletion_confirmation_title">Supprimer une mesure</string>
- <string name="deletion_confirmation_message">Êtes vous sûr de vouloir\nsupprimer la saisie\n%s ?</string>
+ <string name="deletion">Suppression</string>
+ <string name="input_deletion_confirmation_title">Supprimer une mesure</string>
+ <string name="input_deletion_confirmation_message">Êtes vous sûr de vouloir\nsupprimer la saisie\n%s ?</string>
+ <string name="item_deletion_confirmation_message">Êtes vous sûr de vouloir\nsupprimer l\'élément\n%s ?</string>
<string name="undefined">Non défini</string>
Modified: trunk/src/fr/ifremer/wlo/WloBaseListActivity.java
===================================================================
--- trunk/src/fr/ifremer/wlo/WloBaseListActivity.java 2014-01-28 15:00:21 UTC (rev 33)
+++ trunk/src/fr/ifremer/wlo/WloBaseListActivity.java 2014-01-28 16:18:29 UTC (rev 34)
@@ -39,12 +39,15 @@
* #L%
*/
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
+import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -55,6 +58,7 @@
import fr.ifremer.wlo.models.BaseModel;
import fr.ifremer.wlo.models.HierarchicalModel;
import fr.ifremer.wlo.storage.WloSqlOpenHelper;
+import fr.ifremer.wlo.utils.UIUtils;
import fr.ifremer.wlo.utils.WloItemListViewBinder;
/**
@@ -209,7 +213,7 @@
* @author kmorin <kmorin(a)codelutin.com>
* @since 0.1
*/
-public abstract class WloBaseListActivity<M extends BaseModel> extends WloBaseActivity implements AdapterView.OnItemLongClickListener {
+public abstract class WloBaseListActivity<M extends BaseModel> extends WloBaseActivity {
private static final String TAG = "WloBaseListActivity";
@@ -276,7 +280,7 @@
adapter.setViewBinder(getAdapterBinder());
setListAdapter(adapter);
- getListView().setOnItemLongClickListener(this);
+ registerForContextMenu(mList);
}
@Override
@@ -354,13 +358,49 @@
}
@Override
- public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
- M model = createNewModel(parent, position);
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenu.ContextMenuInfo menuInfo) {
+ if (mList.equals(v)) {
+ int[] menuItems = new int[]{R.string.edit, R.string.delete};
+ for (int i = 0; i<menuItems.length; i++) {
+ menu.add(Menu.NONE, i, i, menuItems[i]);
+ }
+ }
+ }
- Log.d(TAG, model.toString(this) + " long clicked");
- Intent intent = new Intent(this, getEditionActivity());
- intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL, model);
- startActivity(intent);
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ AdapterView.AdapterContextMenuInfo info =
+ (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
+
+ AdapterView<?> parent = (AdapterView<?>) info.targetView.getParent();
+ final M model = createNewModel(parent, info.position);
+
+ switch (item.getItemId()) {
+ case 0:
+ Intent intent = new Intent(this, getEditionActivity());
+ intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL, model);
+ startActivity(intent);
+ break;
+
+ case 1:
+ new AlertDialog.Builder(this).setTitle(R.string.deletion)
+ .setMessage(getString(R.string.item_deletion_confirmation_message, model.toString(this)))
+ .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ WloSqlOpenHelper soh = new WloSqlOpenHelper(WloBaseListActivity.this);
+ soh.deleteData(model);
+ soh.close();
+ Cursor cursor = getAllData();
+ adapter.swapCursor(cursor);
+ }
+ })
+ .setNegativeButton(android.R.string.cancel, UIUtils.getCancelClickListener())
+ .create()
+ .show();
+
+ break;
+ }
return true;
}
Modified: trunk/src/fr/ifremer/wlo/measurement/LogsFragment.java
===================================================================
--- trunk/src/fr/ifremer/wlo/measurement/LogsFragment.java 2014-01-28 15:00:21 UTC (rev 33)
+++ trunk/src/fr/ifremer/wlo/measurement/LogsFragment.java 2014-01-28 16:18:29 UTC (rev 34)
@@ -3,8 +3,8 @@
/*
* #%L
* WLO
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2013 - 2014 Ifremer
* %%
@@ -36,7 +36,6 @@
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import fr.ifremer.wlo.R;
import fr.ifremer.wlo.models.MeasurementModel;
@@ -48,7 +47,6 @@
import org.apache.commons.lang3.StringUtils;
import java.util.Comparator;
-import java.util.Date;
import java.util.List;
/**
@@ -102,7 +100,7 @@
});
dialogBuilder = new AlertDialog.Builder(activity)
- .setTitle(R.string.deletion_confirmation_title)
+ .setTitle(R.string.input_deletion_confirmation_title)
.setNegativeButton(android.R.string.cancel, UIUtils.getCancelClickListener());
// Find and set up the ListView for paired devices
@@ -113,7 +111,7 @@
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final MeasurementModel measurement = (MeasurementModel) parent.getItemAtPosition(position);
- dialogBuilder.setMessage(getString(R.string.deletion_confirmation_message,
+ dialogBuilder.setMessage(getString(R.string.input_deletion_confirmation_message,
measurement.toString(getActivity(), measurements.getPrecision())))
.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Modified: trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java
===================================================================
--- trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java 2014-01-28 15:00:21 UTC (rev 33)
+++ trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java 2014-01-28 16:18:29 UTC (rev 34)
@@ -66,7 +66,7 @@
private static final String TAG = "WloOpenHelper";
public static final String DATABASE_NAME = "wlo.db";
- public static final int DATABASE_VERSION = 10;
+ public static final int DATABASE_VERSION = 13;
public static final String TEXT_TYPE = " TEXT";
public static final String BIGINT_TYPE = " BIGINT";
@@ -95,7 +95,7 @@
LocationModel.COLUMN_LOCATION + TEXT_TYPE + NOT_NULL + COMMA_SEP +
LocationModel.COLUMN_CONTEXT_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + LocationModel.COLUMN_CONTEXT_ID + ") REFERENCES " +
- ContextModel.TABLE_NAME + "(" + ContextModel._ID + ")" + COMMA_SEP +
+ ContextModel.TABLE_NAME + "(" + ContextModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
"FOREIGN KEY(" + LocationModel.COLUMN_LOCATION + ") REFERENCES " +
Location.TABLE_NAME + "(" + Location._ID + ")" +
" )";
@@ -113,7 +113,7 @@
VesselModel.COLUMN_LANDING_LOCATION + TEXT_TYPE + COMMA_SEP +
VesselModel.COLUMN_LOCATION_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + VesselModel.COLUMN_LOCATION_ID + ") REFERENCES " +
- LocationModel.TABLE_NAME + "(" + LocationModel._ID + ")" + COMMA_SEP +
+ LocationModel.TABLE_NAME + "(" + LocationModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
"FOREIGN KEY(" + VesselModel.COLUMN_LANDING_LOCATION + ") REFERENCES " +
Location.TABLE_NAME + "(" + Location._ID + ")" +
" )";
@@ -130,7 +130,7 @@
MetierModel.COLUMN_SAMPLE_ROW_CODE + TEXT_TYPE + COMMA_SEP +
MetierModel.COLUMN_VESSEL_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + MetierModel.COLUMN_VESSEL_ID + ") REFERENCES " +
- VesselModel.TABLE_NAME + "(" + VesselModel._ID + ")" + COMMA_SEP +
+ VesselModel.TABLE_NAME + "(" + VesselModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
"FOREIGN KEY(" + MetierModel.COLUMN_GEAR_SPECIES + ") REFERENCES " +
Metier.TABLE_NAME + "(" + Metier._ID + ")" +
" )";
@@ -151,7 +151,7 @@
CommercialSpeciesModel.COLUMN_PRESENTATION + TEXT_TYPE + COMMA_SEP +
CommercialSpeciesModel.COLUMN_METIER_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_METIER_ID + ") REFERENCES " +
- MetierModel.TABLE_NAME + "(" + MetierModel._ID + ")" + COMMA_SEP +
+ MetierModel.TABLE_NAME + "(" + MetierModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
"FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_FAO_CODE + ") REFERENCES " +
CommercialSpecies.TABLE_NAME + "(" + CommercialSpecies._ID + ")" + COMMA_SEP +
"FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_MEASUREMENT_METHOD + ") REFERENCES " +
@@ -173,7 +173,7 @@
ScientificSpeciesModel.COLUMN_TAKING_ACTIVATION + BYTE_TYPE + COMMA_SEP +
ScientificSpeciesModel.COLUMN_COMMERCIAL_SPECIES_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + ScientificSpeciesModel.COLUMN_COMMERCIAL_SPECIES_ID + ") REFERENCES " +
- CommercialSpeciesModel.TABLE_NAME + "(" + CommercialSpeciesModel._ID + ")" + COMMA_SEP +
+ CommercialSpeciesModel.TABLE_NAME + "(" + CommercialSpeciesModel._ID + ") ON DELETE CASCADE" + COMMA_SEP +
"FOREIGN KEY(" + ScientificSpeciesModel.COLUMN_NAME + ") REFERENCES " +
ScientificSpecies.TABLE_NAME + "(" + ScientificSpecies._ID + ")" +
" )";
@@ -192,7 +192,7 @@
MeasurementModel.COLUMN_CATEGORY_3 + TEXT_TYPE + COMMA_SEP +
MeasurementModel.COLUMN_SCIENTIFIC_SPECIES_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP +
"FOREIGN KEY(" + MeasurementModel.COLUMN_SCIENTIFIC_SPECIES_ID + ") REFERENCES " +
- ScientificSpeciesModel.TABLE_NAME + "(" + ScientificSpeciesModel._ID + ")" +
+ ScientificSpeciesModel.TABLE_NAME + "(" + ScientificSpeciesModel._ID + ") ON DELETE CASCADE" +
" )";
protected static final String SQL_DELETE_MEASUREMENTS =
@@ -399,6 +399,15 @@
}
@Override
+ public void onOpen(SQLiteDatabase db) {
+ super.onOpen(db);
+ if (!db.isReadOnly()) {
+ // Enable foreign key constraints
+ db.execSQL("PRAGMA foreign_keys=ON;");
+ }
+ }
+
+ @Override
public synchronized void close() {
super.close();
getReadableDatabase().close();
@@ -619,6 +628,15 @@
db.endTransaction();
}
+ public <M extends BaseModel> void deleteData(M model) {
+ Preconditions.checkNotNull(model);
+ if (model.isNew()) {
+ return;
+ }
+ SQLiteDatabase db = getWritableDatabase();
+ db.delete(model.getTableName(), BaseModel._ID + " = ?", new String[]{ model.getId() });
+ }
+
public static <E> List<E> transformCursorIntoCollection(Cursor cursor,
Function<Cursor, E> function) {
1
0