diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136Activity.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136Activity.java index 9473f455..09c808ef 100644 --- a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136Activity.java +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136Activity.java @@ -16,7 +16,6 @@ import java.util.List; import edu.hzuapps.androidlabs.R; -import edu.hzuapps.androidlabs.homworks.net1414080903136.db.ExpressDB; public class Net1414080903136Activity extends FragmentActivity { public static String url; diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136ExpressInquiry.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136ExpressInquiry.java index 01585c1c..53a2f9c8 100644 --- a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136ExpressInquiry.java +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136ExpressInquiry.java @@ -12,8 +12,6 @@ import android.widget.TextView; import edu.hzuapps.androidlabs.R; -import edu.hzuapps.androidlabs.homworks.net1414080903136.db.ExpressDB; -import edu.hzuapps.androidlabs.homworks.net1414080903136.db.ExpressDao; import static edu.hzuapps.androidlabs.homworks.net1414080903136.Net1414080903136Activity.bt; @@ -22,35 +20,10 @@ */ public class Net1414080903136ExpressInquiry extends Fragment{ - - ExpressDB expressDB; - private Button queryBt; - private EditText comName; - private EditText exNum; - private ExpressDao expressDao; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view=inflater.inflate(R.layout.tab1_net1414080903136,container,false); - queryBt= (Button) view.findViewById(R.id.bt); - comName= (EditText) view.findViewById(R.id.et1); - exNum=(EditText) view.findViewById(R.id.et2); - expressDao=new ExpressDao(getContext()); - queryBt.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - //测试数据 - String companyName=comName.getText().toString(); - String expressNum=exNum.getText().toString(); - String date="2017-5-18"; - String content="惠州学院快递服务站正在第1次派件 电话:15766844117 请保持电话畅通、耐心等待"; - String state="派件"; - expressDao.insert(companyName,expressNum,date,content,state); - } - }); - return view; - - + return inflater.inflate(R.layout.tab1_net1414080903136,container,false); } } diff --git a/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136MainActivity.java b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136MainActivity.java new file mode 100644 index 00000000..b0155174 --- /dev/null +++ b/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/Net1414080903136MainActivity.java @@ -0,0 +1,90 @@ +package edu.hzuapps.androidlabs.homeworksrks.net1414080903136; + +import android.os.Handler; +import android.os.Message; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.widget.TextView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + +import edu.hzuapps.androidlabs.R; + +public class Net1414080903136ShowJsonActivity extends AppCompatActivity { + TextView tv; + + Handler handler=new Handler(){ + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + String a= parseJson((String) msg.obj); + tv.setText(a); + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_net1414080903136_show_json); + tv= (TextView) findViewById(R.id.tv_json); + new Thread(){ + @Override + public void run() { + super.run(); + String a=a("https://raw.githubusercontent.com/zhongxiwu/android-labs-2017/master/AndroidLabs/app/src/main/java/edu/hzuapps/androidlabs/homeworks/net1414080903136/1414080903136.json"); + Message msg=handler.obtainMessage(); + msg.obj=a; + handler.sendMessage(msg); + } + }.start(); + } + + public String a(String u) { + try { + URL url = new URL(u); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.setConnectTimeout(5000); + InputStream is = conn.getInputStream(); + byte[] b = new byte[1024]; + StringBuilder sb = new StringBuilder(); + String a; + int len; + while ((len=is.read(b)) != -1) { + a=new String(b,0,len); + sb.append(a); + } + return sb.toString(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } + + public String parseJson(String data){ + StringBuilder sb=new StringBuilder(); + try { + JSONArray jsonArray=new JSONArray(data); + for (int i=0;i + + +