Skip to content
Snippets Groups Projects
Commit 00c98526 authored by melvinabraham's avatar melvinabraham
Browse files

Changed UserActivity from ComposeMail Activity and added Alert Dialog

parent eb6e507e
Branches
No related tags found
No related merge requests found
......@@ -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
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();
}
}
}
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");
FirebaseUser user = firebaseAuth.getCurrentUser();
}
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();
}
}
@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();
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
public void onClick(View v) {
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));
}
}
}
<?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>
......@@ -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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment