<commit_before>package com.mobile.countme.implementation.controllers;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.location.Location;
import android.net.ConnectivityManager;
import android.util.Log;

import com.mobile.countme.framework.AppMenu;
import com.mobile.countme.framework.GPSFilter;
import com.mobile.countme.implementation.models.ErrorModel;
import com.mobile.countme.implementation.models.UserModel;

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

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;

import static com.google.android.gms.internal.zzhu.runOnUiThread;

/**
 * Created by Torgeir on 14.10.2015.
 */
public class HTTPSender {

    private static final String SERVER_URL = "https://tf2.sintef.no:8084/smioTest/api/";
    //private static final String USERID = "560946d9b2af57c413ac8427";
    //private static final String TOKEN = <PASSWORD>";
    //private static final String USERNAME = "sondre";
    //private static final String PASSWORD = "<PASSWORD>";

    static private LoginInfo info;
    static private UserModel userModel;
    private static boolean clicked;
    private static AppMenu context;
    private static UUID tripID;
    private static JSONObject survey;


    public HTTPSender() {

    }


    //sendTrip method creates a json from an arraylist of locations, an arraylist of ints and a context
    //Then it uses delegation to send the json to the server via a specified url
    public static void sendTrip(ArrayList<Location> trip, ArrayList<Integer> connectionTypes, UserModel userModel, AppMenu context) {
        HTTPSender.context = context;


        Log.d("SendTrip", "SendTrip started");

//        GPSFilter.filterTrip(trip, connectionTypes);
//        if(trip.size() < 20){
//            return;
//        }
        JSONObject jsonObject = null;
        /*
        var json = {
            "_userId": [unik brukar-ID],
            "startTime": [timestamp start],                      //"2014-02-13T15:00:00-0100";
            "endTime": [timestamp slutt],     //"2014-02-14T16:25:43-0100";
            "tripData": [dataPoints, feks arrayet de har],
            "purpose": [sikkert irrelevant for dykk, kan berre vere ein tom string],
            "OS": [Ext.os.name + " " + Ext.os.version]                        //OS Information
        };


         */
        try {
            jsonObject = new JSONObject();
            jsonObject.put("_userId", info.getUserID());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
            sdf.setTimeZone(TimeZone.getTimeZone("CET"));
            jsonObject.put("startTime", sdf.format(new Date(trip.get(0).getTime())));<commit_msg>Tried to fix nullpointer and changed string in back button in map view.<commit_after>package com.mobile.countme.implementation.controllers;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.location.Location;
import android.net.ConnectivityManager;
import android.util.Log;

import com.mobile.countme.framework.AppMenu;
import com.mobile.countme.framework.GPSFilter;
import com.mobile.countme.implementation.models.ErrorModel;
import com.mobile.countme.implementation.models.UserModel;

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

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;

import static com.google.android.gms.internal.zzhu.runOnUiThread;

/**
 * Created by Torgeir on 14.10.2015.
 */
public class HTTPSender {

    private static final String SERVER_URL = "https://tf2.sintef.no:8084/smioTest/api/";
    //private static final String USERID = "560946d9b2af57c413ac8427";
    //private static final String TOKEN = <PASSWORD>";
    //private static final String USERNAME = "sondre";
    //private static final String PASSWORD = "<PASSWORD>";

    static private LoginInfo info;
    static private UserModel userModel;
    private static boolean clicked;
    private static AppMenu context;
    private static UUID tripID;
    private static JSONObject survey;


    public HTTPSender() {

    }


    //sendTrip method creates a json from an arraylist of locations, an arraylist of ints and a context
    //Then it uses delegation to send the json to the server via a specified url
    public static void sendTrip(ArrayList<Location> trip, ArrayList<Integer> connectionTypes, UserModel userModel, AppMenu context) {
        HTTPSender.context = context;


        Log.d("SendTrip", "SendTrip started");

        GPSFilter.filterTrip(trip, connectionTypes);
        if(trip.size() < 20){
            return;
        }
        JSONObject jsonObject = null;
        /*
        var json = {
            "_userId": [unik brukar-ID],
            "startTime": [timestamp start],                      //"2014-02-13T15:00:00-0100";
            "endTime": [timestamp slutt],     //"2014-02-14T16:25:43-0100";
            "tripData": [dataPoints, feks arrayet de har],
            "purpose": [sikkert irrelevant for dykk, kan berre vere ein tom string],
            "OS": [Ext.os.name + " " + Ext.os.version]                        //OS Information
        };


         */
        try {
            jsonObject = new JSONObject();
            jsonObject.put("_userId", info.getUserID());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
            sdf.setTimeZone(TimeZone.getTimeZone("CET"));
            jsonObject.put("startTime", sdf.format(new Date(trip.get(0).getTime())));
{'fraction_non_alphanumeric': 0.11230037376826367, 'fraction_numerical': 0.023445463812436288, 'mean_word_length': 3.010217983651226, 'pattern_counts': {'":': 12, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '142651', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1695, 'n_words': 439}