<commit_before>package com.psu.shoppinglist;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.AsyncTask;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import ai.api.model.Result;
import ai.api.AIConfiguration;
import ai.api.AIDataService;
import ai.api.model.AIRequest;
import ai.api.AIServiceException;
import ai.api.AIListener;
import ai.api.AIService;
import ai.api.model.AIError;
import ai.api.model.AIResponse;
import ai.api.model.Result;
import com.google.gson.JsonElement;


public class ManageListActivity extends AppCompatActivity {
    String listName;
    ShoppingList sl;
    final int MAX_NUM_ITEMS = 100; //allow a max of 100 items on the list!
    private static final int SPEECH_REQUEST_CODE = 0;
    TextToSpeech t1;
    int numItem;
    Boolean noToast;

    String menuHelp = "This is the Manage List Activity page. \n\nYou can Add, Remove, Count items, Or go back to the Main Menu. " +
            "Use the following commands: " +
            "\n\n\t- Add apples." +
            "\n\t- Remove apples." +
            "\n\t- Count items." +
            "\n\t- Back to Main Menu." +
            "\n\t- Exit." +
            "\n\t- Who created this app?" +
            "\n\nThese functions are also accessible from the overflow menu.";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manage_list);
        Intent intent = getIntent();
        listName = intent.getExtras().getString("listName", "Error");
        sl = new ShoppingList(listName, null);
        setTitle(listName);

        if(getIntent().getStringExtra("methodName") != null){
            String item = intent.getStringExtra("item");
            String result = addItem(item);
            listItems();
            initializeSpeech(result, true);
        } else {
            initializeSpeech(listName, false);
            listItems();
        }
    }

    /**
     * Receiving speech input
     * */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
            List<String> results = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            String spokenText = results.get(0);
            makeAPIRequest(spokenText);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    protected void makeAPIRequest(String speech) {

        //Log.v ("----API req:", speech + ".");
        final AIRequest aiRequest = new AIRequest();
        final AIConfiguration config = new AIConfiguration("903fe05ba6064111aed341dc9c051e59",
                AIConfiguration.SupportedLanguages.English,
                AIConfiguration.RecognitionEngine.System);

        final AIDataService aiDataService = new AIDataService(this, config);
        aiRequest.setQuery(speech);

        new AsyncTask<AIRequest, Void, AIResponse>() {
            @Override
            protected AIResponse doInBackground(AIRequest... requests) {
                final AIRequest request = requests[0];
                try {
                    final AIResponse response = aiDataService.request(aiRequest);
                    return response;
                } catch (AIServiceException e) {
                    e.printStackTrace();
                }
                return null;
            }
            @Override
            protected void onPostExecute(AIResponse aiResponse) {
                if (aiResponse != null) {
                    Result result = aiResponse.getResult();

                    // Get parameters
                /*    String parameterString = "";
                    if (result.getParameters() != null && !result.getParameters().isEmpty()) {
                        for (final Map.Entry<String, JsonElement> entry : result.getParameters().entrySet()) {
                            parameterString += "(" + entry.getKey() + ", " + entry.getValue() + ") ";
                        }
                    }*/

                    // Need to decide what to do with our response:
                    String intent = result.getMetadata().getIntentName();
                    String response = " ";
                    //Log.v ("-----------API: ", intent + ".");

                    if (intent == null) {<commit_msg>Fixed small talk bug from list activity.<commit_after>package com.psu.shoppinglist;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.AsyncTask;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import ai.api.model.Result;
import ai.api.AIConfiguration;
import ai.api.AIDataService;
import ai.api.model.AIRequest;
import ai.api.AIServiceException;
import ai.api.AIListener;
import ai.api.AIService;
import ai.api.model.AIError;
import ai.api.model.AIResponse;
import ai.api.model.Result;
import com.google.gson.JsonElement;


public class ManageListActivity extends AppCompatActivity {
    String listName;
    ShoppingList sl;
    final int MAX_NUM_ITEMS = 100; //allow a max of 100 items on the list!
    private static final int SPEECH_REQUEST_CODE = 0;
    TextToSpeech t1;
    int numItem;
    Boolean noToast;

    String menuHelp = "This is the Manage List Activity page. \n\nYou can Add, Remove, Count items, Or go back to the Main Menu. " +
            "Use the following commands: " +
            "\n\n\t- Add apples." +
            "\n\t- Remove apples." +
            "\n\t- Count items." +
            "\n\t- Back to Main Menu." +
            "\n\t- Exit." +
            "\n\t- Who created this app?" +
            "\n\nThese functions are also accessible from the overflow menu.";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manage_list);
        Intent intent = getIntent();
        listName = intent.getExtras().getString("listName", "Error");
        sl = new ShoppingList(listName, null);
        setTitle(listName);

        if(getIntent().getStringExtra("methodName") != null){
            String item = intent.getStringExtra("item");
            String result = addItem(item);
            listItems();
            initializeSpeech(result, true);
        } else {
            initializeSpeech(listName, false);
            listItems();
        }
    }

    /**
     * Receiving speech input
     * */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
            List<String> results = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            String spokenText = results.get(0);
            makeAPIRequest(spokenText);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    protected void makeAPIRequest(String speech) {

        //Log.v ("----API req:", speech + ".");
        final AIRequest aiRequest = new AIRequest();
        final AIConfiguration config = new AIConfiguration("903fe05ba6064111aed341dc9c051e59",
                AIConfiguration.SupportedLanguages.English,
                AIConfiguration.RecognitionEngine.System);

        final AIDataService aiDataService = new AIDataService(this, config);
        aiRequest.setQuery(speech);

        new AsyncTask<AIRequest, Void, AIResponse>() {
            @Override
            protected AIResponse doInBackground(AIRequest... requests) {
                final AIRequest request = requests[0];
                try {
                    final AIResponse response = aiDataService.request(aiRequest);
                    return response;
                } catch (AIServiceException e) {
                    e.printStackTrace();
                }
                return null;
            }
            @Override
            protected void onPostExecute(AIResponse aiResponse) {
                if (aiResponse != null) {
                    Result result = aiResponse.getResult();
                    noToast = false;

                    // Get parameters
                /*    String parameterString = "";
                    if (result.getParameters() != null && !result.getParameters().isEmpty()) {
                        for (final Map.Entry<String, JsonElement> entry : result.getParameters().entrySet()) {
                            parameterString += "(" + entry.getKey() + ", " + entry.getValue() + ") ";
                        }
                    }*/

                    // Need to decide what to do with our response:
                    String intent = result.getMetadata().getIntentName();
                    String response = " ";
                    //Log.v ("-----------API: ", intent + ".");

                    if (intent == null) {
{'fraction_non_alphanumeric': 0.10486641221374046, 'fraction_numerical': 0.006297709923664122, 'mean_word_length': 2.2539583980130393, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6539845', 'n_tokens_mistral': 2836, 'n_tokens_neox': 2694, 'n_words': 680}