com.sidekickApp.AppState.java Source code

Java tutorial

Introduction

Here is the source code for com.sidekickApp.AppState.java

Source

package com.sidekickApp;

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

import android.graphics.Bitmap;
import android.os.Build;
import android.util.Log;

public class AppState {

    private static Object stateLock = new Object();
    private static String TAG = "AppState";
    private static AppState AppStateSingleton;

    /*******************************************/
    /* SUPER IMPORTANT THAT THESE BE CORRECT!!! */
    public static String APP_TYPE = "dev";
    public static int DEVICE_TYPE = 3;
    public static boolean IS_SECURE = true;
    public static boolean DEBUG = false;
    public static boolean LOG = true;

    // Define urls for API calls and node.js server
    public static String productionSocketUrl = "node.side.cr";
    public static String productionWebUrl = "app.side.cr";
    public static String devSocketUrl = "dnode.side.cr";
    public static String devWebUrl = "dev.side.cr";

    public static String supportPhone = "4157455553";
    public static int uiTemplateID = -1;
    public static JSONObject uiTemplate;
    /*******************************************/

    /* the following are set on app creation */
    public static int currentApiVersion;
    public static int froyoApiVersion;
    public static String deviceMakeModel;

    // Alohar constants
    public static String aloharUID = "";
    public static String motionState = "";
    public static String movementState = "";
    public static boolean isStationary = true;

    // Application information
    public static boolean firstRun = true;
    public static int versionCode = -1;

    // State information
    public static String deviceID = "";
    public static String phoneNo = "";
    public static int driverID = 1;
    public static String driverName = "";
    public static String driverSecret = "";
    public static Bitmap driverPic = null;
    public static String driverPicFilename = "";
    public static Bitmap vehiclePic = null;
    public static String vehiclePicFilename = "";
    public static String driverTCP = "";
    public static String licensePlate = "";
    public static String vehicleDesc = "";

    public static int vehicleID = -1;
    public static int lastRouteID = -1;
    public static int routeID = -1;
    public static int routeState = -1;
    public static int queuedRouteID = -1;
    public static int vehicleType = 0;
    public static int driverStatus = 0;
    public static int smartQueue = 0;
    public static int smartQueueActivated = 0;
    public static int newsUnread = 0;
    public static int batteryLevel = 100;
    public static int pluggedIn = 0;
    public static JSONArray neighbors;
    public static JSONArray blockedUsers;
    public static int serverTime = -1;

    // Route-based constants
    public static String pickupCross1 = "";
    public static String pickupCross2 = "";
    public static String dropoffCross1 = "";
    public static String dropoffCross2 = "";

    public static boolean isServiceBound = false;
    public static boolean isConnected = false;
    public static int disconnectType = -1;
    public static boolean hasGPSFix = false;
    public static boolean gpsPaused = false;
    public static boolean servicePaused = false;
    public static boolean mapCentered;
    public static boolean inBackground = false;

    // Pkt send variables
    public static double latitude = 0.0;
    public static double longitude = 0.0;
    public static double DEFAULT_LATITUDE = 37.769086;
    public static double DEFAULT_LONGITUDE = -122.441597;
    public static float MAX_GPS_ACCURACY = 250;
    public static long MAX_GPS_AGE = 600;
    public static float heading = -1;
    public static float speed = -1;
    public static float accuracy = 0;

    public static boolean driverInputOpen = false;
    public static boolean arrivalOpen = false;
    public static boolean pickupOpen = false;
    public static boolean waybillOpen = false;
    public static boolean feedbackOpen = false;

    public static boolean alertSent = false;
    public static boolean alertShown = false;
    public static boolean arrivalShown = false;
    public static boolean hideNavigationHelp = false;
    public static boolean hasWazeInstalled = false;

    public static int STATUS_LOGGED_OUT = -1;
    public static int STATUS_OFF_DUTY = 0;
    public static int STATUS_AVAILABLE = 1;
    public static int STATUS_BOOKED = 2;
    public static int STATUS_CLAIMING = 3;

    public static int ACTION_ARRIVAL = 0;
    public static int ACTION_BEGIN = 1;
    public static int ACTION_CLOSE = 2;

