package com.contact;
import java.util.regex.Pattern;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class ContactusActivity extends Activity {
// Initializing variables
EditText inputName;
EditText inputEmail;
EditText inputphone;
EditText inputcomment;
ImageView iv;
public final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile(
"[a-zA-Z0-9+._%-+]{1,256}" +
"@" +
"[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" +
"(" +
"." +
"[a-zA-Z0-9][a-zA-Z0-9-]{0,25}" +
")+"
);
String regexStr = "^[0-9]$";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
inputName = (EditText) findViewById(R.id.name);
inputEmail = (EditText) findViewById(R.id.email);
inputphone = (EditText) findViewById(R.id.phone);
inputcomment = (EditText) findViewById(R.id.comment);
Button sendmail = (Button) findViewById(R.id.sendmail);
final ImageView iv= (ImageView) findViewById(R.id.test_image);
iv.setBackgroundResource(R.animator.animation);
sendmail.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
String strname=inputName.getText().toString();
String strmail=inputEmail.getText().toString();
String strphone=inputphone.getText().toString();
String strcmnt=inputcomment.getText().toString();
if(strname.length() == 0 || strmail.length() == 0
|| strphone.length() == 0 || strcmnt.length() == 0 )
{
Dialog d=new Dialog(ContactusActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("");
d.show();
//Toast toast=Toast.makeText(ContactusActivity.this, "please fill all the details.....", 7000);
//toast.setGravity(Gravity.CENTER,0,0);
// toast.show();
}
else
if(strcmnt.length() <=20) {
Dialog d=new Dialog(ContactusActivity.this);
d.setContentView(R.layout.comment);
d.setTitle("");
d.show();
}
else
if(strname.length() <=3) {
Dialog d=new Dialog(ContactusActivity.this);
d.setContentView(R.layout.name);
d.setTitle("");
d.show();
}
else
if(strphone.length() <10 || strphone.length() >10) {
Dialog d=new Dialog(ContactusActivity.this);
d.setContentView(R.layout.phone);
d.setTitle("");
d.show();
}
else{
if(checkEmail(strmail)){
String result=strname +"\n"+ strmail+"\n" + strphone+"\n" + strcmnt;
Intent mailintent = new Intent(android.content.Intent.ACTION_SEND);
mailintent.setType("text/plain");
mailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"amitk.cql@gmail.com" , "ankush.cql@gmail.com"});
mailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Please collect my info...");
mailintent.putExtra(android.content.Intent.EXTRA_TEXT, result );
startActivity(Intent.createChooser(mailintent, "Sending mail..."));
inputName.setText("");
inputEmail.setText("");
inputphone.setText("");
inputcomment.setText("");
}
else
{
Dialog d=new Dialog(ContactusActivity.this);
d.setContentView(R.layout.email);
d.setTitle("");
d.show();
}
}
}
});
// iv.setOnClickListener(new OnClickListener(){
// public void onClick(View v) {
AnimationDrawable anim= (AnimationDrawable) iv.getBackground();
anim. start();
}
// });
// }
private boolean checkEmail(String strmail) {
return EMAIL_ADDRESS_PATTERN.matcher(strmail).matches();
}
}