Skip to content
This repository was archived by the owner on Nov 5, 2020. It is now read-only.

Commit 87a277d

Browse files
committed
feat: 校园卡明细查询
1 parent 7f44f59 commit 87a277d

File tree

9 files changed

+367
-14
lines changed

9 files changed

+367
-14
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package io.github.zhaoqi99.snnu_android;
2+
3+
4+
import android.os.AsyncTask;
5+
import android.os.Bundle;
6+
import android.support.v4.app.Fragment;
7+
import android.support.v7.widget.LinearLayoutManager;
8+
import android.support.v7.widget.RecyclerView;
9+
import android.view.LayoutInflater;
10+
import android.view.View;
11+
import android.view.ViewGroup;
12+
import android.widget.Button;
13+
import android.widget.EditText;
14+
import android.widget.TextView;
15+
16+
import org.ksoap2.serialization.SoapObject;
17+
import org.ksoap2.serialization.SoapSerializationEnvelope;
18+
import org.ksoap2.transport.HttpTransportSE;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
/**
24+
* A simple {@link Fragment} subclass.
25+
*/
26+
public class CardFragment extends Fragment {
27+
28+
29+
public CardFragment() {
30+
// Required empty public constructor
31+
}
32+
33+
View view;
34+
String result;
35+
RecyclerView recyclerView;
36+
Button button;
37+
EditText editText;
38+
private ArrayList<CardMessage> messageList2 ;
39+
40+
@Override
41+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
42+
Bundle savedInstanceState) {
43+
// Inflate the layout for this fragment
44+
view = inflater.inflate(R.layout.fragment_card, container, false);
45+
recyclerView = view.findViewById(R.id.recycler_view_card);
46+
button=view.findViewById(R.id.button_search);
47+
editText=view.findViewById(R.id.editText_id);
48+
49+
button.setOnClickListener(new View.OnClickListener() {
50+
@Override
51+
public void onClick(View v) {
52+
QueryTask queryTask=new QueryTask();
53+
String id=editText.getText().toString();
54+
queryTask.execute(id);
55+
}
56+
});
57+
return view;
58+
}
59+
60+
private class QueryTask extends AsyncTask<String, Integer, String> {
61+
62+
@Override
63+
protected String doInBackground(String... strings) {
64+
try {
65+
getRemoteInfo(strings[0]);
66+
} catch (Exception e) {
67+
e.printStackTrace();
68+
}
69+
return result;
70+
}
71+
72+
@Override
73+
protected void onPostExecute(String result) {
74+
messageList2 = getCard(result);
75+
myCardRecyclerViewAdapter myCardRecyclerViewAdapter = new myCardRecyclerViewAdapter(messageList2);
76+
LinearLayoutManager layoutManager = new LinearLayoutManager(view.getContext());
77+
recyclerView.setLayoutManager(layoutManager);
78+
recyclerView.setAdapter(myCardRecyclerViewAdapter);
79+
}
80+
81+
private void getRemoteInfo(String id) throws Exception {
82+
String Target_URL = "http://webxml.zhaoqi.vip/CampusCard.asmx";
83+
String namespace = "http://webxml.zhaoqi.vip/";
84+
String methodName = "getConsumptionDdetails";
85+
SoapObject request = new SoapObject(namespace, methodName);
86+
request.addProperty("id", id);
87+
SoapSerializationEnvelope envelope = new
88+
SoapSerializationEnvelope(SoapSerializationEnvelope.VER12);
89+
envelope.bodyOut = request;
90+
envelope.dotNet = true;
91+
HttpTransportSE httpTransportSE = new HttpTransportSE(Target_URL);
92+
httpTransportSE.call(null, envelope);
93+
SoapObject object = (SoapObject) envelope.bodyIn;
94+
result = object.getProperty(0).toString();
95+
}
96+
97+
private ArrayList<CardMessage> getCard(String str) {
98+
String str_Date = "";
99+
String str_Frequency = "";
100+
String str_OrigiAmount = "";
101+
String str_TransAmount = "";
102+
String str_Balance = "";
103+
String str_Location = "";
104+
ArrayList<CardMessage> messageList2=new ArrayList<>();
105+
for (int i = 0; i < str.length(); i++) {
106+
if (i + 4 < str.length() && str.substring(i, i + 4).equals("Date")) {
107+
i += 5;
108+
int tag1 = str.indexOf(';', i);
109+
str_Date = str.substring(i, tag1);
110+
str_Date = str_Date.replace("T", " "); //Date
111+
i = tag1 + 1;
112+
i += 11;
113+
int tag2 = str.indexOf(';', i);
114+
str_Frequency = str.substring(i, tag2); //Frequency
115+
i = tag2 + 1;
116+
i += 13;
117+
int tag3 = str.indexOf(';', i);
118+
str_OrigiAmount = str.substring(i, tag3); //OrigiAmount
119+
i = tag3 + 1;
120+
i += 13;
121+
int tag4 = str.indexOf(';', i);
122+
str_TransAmount = str.substring(i, tag4); //TransAmount
123+
i = tag4 + 1;
124+
i += 9;
125+
int tag5 = str.indexOf(';', i);
126+
str_Balance = str.substring(i, tag5);
127+
i = tag5 + 1;
128+
i += 10;
129+
int tag6 = str.indexOf(';', i);
130+
str_Location = str.substring(i, tag6);
131+
i = tag6 + 1;
132+
CardMessage message = new CardMessage("时间:" + str_Date, "次数:" + str_Frequency, str_OrigiAmount, "消费:" + str_TransAmount + "元", "余额:" + str_Balance + "元", "地点:" + str_Location);
133+
messageList2.add(message);
134+
}
135+
}
136+
return messageList2;
137+
}
138+
}
139+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.github.zhaoqi99.snnu_android;
2+
3+
public class CardMessage {
4+
private String OrigiAmount;
5+
private String Date;
6+
private String Frequency;
7+
private String TransAmount;
8+
private String Balance;
9+
private String Location;
10+
public CardMessage(String Date , String Frequency , String OrigiAmount ,String TransAmount ,String Balance , String Location)
11+
{
12+
this.Date = Date;
13+
this.Frequency = Frequency;
14+
this.OrigiAmount = OrigiAmount;
15+
this.TransAmount = TransAmount;
16+
this.Balance = Balance;
17+
this.Location = Location;
18+
}
19+
public String GetOrigiAmount()
20+
{
21+
return this.OrigiAmount;
22+
}
23+
public String GetFrequency()
24+
{
25+
return this.Frequency;
26+
}
27+
public String GetDate()
28+
{
29+
return this.Date;
30+
}
31+
public String GetTransAmount()
32+
{
33+
return this.TransAmount;
34+
}
35+
public String GetBalance()
36+
{
37+
return this.Balance;
38+
}
39+
public String GetLocation(){return this.Location;}
40+
}

