public void onClick(View v) { if( v == voltar ) { setResult( RESULT_CANCELED ); finish( ); } else if( v == avancar ) { if( ! Utils.validateCPF( editCPF ) ) return; if( ! Utils.validateEmail( editEmail ) ) return; final ProgressDialog dialog = ProgressDialog.show( this, "Verificando", "Por favor, aguarde...", true ); final String edCpf = editCPF.getCleanText(); final String edEmail = editEmail.getText().toString(); final Activity instance = this; Runnable runnable = new Runnable() { public void run() { String reqUrl = "http://url/login?"; String reqParams = ""; try { reqParams = "cpf=" + URLEncoder.encode( edCpf, "UTF-8" ) +"&email=" +/* URLEncoder.encode( edEmail, "UTF-8" )*/ (String) edEmail; } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } Log.d("",reqUrl + reqParams); StringBuilder is = Utils.sendHttpGet( reqUrl + reqParams ); instance.runOnUiThread( new Runnable() { public void run() { dialog.dismiss( ); } }); String msg = null; if( is == null ) { msg = "Erro ao verificar cadastro.\nCertifique-se de que a conexão com a internet esteja ativada e tente novamente."; } else { msg = "Erro interno ao verificar cadastro."; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder( ); Document dom = builder.parse( new ByteArrayInputStream( is.toString().getBytes() ) ); Element root = dom.getDocumentElement( ); NodeList list = root.getElementsByTagName( "UserClientEntity" ); if( list.getLength() < 1 ) { msg = "Usuário não encontrado."; } else { String cpf = ""; msg = "Usuário não encontrado."; NodeList user = list.item( 0 ).getChildNodes( ); for( int i = 0; i < user.getLength(); ++i ) { if( user.item( i ).getNodeName().equals( "cpf" ) ) { cpf = user.item( i ).getChildNodes().item(0).getNodeValue(); if( cpf == null ) { cpf = ""; } break; } } if( cpf.equals( edCpf ) ) { instance.runOnUiThread( new Runnable() { public void run() { LastLoginData.setCpf( edCpf ); LastLoginData.setEmail( edEmail ); LastLoginData.saveData( instance ); setResult( RESULT_OK ); finish( ); } }); msg = null; } } } catch( Exception e ) { } } if( msg != null ) { final String xmsg = msg; instance.runOnUiThread( new Runnable() { public void run() { Utils.showInformation( instance, "Atenção", xmsg ); } }); } } }; Thread thread = new Thread( runnable ); thread.start( ); } }