Android Open Source - AndroidWeb Web Response






From Project

Back to project page AndroidWeb.

License

The source code is released under:

Copyright (c) 2012, The Smyth Group Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in ...

If you think the Android project AndroidWeb listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.tsg.web;
/*w w w.j  a v  a  2  s . c o m*/
import android.content.Context;
import android.os.Bundle;
import java.io.InputStream;
import java.io.Serializable;

public class WebResponse {

  private Context mContext;
  private int mResultCode;
  private Bundle mResultData;
  private Bundle mSerializables;

  public WebResponse(Context context) {
    this(context, 0, null);
  }

  public WebResponse(Context context, int resultCode, Bundle resultData) {
    mContext = context;
    mResultCode = resultCode;
    mResultData = resultData;
    mSerializables = new Bundle();
  }

  public <T extends Serializable> T get(String key) {
    return (T) mSerializables.getSerializable(key);
  }

  public void set(String key, Serializable obj) {
    mSerializables.putSerializable(key, obj);
  }

  public synchronized void join() {
    while(isRunning()) {
      try {
        wait();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }

  public synchronized void setResultCode(int resultCode) {
    mResultCode = resultCode;
    if (!isRunning()) {
      notifyAll();
    }
  }

  public void setResultData(Bundle resultData) {
    mResultData = resultData;
  }

  public Context getContext() {
    return mContext;
  }

  public int getStatus() {
    return mResultCode;
  }

  public boolean isRunning() {
    // return mResultCode == WebReceiver.STATUS_RUNNING;
    return !isFinished() && !isException();
  }

  public boolean isFinished() {
    return mResultCode == WebReceiver.STATUS_FINISHED;
  }

  public boolean isException() {
    return mResultCode == WebReceiver.STATUS_ERROR;
  }

  public String getRequestKey() {
    return mResultData.getString(WebReceiver.REQUEST_KEY);
  }

  public String getString() {
    return WebService.getResponseString(mContext, getRequestKey());
  }

  public byte[] getBytes() {
    return WebService.getResponseBytes(mContext, getRequestKey());
  }

  public InputStream getStream() {
    return WebService.getResponseStream(mContext, getRequestKey());
  }

  public Exception getException() {
    return (Exception) mResultData.getSerializable(WebReceiver.RESPONSE_EXCEPTION);
  }

}




Java Source Code List

org.tsg.web.WebClient.java
org.tsg.web.WebContentProvider.java
org.tsg.web.WebReceiver.java
org.tsg.web.WebRequest.java
org.tsg.web.WebResponse.java
org.tsg.web.WebService.java