<commit_before>package de.andreasgiemza.ubicomproject.gcm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import de.andreasgiemza.ubicomproject.helpers.Preferences;

public enum GcmServer {
	INSTANCE;

	private InputStream is = null;
	private JSONObject jObj = null;
	private String json = "";

	public void register(Context context, String regId) {
		final Preferences prefs = new Preferences(context);

		List<NameValuePair> getPrarams = new ArrayList<NameValuePair>();
		getPrarams.add(new BasicNameValuePair("number", prefs.getNumber()));
		getPrarams.add(new BasicNameValuePair("gcm", regId));

		makeHttpRequest("http://ucp.g8j.de/register.php", "GET", getPrarams);
	}

	public void updatePosition(Context context, final Location location) {
		final Preferences prefs = new Preferences(context);

		if (prefs.isRegistered() && checkInternetConnection(context)) {
			new Thread(new Runnable() {
				public void run() {
					String message = prefs.getNumber() + ";"
							+ String.valueOf(location.getLatitude()) + ";"
							+ String.valueOf(location.getLongitude());

					List<NameValuePair> postParams = new ArrayList<NameValuePair>();
					postParams.add(new BasicNameValuePair("message", message));

					makeHttpRequest("http://ucp.g8j.de/update_position.php",
							"GET", postParams);
				}
			}).start();
		}
	}

	public List<String> getKnownNumbers(final List<String> numbers) {
		String numbersString = "";

		for (String number : numbers) {
			if (number != null)
				numbersString += number + ";";
		}

		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
		postParams.add(new BasicNameValuePair("numbers", numbersString));

		JSONObject answer = makeHttpRequest(
				"http://ucp.g8j.de/known_numbers.php", "GET", postParams);

		List<String> knownNumbers = new LinkedList<>();

		try {
			if (answer != null) {
				// Checking for SUCCESS TAG
				int success = answer.getInt("success");

				if (success == 1) {
					// Getting Array of Products
					JSONArray jsonKnownNumbers = answer
							.getJSONArray("knownNumbers");

					// looping through All Products
					for (int i = 0; i < jsonKnownNumbers.length(); i++) {
						JSONObject c = jsonKnownNumbers.getJSONObject(i);

						knownNumbers.add(c.getString("number"));
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		for (String number : knownNumbers) {
			Log.d("AllowedNumbers", number);
		}
		return knownNumbers;

	}

	// function get json from url
	// by making HTTP POST or GET mehtod
	public JSONObject makeHttpRequest(String url, String method,
			List<NameValuePair> params) {

		// Making HTTP request
		try {<commit_msg>Removed irritating log message<commit_after>package de.andreasgiemza.ubicomproject.gcm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import de.andreasgiemza.ubicomproject.helpers.Preferences;

public enum GcmServer {
	INSTANCE;

	private InputStream is = null;
	private JSONObject jObj = null;
	private String json = "";

	public void register(Context context, String regId) {
		final Preferences prefs = new Preferences(context);

		List<NameValuePair> getPrarams = new ArrayList<NameValuePair>();
		getPrarams.add(new BasicNameValuePair("number", prefs.getNumber()));
		getPrarams.add(new BasicNameValuePair("gcm", regId));

		makeHttpRequest("http://ucp.g8j.de/register.php", "GET", getPrarams);
	}

	public void updatePosition(Context context, final Location location) {
		final Preferences prefs = new Preferences(context);

		if (prefs.isRegistered() && checkInternetConnection(context)) {
			new Thread(new Runnable() {
				public void run() {
					String message = prefs.getNumber() + ";"
							+ String.valueOf(location.getLatitude()) + ";"
							+ String.valueOf(location.getLongitude());

					List<NameValuePair> postParams = new ArrayList<NameValuePair>();
					postParams.add(new BasicNameValuePair("message", message));

					makeHttpRequest("http://ucp.g8j.de/update_position.php",
							"GET", postParams);
				}
			}).start();
		}
	}

	public List<String> getKnownNumbers(final List<String> numbers) {
		String numbersString = "";

		for (String number : numbers) {
			if (number != null)
				numbersString += number + ";";
		}

		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
		postParams.add(new BasicNameValuePair("numbers", numbersString));

		JSONObject answer = makeHttpRequest(
				"http://ucp.g8j.de/known_numbers.php", "GET", postParams);

		List<String> knownNumbers = new LinkedList<>();

		try {
			if (answer != null) {
				// Checking for SUCCESS TAG
				int success = answer.getInt("success");

				if (success == 1) {
					// Getting Array of Products
					JSONArray jsonKnownNumbers = answer
							.getJSONArray("knownNumbers");

					// looping through All Products
					for (int i = 0; i < jsonKnownNumbers.length(); i++) {
						JSONObject c = jsonKnownNumbers.getJSONObject(i);

						knownNumbers.add(c.getString("number"));
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return knownNumbers;

	}

	// function get json from url
	// by making HTTP POST or GET mehtod
	public JSONObject makeHttpRequest(String url, String method,
			List<NameValuePair> params) {

		// Making HTTP request
		try {
{'fraction_non_alphanumeric': 0.12109264995775838, 'fraction_numerical': 0.0014080540692762602, 'mean_word_length': 4.426279602750191, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, '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': '2491186', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2129, 'n_words': 473}