Skip to content

Commit eb6b200

Browse files
committed
Client:自动生成代码界面新增各种HTTP方法;优化UI
1 parent 13a0f23 commit eb6b200

7 files changed

Lines changed: 89 additions & 44 deletions

File tree

APIJSON(Android)/APIJSON(ADT)/APIJSONTest/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
android:label="@string/request" />
3333
<activity
3434
android:name="apijson.demo.ui.AutoActivity"
35+
android:label="@string/auto"
3536
android:screenOrientation="landscape" />
3637
</application>
3738

APIJSON(Android)/APIJSON(ADT)/APIJSONTest/res/layout/auto_activity.xml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,28 @@
1515
android:id="@+id/tvAutoRequest"
1616
android:layout_width="0dp"
1717
android:layout_height="wrap_content"
18+
android:layout_marginRight="6dp"
1819
android:layout_weight="1"
1920
android:background="@null"
2021
android:gravity="top|left"
2122
android:hint="request"
22-
android:padding="@dimen/activity_horizontal_margin" />
23+
android:textSize="15sp" />
2324

2425
<View
2526
android:layout_width="1dp"
2627
android:layout_height="match_parent"
27-
android:layout_marginLeft="6dp"
28-
android:layout_marginRight="6dp"
2928
android:background="@android:color/white" />
3029

3130
<TextView
3231
android:id="@+id/tvAutoResponse"
3332
android:layout_width="0dp"
3433
android:layout_height="wrap_content"
35-
android:layout_weight="1"
34+
android:layout_marginLeft="6dp"
35+
android:layout_weight="2"
3636
android:background="@null"
3737
android:gravity="top|left"
3838
android:hint="response"
39-
android:onClick="copy"
40-
android:padding="@dimen/activity_horizontal_margin"
41-
android:selectAllOnFocus="true" />
39+
android:onClick="copy" />
4240
</LinearLayout>
4341
</ScrollView>
4442

@@ -53,33 +51,42 @@
5351
android:gravity="bottom"
5452
android:orientation="horizontal" >
5553

56-
<ProgressBar
57-
android:id="@+id/pbAuto"
54+
<Button
55+
android:layout_width="match_parent"
56+
android:layout_height="match_parent"
57+
android:layout_weight="1"
58+
android:onClick="auto"
59+
android:text="Auto" />
60+
61+
<Button
5862
android:layout_width="wrap_content"
5963
android:layout_height="match_parent"
60-
android:visibility="gone" />
64+
android:onClick="get"
65+
android:text="GET" />
6166

62-
<EditText
63-
android:id="@+id/etAutoUrl"
64-
style="@style/select_name"
67+
<Button
68+
android:layout_width="wrap_content"
6569
android:layout_height="match_parent"
66-
android:layout_gravity="bottom"
67-
android:layout_weight="1"
68-
android:gravity="bottom|left"
69-
android:padding="0dp"
70-
android:text="uri" />
70+
android:onClick="head"
71+
android:text="HEAD" />
7172

7273
<Button
7374
android:layout_width="wrap_content"
7475
android:layout_height="match_parent"
75-
android:onClick="query"
76-
android:text="Query" />
76+
android:onClick="get"
77+
android:text="POST" />
7778

7879
<Button
7980
android:layout_width="wrap_content"
8081
android:layout_height="match_parent"
81-
android:onClick="auto"
82-
android:text="Auto" />
82+
android:onClick="put"
83+
android:text="PUT" />
84+
85+
<Button
86+
android:layout_width="wrap_content"
87+
android:layout_height="match_parent"
88+
android:onClick="delete"
89+
android:text="DELETE" />
8390
</LinearLayout>
8491

8592
</LinearLayout>

APIJSON(Android)/APIJSON(ADT)/APIJSONTest/res/layout/request_activity.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
android:id="@+id/tvRequestResult"
1616
style="@style/select_json"
1717
android:hint="result"
18-
android:padding="@dimen/activity_horizontal_margin"
18+
android:padding="16dp"
1919
android:textIsSelectable="true" />
2020
</LinearLayout>
2121
</ScrollView>

APIJSON(Android)/APIJSON(ADT)/APIJSONTest/res/layout/select_activity.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
style="@style/match_wrap"
9898
android:layout_marginTop="30dp"
9999
android:onClick="toAuto"
100-
android:text="auto" />
100+
android:text="@string/auto" />
101101

102102
<Button
103103
android:onClick="toUpdateLog"

APIJSON(Android)/APIJSON(ADT)/APIJSONTest/res/values-en/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<string name="complex">Complex</string>
1414
<string name="access_error">Access Error</string>
1515
<string name="access_permitted">Access Permitted</string>
16+
<string name="auto">Auto Code</string>
1617
<string name="update_log">Update Log</string>
1718
<string name="received_result">received result!</string>
1819
<string name="browser_can_only_receive_get_response">Browsers can only receive GET responses</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<string name="complex">复杂结构</string>
1616
<string name="access_error">没有访问权限</string>
1717
<string name="access_permitted">允许使用权限</string>
18+
<string name="auto">自动生成代码</string>
1819
<string name="update_log">更新日志</string>
1920
<string name="received_result">已获得结果!</string>
2021
<string name="browser_can_only_receive_get_response">用浏览器只能获取GET结果</string>

