@@ -87,15 +87,19 @@ public static Intent createIntent(Context context, int type, String url) {
8787 public static final int TYPE_ACCESS_PERMITTED = 16 ;
8888
8989
90- private int type = TYPE_SINGLE ;
91- private String url ;
9290
9391 private Activity context ;
9492 private boolean isAlive ;
9593
94+ private int type = TYPE_COMPLEX ;
95+ private String url ;
96+ private String error ;
97+
9698 private TextView tvQueryResult ;
9799 private ProgressBar pbQuery ;
98100 private EditText etQueryUrl ;
101+ private Button btnQueryQuery ;
102+
99103 @ Override
100104 protected void onCreate (Bundle savedInstanceState ) {
101105 super .onCreate (savedInstanceState );
@@ -111,15 +115,18 @@ protected void onCreate(Bundle savedInstanceState) {
111115 tvQueryResult = (TextView ) findViewById (R .id .tvQueryResult );
112116 pbQuery = (ProgressBar ) findViewById (R .id .pbQuery );
113117 etQueryUrl = (EditText ) findViewById (R .id .etQueryUrl );
118+ btnQueryQuery = (Button ) findViewById (R .id .btnQueryQuery );
119+
114120
115121 etQueryUrl .setText (StringUtil .getString (StringUtil .isNotEmpty (url , true )
116122 ? url : "http://139.196.140.118:8080/" ));//TODO my server ipv4 address, edit it to your server url
123+ btnQueryQuery .setText (getMethod (type ));
117124
118- query ();
119125
126+ error = String .format (getResources ().getString (R .string .query_error ), StringUtil .getTrimedString (btnQueryQuery ));
127+
128+ query ();
120129
121- Button btnQueryQuery = (Button ) findViewById (R .id .btnQueryQuery );
122- btnQueryQuery .setText (getMethod (type ));
123130
124131 btnQueryQuery .setOnClickListener (new OnClickListener () {
125132
@@ -144,14 +151,15 @@ public boolean onLongClick(View v) {
144151 private void query () {
145152 setRequest ();
146153
147- tvQueryResult .setText ("requesting...\n \n url = " + url + "\n \n request = \n " + request
148- + "\n \n \n " + getResources ().getString (R .string .query_error ));
154+ final String fullUrl = getUrl (type );
155+
156+ tvQueryResult .setText ("requesting...\n \n url = " + fullUrl + "\n \n request = \n " + request + "\n \n \n " + error );
149157 pbQuery .setVisibility (View .VISIBLE );
150158
151159 if (type < 10 ) {
152- HttpManager .getInstance ().post (getUrl ( type ) , request , this );
160+ HttpManager .getInstance ().post (fullUrl , request , this );
153161 } else {
154- HttpManager .getInstance ().get (getUrl ( type ) , request , this );
162+ HttpManager .getInstance ().get (fullUrl , request , this );
155163 }
156164 }
157165
@@ -175,12 +183,12 @@ public void openWebSite() {
175183 }
176184
177185
178-
179-
186+
187+
180188 private String getUrl (int type ) {
181- return url + getMethod ( type ) + "/" ;
189+ return url + StringUtil . getTrimedString ( btnQueryQuery ) + "/" ;
182190 }
183-
191+
184192 private String getMethod (int type ) {
185193 switch (type ) {
186194 case TYPE_POST :
@@ -193,7 +201,7 @@ private String getMethod(int type) {
193201 return "get" ;
194202 }
195203 }
196-
204+
197205 private String request ;
198206 public void setRequest () {
199207 url = StringUtil .getNoBlankString (etQueryUrl );
@@ -247,15 +255,15 @@ public void onHttpResponse(int requestCode, final String resultJson, final Excep
247255 JSONArray array = JSONResponse .getJSONArray (response .getJSONObject ("[]" ));//, "Comment[]");//
248256 if (array == null || array .isEmpty ()) {
249257 Log .e (TAG , "onHttpResponse type == TYPE_COMPLEX >> array == null || array.isEmpty() >> return;" );
250- return ;
258+ } else {
259+ response = new JSONResponse (array .getJSONObject (0 ));
260+
261+ User user = JSONResponse .getObject (response , User .class );
262+ Log .d (TAG , "onHttpResponse type == TYPE_COMPLEX >> user = " + JSON .toJSONString (user ));
263+ Work work = JSONResponse .getObject (response , Work .class );
264+ Log .d (TAG , "onHttpResponse type == TYPE_COMPLEX >> work = " + JSON .toJSONString (work ));
265+ logList (JSONResponse .getList (response == null ? null : response .getJSONObject ("Comment[]" ), Comment .class ));
251266 }
252- response = new JSONResponse (array .getJSONObject (0 ));
253-
254- User user = JSONResponse .getObject (response , User .class );
255- Log .d (TAG , "onHttpResponse type == TYPE_COMPLEX >> user = " + JSON .toJSONString (user ));
256- Work work = JSONResponse .getObject (response , Work .class );
257- Log .d (TAG , "onHttpResponse type == TYPE_COMPLEX >> work = " + JSON .toJSONString (work ));
258- logList (JSONResponse .getList (response == null ? null : response .getJSONObject ("Comment[]" ), Comment .class ));
259267 } else if (type == TYPE_ACCESS_PERMITTED ) {
260268 response = new JSONResponse (resultJson );
261269 Wallet wallet = JSONResponse .getObject (response , Wallet .class );
@@ -271,8 +279,7 @@ public void run() {
271279 Toast .makeText (context , "received result!" , Toast .LENGTH_SHORT ).show ();
272280
273281 tvQueryResult .setText (e == null || JSON .isJsonCorrect (resultJson )
274- ? StringUtil .getTrimedString (resultJson )
275- : e .getMessage () + "\n \n \n " + getResources ().getString (R .string .query_error ));
282+ ? StringUtil .getTrimedString (resultJson ) : e .getMessage () + "\n \n \n " + error );
276283
277284 }
278285 }
0 commit comments