Advertisement
ddkclaudio

Untitled

Jan 18th, 2013
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.90 KB | None | 0 0
  1.   public void onClick(View v) {
  2.         if( v == voltar ) {
  3.             setResult( RESULT_CANCELED );
  4.             finish( );
  5.         }
  6.         else if( v == avancar ) {
  7.             if( ! Utils.validateCPF( editCPF ) ) return;
  8.             if( ! Utils.validateEmail( editEmail ) ) return;
  9.  
  10.             final ProgressDialog dialog = ProgressDialog.show( this, "Verificando", "Por favor, aguarde...", true );
  11.             final String edCpf = editCPF.getCleanText();
  12.             final String edEmail = editEmail.getText().toString();
  13.             final Activity instance = this;
  14.  
  15.             Runnable runnable = new Runnable() {
  16.                 public void run() {
  17.  
  18.                     String reqUrl = "http://url/login?";
  19.                     String reqParams = "";
  20.                     try {
  21.                         reqParams = "cpf=" + URLEncoder.encode( edCpf, "UTF-8" ) +"&email=" +/* URLEncoder.encode( edEmail, "UTF-8" )*/ (String) edEmail;
  22.                     } catch (UnsupportedEncodingException e1) {
  23.                         e1.printStackTrace();
  24.                     }
  25.                          Log.d("",reqUrl + reqParams);
  26.                     StringBuilder is = Utils.sendHttpGet( reqUrl + reqParams );
  27.                              
  28.                     instance.runOnUiThread( new Runnable() {
  29.                         public void run() {
  30.                             dialog.dismiss( );
  31.                         }
  32.                     });
  33.  
  34.                     String msg = null;
  35.                     if( is == null ) {
  36.                         msg = "Erro ao verificar cadastro.\nCertifique-se de que a conexão com a internet esteja ativada e tente novamente.";
  37.                     }
  38.                     else {
  39.                         msg = "Erro interno ao verificar cadastro.";
  40.                         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  41.                         try {
  42.                             DocumentBuilder builder = factory.newDocumentBuilder( );
  43.                             Document dom = builder.parse( new ByteArrayInputStream( is.toString().getBytes() ) );
  44.                             Element  root = dom.getDocumentElement( );
  45.                             NodeList list = root.getElementsByTagName( "UserClientEntity" );
  46.                             if( list.getLength() < 1 ) {
  47.                                 msg = "Usuário não encontrado.";
  48.                             }
  49.                             else {
  50.                                 String cpf = "";
  51.                                 msg = "Usuário não encontrado.";
  52.  
  53.                                 NodeList user = list.item( 0 ).getChildNodes( );
  54.        
  55.                                 for( int i = 0; i < user.getLength(); ++i ) {
  56.                                     if( user.item( i ).getNodeName().equals( "cpf" ) ) {
  57.                                         cpf = user.item( i ).getChildNodes().item(0).getNodeValue();
  58.                                         if( cpf == null ) {
  59.                                             cpf = "";
  60.                                         }
  61.                                         break;
  62.                                     }
  63.                                 }
  64.  
  65.                                 if( cpf.equals( edCpf ) ) {
  66.            
  67.                                     instance.runOnUiThread( new Runnable() {
  68.                                         public void run() {
  69.                                             LastLoginData.setCpf( edCpf );
  70.                                             LastLoginData.setEmail( edEmail );
  71.                                             LastLoginData.saveData( instance );
  72.  
  73.                                             setResult( RESULT_OK );
  74.                                             finish( );
  75.                                         }
  76.                                     });
  77.                                     msg = null;
  78.                                 }
  79.                             }
  80.                         }
  81.                         catch( Exception e ) {
  82.                         }
  83.                     }
  84.                     if( msg != null ) {
  85.                         final String xmsg = msg;
  86.                         instance.runOnUiThread( new Runnable() {
  87.                             public void run() {
  88.                                 Utils.showInformation( instance, "Atenção", xmsg );
  89.                             }
  90.                         });
  91.                     }
  92.                 }
  93.             };
  94.             Thread thread = new Thread( runnable );
  95.             thread.start( );
  96.         }
  97.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement