<commit_before>/*******************************************************************************
 * Copyright 2013 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package org.sharetomail;

import org.sharetomail.util.Configuration;
import org.sharetomail.util.Constants;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class AddModifyEmailAddressActivity extends Activity {

	private Configuration config;
	private String origEmail = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_email_address);
		// Show the Up button in the action bar.
		setupActionBar();

		config = new Configuration(getSharedPreferences(
				Constants.SHARED_PREFERENCES_NAME, MODE_PRIVATE));

		final Button addModifyEmailAddressButton = (Button) findViewById(R.id.addModifyEmailAddressButton);
		final TextView emailAddressTextView = (TextView) findViewById(R.id.emailAddressTextView);

		// Custom text change listener to enable/disable the add/modify email
		// address button when the input text changes.
		emailAddressTextView.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				if (s.length() > 0) {
					addModifyEmailAddressButton.setEnabled(true);
				} else {
					addModifyEmailAddressButton.setEnabled(false);
				}
			}
		});

		addModifyEmailAddressButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// Check if the input is in email address format. If it is not
				// warn the user.
				// NOTE: The default Android Patterns.EMAIL_ADDRESS does not
				// seems to be handling user@host (host without TLD) so we try
				// to workaround this here by appending a ".com" string.
				String inputText = emailAddressTextView.getText().toString()
						.trim();
				if (isInEmailFormat(inputText)
						|| isInEmailFormat(inputText + ".com")) {
					if (origEmail != null) {
						int position = -1;
						for (int i = 0; i < config.getEmailAddresses().size(); i++) {
							if (origEmail.equals(config.getEmailAddresses()
									.get(i))) {
								position = i;
								break;
							}
						}

						// TODO: original email address was not found (somebody
						// removed it in the mean time?) so we add it.
						if (position < 0) {
							config.addEmailAddress(inputText);
						}

						config.setEmailAddress(position, inputText);
					} else {
						config.addEmailAddress(inputText);
					}

					setResult(Activity.RESULT_OK, getIntent());
					finish();
				} else {
					Toast.makeText(
							AddModifyEmailAddressActivity.this,<commit_msg>remove todo<commit_after>/*******************************************************************************
 * Copyright 2013 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package org.sharetomail;

import org.sharetomail.util.Configuration;
import org.sharetomail.util.Constants;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class AddModifyEmailAddressActivity extends Activity {

	private Configuration config;
	private String origEmail = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_email_address);
		// Show the Up button in the action bar.
		setupActionBar();

		config = new Configuration(getSharedPreferences(
				Constants.SHARED_PREFERENCES_NAME, MODE_PRIVATE));

		final Button addModifyEmailAddressButton = (Button) findViewById(R.id.addModifyEmailAddressButton);
		final TextView emailAddressTextView = (TextView) findViewById(R.id.emailAddressTextView);

		// Custom text change listener to enable/disable the add/modify email
		// address button when the input text changes.
		emailAddressTextView.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				if (s.length() > 0) {
					addModifyEmailAddressButton.setEnabled(true);
				} else {
					addModifyEmailAddressButton.setEnabled(false);
				}
			}
		});

		addModifyEmailAddressButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// Check if the input is in email address format. If it is not
				// warn the user.
				// NOTE: The default Android Patterns.EMAIL_ADDRESS does not
				// seems to be handling user@host (host without TLD) so we try
				// to workaround this here by appending a ".com" string.
				String inputText = emailAddressTextView.getText().toString()
						.trim();
				if (isInEmailFormat(inputText)
						|| isInEmailFormat(inputText + ".com")) {
					if (origEmail != null) {
						int position = -1;
						for (int i = 0; i < config.getEmailAddresses().size(); i++) {
							if (origEmail.equals(config.getEmailAddresses()
									.get(i))) {
								position = i;
								break;
							}
						}

						// Original email address was not found (somebody
						// removed it in the mean time?) so we add it.
						if (position < 0) {
							config.addEmailAddress(inputText);
						}

						config.setEmailAddress(position, inputText);
					} else {
						config.addEmailAddress(inputText);
					}

					setResult(Activity.RESULT_OK, getIntent());
					finish();
				} else {
					Toast.makeText(
							AddModifyEmailAddressActivity.this,
{'fraction_non_alphanumeric': 0.12870394228291676, 'fraction_numerical': 0.0033496521515073434, 'mean_word_length': 3.777230769230769, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6541403', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2067, 'n_words': 641}