    public static int STOP_TYPE_PICKUP = 0;
    public static int STOP_TYPE_AS_DIRECTED = 1;
    public static int STOP_TYPE_DESTINATION = 2;

    // Signals for broadcast receivers
    public static String JOB_OFFER = "com.sidekickApp.JobOffer";
    public static String JOB_ASSIGNED = "com.sidekickApp.JobAssigned";
    public static String JOB_TAKEN = "com.sidekickApp.JobTaken";
    public static String JOB_EXPIRED = "com.sidekickApp.JobExpired";
    public static String JOB_CANCELLED = "com.sidekickApp.JobCancelled";
    public static String JOB_CLOSED = "com.sidekickApp.JobClosed";
    public static String MASTER_KILL = "com.sidekickApp.MasterKill";
    public static String GOOD_GPS = "com.sidekickApp.GoodGPS";
    public static String BAD_GPS = "com.sidekickApp.BadGPS";
    public static String OFFER_COUNTDOWN = "com.sidekickApp.OfferCountdown";
    public static String STOP_ARRIVAL = "com.sidekickApp.StopArrival";
    public static String ARRIVAL_NOTIFY = "com.sidekickApp.ArrivalNotify";
    public static String PHONE_SHUTDOWN = "com.sidekickApp.PhoneShutdown";
    public static String LOAD_PROGRESS = "com.sidekickApp.LoadProgress";
    public static String HIDE_SPLASH = "com.sidekickApp.HideSplash";
    public static String SHOW_EXIT = "com.sidekickApp.ShowExit";
    public static String SIDECAR_INTEREST = "com.sidekickApp.SidecarInterest";
    public static String UNBLOCK_USER = "com.sidekickApp.UnblockUser";

    // Return values from job offer window
    public static int OFFER_ACCEPT = 0;
    public static int OFFER_REJECT = 1;
    public static int OFFER_EXPIRED = 2;
    public static int OFFER_TAKEN = 3;
    public static int OFFER_CANCELLED = 4;

    // Special ride request images
    public static int DRIVER_SELECTED = 0;
    public static int DRIVER_FIRST = 1;

    // Values to pass to processRouteClosedMessage
    public static int CLOSED_JOB_COMPLETE = 0;
    public static int CLOSED_DRIVER_CANCEL = 1;
    public static int CLOSED_PASSENGER_CANCEL = 2;
    public static int CLOSED_JOB_INVALID = 3;

    // Request codes for startActivityForResult
    public static int REQUEST_LOGIN = 0;
    public static int REQUEST_SETTINGS = 1;
    public static int REQUEST_INTERNET = 2;
    public static int REQUEST_PASSENGER = 3;
    public static int REQUEST_ARRIVAL = 4;
    public static int REQUEST_AT_STOP = 5;
    public static int REQUEST_OFFER = 7;
    public static int REQUEST_CLOSED = 8;
    public static int REQUEST_NAVIGATOR_HELP = 9;
    public static int REQUEST_NAVIGATOR_INPUT = 10;
    public static int REQUEST_WAYBILL = 11;
    public static int REQUEST_SUMMARY = 12;
    public static int REQUEST_CANCEL = 13;
    public static int REQUEST_CALL = 14;
    public static int REQUEST_SPLASH = 15;
    public static int REQUEST_AS_DIRECTED = 16;
    public static int REQUEST_AS_PLANNED = 17;
    public static int REQUEST_WARNING = 18;
    public static int REQUEST_SIGNUP = 19;
    public static int REQUEST_LOCATIONS = 20;
    public static int REQUEST_EXIT = 21;
    public static int REQUEST_AT_PICKUP = 22;
    public static int REQUEST_AT_DROPOFF = 23;
    public static int REQUEST_DETAILS = 24;
    public static int REQUEST_BLOCKED = 25;
    public static int REQUEST_REJECTION = 26;
    public static int REQUEST_INACTIVE = 27;
    public static int REQUEST_NEWS = 28;
    public static int REQUEST_DISCONNECTED = 29;
    public static int REQUEST_NOT_ACTIVATED = 30;
    public static int REQUEST_NOT_OPERATIONAL = 31;
    public static int REQUEST_DRIVER_OVERTIME = 32;