app/src/main/java/io/github/zhaoqi99/snnu_android/MainActivity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,19 @@ protected void onCreate(Bundle savedInstanceState) {
4545
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
4646
switch (menuItem.getItemId()) {
4747
case R.id.navigation_item_notice:
48-
Toast.makeText(MainActivity.this, "x", Toast.LENGTH_SHORT).show();
4948
switchToNotice();
5049
break;
5150
case R.id.navigation_item_news:
5251
switchToNews();
5352
break;
53+
case R.id.navigation_card:
54+
switchToCard();
55+
Toast.makeText(MainActivity.this, "x", Toast.LENGTH_SHORT).show();
56+
break;
57+
case R.id.navigation_item_lib:
58+
break;
59+
case R.id.navigation_item_jwc:
60+
break;
5461
case R.id.navigation_item_about:
5562
switchToAbout();
5663
break;
@@ -108,6 +115,10 @@ private void switchToNotice() {
108115
NewsFragment nf= new NewsFragment();
109116
nf.setType("通知");
110117
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,nf ).commit();
118+
// mToolbar.setTitle(R.string.navigation_book);
119+
}
120+
private void switchToCard() {
121+
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new CardFragment() ).commit();
111122
// mToolbar.setTitle(R.string.navigation_book);
112123
}
113124
// @Override

app/src/main/java/io/github/zhaoqi99/snnu_android/NewsFragment.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.zhaoqi99.snnu_android;
22

33

4-
import android.os.AsyncTask;
4+
;
55
import android.os.Bundle;
66
import android.support.design.widget.TabLayout;
77
import android.support.v4.app.Fragment;
@@ -12,9 +12,6 @@
1212

1313
import java.util.ArrayList;
1414
import java.util.List;
15-
import org.ksoap2.serialization.SoapObject;
16-
import org.ksoap2.serialization.SoapSerializationEnvelope;
17-
import org.ksoap2.transport.HttpTransportSE;
1815

