From 00c985264405c15409c08c2ab17f5117b9878760 Mon Sep 17 00:00:00 2001 From: melvinabraham <melvin.abraham1996@gmail.com> Date: Wed, 22 Feb 2017 21:26:30 +0530 Subject: [PATCH] Changed UserActivity from ComposeMail Activity and added Alert Dialog --- app/src/main/AndroidManifest.xml | 5 +- .../java/com/mapps/seproject/ComposeMail.java | 227 ++++++++++++++++++ .../com/mapps/seproject/UserActivity.java | 163 ++----------- .../main/res/layout/activity_compose_mail.xml | 52 ++++ app/src/main/res/layout/activity_user.xml | 40 +-- 5 files changed, 306 insertions(+), 181 deletions(-) create mode 100644 app/src/main/java/com/mapps/seproject/ComposeMail.java create mode 100644 app/src/main/res/layout/activity_compose_mail.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 002195d..f1a5b4b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mapps.seproject"> - <uses-permission android:name="android.permission.INTERNET"/> + <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" @@ -18,7 +18,8 @@ </intent-filter> </activity> <activity android:name=".RegisterActivity" /> - <activity android:name=".UserActivity"></activity> + <activity android:name=".UserActivity" /> + <activity android:name=".ComposeMail"></activity> </application> </manifest> \ No newline at end of file diff --git a/app/src/main/java/com/mapps/seproject/ComposeMail.java b/app/src/main/java/com/mapps/seproject/ComposeMail.java new file mode 100644 index 0000000..22b79ae --- /dev/null +++ b/app/src/main/java/com/mapps/seproject/ComposeMail.java @@ -0,0 +1,227 @@ +package com.mapps.seproject; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.provider.MediaStore; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +public class ComposeMail extends AppCompatActivity implements View.OnClickListener{ + + + int flag =0; + Button bComposeMail; + Spinner dropdown; + TextView emailText; + + Button bAddImage; + Uri imageUri; + private static int RESULT_LOAD_IMAGE = 1; + private static int RESULT_MAIL = 2; + + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_compose_mail); + + + + + bComposeMail = (Button) findViewById(R.id.bComposeMail); + emailText = (TextView) findViewById(R.id.tvEmailMessage); + bAddImage = (Button) findViewById(R.id.bAddImage); + + // Get user + dropdown = (Spinner) findViewById(R.id.spSelectCitiy); + String [] items = new String[]{"Coimbatore","Chennai"}; + ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,items); + dropdown.setAdapter(arrayAdapter); + + + + + + bAddImage.setOnClickListener(this); + bComposeMail.setOnClickListener(this); + dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + + switch (position) { + + case 0: + // setCityCoimbatore(); + Log.i("City: ","Coimbatore"); + flag =0; + break; + + case 1: + // setCityChennai(); + Log.i("City:","Chennai"); + flag = 1; + break; + + } + + + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + + } + }); + + + + + + + } + + + + public void composeEmail() { + + Log.i("Sending Email",""); + String[] TO; + if (flag == 0) { + + TO = new String[]{"commr.coimbatore@tn.gov.in"}; + + } + else { + TO = new String[]{"mayor@chennaicorporation.gov.in"}; + } + String [] CC = {""}; + + String mailText = emailText.getText().toString(); + + + Intent emailIntent = new Intent(Intent.ACTION_SEND); + + emailIntent.setData(Uri.parse("mailto")); + emailIntent.setType("text/plain"); + emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); + if ( flag == 0) { + emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Regarding cleanliness in Coimbatore"); + } + else { + emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Regarding cleanliness in Chennai"); + + } + emailIntent.putExtra(Intent.EXTRA_TEXT,mailText); + emailIntent.setType("application/image"); + emailIntent.putExtra(Intent.EXTRA_STREAM,imageUri); + + try { + + startActivityForResult(Intent.createChooser(emailIntent,"Send Mail..."),2); + + 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 == bComposeMail) { + + + Log.i("Clicked","Compose"); + composeEmail(); + + + } + + if(v == bAddImage) { + + Intent cameraIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI); + startActivityForResult(cameraIntent,RESULT_LOAD_IMAGE); + + } + + + + + } + + + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data!=null) { + + imageUri = data.getData(); + Toast.makeText(this, "Image Added. Press Compose to transfer to Mail Window", Toast.LENGTH_SHORT).show(); + + } + + if(requestCode == RESULT_MAIL) { + + new AlertDialog.Builder(this) + .setTitle("Select action") + .setMessage("Do you want to go back?") + .setPositiveButton("Yes", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + startActivity(new Intent(getApplicationContext(),UserActivity.class)); + } + }) + .setNegativeButton("No", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + return; + } + }).show(); + + } + + + } + + + + + + + + + + + + +} diff --git a/app/src/main/java/com/mapps/seproject/UserActivity.java b/app/src/main/java/com/mapps/seproject/UserActivity.java index 9ecd79f..bbd0b95 100644 --- a/app/src/main/java/com/mapps/seproject/UserActivity.java +++ b/app/src/main/java/com/mapps/seproject/UserActivity.java @@ -1,5 +1,6 @@ package com.mapps.seproject; +import android.app.ProgressDialog; import android.content.Intent; import android.media.Image; import android.net.Uri; @@ -21,17 +22,11 @@ import com.google.firebase.auth.FirebaseUser; public class UserActivity extends AppCompatActivity implements View.OnClickListener { - FirebaseAuth firebaseAuth; Button bSignOut; - Button bComposeMail; TextView welcome; - Spinner dropdown; - TextView emailText; - int flag =0; - Button bAddImage; - Uri imageUri; + FirebaseAuth firebaseAuth; + Button bComposeScreen; - private static int RESULT_LOAD_IMAGE = 1; @Override protected void onCreate(Bundle savedInstanceState) { @@ -40,13 +35,6 @@ public class UserActivity extends AppCompatActivity implements View.OnClickListe setContentView(R.layout.activity_user); - welcome = (TextView) findViewById(R.id.tvWelcome); - bSignOut = (Button) findViewById(R.id.bSignOut); - bComposeMail = (Button) findViewById(R.id.bComposeMail); - emailText = (TextView) findViewById(R.id.tvEmailMessage); - bAddImage = (Button) findViewById(R.id.bAddImage); - - firebaseAuth = FirebaseAuth.getInstance(); @@ -57,156 +45,37 @@ public class UserActivity extends AppCompatActivity implements View.OnClickListe } - FirebaseUser user = firebaseAuth.getCurrentUser(); // Get user - welcome.setText("Welcome "+user.getEmail()); // Get Email - - dropdown = (Spinner) findViewById(R.id.spSelectCitiy); - String [] items = new String[]{"Coimbatore","Chennai"}; - ArrayAdapter <String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,items); - dropdown.setAdapter(arrayAdapter); - - - - - - bAddImage.setOnClickListener(this); - bSignOut.setOnClickListener(this); // Start listener on Button - bComposeMail.setOnClickListener(this); - dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { - - switch (position) { - - case 0: - // setCityCoimbatore(); - Log.i("City: ","Coimbatore"); - flag =0; - break; - - case 1: - // setCityChennai(); - Log.i("City:","Chennai"); - flag = 1; - break; - - } - - - } - - @Override - public void onNothingSelected(AdapterView<?> parent) { - - } - }); - - - } - - - public void composeEmail() { - - Log.i("Sending Email",""); - String[] TO; - if (flag == 0) { - - TO = new String[]{"commr.coimbatore@tn.gov.in"}; - - } - else { - TO = new String[]{"mayor@chennaicorporation.gov.in"}; - } - String [] CC = {""}; - - String mailText = emailText.getText().toString(); - - - Intent emailIntent = new Intent(Intent.ACTION_SEND); - - emailIntent.setData(Uri.parse("mailto")); - emailIntent.setType("text/plain"); - emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); - if ( flag == 0) { - emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Regarding cleanliness in Coimbatore"); - } - else { - emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Regarding cleanliness in Chennai"); - - } - emailIntent.putExtra(Intent.EXTRA_TEXT,mailText); - emailIntent.setType("application/image"); - emailIntent.putExtra(Intent.EXTRA_STREAM,imageUri); - - 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(); - } - + FirebaseUser user = firebaseAuth.getCurrentUser(); + welcome = (TextView) findViewById(R.id.tvWelcome); + welcome.setText("Welcome "+user.getEmail()); // Get Email' + bSignOut = (Button) findViewById(R.id.bSignOut); + bSignOut.setOnClickListener(this); + bComposeScreen = (Button) findViewById(R.id.bGotoCompose); + bComposeScreen.setOnClickListener(this); } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data!=null) { - - imageUri = data.getData(); - - - } - - - - } - @Override public void onClick(View v) { - if(v == bSignOut) { + if(v == bSignOut) { + firebaseAuth.signOut(); // sign out finish(); - startActivity(new Intent(this,LoginActivity.class)); // Go back to login activity - - } - - if(v == bComposeMail) { - - - Log.i("Clicked","Compose"); - composeEmail(); + startActivity(new Intent(this,LoginActivity.class)); // Go back to login activitys } - if(v == bAddImage) { + if(v == bComposeScreen) { - Intent cameraIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI); - startActivityForResult(cameraIntent,RESULT_LOAD_IMAGE); + finish(); + startActivity(new Intent(this,ComposeMail.class)); } - - - - } - - } diff --git a/app/src/main/res/layout/activity_compose_mail.xml b/app/src/main/res/layout/activity_compose_mail.xml new file mode 100644 index 0000000..1aedbe9 --- /dev/null +++ b/app/src/main/res/layout/activity_compose_mail.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/activity_compose_mail" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + tools:context="com.mapps.seproject.ComposeMail"> + + <Spinner + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/spSelectCitiy" + android:layout_marginTop="11dp" + android:layout_alignParentTop="true" + android:layout_alignParentStart="true" /> + + <Button + android:text="Compose Email" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/bComposeMail" + android:layout_alignParentBottom="true" + android:layout_alignParentStart="true" + android:layout_marginBottom="16dp" + android:layout_alignParentEnd="true" /> + + <Button + android:text="Add Image" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/bAddImage" + android:layout_above="@+id/bComposeMail" + android:layout_alignParentStart="true" /> + + <EditText + android:layout_width="match_parent" + android:inputType="textPersonName" + android:ems="10" + android:id="@+id/tvEmailMessage" + android:visibility="visible" + android:layout_height="280dp" + android:layout_above="@+id/bAddImage" + android:layout_alignParentStart="true" + android:layout_marginBottom="19dp" + android:hint="Enter your complaint here" /> + + +</RelativeLayout> diff --git a/app/src/main/res/layout/activity_user.xml b/app/src/main/res/layout/activity_user.xml index 710493b..d5a5520 100644 --- a/app/src/main/res/layout/activity_user.xml +++ b/app/src/main/res/layout/activity_user.xml @@ -24,43 +24,19 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/bSignOut" - android:layout_alignParentTop="true" + android:layout_marginBottom="116dp" + android:layout_alignParentBottom="true" + android:layout_alignParentStart="true" android:layout_alignParentEnd="true" /> - <Spinner + <Button + android:text="Compose E-Mail" android:layout_width="match_parent" android:layout_height="wrap_content" - android:id="@+id/spSelectCitiy" - android:layout_marginTop="31dp" - android:layout_below="@+id/bSignOut" + android:layout_marginBottom="10dp" + android:id="@+id/bGotoCompose" + android:layout_above="@+id/bSignOut" android:layout_alignParentStart="true" /> - <Button - android:text="Add Image" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:id="@+id/bAddImage" - android:layout_above="@+id/bComposeMail" - android:layout_alignEnd="@+id/bComposeMail" - android:layout_alignStart="@+id/bComposeMail" /> - - <Button - android:text="Compose Email" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:id="@+id/bComposeMail" - android:layout_alignParentBottom="true" - android:layout_centerHorizontal="true" /> - - <EditText - android:layout_width="match_parent" - android:layout_height="250dp" - android:inputType="textPersonName" - android:ems="10" - android:layout_centerVertical="true" - android:layout_centerHorizontal="true" - android:id="@+id/tvEmailMessage" - android:hint="Enter your complaint here" - android:visibility="visible" /> </RelativeLayout> -- GitLab