daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2.     public void onLocationChanged(Location loc) {
  3.     /* Get current speed */
  4.         loc.getSpeed();
  5.  
  6.     /* Assign speed value to double variable in meter/sec, convert to miles/hr, and convert to string*/
  7.         float currentSpeedInMeterPerSecond = loc.getSpeed();
  8.         float currentSpeed = currentSpeedInMeterPerSecond * 2.237f;
  9.  
  10.         currentSpeedMPHInt = Math.round(currentSpeed);
  11.         currentSpeedString = Integer.toString(currentSpeedMPHInt);
  12.  
  13.     /* Print out current speed */
  14.         TextView currentSpeedText = (TextView) findViewById(R.id.speed);
  15.         currentSpeedText.setText(currentSpeedString);
  16.  
  17.     /* Get headwind, frontal area, drag coefficent (Cd), rolling coeffiecent (Cr) */
  18.         mySharedPreferences = getSharedPreferences(MY_PREFS, prefMode);
  19.         headWindString = mySharedPreferences.getString("keyheadWindString", "0");
  20.         headWind = new Float(headWindString);
  21.  
  22.         frontalAreaString = mySharedPreferences.getString("keyfrontalAreaString", "6.6");
  23.         frontalArea = new Float(frontalAreaString);
  24.  
  25.         dragCoefficentString = mySharedPreferences.getString("keydragCoefficentString", "1.15");
  26.         dragCoefficent = new Float(dragCoefficentString);
  27.  
  28.         riderWeightString = mySharedPreferences.getString("keyriderWeightString", "205");
  29.         riderWeight = new Float(riderWeightString);
  30.  
  31.         bikeWeightString = mySharedPreferences.getString("keybikeWeightString", "30");
  32.         bikeWeight = new Float(bikeWeightString);
  33.  
  34.         rollingCoefficentString = mySharedPreferences.getString("keyrollingCoefficentString", "0.0075");
  35.         rollingCoefficent = new Float(rollingCoefficentString);
  36.  
  37.     /* get current time and location and speed and altitude*/
  38.         System.currentTimeMillis();
  39.         loc.getLatitude();
  40.         loc.getLongitude();
  41.         loc.getAltitude();
  42.  
  43.     /* Set start time and location */
  44.         if (i < j) {
  45.             i = i + 1;
  46.             time1 = System.currentTimeMillis();
  47.             altitudeStart = loc.getAltitude();
  48.             altitudeA = loc.getAltitude();
  49.             latA = loc.getLatitude();
  50.             logA = loc.getLongitude();
  51.             Location.distanceBetween(latA, logA, latB, logB, distance);
  52.         } else {
  53.  
  54.         /* Get new location and time*/
  55.             timeNew = System.currentTimeMillis();
  56.             latB = loc.getLatitude();
  57.             logB = loc.getLongitude();
  58.             altitudeB = loc.getAltitude();
  59.  
  60.         /* Get distance between point A and point B*/
  61.             Location.distanceBetween(latA, logA, latB, logB, distance);
  62.             distanceTraveledMeters = distance[0];           /* distance between A and B in meters*/
  63.             distanceTraveledMiles = distanceTraveledMeters * 0.0006213712f;
  64.             if (distanceTraveledMiles < 0.02f) {
  65.                 distanceTraveledMiles = 0f;
  66.             }
  67.          /* Get and find time, total distance, average power , average speed, total Kcal, total elevation diff*/
  68.             timeinterval = timeNew - time1;
  69.             timeintervalSec = timeinterval / 1000f;
  70.             tripTimeTotalmin = tripTimeTotalmin + (timeintervalSec / 60f);
  71.             totalDistance = totalDistance + distanceTraveledMiles;
  72.             averageSpeed = totalDistance / (tripTimeTotalmin / 60f);
  73.             elevChange = (((altitudeB + altitudeA) / 2) - altitudeStart) * 3.2808d;
  74.             elevChangeFloat = (float) elevChange;
  75.             powerElevationChangeWattsAve = ((((riderWeight + bikeWeight) * 32.174f) * elevChangeFloat) / tripTimeTotalmin) * 0.00070234f;
  76.             intervalSpeedMPH = distanceTraveledMiles / (timeintervalSec / 3600f);
  77.             powerAirResistanceWattsAve = (0.5f * dragCoefficent * 0.075f * ((averageSpeed + headWind) * (averageSpeed + headWind)) * frontalArea * (averageSpeed + headWind)) * 0.13295f;
  78.             powerRollingResistanceWattsAve = rollingCoefficent * (riderWeight + bikeWeight) * 32.174f * averageSpeed * 0.062f;
  79.             powerTotalWattsAve = powerElevationChangeWattsAve + powerAirResistanceWattsAve + powerRollingResistanceWattsAve;
  80.             totalKcalBurned = (powerTotalWattsAve * tripTimeTotalmin * 0.01433f) / 0.24f;
  81.             mechBtuUsed = powerTotalWattsAve * tripTimeTotalmin * 0.056869f;
  82.  
  83.          /*Round off values*/
  84.             totalDistance = totalDistance * 10f;
  85.             totalDistance = Math.round(totalDistance);
  86.             totalDistance = totalDistance / 10f;
  87.  
  88.             tripTimeMin = Math.round(tripTimeTotalmin);
  89.             timeintervalSec = Math.round(timeintervalSec);
  90.             averageSpeedInt = Math.round(averageSpeed);
  91.             powerTotalWattsInt = Math.round(powerTotalWattsAve);
  92.             totalKcalBurnedInt = Math.round(totalKcalBurned);
  93.             intervalSpeedMPHInt = Math.round(intervalSpeedMPH);
  94.             mechBtuUsedInt = Math.round(mechBtuUsed);
  95.             elevChangeInt = Math.round(elevChangeFloat);
  96.  
  97.          /*convert to stings*/
  98.             totalDistanceString = Float.toString(totalDistance);
  99.             tripTimeTotalminString = Integer.toString(tripTimeMin);
  100.             averageSpeedString = Integer.toString(averageSpeedInt);
  101.             powerTotalWattsString = Integer.toString(powerTotalWattsInt);
  102.             totalKcalBurnedString = Integer.toString(totalKcalBurnedInt);
  103.             mechBtuUsedString = Integer.toString(mechBtuUsedInt);
  104.             elevChangeString = Integer.toString(elevChangeInt);
  105.  
  106.          /* Print out */
  107.             TextView totalDistanceText = (TextView) findViewById(R.id.distance);
  108.             totalDistanceText.setText(totalDistanceString);
  109.             TextView tripTimeTotalminText = (TextView) findViewById(R.id.triptime);
  110.             tripTimeTotalminText.setText(tripTimeTotalminString);
  111.             TextView averageSpeedText = (TextView) findViewById(R.id.avespeed);
  112.             averageSpeedText.setText(averageSpeedString);
  113.             TextView powerTotalWattsText = (TextView) findViewById(R.id.watts);
  114.             powerTotalWattsText.setText(powerTotalWattsString);
  115.             TextView totalKcalBurnedText = (TextView) findViewById(R.id.burnedkcal);
  116.             totalKcalBurnedText.setText(totalKcalBurnedString);
  117.             TextView mechBtuUsedText = (TextView) findViewById(R.id.mechbtu);
  118.             mechBtuUsedText.setText(mechBtuUsedString);
  119.             TextView elevChangeText = (TextView) findViewById(R.id.elevchange);
  120.             elevChangeText.setText(elevChangeString);
  121.  
  122.          /*reset start time and location and interval elevation */
  123.             time1 = timeNew;
  124.             latA = latB;
  125.             logA = logB;
  126.             altitudeA = altitudeB;
  127.  
  128.          /* check iterations*/
  129.             k = k + 1;
  130.             kString = Integer.toString(k);
  131.             TextView kStringText = (TextView) findViewById(R.id.k);
  132.             kStringText.setText(kString);
  133.         }
  134.     }
  135.    
  136. public final LocationListener locationListener = new LocationListener() {
  137.     public void onLocationChanged(Location location) {
  138.         SimpleDateFormat s = new SimpleDateFormat("hh:mm:ss");
  139.         String timeStamp = s.format(new Date());
  140.    
  141. 07-23 15:50:58.110: I/LocationListener(27513): Time of location change: 03:50:58. Latitude: 35.3597361 Longitude: -76.4046144
RAW Paste Data
Top