1916
/**
2017
* A simple {@link Fragment} subclass.
@@ -56,7 +53,7 @@ private void InitTab() {
5653

5754
String keys[]={"学校主页","学生处","计算机科学学院","教务处"};
5855
for (String s:keys) {
59-
Tab t=new Tab();
56+
NewsTab t=new NewsTab();
6057
t.setDep(s);
6158
t.setType(type);
6259
mFragmentList.add(t);

app/src/main/java/io/github/zhaoqi99/snnu_android/Tab.java renamed to app/src/main/java/io/github/zhaoqi99/snnu_android/NewsTab.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* A simple {@link Fragment} subclass.
2323
*/
24-
public class Tab extends Fragment {
24+
public class NewsTab extends Fragment {
2525
private RecyclerView recyclerView;
2626
private mNoticeRecyclerViewAdapter mNoticeRecyclerViewAdapter;
2727

@@ -40,7 +40,7 @@ public void setType(String type) {
4040
ArrayList<NoticeMessage> newsList = new ArrayList<>();
4141
String result;
4242

43-
public Tab() {
43+
public NewsTab() {
4444
// Required empty public constructor
4545
}
4646

@@ -70,7 +70,6 @@ protected String doInBackground(String... strings) {
7070

7171
@Override
7272
protected void onPostExecute(String result) {
73-
newsList.add(new NoticeMessage("title", "date", "link", "dasda", "da"));
7473
newsList=getNotice(result);
7574
mNoticeRecyclerViewAdapter = new mNoticeRecyclerViewAdapter(newsList);
7675
LinearLayoutManager layoutManager = new LinearLayoutManager(view.getContext());
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.github.zhaoqi99.snnu_android;
2+
3+
import android.support.v7.widget.RecyclerView;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.TextView;
8+
9+
import java.util.List;
10+
11+
public class myCardRecyclerViewAdapter extends RecyclerView.Adapter<myCardRecyclerViewAdapter.ViewHolder>{
12+
private List<CardMessage> messageList;
13+
14+
public myCardRecyclerViewAdapter(List<CardMessage> messageList)
15+
{
16+
this.messageList = messageList;
17+
}
18+
19+
static class ViewHolder extends RecyclerView.ViewHolder{
20+
21+
TextView Frequency;
22+
TextView Date;
23+
TextView Location;
24+
TextView TransAmount;
25+
TextView Balance;
26+
public ViewHolder(View view)
27+
{
28+
super(view);
29+
Frequency = (TextView)view.findViewById(R.id.txt_Frequency);
30+
Date = (TextView)view.findViewById(R.id.txt_Date2);
31+
TransAmount = (TextView)view.findViewById(R.id.txt_TransAmount);
32+
Balance = (TextView)view.findViewById(R.id.txt_Balance);
33+
Location = (TextView)view.findViewById(R.id.txt_Location);
34+
}
35+
}
36+
@Override
37+
public int getItemCount() {
38+
return messageList.size();
39+
}
40+
41+
@Override
42+
public void onBindViewHolder(ViewHolder holder, int position) {
43+
CardMessage message = messageList.get(position);
44+
holder.Date.setText(message.GetDate());
45+
holder.Frequency.setText(message.GetFrequency());
46+
holder.TransAmount.setText(message.GetTransAmount());
47+
holder.Balance.setText(message.GetBalance());
48+
holder.Location.setText(message.GetLocation());
49+
}
50+
51+
@Override
52+
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
53+
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_recycler_layout
54+
,parent,false);
55+
ViewHolder holder = new ViewHolder(view);
56+
return holder;
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="120dp">
6+
7+
<TextView
8+
android:layout_width="wrap_content"
9+
android:layout_height="20dp"
10+
android:id="@+id/txt_Location"
11+
android:layout_marginStart="20dp"
12+
android:layout_centerVertical="true"
13+
android:layout_alignParentStart="true"
14+
android:textColor="#000"
15+
android:textSize="15sp"/>
16+
17+
<TextView
18+
android:layout_width="wrap_content"
19+
android:layout_height="20dp"
20+
android:id="@+id/txt_Frequency"
21+
android:layout_alignBaseline="@+id/txt_Date2"
22+
android:layout_alignBottom="@+id/txt_Date2"
23+
android:layout_alignStart="@+id/txt_Location"
24+
android:textSize="15sp"
25+
android:textColor="#000"/>
26+
27+
<TextView
28+
android:layout_width="wrap_content"
29+
android:layout_height="20dp"
30+
android:id="@+id/txt_TransAmount"
31+
android:layout_alignBaseline="@+id/txt_Location"
32+
android:layout_alignBottom="@+id/txt_Location"
33+
android:layout_alignStart="@+id/txt_Date2"
34+
android:textSize="15sp"
35+
android:textColor="#000"/>
36+
37+
<TextView
38+
android:layout_width="wrap_content"
39+
android:layout_height="20dp"
40+
android:id="@+id/txt_Balance"
41+
android:textSize="15sp"
42+
android:textColor="#000"
43+
android:layout_below="@+id/txt_Location"
44+
android:layout_alignStart="@+id/txt_Location"
45+
android:layout_marginTop="14dp" />
46+
47+
<TextView
48+
android:layout_width="wrap_content"
49+
android:layout_height="20dp"
50+
android:id="@+id/txt_Date2"
51+
android:layout_marginEnd="34dp"
52+
android:textSize="15sp"
53+
android:textColor="#000"
54+
android:layout_marginBottom="12dp"
55+
android:layout_above="@+id/txt_TransAmount"
56+
android:layout_alignParentEnd="true" />
57+
58+
</RelativeLayout>

0 commit comments

Comments
 (0)