Вы находитесь на странице: 1из 3

package com.example.

conexionserver;
import
import
import
import

java.io.BufferedReader;
java.io.IOException;
java.io.InputStream;
java.io.InputStreamReader;

import
import
import
import

org.apache.http.HttpResponse;
org.apache.http.client.HttpClient;
org.apache.http.client.methods.HttpGet;
org.apache.http.impl.client.DefaultHttpClient;

import
import
import
import
import
import

android.app.Activity;
android.os.AsyncTask;
android.os.Bundle;
android.view.Menu;
android.widget.TextView;
android.widget.Toast;

public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new ProcesoAsyncTask().execute("http://190.129.86.245/easytaxi/c
ercanos.php");
}
private class ProcesoAsyncTask extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... url) { //significa vec
tor
// TODO Auto-generated method stub
return BajarDatos(url[0]);
}
protected void onPostExecute(String resultado) {
TextView tv = (TextView) findViewById(R.id.textView1);
TextView tv2 = (TextView) findViewById(R.id.textView2);
resultado=resultado.replaceAll("<br>", " ");
resultado=resultado.replaceAll(";", " ");
resultado=resultado.replaceAll(":", "");
String taxis105[]=new String[50];
taxis105=resultado.split("Taxi");
resultado="";
for(int i =0;i<taxis105.length;i++){
resultado+=""+taxis105[i]+"\n";
}
tv.setText("Oscar Jemio Peafiel"+"\nCod 408");
String res[]=new String[50],rer="";
for(int i =1;i<taxis105.length;i++){
String vv105[]=new String[50];
vv105=taxis105[i].split(" ");
int cont105=0;
for(int j=1;j<taxis105.length;j++){
String vv1[]=new String[50];
vv1=taxis105[j].split(" ");
if(vv105[1].equals(vv1[1])){
cont105++;

if(cont105==1)
res[i]="Taxi "+vv105[1]+
" "+vv105[2];
}
}
res[i]+=" "+cont105+" veces.";
//resultado+="Taxi"+taxis[i]+"\n";
}
resultado="";
for(int i =1;i<taxis105.length;i++){
resultado+=res[i]+"\n";
}
String ser105=res[1]+";";
for(int k=1;k<17;k++){
for(int y=1;y<17;y++){
if((!res[k].equals(res[y]))&&(!ser105.co
ntains(res[k]))){
ser105+=res[k]+";";
}
}
}
String h[]=new String[50];
h=ser105.split(";");
String hser105="";
String aux;
for(int t=0;t<h.length;t++){
for(int r=0;r<h.length-1;r++){
String gg105[]=new String[20];
gg105=h[r].split(" ");
String ggg105[]=new String[20];
ggg105=h[r+1].split(" ");
int m=0,n=0;
for(int u=0;u<gg105[1].length();u++){
m+=gg105[1].codePointAt(u);
}
for(int q=0;q<ggg105[1].length();q++){
n+=ggg105[1].codePointAt(q);
}
//m=gg105[2].codePointCount(0, gg105[2].
length()-1);
//n=ggg105[2].codePointCount(0, ggg105[2
].length()-1);
if(m>n){
aux=h[r];
h[r]=h[r+1];
h[r+1]=aux;
}
}
}

for(int p=0;p<h.length;p++)
hser105+=h[p]+"\n";
tv2.setText(hser105);
}
}
private static String convierteString(InputStream bloque) throws IOExcep
tion{
BufferedReader pt= new BufferedReader(new InputStreamReader (blo
que));
String linea="",res="";
while ((linea=pt.readLine())!=null){
res+=linea;
}
pt.close();
return res;
}
public static String BajarDatos(String url){
InputStream puntero = null;
String resultado ="";
try{
HttpClient hc = new DefaultHttpClient();
HttpResponse hr = hc.execute(new HttpGet(url));
//Se conecta con el IP, jala el reporte y lo carga al si
stema
puntero = hr.getEntity().getContent();
if (puntero!=null)
resultado=convierteString(puntero);
else
resultado = "Error en la IP del WS";
}
catch(Exception e){
e.printStackTrace();
}
return resultado;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

Вам также может понравиться