Author: kmorin Date: 2014-03-11 18:18:53 +0100 (Tue, 11 Mar 2014) New Revision: 74 Url: http://forge.codelutin.com/projects/wlo/repository/revisions/74 Log: fixes #4679 [OBSERVATIONS] Les mesures sont dites autant de fois qu'on est arriv?\195?\169 sur l'?\195?\169cran fixes #4680 [OBSERVATIONS] Quand on change d'esp?\195?\168ce, les mesures ne sont pas mises ?\195?\160 jour fixes #4686 [OBSERVATIONS] Les modifications de l'esp?\195?\168ce ne sont pas prises en compte quand on revient sur l'?\195?\169cran Modified: trunk/res/values-fr/strings.xml trunk/res/values/strings.xml trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java trunk/src/fr/ifremer/wlo/DeviceListActivity.java trunk/src/fr/ifremer/wlo/MainActivity.java trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java trunk/src/fr/ifremer/wlo/WloBaseActivity.java trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java Modified: trunk/res/values/strings.xml =================================================================== --- trunk/res/values/strings.xml 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/res/values/strings.xml 2014-03-11 17:18:53 UTC (rev 74) @@ -38,6 +38,8 @@ <string name="devices_none_paired">No devices have been paired</string> <string name="devices_title_paired_devices">Paired Devices</string> <string name="bt_not_enabled">Bluetooth is off. No ichtyometer can be connected.</string> + <string name="connecting_device">Connecting. Please wait...</string> + <string name="connected_to_device">Connected to %s</string> <!-- Measurement --> <string name="measurement_title">Measurement</string> Modified: trunk/res/values-fr/strings.xml =================================================================== --- trunk/res/values-fr/strings.xml 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/res/values-fr/strings.xml 2014-03-11 17:18:53 UTC (rev 74) @@ -36,6 +36,8 @@ <string name="devices_none_paired">Aucun appareil n\'a été appairé.</string> <string name="devices_title_paired_devices">Appareils appairés</string> <string name="bt_not_enabled">Le bluetooth est désactivé, connexion d\'un ichtyomètre impossible.</string> + <string name="connecting_device">Connexion en cours. Veuillez patienter...</string> + <string name="connected_to_device">Connecté à %s</string> <!-- Measurement --> <string name="measurement_title">Observations</string> Modified: trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java =================================================================== --- trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/src/fr/ifremer/wlo/BigFinCommunicationService.java 2014-03-11 17:18:53 UTC (rev 74) @@ -167,18 +167,10 @@ } else { title = R.string.bigfin_no_ichtyometer_connected_title; text = R.string.bigfin_no_ichtyometer_connected_text; -// stackBuilder.addNextIntent(new Intent(this, MainActivity.class)); } - // Gets a PendingIntent containing the entire back stack -// PendingIntent pendingIntent = -// stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); - -// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); - notificationBuilder.setContentTitle(getText(title)) .setContentText(getText(text)); -// .setContentIntent(pendingIntent); if (connected) { startForeground(NOIFICATION_ID, notificationBuilder.build()); @@ -414,7 +406,7 @@ // successful connection or an exception socket = mmServerSocket.accept(); } catch (IOException e) { - Log.e(TAG, "Socket accept() failed", e); + Log.e(TAG, "Socket accept() failed"); break; } @@ -526,6 +518,7 @@ protected final BluetoothSocket mmSocket; protected final InputStream mmInStream; protected final OutputStream mmOutStream; + protected boolean stop; public ConnectedThread(BluetoothSocket socket) { Log.d(TAG, "create ConnectedThread"); @@ -543,6 +536,8 @@ mmInStream = tmpIn; mmOutStream = tmpOut; + + stop = false; } public void run() { @@ -564,9 +559,9 @@ boolean complete = false; while (!complete) { while (mmInStream.available() > 0) { -// if (stop) { -// break; -// } + if (stop) { + break; + } int c = mmInStream.read(); if (c == '@') { complete = true; @@ -594,7 +589,7 @@ sendMessage(MESSAGE_READ, -1, -1, readerRecord); } catch (IOException e) { - Log.e(TAG, "disconnected", e); + Log.e(TAG, "disconnected"); connectionLost(); } } @@ -622,6 +617,7 @@ } catch (IOException e) { Log.e(TAG, "close() of connect socket failed", e); } + stop = true; } } Modified: trunk/src/fr/ifremer/wlo/DeviceListActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/DeviceListActivity.java 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/src/fr/ifremer/wlo/DeviceListActivity.java 2014-03-11 17:18:53 UTC (rev 74) @@ -77,9 +77,6 @@ // Debugging private static final String TAG = "DeviceListActivity"; - // Return Intent extra - public static final String EXTRA_DEVICE_ADDRESS = "device_address"; - // Member fields protected BluetoothAdapter mBtAdapter; protected ArrayAdapter<String> mPairedDevicesArrayAdapter; @@ -220,13 +217,14 @@ sendDataToDevice("b"); dialog.dismiss(); + setResult(RESULT_OK); finish(); break; case BigFinCommunicationService.STATE_CONNECTING: dialog = ProgressDialog.show(DeviceListActivity.this, "", - "Connecting. Please wait...", true); + getString(R.string.connecting_device), true); break; } @@ -248,8 +246,9 @@ case BigFinCommunicationService.MESSAGE_DEVICE_NAME: // save the connected device's name String mConnectedDeviceName = msg.getData().getString(BigFinCommunicationService.DEVICE_NAME); - Toast.makeText(getApplicationContext(), "Connected to " - + mConnectedDeviceName, Toast.LENGTH_SHORT).show(); + Toast.makeText(getApplicationContext(), + getString(R.string.connected_to_device, mConnectedDeviceName), + Toast.LENGTH_SHORT).show(); break; case BigFinCommunicationService.MESSAGE_CONNECTION_FAILED: Modified: trunk/src/fr/ifremer/wlo/MainActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/MainActivity.java 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/src/fr/ifremer/wlo/MainActivity.java 2014-03-11 17:18:53 UTC (rev 74) @@ -85,6 +85,29 @@ protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "create"); + super.onCreate(savedInstanceState); + + new InitializationTask().execute(); + new UpdateCheckTask(this).execute(); + + mainPanel = (LinearLayout) findViewById(R.id.main_panel); + logoPanel = (LinearLayout) findViewById(R.id.logo_panel); + buttonPanel = (LinearLayout) findViewById(R.id.button_panel); + + // Get local Bluetooth adapter + mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + + // If the adapter is null, then Bluetooth is not supported + if (mBluetoothAdapter == null) { + findViewById(R.id.main_connect_ichtyometer_button).setEnabled(false); + } + + connectButton = (Button) findViewById(R.id.main_connect_ichtyometer_button); + disconnectButton = (Button) findViewById(R.id.main_disconnect_ichtyometer_button); + + Configuration config = getResources().getConfiguration(); + setOrientation(config.orientation); + mMessenger = new Messenger(new Handler() { @Override public void handleMessage(Message msg) { @@ -109,30 +132,7 @@ } } }); - - super.onCreate(savedInstanceState); - - new InitializationTask().execute(); - new UpdateCheckTask(this).execute(); - - mainPanel = (LinearLayout) findViewById(R.id.main_panel); - logoPanel = (LinearLayout) findViewById(R.id.logo_panel); - buttonPanel = (LinearLayout) findViewById(R.id.button_panel); - - // Get local Bluetooth adapter - mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - - // If the adapter is null, then Bluetooth is not supported - if (mBluetoothAdapter == null) { - findViewById(R.id.main_connect_ichtyometer_button).setEnabled(false); - } - - connectButton = (Button) findViewById(R.id.main_connect_ichtyometer_button); - disconnectButton = (Button) findViewById(R.id.main_disconnect_ichtyometer_button); bigfinDisconnected(); - - Configuration config = getResources().getConfiguration(); - setOrientation(config.orientation); } protected void bigfinConnected() { @@ -208,9 +208,11 @@ switch (requestCode) { case REQUEST_CONNECT_ICHTYOMETER: // When DeviceListActivity returns with a device to connect -// if (resultCode == Activity.RESULT_OK) { -// connectDevice(data); -// } + if (resultCode == Activity.RESULT_OK) { + bigfinConnected(); + } else { + bigfinDisconnected(); + } break; case REQUEST_ENABLE_BT: Modified: trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/src/fr/ifremer/wlo/ScientificSpeciesFormActivity.java 2014-03-11 17:18:53 UTC (rev 74) @@ -118,21 +118,10 @@ } @Override - public void validate(View view) { - boolean newModel = model.isNew(); - - WloSqlOpenHelper woh = new WloSqlOpenHelper(this); - woh.saveData(model); - woh.close(); - - if (newModel) { - Intent intent = new Intent(this, MeasurementActivity.class); - intent.putExtra(MeasurementActivity.INTENT_EXTRA_SCIENTIFIC_SPECIES, model); - startActivity(intent); - - } else { - finish(); - } + public void gotoNextActivity() { + Intent intent = new Intent(this, MeasurementActivity.class); + intent.putExtra(MeasurementActivity.INTENT_EXTRA_SCIENTIFIC_SPECIES, model); + startActivity(intent); } } Modified: trunk/src/fr/ifremer/wlo/WloBaseActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/WloBaseActivity.java 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/src/fr/ifremer/wlo/WloBaseActivity.java 2014-03-11 17:18:53 UTC (rev 74) @@ -107,7 +107,11 @@ ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(getUpActivity() != null); + } + @Override + protected void onStart() { + super.onStart(); bindService(new Intent(this, BigFinCommunicationService.class), this, Context.BIND_AUTO_CREATE); } @@ -120,19 +124,20 @@ @Override protected void onPause() { + Log.d(TAG, "pause"); super.onPause(); unregisterReceiver(downloadReceiver); } @Override - protected void onDestroy() { - Log.d(TAG, "destroy"); - super.onDestroy(); + protected void onStop() { + Log.d(TAG, "stop"); + super.onStop(); doUnbindService(); } protected void doUnbindService() { - Log.d(TAG, "doUnbindService"); + Log.d(TAG, "doUnbindService " + this); // If we have received the service, and hence registered with it, then now is the time to unregister. if (mServiceMessenger != null && mMessenger != null) { try { @@ -150,6 +155,7 @@ @Override public void onServiceConnected(ComponentName name, IBinder service) { + Log.d(TAG, "onServiceConnected " + this); mServiceMessenger = new Messenger(service); Log.d(TAG, "mMessenger " + mMessenger); if (mMessenger != null) { @@ -166,7 +172,7 @@ @Override public void onServiceDisconnected(ComponentName name) { - Log.d(TAG, "onServiceDisconnected"); + Log.d(TAG, "onServiceDisconnected " + this); mServiceMessenger = null; } Modified: trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-03-11 17:18:53 UTC (rev 74) @@ -167,10 +167,7 @@ saveModel(); if (newModel) { -// Intent intent = new Intent(this, getNextEditionActivity()); - Intent intent = new Intent(this, getNextListActivity()); - intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_PARENT_MODEL, model); - startActivity(intent); + gotoNextActivity(); } else { Intent intent = new Intent(); @@ -202,6 +199,12 @@ } } + protected void gotoNextActivity() { + Intent intent = new Intent(this, getNextListActivity()); + intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_PARENT_MODEL, model); + startActivity(intent); + } + /* Protected methods */ protected void saveModel() { Modified: trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-03-11 12:59:38 UTC (rev 73) +++ trunk/src/fr/ifremer/wlo/measurement/MeasurementActivity.java 2014-03-11 17:18:53 UTC (rev 74) @@ -152,6 +152,8 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Log.d(TAG, "on create"); + measurements = (MeasurementsModel) getIntent().getSerializableExtra(INTENT_EXTRA_MEASUREMENTS); if (measurements != null) { scientificSpecies = measurements.getScientificSpecies(); @@ -206,48 +208,71 @@ validateButton = (Button) findViewById(R.id.measurement_add_button); - sizeText = (EditText) findViewById(R.id.size); - int inputType = InputType.TYPE_CLASS_NUMBER; - if (measurements.getPrecision().isDecimal()) { - inputType |= InputType.TYPE_NUMBER_FLAG_DECIMAL; - } - sizeText.setRawInputType(inputType); - sizeText.addTextChangedListener(new BaseTextWatcher() { - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - sizeText.setSelection(start + count); - } + initSizeText(); + observedNumberText = (TextView) findViewById(R.id.observed_number); + observedNumberText.setText(String.valueOf(measurements.getMeasurements().size())); + + initCategories(); + + initFishMeasurement(10 * measurements.getPrecision().getUnitDivider(), null, null, null); + + initDrawer(); + + initActionBar(); + + mMessenger = new Messenger(new Handler() { @Override - public void afterTextChanged(Editable s) { - if (s.toString().isEmpty()) { - measurement.setSize(null); + public void handleMessage(Message msg) { + if (!MeasurementActivity.this.isFinishing()) { + switch (msg.what) { + case BigFinCommunicationService.MESSAGE_READ: + BigFinFeedReaderRecord record = (BigFinFeedReaderRecord) msg.obj; - } else { - Mensuration.Precision precision = measurements.getPrecision(); - int multiplier = precision.getUnitDivider(); - try { - NumberFormat format = NumberFormat.getInstance(Locale.US); - Number number = format.parse(s.toString()); - double d = number.doubleValue(); - int size = (int)(d * multiplier); - measurement.setSize(size); + if (record != null && record.getLength() != null) { - } catch (ParseException e) { - Log.e(TAG, "ParseException " + e.getMessage()); - measurement.setSize(null); + int size = (int) Math.floor(record.getLength()); + measurement.setSize(size); + MeasurementModel savedMeasurement = addMeasurement(); + + if (useTextToSpeech) { + String formattedSize = UIUtils.getFormattedSize(savedMeasurement.getSize(), measurements.getPrecision()); + textToSpeech.speak(formattedSize, TextToSpeech.QUEUE_ADD, null); + + } else { + ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, ToneGenerator.MAX_VOLUME); + tg.startTone(ToneGenerator.TONE_PROP_BEEP); + } + + // Get instance of Vibrator from current Context + Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE); + // Vibrate for 300 milliseconds + v.vibrate(300); + } + break; } } } }); - observedNumberText = (TextView) findViewById(R.id.observed_number); - observedNumberText.setText(String.valueOf(measurements.getMeasurements().size())); + Intent checkIntent = new Intent(); + checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); + startActivityForResult(checkIntent, CHECK_TTS_REQUEST_CODE); + } - initCategories(); + protected void initActionBar() { + ActionBar actionBar = getActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + actionBar.setTitle(commercialSpecies.toString(this) + " / " + + scientificSpecies.toString(this) + " / " + + commercialSpecies.getMeasurementMethod().toString(this) + " / " + + commercialSpecies.getPrecision()); + actionBar.setSubtitle(vessel.toString(this) + " / " + + metier.toString(this)); + } - initFishMeasurement(10 * measurements.getPrecision().getUnitDivider(), null, null, null); - + protected void initDrawer() { DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); @@ -279,52 +304,43 @@ // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); + } - ActionBar actionBar = getActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setHomeButtonEnabled(true); - actionBar.setTitle(commercialSpecies.toString(this) + " / " + - scientificSpecies.toString(this) + " / " + - commercialSpecies.getMeasurementMethod().toString(this) + " / " + - commercialSpecies.getPrecision()); - actionBar.setSubtitle(vessel.toString(this) + " / " + - metier.toString(this)); + protected void initSizeText() { + sizeText = (EditText) findViewById(R.id.size); + int inputType = InputType.TYPE_CLASS_NUMBER; + if (measurements.getPrecision().isDecimal()) { + inputType |= InputType.TYPE_NUMBER_FLAG_DECIMAL; + } + sizeText.setRawInputType(inputType); + sizeText.addTextChangedListener(new BaseTextWatcher() { + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + sizeText.setSelection(start + count); + } - mMessenger = new Messenger(new Handler() { @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case BigFinCommunicationService.MESSAGE_READ: - BigFinFeedReaderRecord record = (BigFinFeedReaderRecord) msg.obj; + public void afterTextChanged(Editable s) { + if (s.toString().isEmpty()) { + measurement.setSize(null); - if (record != null && record.getLength() != null) { + } else { + Mensuration.Precision precision = measurements.getPrecision(); + int multiplier = precision.getUnitDivider(); + try { + NumberFormat format = NumberFormat.getInstance(Locale.US); + Number number = format.parse(s.toString()); + double d = number.doubleValue(); + int size = (int)(d * multiplier); + measurement.setSize(size); - int size = (int) Math.floor(record.getLength()); - measurement.setSize(size); - MeasurementModel savedMeasurement = addMeasurement(); - - if (useTextToSpeech) { - String formattedSize = UIUtils.getFormattedSize(savedMeasurement.getSize(), measurements.getPrecision()); - textToSpeech.speak(formattedSize, TextToSpeech.QUEUE_ADD, null); - - } else { - ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, ToneGenerator.MAX_VOLUME); - tg.startTone(ToneGenerator.TONE_PROP_BEEP); - } - - // Get instance of Vibrator from current Context - Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE); - // Vibrate for 300 milliseconds - v.vibrate(300); - } - break; + } catch (ParseException e) { + Log.e(TAG, "ParseException " + e.getMessage()); + measurement.setSize(null); + } } } }); - - Intent checkIntent = new Intent(); - checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); - startActivityForResult(checkIntent, CHECK_TTS_REQUEST_CODE); } protected void initCategories() { @@ -402,8 +418,6 @@ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == CHECK_TTS_REQUEST_CODE && resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { // Succès, au moins un moteur de TTS à été trouvé, on l'instancie textToSpeech = new TextToSpeech(this, this); @@ -412,6 +426,7 @@ } } else if (resultCode == RESULT_OK) { + Log.d(TAG, "requestCode " + requestCode); switch (requestCode) { case 1: vessel = (VesselModel) data.getSerializableExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL); @@ -430,6 +445,9 @@ break; } setDrawerListAdapter(); + + } else { + super.onActivityResult(requestCode, resultCode, data); } } @@ -644,15 +662,16 @@ } protected void setDrawerListAdapter() { + Log.d(TAG, scientificSpecies.toString(this)); mDrawerList.setAdapter(new ArrayAdapter<>(this, - android.R.layout.simple_list_item_1, - new String[]{ - getString(R.string.home_title), - vessel.toString(this), - metier.toString(this), - commercialSpecies.toString(this), - scientificSpecies.toString(this) - })); + android.R.layout.simple_list_item_1, + new String[]{ + getString(R.string.home_title), + vessel.toString(this), + metier.toString(this), + commercialSpecies.toString(this), + scientificSpecies.toString(this) + })); } protected void fetchCalcifiedPartTakings() { @@ -670,7 +689,6 @@ } } - /** Swaps fragments in the main content view */ protected void editItem(int position) { Class clazz; BaseModel modelToEdit; @@ -702,6 +720,7 @@ if (clazz != null) { Intent intent = new Intent(this, clazz); intent.putExtra(WloModelEditionActivity.INTENT_EXTRA_MODEL, modelToEdit); + Log.d(TAG, "startActivityForResult " + position); startActivityForResult(intent, position); } }