package com.ids1024.whitakerswords;

import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import java.lang.RuntimeException;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.os.Bundle;

import android.util.Log;

public class WhitakersWords extends Activity
{
    /** Called when the activity is first created. */

    public void copyFiles() throws IOException {
        String[] filenames = {"ADDONS.LAT", "DICTFILE.GEN", "EWDSFILE.GEN",
                "INDXFILE.GEN", "INFLECTS.SEC", "STEMFILE.GEN",
                "UNIQUES.LAT", "words"};
        for (String filename: filenames) {
            // Note: Android does not accept upper case in resource names, so it is converted
            // And file extensions are stripped, so remove that
            String resourcename = filename.toLowerCase();
            if (resourcename.contains(".")) { 
                resourcename = resourcename.substring(0, filename.lastIndexOf('.'));
            }

            int identifier = getResources().getIdentifier(resourcename, "raw", getPackageName());
            InputStream ins = getResources().openRawResource(identifier);
            byte[] buffer = new byte[ins.available()];
            ins.read(buffer);
            ins.close();
            FileOutputStream fos = openFileOutput(filename, MODE_PRIVATE);
            fos.write(buffer);
            fos.close();
        }
        File wordsbin = getFileStreamPath("words");
        wordsbin.setExecutable(true);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            copyFiles();
        } catch(IOException e) {
                throw new RuntimeException(e.getMessage());
        }
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        switch (item.getItemId()) {
            case R.id.action_search:
                // TODO
                return true;
            case R.id.action_settings:
		// TODO
                return true;
            default:
                return super.onOptionsItemSelected(item);
    }
}
}

@@ -50,32 +50,97 @@
 io.InputStream;%0A
+import java.io.InputStreamReader;%0Aimport java.io.BufferedReader;%0A
 import java.io.F
@@ -236,24 +236,63 @@
 eException;%0A
+import java.lang.InterruptedException;%0A
 import andro
@@ -308,16 +308,42 @@
 tivity;%0A
+import android.view.View;%0A
 import a
@@ -443,43 +443,81 @@
 oid.
-os.Bundle;%0A%0Aimport android.util.Log
+widget.TextView;%0Aimport android.widget.EditText;%0Aimport android.os.Bundle
 ;%0A%0Ap
@@ -1765,32 +1765,1542 @@
 e(true);%0A    %7D%0A%0A
+    public String executeWords(String text, boolean fromenglish) %7B%0A        String wordspath = getFilesDir().getPath() + %22/words%22;%0A        Process process;%0A        try %7B%0A            if (fromenglish) %7B%0A                String%5B%5D command = %7Bwordspath, %22~E%22, text%7D;%0A                process = Runtime.getRuntime().exec(command, null, getFilesDir());%0A            %7D else %7B%0A                String%5B%5D command = %7Bwordspath, text%7D;%0A                process = Runtime.getRuntime().exec(command, null, getFilesDir());%0A            %7D%0A%0A            BufferedReader reader = new BufferedReader(%0A                new InputStreamReader(process.getInputStream()));%0A            int read;%0A            char%5B%5D buffer = new char%5B4096%5D;%0A            StringBuffer output = new StringBuffer();%0A            while ((read = reader.read(buffer)) %3E 0) %7B%0A                output.append(buffer, 0, read);%0A            %7D%0A            %0A            reader.close();%0A            process.waitFor();%0A%0A            return output.toString();%0A%0A        %7D catch(IOException e) %7B%0A            throw new RuntimeException(e.getMessage());%0A        %7D catch(InterruptedException e) %7B%0A            throw new RuntimeException(e.getMessage());%0A        %7D%0A    %7D%0A%0A    public void searchWord(View view) %7B%0A        TextView result_text = (TextView)findViewById(R.id.result_text);%0A        EditText search_term = (EditText)findViewById(R.id.search_term);%0A        String term = search_term.getText().toString();%0A        result_text.setText((CharSequence)executeWords(term, false));%0A    %7D%0A%0A
     @Override%0A  
@@ -4269,14 +4269,22 @@
 m);%0A    
-%7D%0A
+    %7D%0A    
 %7D%0A%7D%0A

Make searching possible