Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.text.TextUtils;
- import android.util.Log;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- import java.io.BufferedInputStream;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- public class Screen2 extends AppCompatActivity {
- EditText matriculatxt, vintxt;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_screen2);
- matriculatxt = (EditText) findViewById(R.id.matricula);
- vintxt = (EditText) findViewById(R.id.vin);
- }
- public void consultar(View v){
- if(TextUtils.isEmpty(matriculatxt.getText().toString()) && TextUtils.isEmpty(vintxt.getText().toString())){
- Toast.makeText(this, "Por favor ingresa una matricula o un bastidor.", Toast.LENGTH_SHORT).show();
- return;
- }
- try{
- URL url;
- url = new URL("http://dbpolicial.x10host.com/?action=consulta&matricula="+matriculatxt.getText().toString()+"&vin="+vintxt.getText().toString());
- GetConsultaTask gct = new GetConsultaTask();
- gct.execute(url);
- }catch(Exception e ){
- e.printStackTrace();
- }
- }
- public void volver(View v){
- this.onBackPressed();
- this.finish();
- }
- public class GetConsultaTask extends AsyncTask<URL, String, String>{
- @Override
- protected String doInBackground(URL... params) {
- try {
- HttpURLConnection con = (HttpURLConnection) params[0].openConnection();
- // Obtener el estado del recurso
- int statusCode = con.getResponseCode();
- if(statusCode!=200) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(getApplicationContext(),"No se pudo hacer la consulta, intenta de nuevo más tarde", Toast.LENGTH_SHORT).show();
- }
- });
- return null;
- }
- InputStreamReader in = new InputStreamReader(con.getInputStream());
- BufferedReader bufferedReader = new BufferedReader(in);
- StringBuilder total = new StringBuilder();
- String line;
- while((line= bufferedReader.readLine()) != null){
- total.append(line);
- }
- return total.toString();
- } catch (IOException e) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(getApplicationContext(), "No se pudo hacer la consulta, intenta de nuevo más tarde", Toast.LENGTH_SHORT).show();
- }
- });
- return null;
- }
- }
- @Override
- protected void onPostExecute(String s) {
- Intent i = null;
- if(s == null){
- }else{
- if(s.equals("")){
- i = new Intent(getApplicationContext(), Screen4_5.class);
- i.putExtra("layout", 4);
- }else {
- i = new Intent(getApplicationContext(), Screen3.class);
- i.putExtra("auto", s);
- }
- }
- startActivity(i);
- finish();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement