Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. package com.example.onc_lap.oncontrolmobile;
  2.  
  3. String TAG = "Response";
  4. EditText usuario;
  5. EditText password;
  6. private Button ingresar;
  7. private ProgressDialog pDialog;
  8.  
  9. public final int dialogo_alert = 0;
  10. public String msje = "";
  11.  
  12.  
  13.  
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16.  
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_principal);
  19. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  20. setSupportActionBar(toolbar);
  21.  
  22. usuario = (EditText) findViewById(R.id.usuario);
  23. password = (EditText) findViewById(R.id.password);
  24. ingresar = (Button) findViewById(R.id.ingresar);
  25. ingresar.setOnClickListener(new View.OnClickListener() {
  26. @Override
  27. public void onClick(View v) {
  28.  
  29. String username = usuario.getText().toString();
  30. String pass = password.getText().toString();
  31. new webserv().execute();
  32.  
  33. } //fin del click view
  34.  
  35. });
  36. }
  37.  
  38.  
  39.  
  40. class webserv extends AsyncTask<String, String, String> {
  41.  
  42.  
  43. public String NAMESPACE = "http://ONControl_MobileWS/";
  44. public String METHOD_NAME = "Login";
  45. public String SOAP_ACTION = "http://ONControl_MobileWS/Login";
  46. public String URL = "http://oncontrol.no-ip.net:9020/ONControl_MobileWS.asmx";
  47. private SoapObject request;
  48. private HttpTransportSE transporte;
  49. private SoapSerializationEnvelope envelope;
  50.  
  51. @Override
  52. protected String doInBackground(String... params) {
  53. Login();
  54. return null;
  55. }
  56.  
  57.  
  58. protected void onPreExecute() {
  59.  
  60. /* Log.i(TAG, "onPreExecute");
  61.  
  62. pDialog = new ProgressDialog(Principal.this);
  63. pDialog.setMessage("Iniciando sesion ...");
  64. pDialog.setIndeterminate(false);
  65. pDialog.setMax(10);
  66. pDialog.setCancelable(false);
  67. pDialog.show();*/
  68. }
  69.  
  70.  
  71.  
  72.  
  73. protected void onPostExecute(String result) {
  74.  
  75. Principal.this.msje = res;
  76. // mostramos la respuesta en un toast
  77. Toast.makeText(Principal.this.getBaseContext(), res, Toast.LENGTH_SHORT).show();
  78.  
  79. if (res.equals("Gracias por Iniciar Sesion")) {
  80. Principal.this.usuario.getText().toString();
  81. Principal.this.usuario.setText("");
  82. Principal.this.password.setText("");
  83. //envia al otro activity
  84. Intent intent = new Intent("menu.class");
  85. startActivity(intent);
  86. finish();
  87. }
  88. Toast.makeText(Principal.this, "Tarea finalizada!",
  89. Toast.LENGTH_SHORT).show();
  90. }
  91.  
  92.  
  93.  
  94. public void Login() {
  95. URL = "http://oncontrol.no-ip.net:9020/ONControl_MobileWS.asmx";
  96. request = new SoapObject(NAMESPACE, METHOD_NAME);
  97. PropertyInfo pi = new PropertyInfo();
  98. envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  99. envelope.dotNet = true;
  100. envelope.setOutputSoapObject(request);
  101. transporte = new HttpTransportSE(URL);
  102.  
  103. request.addProperty("usuario", Principal.this.usuario.getText().toString());
  104. request.addProperty("password", Principal.this.password.getText().toString());
  105.  
  106. try {
  107. transporte.call(SOAP_ACTION, envelope);
  108.  
  109. SoapPrimitive resultado_xml = (SoapPrimitive) envelope.getResponse();
  110. res = resultado_xml.toString();
  111.  
  112. } catch (Exception e) {
  113. Log.e(TAG, "Error: " + e.getMessage());
  114. }
  115.  
  116. }
  117.  
  118. }
  119.  
  120. //run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement