Skip to content

Commit 725fc68

Browse files
committed
Merge remote-tracking branch 'origin/dev'
Conflicts: dist/build-full.jardesc src/com/androidquery/callback/AbstractAjaxCallback.java src/com/androidquery/util/Constants.java
2 parents 5784742 + 578eb9d commit 725fc68

File tree

11 files changed

+288
-91
lines changed

11 files changed

+288
-91
lines changed

demo/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="aquery"/>
4-
<classpathentry kind="src" path="beta"/>
54
<classpathentry kind="src" path="auth"/>
5+
<classpathentry kind="src" path="beta"/>
66
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
77
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
88
<classpathentry kind="src" path="src"/>

demo/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.androidquery"
4-
android:versionCode="51"
5-
android:versionName="0.29.51">
4+
android:versionCode="52"
5+
android:versionName="0.29.52">
66

77

88
<uses-permission android:name="android.permission.INTERNET" />

dist/build-full.jardesc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
22
<jardesc>
33

4-
<jar path="AndroidQuery/dist/android-query-full.0.23.16.jar"/>
4+
<jar path="AndroidQuery/dist/android-query-full.0.24.3.jar"/>
55

66
<options buildIfNeeded="true" compress="true" descriptionLocation="/AndroidQuery/dist/build-full.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
77
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>

src/com/androidquery/AbstractAQuery.java

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.WeakHashMap;
2727

2828
import org.apache.http.HttpEntity;
29+
import org.apache.http.HttpHost;
2930

3031
import android.app.Activity;
3132
import android.app.Dialog;
@@ -99,6 +100,7 @@ public abstract class AbstractAQuery<T extends AbstractAQuery<T>> implements Con
99100
protected AccountHandle ah;
100101
private Transformer trans;
101102
private int policy = CACHE_DEFAULT;
103+
private HttpHost proxy;
102104