    // Constants for use in Main and GPSService
    public static int ERROR_NONE = 0;
    public static int ERROR_SERVER = 1;
    public static int ERROR_DB = 2;
    public static int ERROR_GPS = 3;
    public static int ERROR_FLEET = 4;
    public static int ERROR_DRIVER_UNKNOWN = 5;
    public static int ERROR_DRIVER_CONFLICT = 6;
    public static int ERROR_VERSION = 7;
    public static int ERROR_ACTIVE = 8;

    public static int INPUT_LOGIN = 9;
    public static int INPUT_LOGGED_OUT = 10;
    public static int INPUT_ON_HOLD = 11;

    public static int MESSAGE_NONE = 0;
    public static int MESSAGE_SYSTEM = 1;
    public static int MESSAGE_ADMIN = 2;
    public static int MESSAGE_CLIENT = 3;
    public static int MESSAGE_PASSENGER = 4;
    public static int MESSAGE_BOARDED = 5;
    public static int MESSAGE_DISEMBARKED = 6;
    public static int MESSAGE_ROUTE = 7;
    public static int MESSAGE_NO_ROUTE = 8;
    public static int MESSAGE_ROUTE_STOP = 9;
    public static int MESSAGE_STOP_REQUEST = 10;
    public static int MESSAGE_CHANGE = 11;
    public static int MESSAGE_TIMEPOINT = 12;
    public static int MESSAGE_GPS = 13;
    public static int MESSAGE_DONE = 14;
    public static int MESSAGE_VEHICLES = 15;

    public static int GPS_NAP = 9999; // sleep for one minute
    public static int GPS_OFF = -1;
    public static int GPS_ON = 1;

    public static int STATUS_CONNECTED = 0;
    public static int STATUS_BAD_FIX = 1;
    public static int STATUS_PHONE_NOT_RECOGNIZED = 2;
    public static int STATUS_DRIVER_NOT_RECOGNIZED = 3;
    public static int STATUS_DRIVER_CONFLICT = 4;
    public static int STATUS_TRYING = 5;
    public static int STATUS_DISCONNECTED = 6;
    public static int STATUS_NO_INTERNET = 7;

    public static int CHANGE_TYPE_VEHICLE = 0;
    public static int CHANGE_TYPE_ROUTE = 1;
    public static int CHANGE_TYPE_BLOCK = 2;
    public static int CHANGE_TYPE_DRIVER = 3;

    public static short READING_GPS = 0x0;
    public static short READING_CELL = 0x1;
    public static short READING_BOGUS = 0xFF;
    public static String PREFERRED_PROVIDER = "gps";

    public static synchronized AppState getInstance() {
        if (AppStateSingleton == null) {
            AppStateSingleton = new AppState();
        }
        return AppStateSingleton;
    }

    // Basic class initializer, pass in no values
    public AppState() {
        mapCentered = false;
        currentApiVersion = android.os.Build.VERSION.SDK_INT;
        froyoApiVersion = android.os.Build.VERSION_CODES.FROYO;
        deviceMakeModel = Build.MANUFACTURER + " " + Build.MODEL;

        log("currentApiVersion = " + currentApiVersion + ", froyoApiVersion = " + froyoApiVersion
                + ", deviceMakeModel = " + deviceMakeModel);

        String prefix = "http";
        String suffix = ":";

        //represents ApiLevel 8, Android 2.2 & below = deprecation town
        /*
        if(currentApiVersion > froyoApiVersion)
        {
           // We can connect over https
           IS_SECURE = true;
           prefix += "s";
           suffix += "8081/";
        }
        else
        {
           // Cannot connect over https.
        */ IS_SECURE = false;
        suffix += "8080/";
        //}
        prefix += "://";

        devSocketUrl = prefix + devSocketUrl + suffix;
        devWebUrl = prefix + devWebUrl;
        productionSocketUrl = prefix + productionSocketUrl + suffix;
        productionWebUrl = prefix + productionWebUrl;
    }

