package com.angrave.week6;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	private EditText mName;
	private EditText mPhone;
	private EditText mEmail;
	private EditText mComments;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mName = (EditText) findViewById(R.id.name);
		mPhone = (EditText) findViewById(R.id.phone);
		mEmail = (EditText) findViewById(R.id.email);
		mComments = (EditText) findViewById(R.id.comments);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	public void launch(View button) {
		String comments = mComments.getText().toString();
		String email = mEmail.getText().toString();
		String phone = mPhone.getText().toString();
		String name = mName.getText().toString();
		int position = 0;
		
		try {
			position = email.indexOf("@");
			if (position == -1) {
				Toast.makeText(this.getApplicationContext(), "Invalid email!", Toast.LENGTH_LONG).show();
				mEmail.requestFocus();
				return;
			}
		}
		catch (Exception e) {
			Log.d("exception", e.toString());
		}
		
		String username = email.substring(0, position);
		String thanks = "Thank you " + username + "!";
		
		Toast.makeText(this.getApplicationContext(), thanks, Toast.LENGTH_LONG).show();
		
		Animation anim = AnimationUtils.makeOutAnimation(this, true);
		button.startAnimation(anim);
		button.setVisibility(View.INVISIBLE);
		Toast.makeText(this.getApplicationContext(), R.string.app_name, Toast.LENGTH_LONG).show();
		Intent i = new Intent(Intent.ACTION_SEND);
		i.setType("text/plain");
		i.putExtra(Intent.EXTRA_TEXT, "What an app");
		startActivity(i);
	}

}

@@ -21,16 +21,40 @@
 week6;%0A%0A
+import android.net.Uri;%0A
 import a
@@ -1996,16 +1996,19 @@
 show();%0A
+%09%09%0A
 %09%09Intent
@@ -2045,68 +2045,392 @@
 SEND
-);%0A%09%09i.setType(%22text/plain%22);%0A%09%09i.putExtra(Intent.EXTRA_TEXT
+TO,%0A%09%09%09%09Uri.fromParts(%22mailtp%22, %22someone@somewhere%22, null)%0A%09%09%09);%0A%09%09i.putExtra(Intent.EXTRA_SUBJECT, %22important news%22);%0A%09%09i.putExtra(Intent.EXTRA_TEXT, name + %22 says %22 + comments);%0A%09%09startActivity(Intent.createChooser(i, %22Select your email app%22));%0A%09%09%0A//%09%09Intent i = new Intent(Intent.ACTION_SEND);%0A//%09%09i.setType(%22text/plain%22);%0A//%09%09i.setData(Uri.parse(phone));%0A//%09%09i.putExtra(%22sms_body%22
 , %22W
@@ -2443,16 +2443,18 @@
  app%22);%0A
+//
 %09%09startA

email Intent