Skip to content

Commit 3561696

Browse files
committed
优化注释和提示;删除不需要的main_activity,xml
1 parent 6c42d81 commit 3561696

6 files changed

Lines changed: 55 additions & 80 deletions

File tree

APIJSON(Android)/APIJSON(ADT)/gen/zuo/biao/apijson/client/R.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,25 @@ public static final class drawable {
2020
public static final int ic_launcher=0x7f020000;
2121
}
2222
public static final class id {
23-
public static final int btnQueryQuery=0x7f070004;
24-
public static final int etMainRequest=0x7f070000;
25-
public static final int etQueryUri=0x7f070003;
26-
public static final int pbQuery=0x7f070002;
27-
public static final int tvQueryResult=0x7f070001;
23+
public static final int btnQueryQuery=0x7f070003;
24+
public static final int etQueryUri=0x7f070002;
25+
public static final int pbQuery=0x7f070001;
26+
public static final int tvQueryResult=0x7f070000;
2827
}
2928
public static final class layout {
30-
public static final int main_activity=0x7f030000;
31-
public static final int query_activity=0x7f030001;
32-
public static final int select_activity=0x7f030002;
29+
public static final int query_activity=0x7f030000;
30+
public static final int select_activity=0x7f030001;
3331
}
3432
public static final class string {
3533
public static final int action_settings=0x7f050003;
3634
public static final int app_name=0x7f050000;
3735
public static final int app_version=0x7f050001;
38-
public static final int demo_array=0x7f050006;
39-
public static final int demo_complex=0x7f050007;
40-
public static final int demo_rely=0x7f050005;
41-
public static final int demo_single=0x7f050004;
36+
public static final int demo_array=0x7f050007;
37+
public static final int demo_complex=0x7f050008;
38+
public static final int demo_rely=0x7f050006;
39+
public static final int demo_single=0x7f050005;
4240
public static final int hello_world=0x7f050002;
41+
public static final int query_error=0x7f050004;
4342
}
4443
public static final class style {
4544
/**

APIJSON(Android)/APIJSON(ADT)/res/layout/main_activity.xml

Lines changed: 0 additions & 29 deletions
This file was deleted.

APIJSON(Android)/APIJSON(ADT)/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<string name="app_version">1.0</string>
66
<string name="hello_world">Hello world!</string>
77
<string name="action_settings">Settings</string>
8+
<string name="query_error">There may be something wrong,you can follow by the steps:\n\n1.Check your net connection\n\n2.Check the url whether it\'s an available ipv4 address\n\n3.Long click the Query button to open the request by web browser\n\n4.Check logs outputed on the target server\n\n5.Try again</string>
89
<string name="demo_single">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":38710\n&#160;&#160;&#160;}\n}</string>
910
<string name="demo_rely">{\n&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"id\":70793\n&#160;&#160;&#160;},\n&#160;&#160;&#160;\"Work\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"userId\":\"User/id\"\n&#160;&#160;&#160;}\n}</string>
1011
<string name="demo_array">{\n&#160;&#160;&#160;\"User[]\":{\n&#160;&#160;&#160;&#160;&#160;&#160;\"count\":10,\n&#160;&#160;&#160;&#160;&#160;&#160;\"User\":{\n&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;\"sex\":0\n&#160;&#160;&#160;&#160;&#160;&#160;}\n&#160;&#160;&#160;}\n}</string>

APIJSON(Android)/APIJSON(ADT)/src/zuo/biao/apijson/client/JSONResponse.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ public static JSONArray toJSONArray(com.alibaba.fastjson.JSONObject arrayObject)
115115
* @return
116116
*/
117117
public static JSONArray toJSONArray(com.alibaba.fastjson.JSONObject arrayObject, String className) {
118+
Set<String> set = arrayObject == null ? null : arrayObject.keySet();
119+
if (set == null || set.isEmpty()) {
120+
return null;
121+
}
122+
118123
String parentString = StringUtil.getTrimedString(com.alibaba.fastjson.JSON.toJSONString(arrayObject));
119124
if (parentString.isEmpty()) {
120125
return null;
@@ -125,12 +130,8 @@ public static JSONArray toJSONArray(com.alibaba.fastjson.JSONObject arrayObject,
125130
}
126131
return JSON.parseArray(parentString);
127132
}
128-
133+
129134
//{"0":{...}, "1":{...}...}
130-
Set<String> set = arrayObject == null ? null : arrayObject.keySet();
131-
if (set == null || set.isEmpty()) {
132-
return null;
133-
}
134135

135136
className = StringUtil.getTrimedString(className);
136137

APIJSON(Android)/APIJSON(ADT)/src/zuo/biao/apijson/client/ui/QueryActivity.java

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ public class QueryActivity extends Activity implements OnHttpResponseListener {
5151

5252

5353
public static final String INTENT_TYPE = "INTENT_TYPE";
54-
public static final String INTENT_URI = "INTENT_URI";
54+
public static final String INTENT_URL = "INTENT_URL";
5555

56-
public static final String RESULT_URI = "RESULT_URI";
56+
public static final String RESULT_URL = "RESULT_URL";
5757

5858
/**
5959
* @param context
6060
* @param type
61-
* @param uri
61+
* @param url
6262
* @return
6363
*/
64-
public static Intent createIntent(Context context, int type, String uri) {
64+
public static Intent createIntent(Context context, int type, String url) {
6565
return new Intent(context, QueryActivity.class)
6666
.putExtra(QueryActivity.INTENT_TYPE, type)
67-
.putExtra(QueryActivity.INTENT_URI, uri);
67+
.putExtra(QueryActivity.INTENT_URL, url);
6868
}
6969

7070

@@ -75,7 +75,7 @@ public static Intent createIntent(Context context, int type, String uri) {
7575

7676

7777
private int type = TYPE_SINGLE;
78-
private String uri;
78+
private String url;
7979

8080
private Activity context;
8181
private boolean isAlive;
@@ -92,15 +92,15 @@ protected void onCreate(Bundle savedInstanceState) {
9292

9393
Intent intent = getIntent();
9494
type = intent.getIntExtra(INTENT_TYPE, type);
95-
uri = intent.getStringExtra(INTENT_URI);
95+
url = intent.getStringExtra(INTENT_URL);
9696

9797

9898
tvQueryResult = (TextView) findViewById(R.id.tvQueryResult);
9999
pbQuery = (ProgressBar) findViewById(R.id.pbQuery);
100100
etQueryUri = (EditText) findViewById(R.id.etQueryUri);
101101

102-
etQueryUri.setText(StringUtil.getString(StringUtil.isNotEmpty(uri, true)
103-
? uri : "http://192.168.1.104:8080/get/"));
102+
etQueryUri.setText(StringUtil.getString(StringUtil.isNotEmpty(url, true)
103+
? url : "http://192.168.1.104:8080/get/"));//TODO my computer ipv4 address,you need to change it
104104

105105

106106
query();
@@ -133,7 +133,7 @@ public void query(View v) {
133133

134134
private String request;
135135
public void setRequest() {
136-
uri = StringUtil.getNoBlankString(etQueryUri);
136+
url = StringUtil.getNoBlankString(etQueryUri);
137137
switch (type) {
138138
case TYPE_SINGLE:
139139
request = JSON.toJSONString(RequestUtil.newSingleRequest());
@@ -154,10 +154,11 @@ public void setRequest() {
154154
private void query() {
155155
setRequest();
156156

157-
tvQueryResult.setText("requesting...\n\n uri = " + uri + "\n\n request = \n" + request);
157+
tvQueryResult.setText("requesting...\n\n url = " + url + "\n\n request = \n" + request
158+
+ "\n\n\n" + getResources().getString(R.string.query_error));
158159
pbQuery.setVisibility(View.VISIBLE);
159160

160-
HttpManager.getInstance().get(uri, request, this);
161+
HttpManager.getInstance().get(url, request, this);
161162
}
162163

163164

@@ -171,29 +172,17 @@ public void onHttpResponse(int requestCode, final String resultJson, final Excep
171172
}
172173
JSONResponse response = new JSONResponse(resultJson);
173174
if (type == TYPE_ARRAY) {
174-
List<User> list = JSONResponse.parseList(response.getJSONObject("User[]"), User.class);
175-
if (list == null || list.isEmpty()) {
176-
Log.e(TAG, "onHttpResponse type == TYPE_ARRAY >> list == null || list.isEmpty()");
177-
return;
178-
}
179-
for (User user : list) {
180-
Log.d(TAG, "\n onHttpResponse type == TYPE_ARRAY >> user = \n" + JSON.toJSONString(user));
181-
}
175+
logList(JSONResponse.parseList(response.getJSONObject("User[]"), User.class));
182176
} else if (type == TYPE_COMPLEX) {
183177
JSONArray array = JSONResponse.toJSONArray(response.getJSONObject("[]"));//, "Comment[]");//
184178
if (array == null || array.isEmpty()) {
185179
Log.e(TAG, "onHttpResponse type == TYPE_COMPLEX >> array == null || array.isEmpty() >> return;");
186180
return;
187181
}
188182
response = new JSONResponse(array.getJSONObject(0));
189-
List<Comment> list = JSONResponse.parseList(response.getJSONObject("Comment[]"), Comment.class);//, Comment.class);//
190-
if (list == null || list.isEmpty()) {
191-
Log.e(TAG, "onHttpResponse type == TYPE_COMPLEX >> list == null || list.isEmpty() >> return;");
192-
return;
193-
}
194-
for (Comment comment : list) {
195-
Log.d(TAG, "\n onHttpResponse type == TYPE_COMPLEX >> comment = \n" + JSON.toJSONString(comment));
196-
}
183+
184+
logList(JSONResponse.parseList(response, User.class));
185+
logList(JSONResponse.parseList(response == null ? null : response.getJSONObject("Comment[]"), Comment.class));
197186
}
198187

199188
runOnUiThread(new Runnable() {
@@ -205,21 +194,35 @@ public void run() {
205194
Toast.makeText(context, "received result!", Toast.LENGTH_SHORT).show();
206195

207196
tvQueryResult.setText(e == null || JSON.isJsonCorrect(resultJson)
208-
? StringUtil.getTrimedString(resultJson) : e.getMessage());
197+
? StringUtil.getTrimedString(resultJson)
198+
: e.getMessage() + "\n\n\n" + getResources().getString(R.string.query_error));
209199

210200
}
211201
}
212202
});
213203
}
214204

215205

206+
private <T> void logList(List<T> list) {
207+
if (list == null || list.isEmpty()) {
208+
Log.e(TAG, "logList list == null || list.isEmpty() >> return;");
209+
return;
210+
}
211+
for (T data : list) {
212+
Log.d(TAG, "\n logList " + (data == null ? "data" : data.getClass().getSimpleName())
213+
+ " = \n" + JSON.toJSONString(data));
214+
}
215+
}
216+
217+
218+
216219
/**打开网站
217220
*/
218221
public void openWebSite() {
219222
setRequest();
220223
String webSite = null;
221224
try {
222-
webSite = StringUtil.getNoBlankString(uri)
225+
webSite = StringUtil.getNoBlankString(url)
223226
+ URLEncoder.encode(StringUtil.getNoBlankString(request), HttpManager.UTF_8);
224227
} catch (UnsupportedEncodingException e) {
225228
e.printStackTrace();
@@ -236,7 +239,7 @@ public void openWebSite() {
236239

237240
@Override
238241
public void finish() {
239-
setResult(RESULT_OK, new Intent().putExtra(RESULT_URI, uri));
242+
setResult(RESULT_OK, new Intent().putExtra(RESULT_URL, url));
240243
super.finish();
241244
}
242245

APIJSON(Android)/APIJSON(ADT)/src/zuo/biao/apijson/client/ui/SelectActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public void selectComplex(View v) {
6161
}
6262
//click event,called form layout android:onClick >>>>>>>>>>>>>>>>
6363

64-
private String uri;
64+
private String url;
6565
private void select(int type) {
66-
startActivityForResult(QueryActivity.createIntent(context, type, uri), REQUEST_TO_QUERY);
66+
startActivityForResult(QueryActivity.createIntent(context, type, url), REQUEST_TO_QUERY);
6767
}
6868

6969
private static final int REQUEST_TO_QUERY = 1;
@@ -79,7 +79,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
7979
Toast.makeText(context, "onActivityResult data == null !!!", Toast.LENGTH_SHORT).show();
8080
return;
8181
}
82-
uri = data.getStringExtra(QueryActivity.RESULT_URI);
82+
url = data.getStringExtra(QueryActivity.RESULT_URL);
8383
break;
8484
default:
8585
break;

0 commit comments

Comments
 (0)