Android Open Source - proximo Backend






From Project

Back to project page proximo.

License

The source code is released under:

Copyright (c) 2010 Evan Martin. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *...

If you think the Android project proximo 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

// Copyright (c) 2010 Evan Martin.  All rights reserved.
// Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
/*from  w ww . j a  v a 2 s  . com*/
package org.neugierig.proximo;

import android.content.*;
import android.os.*;
import android.util.Log;

import java.net.*;
import java.io.*;
import org.json.*;

// The Backend knows how to query both the local database and the
// remote server for MUNI data.  Its calls are all blocking and so
// it's typically used from a background thread.
public class Backend {
  // Tag for logging.
  private static final String TAG = "proximo Backend";

  Backend(Context context) {
    mContext = context;
    mDatabase = new Database(context);
  }

  ProximoBus.Route[] fetchRoutes()
      throws MalformedURLException, IOException, JSONException
  {
    return ProximoBus.parseRoutes(queryAPI(ProximoBus.getAllRoutesPath(), false));
  }

  ProximoBus.Run[] fetchRunsOnRoute(String routeId)
      throws MalformedURLException, IOException, JSONException
  {
    return ProximoBus.parseRuns(queryAPI(ProximoBus.getRunsOnRoutePath(routeId), false));
  }

  ProximoBus.Stop[] fetchStopsOnRun(String routeId, String runId)
      throws MalformedURLException, IOException, JSONException
  {
    return ProximoBus.parseStops(queryAPI(ProximoBus.getStopsOnRunPath(routeId, runId), false));
  }

  ProximoBus.Prediction[] fetchPredictionsForRouteAtStop(String routeId, String stopId, boolean forceRefresh)
      throws MalformedURLException, IOException, JSONException
  {
    return ProximoBus.parsePredictions(queryAPI(ProximoBus.getStopPredictionsByRoutePath(stopId, routeId), forceRefresh));
  }

  String queryAPI(String path, boolean reload)
      throws MalformedURLException, IOException
  {
    String data = null;

    if (!reload)
      data = mDatabase.get(path);

    if (data == null) {
      data = ProximoBus.queryNetwork(path);
      Log.i(TAG, "Network fetch: " + data);
      mDatabase.put(path, data);
    }

    return data;
  }

  private Context mContext;
  private Database mDatabase;
}




Java Source Code List

org.neugierig.proximo.AsyncBackendHelper.java
org.neugierig.proximo.AsyncBackend.java
org.neugierig.proximo.Backend.java
org.neugierig.proximo.Database.java
org.neugierig.proximo.ProximoBus.java
org.neugierig.proximo.Route.java
org.neugierig.proximo.Routes.java
org.neugierig.proximo.SplitListAdapter.java
org.neugierig.proximo.StarDBAdapter.java
org.neugierig.proximo.Stop.java
org.neugierig.proximo.Stops.java
org.neugierig.proximo.UpdateService.java
org.neugierig.proximo.ViewState.java