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);