APIJSON(Android)/APIJSON(ADT)/APIJSONTest/src/apijson/demo/ui/AutoActivity.java

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,48 @@ protected void onCreate(Bundle savedInstanceState) {
6666

6767

6868

69-
String request = "{\"User\":{\"id\":38710,\"@column\":\"id,name\"},\"[]\":{\"count\":3,\"page\":1,\"Moment\":{\"userId@\":\"User/id\"}}}";
69+
String request = "{\"User\":{\"id\":38710},\"[]\":{\"count\":3,\"page\":1,\"Moment\":{\"userId@\":\"User/id\",\"@column\":\"id,userId,content\"}}}";
7070

7171
tvAutoRequest.setText(StringUtil.getString(JSON.format(request)));
7272

7373
}
7474

7575

76-
public void query(View v) {
77-
startActivityForResult(RequestActivity.createIntent(context, 0, null, "get"
78-
, JSON.parseObject(StringUtil.getString(tvAutoRequest)), false), REQUEST_TO_REQUEST);
76+
public void copy(View v) {
77+
StringUtil.copyText(context, StringUtil.getString(tvAutoResponse));
7978
}
8079

81-
82-
8380
public void auto(View v) {
8481
auto(StringUtil.getString(tvAutoRequest));
8582
}
83+
84+
public void get(View v) {
85+
request((TextView) v);
86+
}
87+
public void head(View v) {
88+
request((TextView) v);
89+
}
90+
public void post(View v) {
91+
request((TextView) v);
92+
}
93+
public void put(View v) {
94+
request((TextView) v);
95+
}
96+
public void delete(View v) {
97+
request((TextView) v);
98+
}
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
86111
public void auto(String request) {
87112
String response = parse("", JSON.parseObject(request)); //newObjectRequest(request);
88113

@@ -92,11 +117,21 @@ public void auto(String request) {
92117
tvAutoResponse.setText(StringUtil.getString(response));
93118
}
94119

95-
public void copy(View v) {
96-
StringUtil.copyText(context, StringUtil.getString(tvAutoResponse));
120+
121+
@SuppressLint("DefaultLocale")
122+
public void request(TextView tv) {
123+
request(StringUtil.getNoBlankString(tv).toLowerCase());
97124
}
125+
public void request(String method) {
126+
startActivityForResult(RequestActivity.createIntent(context, 0, null, method
127+
, JSON.parseObject(StringUtil.getString(tvAutoRequest)), false), REQUEST_TO_REQUEST);
128+
}
129+
98130

99131

132+
133+
134+
100135
public static final String NEWLINE = "\n";
101136

102137
/**
@@ -105,9 +140,9 @@ public void copy(View v) {
105140
* @return
106141
*/
107142
public static String parse(final String name, final JSONObject request) {
108-
// Log.i(TAG, "parse request = \n" + JSON.toJSONString(request));
143+
// Log.i(TAG, "parse request = \n" + JSON.toJSONString(request));
109144
if (request == null || request.isEmpty()) {
110-
// Log.i(TAG, "parse request == null || request.isEmpty() >> return request;");
145+
// Log.i(TAG, "parse request == null || request.isEmpty() >> return request;");
111146
return null;
112147
}
113148
String parentKey = isArrayKey(name) ? getItemKey(name) : getTableKey(name);
@@ -126,7 +161,7 @@ public static String parse(final String name, final JSONObject request) {
126161
if (value instanceof JSONObject) {//APIJSON Array转为常规JSONArray
127162
if (isArrayKey(key)) {//APIJSON Array转为常规JSONArray
128163
response += NEWLINE + NEWLINE + "//" + key + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
129-
164+
130165
int count = ((JSONObject) value).getIntValue(JSONRequest.KEY_COUNT);
131166
int page = ((JSONObject) value).getIntValue(JSONRequest.KEY_PAGE);
132167
((JSONObject) value).remove(JSONRequest.KEY_COUNT);
@@ -139,11 +174,11 @@ public static String parse(final String name, final JSONObject request) {
139174
response += NEWLINE + NEWLINE
140175
+ parentKey + ".add(" + getItemKey(key) + ".toArray("
141176
+ count + ", " + page + (prefix.isEmpty() ? "" : ", " + prefix) + "));";
142-
177+
143178
response += NEWLINE + "//" + key + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + NEWLINE;
144179
} else {//常规JSONObject,往下一级提取
145180
response += NEWLINE + NEWLINE + "//" + key + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
146-
181+
147182
response += parse(key, (JSONObject) value);
148183

149184
response += NEWLINE + NEWLINE + parentKey + ".put(" + pairKey + ", " + getTableKey(key) + ");";
@@ -157,7 +192,7 @@ public static String parse(final String name, final JSONObject request) {
157192
}
158193
}
159194

160-
// Log.i(TAG, "parse return response = \n" + response);
195+
// Log.i(TAG, "parse return response = \n" + response);
161196
return response;
162197
}
163198

@@ -220,12 +255,12 @@ private static String firstCase(String key, boolean upper) {
220255
private static boolean isArrayKey(String key) {
221256
return JSONResponse.isArrayKey(key);
222257
}
223-
224-
225-
226-
227-
228-
258+
259+
260+
261+
262+
263+
229264
private static final int REQUEST_TO_REQUEST = 1;
230265
@Override
231266
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

0 commit comments

Comments
 (0)