<commit_before>package com.pamulabs.pamu.supertaxi;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.TextView;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

import java.net.SocketTimeoutException;
import java.net.URL;


public class UserDetailsActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_details);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_user_details, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_user_details, container, false);
            final TextView textView = (TextView) rootView.findViewById(R.id.user_details_textview);
            Button go = (Button) rootView.findViewById(R.id.paygo);

            go.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = getActivity().getIntent();
                    if (intent != null && intent.getExtras() != null) {
                        Bundle bundle = intent.getExtras();
                        if (bundle.containsKey("SOURCE") &&
                                bundle.containsKey("DESTINATION")) {
                            String source = bundle.getString("SOURCE");
                            String destination = bundle.getString("DESTINATION");
                            Long id = PreferenceManager.getDefaultSharedPreferences(getActivity()).getLong("ID", 123);
                            String text = "User with id: " + id + " starts at " + source + " ends at "+destination;
                            textView.setText(text);
                            new PostTask(getActivity()).execute(new String[]{id.toString(), source, destination});
                        }
                    }
                }
            });
            return rootView;
        }
    }
    public static class PostTask extends AsyncTask<String, Void, Integer> {
        ProgressDialog dialog;
        Activity activity;

        String URL = "http://supertaxi.herokuapp.com/client";

        String LOG_TAG = PostTask.class.getSimpleName();

        public PostTask(Activity activity) {
            super();
            this.activity = activity;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dialog = new ProgressDialog(activity);
        }

        @Override
        protected void onPostExecute(Integer integer) {
            super.onPostExecute(integer);
        }

        @Override
        protected void onCancelled(Integer integer) {
            super.onCancelled(integer);
            if (dialog != null && dialog.isShowing()) dialog.dismiss();
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
            if (dialog != null && dialog.isShowing()) dialog.dismiss();
        }

        @Override
        protected Integer doInBackground(String... params) {
            Uri uri = Uri.parse(URL).buildUpon().appendQueryParameter("id", params[0])
                    .appendQueryParameter("source", params[1])
                    .appendQueryParameter("destination", params[2])
                    .build();

            String result = null;
            try {
                java.net.URL url = new URL(uri.toString());
                Log.d(LOG_TAG, url.toString());

                HttpGet get = new HttpGet(url.toString());

                HttpParams httpParams = new BasicHttpParams();
                HttpConnectionParams.setConnectionTimeout(httpParams, 10000);

                HttpClient client = new DefaultHttpClient(httpParams);

                HttpResponse response = client.execute(get);

                if(response == null) return null;
                HttpEntity entity = response.getEntity();
                if(entity == null) return null;
                if(response.getStatusLine().getStatusCode() == 200) {
                    result = EntityUtils.toString(entity);
                    Log.i(LOG_TAG, result);
                    Log.i(LOG_TAG, "Got data successfully");
                }<commit_msg>ready<commit_after>package com.pamulabs.pamu.supertaxi;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.TextView;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

import java.net.SocketTimeoutException;
import java.net.URL;


public class UserDetailsActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_details);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_user_details, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_user_details, container, false);
            final TextView textView = (TextView) rootView.findViewById(R.id.user_details_textview);
            Button go = (Button) rootView.findViewById(R.id.paygo);

            Intent intent = getActivity().getIntent();
            if (intent != null && intent.getExtras() != null) {
                Bundle bundle = intent.getExtras();
                if (bundle.containsKey("SOURCE") &&
                        bundle.containsKey("DESTINATION")) {
                    String source = bundle.getString("SOURCE");
                    String destination = bundle.getString("DESTINATION");
                    Long id = PreferenceManager.getDefaultSharedPreferences(getActivity()).getLong("ID", 123);
                    String text = "User with id: " + id + " starts at " + source + " ends at " + destination;
                    textView.setText(text);
                }
            }

            go.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = getActivity().getIntent();
                    if (intent != null && intent.getExtras() != null) {
                        Bundle bundle = intent.getExtras();
                        if (bundle.containsKey("SOURCE") &&
                                bundle.containsKey("DESTINATION")) {
                            String source = bundle.getString("SOURCE");
                            String destination = bundle.getString("DESTINATION");
                            Long id = PreferenceManager.getDefaultSharedPreferences(getActivity()).getLong("ID", 123);
                            String text = "User with id: " + id + " starts at " + source + " ends at "+destination;
                            textView.setText(text);
                            new PostTask(getActivity()).execute(new String[]{id.toString(), source, destination});
                        }
                    }
                }
            });
            return rootView;
        }
    }
    public static class PostTask extends AsyncTask<String, Void, Integer> {
        ProgressDialog dialog;
        Activity activity;

        String URL = "http://supertaxi.herokuapp.com/client";

        String LOG_TAG = PostTask.class.getSimpleName();

        public PostTask(Activity activity) {
            super();
            this.activity = activity;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dialog = new ProgressDialog(activity);
            dialog.show();
        }

        @Override
        protected void onPostExecute(Integer integer) {
            super.onPostExecute(integer);
        }

        @Override
        protected void onCancelled(Integer integer) {
            super.onCancelled(integer);
            if (dialog != null && dialog.isShowing()) dialog.dismiss();
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
            if (dialog != null && dialog.isShowing()) dialog.dismiss();
        }

        @Override
        protected Integer doInBackground(String... params) {
            Uri uri = Uri.parse(URL).buildUpon().appendQueryParameter("id", params[0])
                    .appendQueryParameter("source", params[1])
                    .appendQueryParameter("destination", params[2])
                    .build();

            String result = null;

            try {
                URL url = new URL(uri.toString());

                Log.d(LOG_TAG, url.toString());

                HttpGet get = new HttpGet(url.toString());

                HttpParams httpParams = new BasicHttpParams();
                HttpConnectionParams.setConnectionTimeout(httpParams, 10000);

                HttpClient client = new DefaultHttpClient(httpParams);

                HttpResponse response = client.execute(get);

                if(response == null) return null;
                HttpEntity entity = response.getEntity();
                if(entity == null) return null;
                if(response.getStatusLine().getStatusCode() == 200) {
                    result = EntityUtils.toString(entity);
                    Log.i(LOG_TAG, result);
                    Log.i(LOG_TAG, "Got data successfully");
                }
{'fraction_non_alphanumeric': 0.09743589743589744, 'fraction_numerical': 0.0026755852842809363, 'mean_word_length': 2.061660978384528, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1891578', 'n_tokens_mistral': 3411, 'n_tokens_neox': 3206, 'n_words': 758}