Search in sources :

Example 1 with InNetworkState

use of im.tny.segvault.s2ls.InNetworkState in project underlx by underlx.

the class MainService method checkStopForeground.

private boolean checkStopForeground(S2LS loc) {
    if (loc.getCurrentTargetRoute() == null && !(loc.getState() instanceof InNetworkState)) {
        SharedPreferences sharedPref = getSharedPreferences("settings", MODE_PRIVATE);
        boolean permanentForeground = sharedPref.getBoolean(PreferenceNames.PermanentForeground, false);
        if (permanentForeground) {
            startPermanentForeground();
        } else {
            stopForeground(true);
        }
        return true;
    }
    return false;
}
Also used : SharedPreferences(android.content.SharedPreferences) InNetworkState(im.tny.segvault.s2ls.InNetworkState)

Example 2 with InNetworkState

use of im.tny.segvault.s2ls.InNetworkState in project underlx by underlx.

the class MainService method dumpDebugInfo.

// DEBUG:
public String dumpDebugInfo() {
    String s = "Service created on " + creationDate.toString();
    s += (wfc.isScanning() ? String.format(". WFC scanning every %d s", wfc.getScanInterval() / 1000) : ". WFC not scanning") + "\n";
    for (Network n : getNetworks()) {
        S2LS loc;
        synchronized (lock) {
            loc = locServices.get(n.getId());
        }
        s += "Network " + n.getNames("en")[0] + "\n";
        s += "State machine: " + loc.getState().toString() + "\n";
        s += String.format("\tIn network? %b\n\tNear network? %b\n", loc.inNetwork(), loc.nearNetwork());
        if (loc.getState() instanceof InNetworkState) {
            s += "\tPossible stops:\n";
            for (Stop stop : loc.getLocation().vertexSet()) {
                s += String.format("\t\t%s (%s)\n", stop.getStation().getName(), stop.getLine().getNames("en")[0]);
            }
            s += "\tPath:\n";
            if (loc.getCurrentTrip() != null) {
                for (Connection c : loc.getCurrentTrip().getEdgeList()) {
                    s += String.format("\t\t%s -> %s\n", c.getSource().toString(), c.getTarget().toString());
                }
                if (loc.getCurrentTargetRoute() != null) {
                    s += String.format("\t\tCurrent path complies? %b\n", loc.getCurrentTargetRoute().checkPathCompliance(loc.getCurrentTrip()));
                }
            }
        }
    }
    try {
        API.AuthTest authTest = API.getInstance().getAuthTest();
        s += "API auth test result: " + authTest.result + "\n";
        s += "API key as perceived by server: " + authTest.key + "\n";
    } catch (APIException e) {
        e.printStackTrace();
        s += "Error testing API authentication\n";
    }
    synchronizer.attemptSync();
    return s;
}
Also used : S2LS(im.tny.segvault.s2ls.S2LS) APIException(im.tny.segvault.disturbances.exception.APIException) Stop(im.tny.segvault.subway.Stop) Network(im.tny.segvault.subway.Network) Connection(im.tny.segvault.subway.Connection) SpannableString(android.text.SpannableString) InNetworkState(im.tny.segvault.s2ls.InNetworkState)

Aggregations

InNetworkState (im.tny.segvault.s2ls.InNetworkState)2 SharedPreferences (android.content.SharedPreferences)1 SpannableString (android.text.SpannableString)1 APIException (im.tny.segvault.disturbances.exception.APIException)1 S2LS (im.tny.segvault.s2ls.S2LS)1 Connection (im.tny.segvault.subway.Connection)1 Network (im.tny.segvault.subway.Network)1 Stop (im.tny.segvault.subway.Stop)1