From 74c5ae00917e99031fe617d044984a5c963bbf5a Mon Sep 17 00:00:00 2001
From: melvinabraham <melvin.abraham1996@gmail.com>
Date: Sun, 19 Feb 2017 03:31:26 +0530
Subject: [PATCH] Basic EMail Integration

---
 .../com/mapps/seproject/UserActivity.java     | 62 +++++++++++++++++--
 app/src/main/res/layout/activity_user.xml     | 25 +++++---
 2 files changed, 75 insertions(+), 12 deletions(-)

diff --git a/app/src/main/java/com/mapps/seproject/UserActivity.java b/app/src/main/java/com/mapps/seproject/UserActivity.java
index 2cc7182..674f1cc 100644
--- a/app/src/main/java/com/mapps/seproject/UserActivity.java
+++ b/app/src/main/java/com/mapps/seproject/UserActivity.java
@@ -1,11 +1,14 @@
 package com.mapps.seproject;
 
 import android.content.Intent;
+import android.net.Uri;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.View;
 import android.widget.Button;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.google.firebase.auth.FirebaseAuth;
 import com.google.firebase.auth.FirebaseUser;
@@ -13,7 +16,8 @@ import com.google.firebase.auth.FirebaseUser;
 public class UserActivity extends AppCompatActivity implements View.OnClickListener {
 
     FirebaseAuth firebaseAuth;
-    Button button;
+    Button bSignOut;
+    Button bComposeMail;
     TextView welcome;
 
     @Override
@@ -22,7 +26,9 @@ public class UserActivity extends AppCompatActivity implements View.OnClickListe
         setContentView(R.layout.activity_user);
 
         welcome = (TextView) findViewById(R.id.tvWelcome);
-        button = (Button) findViewById(R.id.bSignOut);
+        bSignOut = (Button) findViewById(R.id.bSignOut);
+        bComposeMail = (Button) findViewById(R.id.bComposeMail);
+
         firebaseAuth = FirebaseAuth.getInstance();
 
 
@@ -37,20 +43,59 @@ public class UserActivity extends AppCompatActivity implements View.OnClickListe
         welcome.setText("Welcome "+user.getEmail());                                        // Get Email
 
 
-        button.setOnClickListener(this);                                                    // Start listener on Button
+        bSignOut.setOnClickListener(this);                                                    // Start listener on Button
+        bComposeMail.setOnClickListener(this);
+
+
+    }
+
+
+    public void composeEmail()  {
+
+        Log.i("Sending Email","");
+        String [] TO = {""};
+        String [] CC = {""};
+
+        Intent emailIntent = new Intent(Intent.ACTION_SEND);
+
+        emailIntent.setData(Uri.parse("mailto"));
+        emailIntent.setType("text/plain");
+        emailIntent.putExtra(Intent.EXTRA_EMAIL,TO);
+        emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Your Subject");
+        emailIntent.putExtra(Intent.EXTRA_TEXT,"Type your text here");
+
+        try {
+
+            startActivity(Intent.createChooser(emailIntent,"Send Mail..."));
+            Log.i("Finished","");
+
+        }
+
+        catch (android.content.ActivityNotFoundException ex)    {
 
+            Toast.makeText(getApplicationContext(), "There is no email client installed.", Toast.LENGTH_SHORT).show();
 
+        }
+        catch (Exception e) {
 
+            e.printStackTrace();
+        }
 
 
 
 
     }
 
+
+
+
+
+
+
     @Override
     public void onClick(View v) {
 
-        if(v == button) {
+        if(v == bSignOut) {
 
             firebaseAuth.signOut();                                                         // sign out
             finish();
@@ -58,6 +103,15 @@ public class UserActivity extends AppCompatActivity implements View.OnClickListe
 
         }
 
+        if(v == bComposeMail)   {
+
+
+            Log.i("Clicked","Compose");
+            composeEmail();
+
+
+        }
+
 
 
 
diff --git a/app/src/main/res/layout/activity_user.xml b/app/src/main/res/layout/activity_user.xml
index 59ddcc0..f846daa 100644
--- a/app/src/main/res/layout/activity_user.xml
+++ b/app/src/main/res/layout/activity_user.xml
@@ -10,21 +10,30 @@
     android:paddingTop="@dimen/activity_vertical_margin"
     tools:context="com.mapps.seproject.UserActivity">
 
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="28dp"
+        android:id="@+id/tvWelcome"
+        android:textSize="24sp"
+        android:layout_alignParentTop="true"
+        android:layout_centerHorizontal="true" />
+
     <Button
         android:text="Sign Out"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_marginBottom="10dp"
+        android:id="@+id/bSignOut"
         android:layout_alignParentBottom="true"
-        android:layout_centerHorizontal="true"
-        android:layout_marginBottom="98dp"
-        android:id="@+id/bSignOut" />
+        android:layout_centerHorizontal="true" />
 
-    <TextView
+    <Button
+        android:text="Compose Email"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_alignParentTop="true"
+        android:layout_below="@+id/tvWelcome"
         android:layout_centerHorizontal="true"
-        android:layout_marginTop="102dp"
-        android:id="@+id/tvWelcome"
-        android:textSize="24sp" />
+        android:layout_marginTop="27dp"
+        android:id="@+id/bComposeMail" />
 </RelativeLayout>
-- 
GitLab