Back to project page Resonos-Android-Framework.
The source code is released under:
Apache License
If you think the Android project Resonos-Android-Framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.resonos.apps.library.util; // w ww. j ava 2s . c om import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; /** * Represents a single network request * @author Chris */ public class NetworkRequest { /** * Base network request builder object. This implementation is a standard HTTP GET. */ public static class BaseRequestBuilder { /** Network request types */ public enum Method {GET, POST}; String mURL; public BaseRequestBuilder(String url) { mURL = url; } public String getFullPath() { return mURL; } public Method getMethod() { return Method.GET; } } public List<NameValuePair> mParams; public BaseRequestBuilder mType; public Enum<?> mID; int mRetries; public boolean mServerBusy; /** * Create a new network request * @param ID : an enum identifier * @param filename : the filename * @param type : a request type that indicates how to build the url and whether to get, post, etc... * @param params : a list of name-value pairs, or null */ public NetworkRequest(Enum<?> ID, BaseRequestBuilder type, List<NameValuePair> params) { mID = ID; mType = type; mParams = params; mRetries = 0; mServerBusy = false; } /** * Convenience method for getting the value of a param * @param name : the String key name * @return the value of the parameter, or an empty String if not found */ public String getParam(String name) { for (int i = 0; i < mParams.size(); i++) { if (mParams.get(i).getName().equals(name)) return mParams.get(i).getValue(); } return ""; } /** * Convenience method for updating/inserting the value of a param * @param name : the String key name * @param value : the value to associate */ public void setParam(String name, String value) { for (int i = 0; i < mParams.size(); i++) { if (mParams.get(i).getName().equals(name)) { mParams.remove(i); break; } } mParams.add(new BasicNameValuePair(name, value)); } /** * Convenience method for getting the value of a param * @param name : the String key name * @return the value of the parameter, or 0 if not found */ public int getParamInt(String name) { for (int i = 0; i < mParams.size(); i++) { if (mParams.get(i).getName().equals(name)) return Integer.parseInt(mParams.get(i).getValue()); } return 0; } }