Advertisement
Guest User

Untitled

a guest
Oct 21st, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.27 KB | None | 0 0
  1. package com.ananta.mastermind.mail5;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.BroadcastReceiver;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.IntentFilter;
  8. import android.net.ConnectivityManager;
  9. import android.net.NetworkInfo;
  10. import android.os.AsyncTask;
  11. import android.os.Bundle;
  12. import android.support.v7.app.AppCompatActivity;
  13. import android.support.v7.widget.Toolbar;
  14. import android.util.Log;
  15. import android.view.Menu;
  16. import android.view.MenuItem;
  17. import android.view.View;
  18. import android.view.View.OnClickListener;
  19. import android.widget.Adapter;
  20. import android.widget.ArrayAdapter;
  21. import android.widget.Button;
  22. import android.widget.EditText;
  23. import android.widget.RadioButton;
  24. import android.widget.RadioGroup;
  25.  
  26. import android.widget.Spinner;
  27. import android.widget.Toast;
  28.  
  29. import java.util.Properties;
  30.  
  31. import javax.mail.Authenticator;
  32. import javax.mail.Message;
  33. import javax.mail.MessagingException;
  34. import javax.mail.PasswordAuthentication;
  35. import javax.mail.Session;
  36. import javax.mail.Transport;
  37. import javax.mail.internet.InternetAddress;
  38. import javax.mail.internet.MimeMessage;
  39.  
  40.  
  41. public class MainActivity extends AppCompatActivity {
  42.     private Toolbar mToolbar;
  43.     Session session = null;
  44.     ProgressDialog pdialog = null;
  45.     Context context = null;
  46.     EditText reciep, sub, msg, ngo, vdc,wrd,village,date,maleA;
  47.     String rec, subject, textMessage, ngoS,district, vdcS,wrdS,villageS,dateS, attendenc,activitYS, ccSupport, vrSupport ,maleAA,femaleA,othersA,maleC,femaleC,otherC,maleV,femaleV,othersC,maleH,femaleH,otherH;
  48.  
  49.  
  50.     @Override
  51.     protected void onCreate(Bundle savedInstanceState) {
  52.         super.onCreate(savedInstanceState);
  53.         setContentView(R.layout.activity_main);
  54.  
  55.         context = this;
  56.  
  57.  
  58.         int num = 0;
  59.         try {
  60.             String value = maleA.getText().trim();
  61.             num = Integer.parseInt( value );
  62.         } catch (NumberFormatException nfe){
  63.             // nothing to do
  64.         }
  65.  
  66.  
  67.         mToolbar = (Toolbar) findViewById(R.id.toolbar);
  68.  
  69.         setSupportActionBar(mToolbar);
  70.         getSupportActionBar().setDisplayShowHomeEnabled(true);
  71.         final Spinner spinner = (Spinner) findViewById(R.id.spinner);
  72.         ArrayAdapter<CharSequence> adapter;
  73.         adapter = ArrayAdapter.createFromResource(this, R.array.activities, android.R.layout.simple_spinner_item);
  74.         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  75.         spinner.setAdapter(adapter);
  76.         final Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
  77.         ArrayAdapter<CharSequence> adapter2;
  78.         adapter2 = ArrayAdapter.createFromResource(this, R.array.district, android.R.layout.simple_spinner_item);
  79.         adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  80.         spinner2.setAdapter(adapter2);
  81.  
  82.  
  83.         Button login = (Button) findViewById(R.id.btn_submit);
  84.  
  85.  
  86.         msg = (EditText) findViewById(R.id.et_text);
  87.         ngo = (EditText) findViewById(R.id.editText);
  88.  
  89.         vdc = (EditText) findViewById(R.id.editText3);
  90.         wrd = (EditText)findViewById(R.id.editText4);
  91.         village = (EditText)findViewById(R.id.editText5);
  92.         date=(EditText)findViewById(R.id.editText6);
  93.  
  94.         login.setOnClickListener(new OnClickListener() {
  95.             @Override
  96.             public void onClick(View v) {
  97.  
  98.                 rec = "anantarajbastola@gmail.com";
  99.                 subject = "IFFA FeedBack";
  100.                 textMessage = msg.getText().toString();
  101.                 ngoS = ngo.getText().toString();
  102.  
  103.                 vdcS = vdc.getText().toString();
  104.                 wrdS=wrd.getText().toString();
  105.                 villageS=village.getText().toString();
  106. dateS=date.getText().toString();
  107.  
  108. activitYS=spinner.getSelectedItem().toString();
  109. district=spinner2.getSelectedItem().toString();
  110.  
  111.  
  112.                 Properties props = new Properties();
  113.                 props.put("mail.smtp.host", "smtp.gmail.com");
  114.                 props.put("mail.smtp.socketFactory.port", "465");
  115.                 props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  116.                 props.put("mail.smtp.auth", "true");
  117.                 props.put("mail.smtp.port", "465");
  118.  
  119.                 session = Session.getDefaultInstance(props, new Authenticator() {
  120.                     protected PasswordAuthentication getPasswordAuthentication() {
  121.                         return new PasswordAuthentication("bastolananta@gmail.com", "coolboy98");
  122.                     }
  123.                 });
  124.  
  125.                 pdialog = ProgressDialog.show(context, "", "Sending feedback..", true);
  126.  
  127.                 RetreiveFeedTask task = new RetreiveFeedTask();
  128.                 task.execute();
  129.             }
  130.         });
  131.     }
  132.  
  133.  
  134.     class RetreiveFeedTask extends AsyncTask<String, Void, String> {
  135.  
  136.         @Override
  137.         protected String doInBackground(String... params) {
  138.  
  139.             try {
  140.                 Message message = new MimeMessage(session);
  141.                 message.setFrom(new InternetAddress("bastolananta4@gmail.com"));
  142.                 message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(rec));
  143.                 message.setSubject(subject);
  144.                 message.setContent("  Name of CW:  "+ textMessage +System.getProperty("line.separator") +"Ngo/Cso : " + ngoS +System.getProperty("line.separator")+"District:" + district +System.getProperty("line.separator")+"VDC :  " +System.getProperty("line.separator")+ vdcS +"Ward:  "+System.getProperty("line.separator")+wrdS+"Village:  "+System.getProperty("line.separator")+System.getProperty("line.separator")+villageS+"Date:  "+System.getProperty("line.separator")+dateS+ "Activity:  " +System.getProperty("line.separator")+activitYS+" Attandence: " +System.getProperty("line.separator")+ attendenc +System.getProperty("line.separator")+ "CC Support:  " +System.getProperty("line.separator")+ ccSupport+"VR Suppot:  "+System.getProperty("line.separator") + vrSupport+ "Help Desk:  ", "text/html; charset=utf-8");
  145.                 Transport.send(message);
  146.             } catch (MessagingException e) {
  147.                 e.printStackTrace();
  148.             } catch (Exception e) {
  149.                 e.printStackTrace();
  150.             }
  151.             return null;
  152.         }
  153.  
  154.         @Override
  155.         protected void onPostExecute(String result) {
  156.             pdialog.dismiss();
  157.  
  158.  
  159.  
  160.             Toast.makeText(getApplicationContext(), "Message sent", Toast.LENGTH_LONG).show();
  161.         }
  162.     }
  163.  
  164.     @Override
  165.     public boolean onCreateOptionsMenu(Menu menu) {
  166.         // Inflate the menu; this adds items to the action bar if it is present.
  167.         getMenuInflater().inflate(R.menu.menu_main, menu);
  168.         return true;
  169.     }
  170.  
  171.     @Override
  172.     public boolean onOptionsItemSelected(MenuItem item) {
  173.         // Handle action bar item clicks here. The action bar will
  174.         // automatically handle clicks on the Home/Up button, so long
  175.         // as you specify a parent activity in AndroidManifest.xml.
  176.         int id = item.getItemId();
  177.  
  178.         //noinspection SimplifiableIfStatement
  179.         if (id == R.id.action_settings) {
  180.             return true;
  181.         }
  182.  
  183.         return super.onOptionsItemSelected(item);
  184.     }
  185.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement