Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/com/androidquery/callback/AbstractAjaxCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public abstract class AbstractAjaxCallback<T, K> implements Runnable{
private long expire;
private String encoding = "UTF-8";
private WeakReference<Activity> act;
private WeakReference<Context> ctx;

private int method = Constants.METHOD_DETECT;
private HttpUriRequest request;
Expand All @@ -165,6 +166,7 @@ private void clear(){
transformer = null;
ah = null;
act = null;
ctx = null;
}

/**
Expand Down Expand Up @@ -884,10 +886,8 @@ public void async(Activity act){
AQUtility.warn("Warning", "type() is not called with response type.");
return;
}

this.act = new WeakReference<Activity>(act);
async((Context) act);

}


Expand All @@ -898,7 +898,7 @@ public void async(Activity act){
* @param context the context
*/
public void async(Context context){
this.ctx = new WeakReference<Context>(context);
if(status == null){
status = new AjaxStatus();
status.redirect(url).refresh(refresh);
Expand Down Expand Up @@ -949,7 +949,6 @@ public void failure(int code, String message){


private void work(Context context){

T object = memGet(url);

if(object != null){
Expand Down Expand Up @@ -985,7 +984,6 @@ public void run() {
AQUtility.debug(e);
status.code(AjaxStatus.NETWORK_ERROR).done();
}

if(!status.getReauth()){
//if doesn't need to reauth
if(uiCallback){
Expand Down Expand Up @@ -1015,6 +1013,11 @@ private void backgroundWork(){
if(result == null){
datastoreWork();
}

if(result == null){
assetsWork();
}


if(result == null){
networkWork();
Expand Down Expand Up @@ -1072,6 +1075,24 @@ private void datastoreWork(){
}
}

private static final String PREFIX_ASSETS = "assets://";

private void assetsWork(){
if (url.startsWith(PREFIX_ASSETS) == false){
return;
}
try {
String u = url.substring(PREFIX_ASSETS.length());
InputStream is = ctx.get().getAssets().open(u);
status.data(AQUtility.toBytes(is)).source(AjaxStatus.ASSETS)
.code(200).done();
result = transform(url, status.getData(), status);
} catch (IOException e) {
AQUtility.debug(e);
status.code(AjaxStatus.ASSETS_ERROR).message(e.getMessage());
}
}

private boolean reauth;
private void networkWork(){

Expand Down
7 changes: 5 additions & 2 deletions src/com/androidquery/callback/AjaxStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ public class AjaxStatus {

/** Source DEVICE. */
public static final int DEVICE = 5;


/** Source ASSET. */
public static final int ASSETS = 6;

public static final int NETWORK_ERROR = -101;
public static final int AUTH_ERROR = -102;
public static final int TRANSFORM_ERROR = -103;

public static final int ASSETS_ERROR = -104;

private int code = 200;
private String message = "OK";
Expand Down