Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实验5和实验6,电脑问题所以晚了 #2654

Merged
merged 7 commits into from
Jun 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions soft1614080902345/App/Java/Json.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.example.administrator;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class Json extends AppCompatActivity {
private String text;
private ListView listView;
private ArrayAdapter<String> adapter;
private List<String> list=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.json);
listView=(ListView)findViewById(R.id.listview);
getjson();
}
public void getjson()
{
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL("https://raw.githubusercontent.com/chinesehope/android-labs-2018/master/soft1614080902345/message1.json");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(8000);
connection.setReadTimeout(8000);
connection.setUseCaches(false);
connection.connect();
InputStream in = connection.getInputStream();
InputStreamReader input=new InputStreamReader(in);
BufferedReader reader=new BufferedReader(input);
if (connection.getResponseCode() == 200) {
StringBuilder response = new StringBuilder();
String Line;
while ((Line = reader.readLine()) != null) {
response.append(Line);
}
text = response.toString();
Log.v("out---------------->",text);
analyzejson();
}
}
catch(Exception e)
{
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter=new ArrayAdapter<String>(Json.this,android.R.layout.simple_list_item_1,list);
listView.setAdapter(adapter);
}
});
}
}).start();
}
public void analyzejson()
{
try{
JSONArray jsonArray=new JSONArray(text);
for(int a=0;a<jsonArray.length();a++)
{
JSONObject jsonObject=jsonArray.getJSONObject(a);
String number=jsonObject.getString("地点");
String number1=jsonObject.getString("时间");
String number2=jsonObject.getString("内容");
String add;
add=number+" "+number1+" "+number2;
list.add(add);
Log.v("结果",add);
}

}
catch (Exception e)
{
e.printStackTrace();
}
}

}
20 changes: 18 additions & 2 deletions soft1614080902345/App/Java/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,36 @@
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
private Button runbutton;
private Button runbutton,run2button,jsonbutton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
runbutton=(Button) findViewById(R.id.button);
runbutton=(Button) findViewById(R.id.button1);
run2button=(Button) findViewById(R.id.button2);
jsonbutton=(Button) findViewById(R.id.button);
runbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =new Intent(MainActivity.this,RunActivity.class);
startActivity(intent);
}
});
run2button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =new Intent(MainActivity.this,Run2.class);
startActivity(intent);
}
});
jsonbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =new Intent(MainActivity.this,Json.class);
startActivity(intent);
}
});

}
}
51 changes: 51 additions & 0 deletions soft1614080902345/App/Java/Run2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.example.administrator;

import android.app.Activity;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ShareActionProvider;
import android.widget.Toast;

public class Run2 extends Activity{
private Button send;
private EditText name,message,phone;
private SharedPreferences pref;
private SharedPreferences.Editor editor;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.run2);
name=(EditText)findViewById(R.id.name);
message=(EditText)findViewById(R.id.message);
phone=(EditText)findViewById(R.id.phone);
send=(Button)findViewById(R.id.send);
pref=getSharedPreferences("JZmessage",MODE_PRIVATE);
editor=pref.edit();

}
public void fabu(View v){
switch (v.getId()){
case R.id.send:
String Name=name.getText().toString();
String Message=message.getText().toString();
String Phone=phone.getText().toString();
editor.putString("发布人姓名",Name);
editor.putString("发布人电话",Phone);
editor.putString("兼职信息",Message);
editor.commit();
Toast.makeText(Run2.this,"登记成功",Toast.LENGTH_LONG).show();


}
}
}
13 changes: 13 additions & 0 deletions soft1614080902345/App/Main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
android:label="@string/run_name">

</activity>
<activity
android:name=".Run2"
android:screenOrientation="portrait"
android:label="兼职页面">

</activity>
<activity
android:name=".Json"
android:screenOrientation="portrait"
android:label="兼职页面">

</activity>

</application>

</manifest>
52 changes: 43 additions & 9 deletions soft1614080902345/App/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,48 @@
android:label="@string/app_name"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">


<Button
android:layout_marginTop="100dp"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="接受兼职"
android:textSize="16sp"

tools:layout_editor_absoluteX="169dp"
tools:layout_editor_absoluteY="272dp" />

<Button
android:id="@+id/button"
android:layout_marginTop="100dp"
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="解 码" />

<Button
android:layout_marginTop="100dp"
android:layout_marginLeft="30dp"
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发布兼职"
android:textSize="16sp"

tools:layout_editor_absoluteX="169dp"
tools:layout_editor_absoluteY="272dp" />
</LinearLayout>



<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="进入兼职"
android:textSize="16sp"
tools:layout_editor_absoluteX="159dp"
tools:layout_editor_absoluteY="284dp"
tools:ignore="MissingConstraints" />
</android.support.constraint.ConstraintLayout>
19 changes: 19 additions & 0 deletions soft1614080902345/App/res/layout/json.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"

/>
</LinearLayout>
</LinearLayout>
86 changes: 86 additions & 0 deletions soft1614080902345/App/res/layout/run2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="兼职信息:"
android:layout_gravity="center"
android:textSize="25sp"
android:textColor="#000000"/>

<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="200dp"
android:ems="500"
android:inputType="text"
android:hint="@string/put_hint" />

</LinearLayout>
<LinearLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="姓 名:"
android:textSize="25sp"
android:textColor="#000000"/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />

</LinearLayout>
<LinearLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电话号码:"
android:textSize="25sp"
android:textColor="#000000"/>
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" />
</LinearLayout>


<Button
android:id="@+id/send"
android:onClick="fabu"
android:layout_marginTop="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="发 布"
android:textSize="30sp"/>
</LinearLayout>
</LinearLayout>
1 change: 1 addition & 0 deletions soft1614080902345/App/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<string name="app_name">小兼职</string>
<string name="run_name">兼职页面</string>
<string name="search_hint">请输入搜索的兼职信息</string>
<string name="put_hint">请输入发布的兼职信息(简要概述)</string>
</resources>
5 changes: 5 additions & 0 deletions soft1614080902345/message1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"地点": "惠州学院",
"时间": "2018.6.6",
"内容": "早上7点,马庄路口派传单"
}
Loading