Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joshdholtz/trajectory

Android routing library
https://github.com/joshdholtz/trajectory

Last synced: 10 days ago
JSON representation

Android routing library

Awesome Lists containing this project

README

        

# Trajectory

Trajectory is an Android routing library.

Download [trajectory-0.0.2.jar](https://github.com/joshdholtz/Trajectory/raw/master/builds/trajectory-0.0.2.jar)

## Changes coming soon
- Pulling query parameters from a route (skeleton-ed out but not functional yet)
- Making a second jar that uses ActionBarSherlock library that extends SherlockActivity to make a SherlockTrajectoryActivity

## Basic example on setting up routes

````java

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);

// Sets a route that excutes when Trajectory.call("/route") is called
Trajectory.setRoute("/route", new Route() {

@Override
public void onRoute(String route, HashMap routeParams, HashMap queryParams) {
Toast.makeText(TestActivity.this, route + " - " + routeParams.toString() + " - " + queryParams.toString(), Toast.LENGTH_SHORT).show();
}

});

// Sets a route that executes when Trajectory.call("/route/N") is called where N is any integer
Trajectory.setRoute(Pattern.compile("^/route/(\\d+)$"), new Route() {

@Override
public void onRoute(String route, HashMap routeParams, HashMap queryParams) {
Toast.makeText(TestActivity.this, route + " - " + routeParams.toString() + " - " + queryParams.toString(), Toast.LENGTH_SHORT).show();
}

});

// Sets a route that executes when Trajectory.call("/route/N/subroute/M") is called where N and M are any integers
Trajectory.setRoute(Pattern.compile("^/route/(\\d+)/subroute/(\\d+)$"), new String[]{"route_id", "subroute_id"}, new Route() {

@Override
public void onRoute(String route, HashMap routeParams, HashMap queryParams) {
Toast.makeText(TestActivity.this, route + " - " + routeParams.toString() + " - " + queryParams.toString(), Toast.LENGTH_SHORT).show();
}

});

}

public void someOnClickMethod() {
Trajectory.call("/route");
}

public void someOtherOnClickMethod() {
Trajectory.call("/route/6");
}

public void andOtherOnClickMethod() {
Trajectory.call("/route/6/subroute/7");
}

````

## Example for registering Activities for routes

#### 1. - Extend Application to register routes
````java

public class TestApplication extends Application {

public void onCreate() {
# Registers a route with a String
Trajectory.registerForRoute(BreweryListActivity.class, "/brewery");

# Register a route with a Pattern
Trajectory.registerForRoute(BreweryActivity.class, Pattern.compile("^/brewery/(\\d+)$"));

# Registers a route with a Pattern with named groups
Trajectory.registerForRoute(BeerActivity.class, Pattern.compile("^/brewery/(\\d+)/beer/(\\d+)$"), new String[]{"brewery_id", "beer_id"});
}

}

````

#### 2. - Extend TrajectoryActivity on all your activites
Note: Extending TrajectoryActivity does nothing more than remember the current Activities "context" so Trajectory can start an Activity
````java

public class BreweryListActivity extends TrajectoryActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_brewery_list);

// Gets all passed in information from the registered TrajectoryActivity intent
String route = this.getIntent().getStringExtra(Trajectory.INTENT_ROUTE);
HashMap params = (HashMap) this.getIntent().getSerializableExtra(Trajectory.INTENT_ROUTE_PARAMS);
HashMap queryParams = (HashMap) this.getIntent().getSerializableExtra(Trajectory.INTENT_QUERY_PARAMS);

Toast.makeText(this, route, Toast.LENGTH_SHORT).show();
}

}

````

#### 3. - Example AndroidManifest.xml (set the )
````xml
















````

#### 4. - Call your route from somewhere
````java

// Starts the BreweryListActivity.java
Trajectory.call("/brewery");

````