<commit_before>package com.sunstreaks.mypisd;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.sunstreaks.mypisd.net.DataGrabber;
import com.sunstreaks.mypisd.net.Domain;
import com.sunstreaks.mypisd.net.PISDException;

/**
 * Activity which displays a login screen to the user, offering registration as
 * well.
 */
public class LoginActivity extends Activity {


	/**
	 * The default email to populate the email field with.
	 */
	public static final String EXTRA_EMAIL = "com.example.android.authenticatordemo.extra.EMAIL";

	/**
	 * Keep track of the login task to ensure we can cancel it if requested.
	 */
	private UserLoginTask mAuthTask = null;

	// Values for email and password at the time of the login attempt.
	private String mEmail;
	private String mPassword;
	private boolean mRememberPassword;
	
	// UI references.
	private EditText mEmailView;
	private EditText mPasswordView;
	private View mLoginFormView;
	private View mLoginStatusView;
	private TextView mLoginStatusMessageView;
	private Spinner domainSpinner;
	private CheckBox rememberPassword;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_login);
		// Set up the Spinner.
		List<String> SpinnerArray =  new ArrayList<String>();
		for (Domain d : Domain.values()) {
			SpinnerArray.add(d.name());
		}
	    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, SpinnerArray);
	    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	    domainSpinner = (Spinner) findViewById(R.id.domain_spinner);
	    domainSpinner.setAdapter(adapter);
		
	    //Set up the remember_password checkbox
	    rememberPassword = (CheckBox) findViewById(R.id.remember_password);
		rememberPassword.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if (rememberPassword.isChecked()) {
						mRememberPassword = true;
					}
					else {
						mRememberPassword = false;
					}
				}
				
			});
		// Set up the login form.
		mEmail = getIntent().getStringExtra(EXTRA_EMAIL);
		mEmailView = (EditText) findViewById(R.id.email);
		//mEmailView.setText(mEmail);

		mPasswordView = (EditText) findViewById(R.id.password);
		mPasswordView
				.setOnEditorActionListener(new TextView.OnEditorActionListener() {
					@Override
					public boolean onEditorAction(TextView textView, int id,
							KeyEvent keyEvent) {
						if (id == R.id.login || id == EditorInfo.IME_NULL) {
							attemptLogin();
							return true;
						}
						return false;
					}
				});

		
		//Load stored username/password
		SharedPreferences sharedPrefs = this.getPreferences(Context.MODE_PRIVATE);
		mEmailView.setText(sharedPrefs.getString("email", mEmail));
		mPasswordView.setText(sharedPrefs.getString("password", ""));
		mRememberPassword = sharedPrefs.getBoolean("remember_password", false);
		rememberPassword.setChecked(mRememberPassword);
		try {
			domainSpinner.setSelection(sharedPrefs.getInt("domain", 0));
		} catch (IndexOutOfBoundsException e) {<commit_msg>Updated Login activity with user agreement pop up. Only allows use of app is user agrees. I'll fix the margins later. I have to do my theory book.<commit_after>package com.sunstreaks.mypisd;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.sunstreaks.mypisd.net.DataGrabber;
import com.sunstreaks.mypisd.net.Domain;
import com.sunstreaks.mypisd.net.PISDException;

/**
 * Activity which displays a login screen to the user, offering registration as
 * well.
 */
public class LoginActivity extends Activity {


	/**
	 * The default email to populate the email field with.
	 */
	public static final String EXTRA_EMAIL = "com.example.android.authenticatordemo.extra.EMAIL";

	/**
	 * Keep track of the login task to ensure we can cancel it if requested.
	 */
	private UserLoginTask mAuthTask = null;

	// Values for email and password at the time of the login attempt.
	private String mEmail;
	private String mPassword;
	private boolean mRememberPassword;
	
	// UI references.
	private EditText mEmailView;
	private EditText mPasswordView;
	private View mLoginFormView;
	private View mLoginStatusView;
	private TextView mLoginStatusMessageView;
	private Spinner domainSpinner;
	private CheckBox rememberPassword;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_login);
		final SharedPreferences sharedPrefs = this.getPreferences(Context.MODE_PRIVATE);
		if(sharedPrefs.getBoolean("FirstTime", false)== false)
		{
			//user agreement
	//		AlertDialog alertDialog = new AlertDialog.Builder(this).create();
	//		alertDialog.setTitle("User Agreement");
	//		alertDialog.setMessage("This app is provided as-is and we will not be responsible for any damage to your " +
	//				"phone. By clicking agree, you (the user), will conform to the" +
	//				"following requirements made by the us (the developers). By entering your" +
	//				"username and password in the fields, the user is giving us permission in parsing their information" +
	//				"for displaying in the app. The app is secure; however, the user assumes full responsability regarding " +
	//				"their information usage and potential damages(extremely unlikely)");
			AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
			alertDialog.setTitle("User Agreement");
			alertDialog.setMessage("This app is provided as-is and we will not be responsible for any damage to your " +
					"phone.\nBy clicking agree, you (the user), will conform to the " +
					"following requirements made by the us (the developers). By entering your " +
					"username and password in the fields, the user is giving us permission in parsing their information " +
					"for displaying in the app. The app is secure; however, the user assumes full responsibility regarding " +
					"his information usage and potential damages(extremely unlikely).");
			// Setting Positive "Yes" Button
	        alertDialog.setPositiveButton("Agree", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog,int which) {
	            	sharedPrefs.edit().putBoolean("FirstTime", true).commit();
	            	dialog.cancel();
	            }
	        });
	 
	        // Setting Negative "NO" Button
	        alertDialog.setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int which) {
	            // Write your code here to invoke NO event
	            	Toast.makeText(LoginActivity.this, "Quitting app", Toast.LENGTH_SHORT).show();
	            	finish();
	            }
	        });
	 
	        // Showing Alert Message
	        alertDialog.show();
		}
			
		// Set up the Spinner.
		List<String> SpinnerArray =  new ArrayList<String>();
		for (Domain d : Domain.values()) {
			SpinnerArray.add(d.name());
		}
	    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, SpinnerArray);
	    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	    domainSpinner = (Spinner) findViewById(R.id.domain_spinner);
	    domainSpinner.setAdapter(adapter);
		
	    //Set up the remember_password checkbox
	    rememberPassword = (CheckBox) findViewById(R.id.remember_password);
		rememberPassword.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if (rememberPassword.isChecked()) {
						mRememberPassword = true;
					}
					else {
						mRememberPassword = false;
					}
				}
				
			});
		// Set up the login form.
		mEmail = getIntent().getStringExtra(EXTRA_EMAIL);
		mEmailView = (EditText) findViewById(R.id.email);
		//mEmailView.setText(mEmail);

		mPasswordView = (EditText) findViewById(R.id.password);
		mPasswordView
				.setOnEditorActionListener(new TextView.OnEditorActionListener() {
					@Override
					public boolean onEditorAction(TextView textView, int id,
							KeyEvent keyEvent) {
						if (id == R.id.login || id == EditorInfo.IME_NULL) {
							attemptLogin();
							return true;
						}
						return false;
					}
				});

		
		//Load stored username/password
		mEmailView.setText(sharedPrefs.getString("email", mEmail));
		mPasswordView.setText(sharedPrefs.getString("password", ""));
		mRememberPassword = sharedPrefs.getBoolean("remember_password", false);
		rememberPassword.setChecked(mRememberPassword);
		try {
			domainSpinner.setSelection(sharedPrefs.getInt("domain", 0));
		} catch (IndexOutOfBoundsException e) {
{'fraction_non_alphanumeric': 0.09573770491803278, 'fraction_numerical': 0.0001873536299765808, 'mean_word_length': 4.169975786924939, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2641051', 'n_tokens_mistral': 3372, 'n_tokens_neox': 2930, 'n_words': 793}