    public static int getCurrentApiVersion() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = currentApiVersion;
        }
        return tmp;
    }

    public static String getDeviceMakeModel() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = deviceMakeModel;
        }
        return tmp;
    }

    public static boolean getDebug() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = DEBUG;
        }
        return tmp;
    }

    public static boolean getProduction() {
        boolean tmp = false;
        synchronized (stateLock) {
            if (APP_TYPE == "prod") {
                tmp = true;
            }
        }
        return tmp;
    }

    public static String getAppType() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = APP_TYPE;
        }
        return tmp;
    }

    public static int getDeviceType() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = DEVICE_TYPE;
        }
        return tmp;
    }

    public static boolean getIsSecure() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = IS_SECURE;
        }
        return tmp;
    }

    public static boolean getLog() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = LOG;
        }
        return tmp;
    }

    public static void setLog(boolean log) {
        synchronized (stateLock) {
            LOG = log;
        }
    }

    public static String getSupportPhone() {
        return supportPhone;
    }

    public static int getUITemplateID() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = uiTemplateID;
        }
        return tmp;
    }

    public static void setUITemplate(int templateId, JSONObject template) {
        synchronized (stateLock) {
            uiTemplateID = templateId;
            uiTemplate = template;
        }
    }

    public static JSONObject getUITemplate() {
        JSONObject tmp = null;
        synchronized (stateLock) {
            tmp = uiTemplate;
        }
        return tmp;
    }

    public static UIComponent getTemplateComponent(String name) {
        log("getTemplateComponent(" + name + ")");

        UIComponent tmp = new UIComponent(true, "");
        if (uiTemplate != null) {
            try {
                synchronized (stateLock) {
                    JSONObject fare = uiTemplate.getJSONObject(name);
                    tmp.display = (fare.getInt("display") != 0);
                    String content = fare.getString("content");
                    if (!content.equals("")) {
                        tmp.replace = content;
                    }

                    log("got component display: " + tmp.display + ", content: " + content);
                }
            } catch (JSONException j) {
                log("JSONException: " + j);
                return tmp;
            }
        }

        return tmp;
    }

    public static String getWebUrl() {
        String tmp = "";
        synchronized (stateLock) {
            if (getProduction()) {
                tmp = productionWebUrl;
            } else {
                tmp = devWebUrl;
            }
        }
        return tmp;
    }

    public static String getSocketUrl() {
        String tmp = "";
        synchronized (stateLock) {
            if (getProduction()) {
                tmp = productionSocketUrl;
            } else {
                tmp = devSocketUrl;
            }
        }
        return tmp;
    }

    public static boolean getFirstRun() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = firstRun;
        }
        return tmp;
    }

    public static void setFirstRun(boolean first) {
        synchronized (stateLock) {
            firstRun = first;
        }
    }

    public static int getVersionCode() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = versionCode;
        }
        return tmp;
    }

    public static void setVersionCode(int v) {
        synchronized (stateLock) {
            versionCode = v;
        }
    }

    public static String getAloharUID() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = aloharUID;
        }
        return tmp;
    }

    public static void setAloharUID(String a) {
        synchronized (stateLock) {
            aloharUID = a;
        }
    }

    public static void setIsStationary(boolean s) {
        synchronized (stateLock) {
            isStationary = s;
        }
    }

    public static boolean getIsStationary() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = isStationary;
        }

        return tmp;
    }

    public static void setMotionState(String state) {
        synchronized (stateLock) {
            motionState = state;
        }
    }

    public static String getMotionState() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = motionState;
        }
        return tmp;
    }

    public static void setMovementState(String state) {
        synchronized (stateLock) {
            movementState = state;
        }
    }

    public static String getMovementState() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = movementState;
        }
        return tmp;
    }

    public static int getVehicleID() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = vehicleID;
        }

        return tmp;
    }

    public static void setVehicleID(int vehicle) {
        synchronized (stateLock) {
            vehicleID = vehicle;
        }
    }

    public static int getRouteID() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = routeID;
        }

        return tmp;
    }

    public static void setRouteID(int route) {
        synchronized (stateLock) {
            //Toast.makeText(main, "setRouteID(" + route + ")", Toast.LENGTH_SHORT).show();
            routeID = route;
        }
    }

    public static int getQueuedRouteID() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = queuedRouteID;
        }
        return tmp;
    }

    public static void setQueuedRouteID(int route) {
        synchronized (stateLock) {
            queuedRouteID = route;
        }
    }

    public static int getRouteState() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = routeState;
        }

        return tmp;
    }

    public static void getRouteState(int state) {
        synchronized (stateLock) {
            routeState = state;
        }
    }

    public static String getDeviceID() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = deviceID;
        }
        return tmp;
    }

    public static void setDeviceID(String dId) {
        synchronized (stateLock) {
            deviceID = dId;
        }
    }

    public static String getPhoneNo() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = phoneNo;
        }
        return tmp;
    }

    public static void setPhoneNo(String phone) {
        synchronized (stateLock) {
            phoneNo = phone;
        }
    }

    public static int getDriverID() {
        int tmp = 1;
        synchronized (stateLock) {
            tmp = driverID;
        }

        return tmp;
    }

    public static void setDriverID(int driver) {
        synchronized (stateLock) {
            driverID = driver;
        }
    }

    public static String getDriverName() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = driverName;
        }
        return tmp;
    }

    public static void setDriverName(String name) {
        synchronized (stateLock) {
            driverName = name;
        }
    }

    public static String getDriverSecret() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = driverSecret;
        }
        return tmp;
    }

    public static void setDriverSecret(String secret) {
        synchronized (stateLock) {
            driverSecret = secret;
        }
    }

    public static String getDriverTCP() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = driverTCP;
        }

        return tmp;
    }

    public static void setDriverTCP(String tcp) {
        synchronized (stateLock) {
            driverTCP = tcp;
        }
    }

    public static String getLicensePlate() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = licensePlate;
        }

        return tmp;
    }

    public static void setLicensePlate(String license) {
        synchronized (stateLock) {
            licensePlate = license;
        }
    }

    public static String getVehicleDesc() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = vehicleDesc;
        }

        return tmp;
    }

    public static void setVehicleDesc(String desc) {
        synchronized (stateLock) {
            vehicleDesc = desc;
        }
    }

    public static int getVehicleType() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = vehicleType;
        }
        return tmp;
    }

    public static void setVehicleType(int type) {
        synchronized (stateLock) {
            vehicleType = type;
        }
    }

    public static String getDriverPicFilename() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = driverPicFilename;
        }
        return tmp;
    }

    public static void setDriverPicFilename(String pic) {
        synchronized (stateLock) {
            driverPicFilename = pic;
        }
    }

    public static Bitmap getDriverPic() {
        Bitmap tmp = null;
        synchronized (stateLock) {
            tmp = driverPic;
        }
        return tmp;
    }

    public static void setDriverPic(Bitmap b) {
        synchronized (stateLock) {
            driverPic = b;
        }
    }

    public static String getVehiclePicFilename() {
        String tmp = "";
        synchronized (stateLock) {
            tmp = vehiclePicFilename;
        }
        return tmp;
    }

    public static void setVehiclePicFilename(String pic) {
        synchronized (stateLock) {
            vehiclePicFilename = pic;
        }
    }

    public static Bitmap getVehiclePic() {
        Bitmap tmp = null;
        synchronized (stateLock) {
            tmp = vehiclePic;
        }
        return tmp;
    }

    public static void setVehiclePic(Bitmap b) {
        synchronized (stateLock) {
            vehiclePic = b;
        }
    }

    public static Double getLatitude() {
        Double tmp = 0.0;
        synchronized (stateLock) {
            tmp = latitude;
        }

        return tmp;
    }

    public static void setLatitude(Double lat) {
        synchronized (stateLock) {
            latitude = lat;
        }
    }

    public static Double getLongitude() {
        Double tmp = 0.0;
        synchronized (stateLock) {
            tmp = longitude;
        }

        return tmp;
    }

    public static void setLongitude(Double lon) {
        synchronized (stateLock) {
            longitude = lon;
        }
    }

    public static Double getDefaultLatitude() {
        Double tmp = -1.0;
        synchronized (stateLock) {
            tmp = DEFAULT_LATITUDE;
        }
        return tmp;
    }

    public static Double getDefaultLongitude() {
        Double tmp = -1.0;
        synchronized (stateLock) {
            tmp = DEFAULT_LONGITUDE;
        }
        return tmp;
    }

    public static float getHeading() {
        float tmp = -1;
        synchronized (stateLock) {
            tmp = heading;
        }

        return tmp;
    }

    public static void setHeading(float head) {
        synchronized (stateLock) {
            heading = head;
        }
    }

    public static float getSpeed() {
        float tmp = -1;
        synchronized (stateLock) {
            tmp = speed;
        }

        return tmp;
    }

    public static void setSpeed(float s) {
        synchronized (stateLock) {
            speed = s;
        }
    }

    public static float getAccuracy() {
        float tmp = -1;
        synchronized (stateLock) {
            tmp = accuracy;
        }

        return tmp;
    }

    public static void setAccuracy(float a) {
        synchronized (stateLock) {
            accuracy = a;
        }
    }

    public static int getBatteryLevel() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = batteryLevel;
        }

        return tmp;
    }

    public static void setBatteryLevel(int level) {
        synchronized (stateLock) {
            batteryLevel = level;
        }
    }

    public static int getPluggedIn() {
        int tmp = 0;
        synchronized (stateLock) {
            tmp = pluggedIn;
        }

        return tmp;
    }

    public static void setPluggedIn(int plugged) {
        synchronized (stateLock) {
            pluggedIn = plugged;
        }
    }

    public static boolean getIsServiceBound() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = isServiceBound;
        }
        return tmp;
    }

    public static void setIsServiceBound(boolean bound) {
        synchronized (stateLock) {
            isServiceBound = bound;
        }
    }

    public static boolean getConnected() {
        // isConnected is true only if our last AJAX request returned a valid JSON response
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = isConnected;
        }
        return tmp;
    }

    public static void setConnected(boolean type) {
        synchronized (stateLock) {
            isConnected = type;
        }
    }

    public static int getDisconnectType() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = disconnectType;
        }
        return tmp;
    }

    public static void setDisconnectType(int type) {
        synchronized (stateLock) {
            disconnectType = type;
        }
    }

    public static boolean getGPSFix() {
        // hasGPSFix is true if our location is currently valid
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = hasGPSFix;
        }
        return tmp;
    }

    public static void setGPSFix(boolean fix) {
        synchronized (stateLock) {
            hasGPSFix = fix;
        }
    }

    public static boolean getGPSPaused() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = gpsPaused;
        }

        return tmp;
    }

    public static void setGPSPaused(boolean pause) {
        synchronized (stateLock) {
            gpsPaused = pause;
        }
    }

    public static boolean getServicePaused() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = servicePaused;
        }

        return tmp;
    }

    public static void setServicePaused(boolean pause) {
        synchronized (stateLock) {
            servicePaused = pause;
        }
    }

    public static boolean getDriverInputOpen() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = driverInputOpen;
        }
        return tmp;
    }

    public static void setDriverInputOpen(boolean open) {
        synchronized (stateLock) {
            driverInputOpen = open;
        }
    }

    public static boolean getArrivalOpen() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = arrivalOpen;
        }
        return tmp;
    }

    public static void setArrivalOpen(boolean open) {
        synchronized (stateLock) {
            arrivalOpen = open;
        }
    }

    public static boolean getPickupOpen() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = pickupOpen;
        }
        return tmp;
    }

    public static void setPickupOpen(boolean open) {
        synchronized (stateLock) {
            pickupOpen = open;
        }
    }

    public static boolean getWaybillOpen() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = waybillOpen;
        }
        return tmp;
    }

    public static void setWaybillOpen(boolean open) {
        synchronized (stateLock) {
            waybillOpen = open;
        }
    }

    public static boolean getFeedbackOpen() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = feedbackOpen;
        }
        return tmp;
    }

    public static void setFeedbackOpen(boolean open) {
        synchronized (stateLock) {
            feedbackOpen = open;
        }
    }

    public static boolean getAlertSent() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = alertSent;
        }

        return tmp;
    }

    public static void setAlertSent(boolean s) {
        synchronized (stateLock) {
            alertSent = s;
        }
    }

    public static boolean getAlertShown() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = alertShown;
        }

        return tmp;
    }

    public static void setAlertShown(boolean a) {
        synchronized (stateLock) {
            alertShown = a;
        }
    }

    public static boolean getArrivalShown() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = arrivalShown;
        }

        return tmp;
    }

    public static void setArrivalShown(boolean a) {
        synchronized (stateLock) {
            arrivalShown = a;
        }
    }

    public static int getServerTime() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = serverTime;
        }

        return tmp;
    }

    public static void setServerTime(int time) {
        synchronized (stateLock) {
            serverTime = time;
        }
    }

    public static int getStatus() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = driverStatus;
        }
        return tmp;
    }

    public static void setStatus(int s) {
        synchronized (stateLock) {
            driverStatus = s;
        }
    }

    public static int getSmartQueue() {
        int tmp = 0;
        synchronized (stateLock) {
            tmp = smartQueue;
        }
        return tmp;
    }

    public static void setSmartQueue(int smart) {
        synchronized (stateLock) {
            smartQueue = smart;
        }
    }

    public static int getSmartQueueActivated() {
        int tmp = 0;
        synchronized (stateLock) {
            tmp = smartQueueActivated;
        }
        return tmp;
    }

    public static void setSmartQueueActivated(int smart) {
        synchronized (stateLock) {
            smartQueueActivated = smart;
        }
    }

    public static int getNewsUnread() {
        int tmp = -1;
        synchronized (stateLock) {
            tmp = newsUnread;
        }
        return tmp;
    }

    public static void setNewsUnread(int news) {
        synchronized (stateLock) {
            newsUnread = news;
        }
    }

    public static boolean getHideNavigationHelp() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = hideNavigationHelp;
        }
        return tmp;
    }

    public static void setHideNavigationHelp(boolean n) {
        synchronized (stateLock) {
            hideNavigationHelp = n;
        }
    }

    public static boolean getHasWazeInstalled() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = hasWazeInstalled;
        }
        return tmp;
    }

    public static void setHasWazeInstalled(boolean waze) {
        synchronized (stateLock) {
            hasWazeInstalled = waze;
        }
    }

    public static JSONArray getNeighbors() {
        synchronized (stateLock) {
            return neighbors;
        }
    }

    public static void setNeighbors(JSONArray n) {
        synchronized (stateLock) {
            neighbors = n;
        }
    }

    public static JSONArray getBlockedUsers() {
        synchronized (stateLock) {
            return blockedUsers;
        }
    }

    public static void setBlockedUsers(JSONArray b) {
        synchronized (stateLock) {
            blockedUsers = b;
        }
    }

    public static String getPickupCross() {
        String ret = "";
        if (!pickupCross1.equals("") && !pickupCross2.equals("")) {
            ret = pickupCross1 + "\n+\n" + pickupCross2;
        }

        return ret;
    }

    public static void setPickupCross(String cross1, String cross2) {
        pickupCross1 = cross1;
        pickupCross2 = cross2;
    }

    public static String getDropoffCross() {
        String ret = "";
        if (!dropoffCross1.equals("") && !dropoffCross2.equals("")) {
            ret = dropoffCross1 + "\n+\n" + dropoffCross2;
        }

        return ret;
    }

    public static void setDropoffCross(String cross1, String cross2) {
        dropoffCross1 = cross1;
        dropoffCross2 = cross2;
    }

    public static void resetCrossStreets() {
        log("resetCrossStreets()");
        pickupCross1 = "";
        pickupCross2 = "";
        dropoffCross1 = "";
        dropoffCross2 = "";
    }

    public static boolean getMapCentered() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = mapCentered;
        }
        return tmp;
    }

    public static void setMapCentered(boolean c) {
        synchronized (stateLock) {
            mapCentered = c;
        }
    }

    public static boolean getInBackground() {
        boolean tmp = false;
        synchronized (stateLock) {
            tmp = inBackground;
        }
        return tmp;
    }

    public static void setInBackground(boolean in) {
        synchronized (stateLock) {
            inBackground = in;
        }
    }

    public static Double haversine(Double lat1, Double lon1, Double lat2, Double lon2) {
        int R = 6371;
        Double dLat = Math.toRadians(lat2 - lat1);
        Double dLon = Math.toRadians(lon2 - lon1);

        Double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2)
                * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));

        Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        Double d = R * c * 1000;

        return d;
    }

    public static void log(String msg) {
        Log.v(TAG, "Debug: " + msg);
    }
}