// Path: src/org/sagemath/droid/exceptions/SageInterruptedException.java
// public class SageInterruptedException extends Exception {
//     private static final long serialVersionUID = -5638564842011063160L;
// }


import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.widget.TextView;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.sagemath.droid.R;
import org.sagemath.droid.exceptions.SageInterruptedException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
                /*
				int port = 10080;
				URI termsURI = new URI(tosURI.getScheme(), tosURI.getUserInfo(), tosURI.getHost(), port, 
						tosURI.getPath(), tosURI.getQuery(), tosURI.getFragment());
				Log.i(TAG, "Terms URI: " + termsURI.toString());
				*/
                HttpGet termsGet = new HttpGet();
                termsGet.setURI(tosURI);

                DefaultHttpClient termsHttpClient = new DefaultHttpClient();
                HttpResponse termsResponse = termsHttpClient.execute(termsGet);
                InputStream termsStream = termsResponse.getEntity().getContent();

                termsString = streamToString(termsStream);
            } catch (Exception e) {
                Log.e(TAG, "Error while getting EULA text." + e.getLocalizedMessage());
            }
            return termsString;
        }

        protected void onPostExecute(String html) {
            try {
                show(html);
            } catch (Exception e) {
                Log.e(TAG, "Error showing terms: " + e.getLocalizedMessage());
            }

        }
    }

// Path: src/org/sagemath/droid/exceptions/SageInterruptedException.java
// public class SageInterruptedException extends Exception {
//     private static final long serialVersionUID = -5638564842011063160L;
// }


// Path: src/org/sagemath/droid/utils/SimpleEula.java
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.widget.TextView;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.sagemath.droid.R;
import org.sagemath.droid.exceptions.SageInterruptedException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;

                /*
				int port = 10080;
				URI termsURI = new URI(tosURI.getScheme(), tosURI.getUserInfo(), tosURI.getHost(), port, 
						tosURI.getPath(), tosURI.getQuery(), tosURI.getFragment());
				Log.i(TAG, "Terms URI: " + termsURI.toString());
				*/
                HttpGet termsGet = new HttpGet();
                termsGet.setURI(tosURI);

                DefaultHttpClient termsHttpClient = new DefaultHttpClient();
                HttpResponse termsResponse = termsHttpClient.execute(termsGet);
                InputStream termsStream = termsResponse.getEntity().getContent();

                termsString = streamToString(termsStream);
            } catch (Exception e) {
                Log.e(TAG, "Error while getting EULA text." + e.getLocalizedMessage());
            }
            return termsString;
        }

        protected void onPostExecute(String html) {
            try {
                show(html);
            } catch (Exception e) {
                Log.e(TAG, "Error showing terms: " + e.getLocalizedMessage());
            }

        }
    }

    public void show(String termsHTML) throws IOException, SageInterruptedException, JSONException, URISyntaxException {