> list, Throwable tr) {
129 | for (Class> clazz : list) {
130 | if (clazz.isInstance(tr)) {
131 | return true;
132 | }
133 | }
134 | return false;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/library/src/main/java/com/lurencun/cfuture09/androidkit/http/async/SyncHttpClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * @(#)SyncHttpClient.java Project:androidkit
3 | * Date:2013-5-9
4 | *
5 | * Copyright (c) 2013 CFuture09, Institute of Software,
6 | * Guangdong Ocean University, Zhanjiang, GuangDong, China.
7 | * All rights reserved.
8 | *
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | */
21 | package com.lurencun.cfuture09.androidkit.http.async;
22 |
23 | import android.content.Context;
24 | import android.os.Message;
25 |
26 | import org.apache.http.HttpResponse;
27 | import org.apache.http.client.methods.HttpUriRequest;
28 | import org.apache.http.impl.client.DefaultHttpClient;
29 | import org.apache.http.protocol.HttpContext;
30 |
31 | /**
32 | * @author Geek_Soledad
37 | */
38 | public abstract class SyncHttpClient extends AsyncHttp {
39 | private int responseCode;
40 | /*
41 | * as this is a synchronous request this is just a helping mechanism to pass
42 | * the result back to this method. Therefore the result object has to be a
43 | * field to be accessible
44 | */
45 | protected String result;
46 | protected AsyncHttpResponseHandler responseHandler = new AsyncHttpResponseHandler() {
47 |
48 | @Override
49 | void sendResponseMessage(HttpResponse response) {
50 | responseCode = response.getStatusLine().getStatusCode();
51 | super.sendResponseMessage(response);
52 | };
53 |
54 | @Override
55 | protected void sendMessage(Message msg) {
56 | /*
57 | * Dont use the handler and send it directly to the analysis
58 | * (because its all the same thread)
59 | */
60 | handleMessage(msg);
61 | }
62 |
63 | @Override
64 | public void onSuccess(String content) {
65 | result = content;
66 | }
67 |
68 | @Override
69 | public void onFailure(Throwable error, String content) {
70 | result = onRequestFailed(error, content);
71 | }
72 | };
73 |
74 | /**
75 | * @return the response code for the last request, might be usefull
76 | * sometimes
77 | */
78 | public int getResponseCode() {
79 | return responseCode;
80 | }
81 |
82 | // Private stuff
83 | @Override
84 | protected void sendRequest(DefaultHttpClient client, HttpContext httpContext,
85 | HttpUriRequest uriRequest, String contentType,
86 | AsyncHttpResponseHandler responseHandler, Context context) {
87 | if (contentType != null) {
88 | uriRequest.addHeader("Content-Type", contentType);
89 | }
90 |
91 | /*
92 | * will execute the request directly
93 | */
94 | new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler).run();
95 | }
96 |
97 | public abstract String onRequestFailed(Throwable error, String content);
98 |
99 | public void delete(String url, RequestParams queryParams,
100 | AsyncHttpResponseHandler responseHandler) {
101 | // TODO what about query params??
102 | delete(url, responseHandler);
103 | }
104 |
105 | public String get(String url, RequestParams params) {
106 | this.get(url, params, responseHandler);
107 | /*
108 | * the response handler will have set the result when this line is
109 | * reached
110 | */
111 | return result;
112 | }
113 |
114 | public String get(String url) {
115 | this.get(url, null, responseHandler);
116 | return result;
117 | }
118 |
119 | public String put(String url, RequestParams params) {
120 | this.put(url, params, responseHandler);
121 | return result;
122 | }
123 |
124 | public String put(String url) {
125 | this.put(url, null, responseHandler);
126 | return result;
127 | }
128 |
129 | public String post(String url, RequestParams params) {
130 | this.post(url, params, responseHandler);
131 | return result;
132 | }
133 |
134 | public String post(String url) {
135 | this.post(url, null, responseHandler);
136 | return result;
137 | }
138 |
139 | public String delete(String url, RequestParams params) {
140 | this.delete(url, params, responseHandler);
141 | return result;
142 | }
143 |
144 | public String delete(String url) {
145 | this.delete(url, null, responseHandler);
146 | return result;
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/githang/androidkit/sample/uibind/UIBindSample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * @(#)UIBindSample.java Project:androidkit.sample
3 | * Date:2013-5-14
4 | *
5 | * Copyright (c) 2013 CFuture09, Institute of Software,
6 | * Guangdong Ocean University, Zhanjiang, GuangDong, China.
7 | * All rights reserved.
8 | *
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | */
21 | package com.githang.androidkit.sample.uibind;
22 |
23 | import android.annotation.SuppressLint;
24 | import android.app.Activity;
25 | import android.os.Bundle;
26 | import android.view.View;
27 | import android.widget.AdapterView;
28 | import android.widget.ArrayAdapter;
29 | import android.widget.ListAdapter;
30 | import android.widget.ListView;
31 | import android.widget.TextView;
32 | import android.widget.Toast;
33 |
34 | import com.githang.androidkit.sample.R;
35 | import com.githang.androidkit.uibind.UIBindUtil;
36 | import com.githang.androidkit.uibind.annotation.AndroidView;
37 | import com.githang.androidkit.uibind.annotation.OnClick;
38 |
39 | /**
40 | * 该类为UIBind及ResBind的示例。使用传统的方法,对于控件,您可能需要这样写:
41 | *
42 | *
43 | * private Button buttonLeft;
44 | * private Button buttonRight;
45 | * private TextView textView;
46 | * private ListView listView;
47 | *
48 | * private Toast toast;
49 | *
50 | * @Override
51 | * protected void onCreate(Bundle savedInstanceState) {
52 | * super.onCreate(savedInstanceState);
53 | * toast = Toast.makeText(this, "", Toast.LENGTH_LONG);
54 | * setContentView(R.layout.activity_bind);
55 | *
56 | * buttonLeft = (Button) findViewById(R.id.bind_buttonLeft);
57 | * buttonRight = (Button) findViewById(R.id.bind_buttonRight);
58 | * textView = (TextView) findViewById(R.id.bind_textview);
59 | * listView = (TextView) findViewById(R.id.bind_listview);
60 | *
61 | * buttonLeft.setOnClickListener(new OnClickListener() {
62 | * @Override
63 | * public void onClick(View v) {
64 | * showToast("click left button");
65 | * }
66 | * });
67 | * buttonRight.setOnClickListener(new OnClickListener() {
68 | * @Override
69 | * public void onClick(View v) {
70 | * showToast("click right button");
71 | * }
72 | * });
73 | * textView.setText(R.string.text);
74 | *
75 | * String[] array = getResources().getStringArray(R.array.listview);
76 | * ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array);
77 | * listView.setAdapter(adapter);
78 | * listView.setOnItemClickListener(new OnItemClickListener() {
79 | * @Override
80 | * public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
81 | * showToast(listView.getAdapter().getItem(arg2).toString());
82 | *
83 | * }
84 | * });
85 | * }
86 | *
87 | * private void showToast(String msg) {
88 | * toast.setText(msg);
89 | * toast.show();
90 | * }
91 | *
92 | *
93 | * 而如果使用本框架的uibind功能模块,初始化的代码将简化如下。
94 | *
95 | * @author Geek_Soledad
100 | */
101 | public class UIBindSample extends Activity {
102 | @AndroidView(id = R.id.bind_textview)
103 | private TextView textView;
104 | @AndroidView(id = R.id.bind_listview, onItemClick = "onItemClick")
105 | private ListView listView;
106 |
107 | private Toast toast;
108 |
109 | @SuppressLint("ShowToast")
110 | @Override
111 | protected void onCreate(Bundle savedInstanceState) {
112 | super.onCreate(savedInstanceState);
113 | toast = Toast.makeText(this, "", Toast.LENGTH_LONG);
114 | UIBindUtil.bind(this, R.layout.activity_bind);
115 | textView.setText(R.string.text);
116 |
117 | String[] array = getResources().getStringArray(R.array.listview);
118 | ListAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,
119 | array);
120 | listView.setAdapter(adapter);
121 | }
122 |
123 | public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {
124 | showToast(listView.getAdapter().getItem(arg2).toString());
125 | }
126 |
127 | @OnClick(viewId = { R.id.bind_buttonLeft, R.id.bind_buttonRight })
128 | public void onClick(View v) {
129 | switch (v.getId()) {
130 | case R.id.bind_buttonLeft:
131 | showToast("click left button");
132 | break;
133 | case R.id.bind_buttonRight:
134 | showToast("click right button");
135 | break;
136 | default:
137 | break;
138 | }
139 | }
140 |
141 | private void showToast(String msg) {
142 | toast.setText(msg);
143 | toast.show();
144 | }
145 | }
146 |
--------------------------------------------------------------------------------