103105
protected T create(View view){
104106

@@ -188,6 +190,23 @@ private View findView(int id){
188190
return result;
189191
}
190192

193+
private View findView(String tag){
194+
195+
//((ViewGroup)findViewById(android.R.id.content)).getChildAt(0)
196+
View result = null;
197+
if(root != null){
198+
result = root.findViewWithTag(tag);
199+
}else if(act != null){
200+
//result = act.findViewById(id);
201+
View top = ((ViewGroup) act.findViewById(android.R.id.content)).getChildAt(0);
202+
if(top != null){
203+
result = top.findViewWithTag(tag);
204+
}
205+
}
206+
return result;
207+
208+
}
209+
191210
private View findView(int... path){
192211

193212
View result = findView(path[0]);
@@ -278,11 +297,7 @@ public View getView(){
278297
* @return self
279298
*/
280299
public T id(int id){
281-
/*
282-
view = findView(id);
283-
reset();
284-
return self();
285-
*/
300+
286301
return id(findView(id));
287302
}
288303

@@ -298,18 +313,18 @@ public T id(View view){
298313
return self();
299314
}
300315

316+
public T id(String tag){
317+
return id(findView(tag));
318+
}
319+
301320
/**
302321
* Find the first view with first id, under that view, find again with 2nd id, etc...
303322
*
304323
* @param path The id path.
305324
* @return self
306325
*/
307326
public T id(int... path){
308-
/*
309-
view = findView(path);
310-
reset();
311-
return self();
312-
*/
327+
313328
return id(findView(path));
314329
}
315330

@@ -396,6 +411,11 @@ public T policy(int cachePolicy){
396411
return self();
397412
}
398413

414+
public T proxy(String host, int port){
415+
proxy = new HttpHost(host, port);
416+
return self();
417+
}
418+
399419
/**
400420
* Set the rating of a RatingBar.
401421
*
@@ -723,23 +743,27 @@ public T image(String url, boolean memCache, boolean fileCache, int targetWidth,
723743
*
724744
*/
725745
public T image(String url, boolean memCache, boolean fileCache, int targetWidth, int fallbackId, Bitmap preset, int animId, float ratio){
726-
return image(url, memCache, fileCache, targetWidth, fallbackId, preset, animId, ratio, 0);
746+
return image(url, memCache, fileCache, targetWidth, fallbackId, preset, animId, ratio, 0, null);
727747
}
728748

729-
private T image(String url, boolean memCache, boolean fileCache, int targetWidth, int fallbackId, Bitmap preset, int animId, float ratio, int round){
749+
protected T image(String url, boolean memCache, boolean fileCache, int targetWidth, int fallbackId, Bitmap preset, int animId, float ratio, int round, String networkUrl){
730750

731751
if(view instanceof ImageView){
732-
BitmapAjaxCallback.async(act, getContext(), (ImageView) view, url, memCache, fileCache, targetWidth, fallbackId, preset, animId, ratio, AQuery.ANCHOR_DYNAMIC, progress, ah, policy, round);
752+
BitmapAjaxCallback.async(act, getContext(), (ImageView) view, url, memCache, fileCache, targetWidth, fallbackId, preset, animId, ratio, AQuery.ANCHOR_DYNAMIC, progress, ah, policy, round, proxy, networkUrl);
733753
reset();
734754
}
735755

736756
return self();
737757
}
738758

739759
public T image(String url, ImageOptions options){
760+
return image(url, options, null);
761+
}
762+
763+
protected T image(String url, ImageOptions options, String networkUrl){
740764

741765
if(view instanceof ImageView){
742-
BitmapAjaxCallback.async(act, getContext(), (ImageView) view, url, progress, ah, options);
766+
BitmapAjaxCallback.async(act, getContext(), (ImageView) view, url, progress, ah, options, proxy, networkUrl);
743767
reset();
744768
}
745769

@@ -1786,6 +1810,10 @@ protected <K> T invoke(AbstractAjaxCallback<?, K> cb){
17861810
cb.transformer(trans);
17871811
cb.policy(policy);
17881812

1813+
if(proxy != null){
1814+
cb.proxy(proxy.getHostName(), proxy.getPort());
1815+
}
1816+
17891817
if(act != null){
17901818
cb.async(act);
17911819
}else{
@@ -1797,12 +1825,13 @@ protected <K> T invoke(AbstractAjaxCallback<?, K> cb){
17971825
return self();
17981826
}
17991827

1800-
private void reset(){
1828+
protected void reset(){
18011829

18021830
ah = null;
18031831
progress = null;
18041832
trans = null;
18051833
policy = CACHE_DEFAULT;
1834+
proxy = null;
18061835

18071836
}
18081837

@@ -2578,4 +2607,4 @@ public T download(String url, File target, Object handler, String callback){
25782607

25792608
}
25802609

2581-
}
2610+
}

src/com/androidquery/callback/AbstractAjaxCallback.java

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.apache.http.client.methods.HttpPut;
5757
import org.apache.http.client.methods.HttpUriRequest;
5858
import org.apache.http.client.protocol.ClientContext;
59+
import org.apache.http.conn.HttpHostConnectException;
5960
import org.apache.http.conn.params.ConnManagerParams;
6061
import org.apache.http.conn.params.ConnPerRouteBean;
6162
import org.apache.http.conn.params.ConnRoutePNames;
@@ -119,6 +120,7 @@ public abstract class AbstractAjaxCallback<T, K> implements Runnable{
119120
private WeakReference<Object> progress;
120121

121122
private String url;
123+
private String networkUrl;
122124
private Map<String, Object> params;
123125
private Map<String, String> headers;
124126
private Map<String, String> cookies;
@@ -255,6 +257,12 @@ public K url(http://github.com/String%20url){
255257
return self();
256258
}
257259

260+
public K networkUrl(String url){
261+
this.networkUrl = url;
262+
return self();
263+
}
264+
265+
258266
/**
259267
* Set the desired ajax response type. Type parameter is required otherwise the ajax callback will not occur.
260268
*
@@ -494,6 +502,8 @@ void callback(){
494502
}
495503
}
496504

505+
}else{
506+
skip(url, result, status);
497507
}
498508

499509
filePut();
@@ -559,6 +569,10 @@ public void callback(String url, T object, AjaxStatus status){
559569

560570
}
561571

572+
protected void skip(String url, T object, AjaxStatus status){
573+
574+
}
575+
562576
protected T fileGet(String url, File file, AjaxStatus status){
563577

564578
try {
@@ -1004,6 +1018,21 @@ private String getCacheUrl(){
10041018
return url;
10051019
}
10061020

1021+
private String getNetworkUrl(String url){
1022+
1023+
String result = url;
1024+
1025+
if(networkUrl != null){
1026+
result = networkUrl;
1027+
}
1028+
1029+
if(ah != null){
1030+
result = ah.getNetworkUrl(result);
1031+
}
1032+
1033+
return result;
1034+
}
1035+
10071036
private void fileWork(){
10081037

10091038
File file = accessFile(cacheDir, getCacheUrl());
@@ -1190,9 +1219,7 @@ private void network() throws IOException{
11901219
params = extractParams(uri);
11911220
}
11921221

1193-
if(ah != null){
1194-
url = ah.getNetworkUrl(url);
1195-
}
1222+
url = getNetworkUrl(url);
11961223

11971224

11981225
if(Constants.METHOD_DELETE == method){
@@ -1450,7 +1477,6 @@ private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers,
14501477
HttpParams hp = hr.getParams();
14511478
if(proxy != null) hp.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
14521479
if(timeout > 0){
1453-
AQUtility.debug("timeout param", CoreConnectionPNames.CONNECTION_TIMEOUT);
14541480
hp.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
14551481
hp.setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
14561482
}
@@ -1465,7 +1491,22 @@ private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers,
14651491
throw new IOException("Aborted");
14661492
}
14671493

1468-
HttpResponse response = client.execute(hr, context);
1494+
HttpResponse response = null;
1495+
1496+
try{
1497+
response = client.execute(hr, context);
1498+
}catch(HttpHostConnectException e){
1499+
1500+
//if proxy is used, automatically retry without proxy
1501+
if(proxy != null){
1502+
AQUtility.debug("proxy failed, retrying without proxy");
1503+
hp.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
1504+
response = client.execute(hr, context);
1505+
}else{
1506+
throw e;
1507+
}
1508+
}
1509+
14691510

14701511
byte[] data = null;
14711512

@@ -1477,25 +1518,29 @@ private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers,
14771518
String error = null;
14781519

14791520
HttpEntity entity = response.getEntity();
1480-
Header eheader = entity.getContentEncoding();
1481-
1482-
String encoding = null;
1483-
if(eheader != null) encoding = eheader.getValue();
1484-
1521+
14851522
File file = null;
14861523

14871524
if(code < 200 || code >= 300){
14881525

1526+
InputStream is = null;
1527+
14891528
try{
14901529

1491-
InputStream is = entity.getContent();
1492-
byte[] s = toData(encoding, is);
1493-
1494-
error = new String(s, "UTF-8");
1530+
if(entity != null){
14951531

1496-
AQUtility.debug("error", error);
1532+
is = entity.getContent();
1533+
byte[] s = toData(getEncoding(entity), is);
1534+
1535+
error = new String(s, "UTF-8");
1536+
1537+
AQUtility.debug("error", error);
1538+
1539+
}
14971540
}catch(Exception e){
14981541
AQUtility.debug(e);
1542+
}finally{
1543+
AQUtility.close(is);
14991544
}
15001545

15011546

@@ -1523,7 +1568,7 @@ private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers,
15231568

15241569
//AQUtility.time("copy");
15251570

1526-
copy(entity.getContent(), os, encoding, (int) entity.getContentLength());
1571+
copy(entity.getContent(), os, getEncoding(entity), (int) entity.getContentLength());
15271572

15281573
//AQUtility.timeEnd("copy", 0);
15291574

@@ -1553,6 +1598,18 @@ private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers,
15531598
status.code(code).message(message).error(error).redirect(redirect).time(new Date()).data(data).file(file).client(client).context(context).headers(response.getAllHeaders());
15541599

15551600

1601+
}
1602+
1603+
1604+
private String getEncoding(HttpEntity entity){
1605+
1606+
if(entity == null) return null;
1607+
1608+
Header eheader = entity.getContentEncoding();
1609+
if(eheader == null) return null;
1610+
1611+
return eheader.getValue();
1612+
15561613
}
15571614

15581615
private void copy(InputStream is, OutputStream os, String encoding, int max) throws IOException{

src/com/androidquery/callback/AjaxStatus.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected AjaxStatus source(int source){
8989
return this;
9090
}
9191

92-
protected AjaxStatus code(int code){
92+
public AjaxStatus code(int code){
9393
this.code = code;
9494
return this;
9595
}
@@ -99,7 +99,7 @@ protected AjaxStatus error(String error){
9999
return this;
100100
}
101101

102-
protected AjaxStatus message(String message){
102+
public AjaxStatus message(String message){
103103
this.message = message;
104104
return this;
105105
}
@@ -139,7 +139,7 @@ protected AjaxStatus headers(Header[] headers){
139139
return this;
140140
}
141141

142-
protected AjaxStatus done(){
142+
public AjaxStatus done(){
143143
this.duration = System.currentTimeMillis() - start;
144144
this.done = true;
145145
this.reauth = false;

0 commit comments

Comments
 (0)