mWater / mWater-Android-App

An Android App that snaps a picture of a petrifilm, counts the bacteria and posts the counts on a server for the mWater project
https://github.com/AndroidImageProcessing
GNU General Public License v3.0
24 stars 16 forks source link

Code Review for GPS detection in takepicture #24

Closed cesine closed 12 years ago

cesine commented 12 years ago

Integrating checking the GPS in the TakePicture activity was actually pretty complicated and needed some complex Android Architecture stuff.

1: initialize stuff in the onCreate method in Activities (stuff you would normally put in a constructor, you can normally put here) https://github.com/AndroidImageProcessing/AndroidBacteriaImageProcessing/commit/e8cb6af4c65da4ece527b172dd1254045776379e

cesine commented 12 years ago

2: the onActivityResult is a pretty awesome pattern to have in your tool belt.

Basically if you need to go out of your activity for a bit to check something (in this case, to let the user change the settings) then you will come back into your activity in the onActivityResult hook. This is where you can create a case statement for each time you leave (in this case we leave twice, once to turn on the GPS if it was turned off, and then secondly to the camera app to take a picture) then we come back and process it. Needing the onActivityResult hook is frequent in Android because we call intents to other modules to do small well defined tasks, like take a picture.

https://github.com/AndroidImageProcessing/AndroidBacteriaImageProcessing/commit/46938e240432dfc6f1d4f3ec05d41113b0abd374

cesine commented 12 years ago

Might still need some code review from GPS expert...but for now it works well enough