package com.example.academicr; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.StrictMode; import android.view.Menu; import android.view.MenuItem; import android.view.Window; import android.view.WindowManager; import android.widget.TextView; public class hop2 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏 setContentView(R.layout.hoptwo); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } Intent intent=getIntent(); String input1=intent.getStringExtra("input1"); String input2=intent.getStringExtra("input2"); TextView startId = (TextView)findViewById(R.id.startid); TextView endId = (TextView)findViewById(R.id.endid); startId.setText(input1); endId.setText(input2); //http://edward.chinacloudapp.cn/bof333?id1=2094437628&id2=2273736245 String result = null; int len = 500; InputStream is = null; try { input1 = input1.replace(" ", "%20"); input2 = input2.replace(" ", "%20"); URL url = new URL("http://45.62.110.239:8080/bof333?id1="+input1+"&id2="+input2); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setDoInput(true); // Starts the query conn.connect(); //int response = conn.getResponseCode(); is = conn.getInputStream(); // Convert the InputStream into a string result = readIt(is, len); // Makes sure that the InputStream is closed after the app is // finished using it. } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } System.out.println(result); //String[] name; //name=getname2(result); get get1=new get(); String[] name; name=get1.getname2(result); System.out.println(name[0]); //String[] name1; //name1=getname3(result); TextView point1 = (TextView)findViewById(R.id.point1); TextView point2 = (TextView)findViewById(R.id.point2); TextView point3 = (TextView)findViewById(R.id.point3); point1.setText(name[0]); point2.setText(name[1]); point3.setText(name[2]); } public String[] getname3(String input)//获取三跳 { //s = input; int num = 0;// int numfor2=0; String[] name3 = new String[6]; input = input.replace("[", ""); //System.out.println(s); String[] sArray = input.split("],"); //System.out.println(sArray[1]); for (int i = 0 ; i < sArray.length; i++) { sArray[i] = sArray[i].replace("]",""); //System.out.println(sArray); String[] aArray = sArray[i].split(","); //System.out.println(aArray[1]); if ((aArray.length == 4)&&(num<=2)) { num++; name3[numfor2]=aArray[1]; name3[numfor2+1]=aArray[2]; numfor2 = numfor2+2; } //System.out.println(aArray); } if(name3.length<6) {for(int j = name3.length; j<6; j++) {name3[j]="NULL";};} return name3; } public String readIt(InputStream stream, int len) throws IOException, UnsupportedEncodingException { Reader reader = null; reader = new InputStreamReader(stream, "UTF-8"); char[] buffer = new char[len]; reader.read(buffer); return new String(buffer); } @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; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override protected void onResume() { /** * 设置为横屏 */ if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } super.onResume(); } }