Created
June 13, 2013 15:52
-
-
Save iraSenthil/5774833 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void findTotalWalkingDistance(JSONArray arrayOfRecords) { | |
| try { | |
| //Each record has activity_type and array of statistics. Traverse to activity_type = Walking | |
| for (int ii = 0; ii < arrayOfRecords.length(); ii++) { | |
| JSONObject statObject = (JSONObject) arrayOfRecords.get(ii); | |
| if ("Walking".equalsIgnoreCase(statObject.getString("activity_type"))) { | |
| //Each activity_type has array of stats, navigate to "Overall" statistic to find the total distance walked. | |
| JSONArray walkingStats = statObject.getJSONArray("stats"); | |
| for (int jj = 0; jj < walkingStats.length(); jj++) { | |
| JSONObject iWalkingStat = (JSONObject) walkingStats.get(jj); | |
| if ("Overall".equalsIgnoreCase(iWalkingStat.getString("stat_type"))) { | |
| long totalWalkingDistanceMeters = iWalkingStat.getLong("value"); | |
| double totalWalkingDistanceMiles = totalWalkingDistanceMeters * 0.00062137; | |
| displayTotalWalkingDistance(totalWalkingDistanceMiles); | |
| return; | |
| } | |
| } | |
| } | |
| } | |
| displayToast("Something went wrong!!!"); | |
| } catch (JSONException e) { | |
| displayToast("Exception occured:("); | |
| e.printStackTrace(); | |
| resetUi(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment