Android Open Source - trip-chain-android Route






From Project

Back to project page trip-chain-android.

License

The source code is released under:

MIT License

If you think the Android project trip-chain-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fi.aalto.tripchain.route;
//from w  ww .  j ava2 s  . c o  m
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import fi.aalto.tripchain.route.Trip.ActivityModel;

import android.location.Location;

/**
 * Models trip as RouteSegments.
 * @author juke
 *
 */
public class Route {
  private List<RouteSegment> route = new ArrayList<RouteSegment>();
  private Location lastLocation;
  
  public void onActivity(ActivityModel am) {
    if (route.size() == 0) {
      route.add(new RouteSegment(am));
      if (lastLocation != null) {
        onLocation(lastLocation);
        lastLocation = null;
      }
    } else {
      RouteSegment lastSegment = route.get(route.size() - 1);
      if (lastSegment.activity != am.activity) {
        // new segment should begin where old one ends
        RouteSegment newSegment = new RouteSegment(am);
        newSegment.addLocation(lastSegment.getLastLocation());
        route.add(newSegment);
      }
    }
  }
  
  
  void onLocation(Location location) {
    if (route.size() == 0) {
      lastLocation = location;
    } else {
      RouteSegment lastRouteSegment = route.get(route.size() - 1);
      lastRouteSegment.addLocation(location);
    }    
  }
  
  public JSONObject toJson() throws JSONException {
    JSONObject featureCollection = new JSONObject();
    JSONArray features = new JSONArray();

    for (RouteSegment rs : route) {
      JSONObject j = rs.toJson();
      if (j != null) {
        features.put(j);
      }
    }

    featureCollection.put("type", "FeatureCollection");
    featureCollection.put("features", features);

    return featureCollection;
  }
}




Java Source Code List

fi.aalto.tripchain.BackgroundService.java
fi.aalto.tripchain.Configuration.java
fi.aalto.tripchain.LoginActivity.java
fi.aalto.tripchain.MainActivity.java
fi.aalto.tripchain.StartFragment.java
fi.aalto.tripchain.TripFragment.java
fi.aalto.tripchain.receivers.ActivityReceiver.java
fi.aalto.tripchain.receivers.EventDispatcher.java
fi.aalto.tripchain.receivers.EventListener.java
fi.aalto.tripchain.receivers.LocationReceiver.java
fi.aalto.tripchain.receivers.Receiver.java
fi.aalto.tripchain.route.ActivityListener.java
fi.aalto.tripchain.route.Activity.java
fi.aalto.tripchain.route.LocationListener.java
fi.aalto.tripchain.route.RoadSegment.java
fi.aalto.tripchain.route.Roads.java
fi.aalto.tripchain.route.RouteSegment.java
fi.aalto.tripchain.route.Route.java
fi.aalto.tripchain.route.TripRecorder.java
fi.aalto.tripchain.route.Trip.java