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
13 changes: 6 additions & 7 deletions app/src/main/java/com/huxq17/example/fragment/MeiziFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.ArrayList;
import java.util.List;

import static com.huxq17.swipecardsview.SwipeCardsView.SlideType.*;

/**
* Created by huxq17 on 2016/4/11.
*/
Expand Down Expand Up @@ -71,13 +73,10 @@ public void onShow(int index) {
@Override
public void onCardVanish(int index, SwipeCardsView.SlideType type) {
String orientation = "";
switch (type) {
case LEFT:
orientation = "向左飞出";
break;
case RIGHT:
orientation = "向右飞出";
break;
if (type == LEFT) {
orientation = "向左飞出";
} else if(type == RIGHT) {
orientation = "向右飞出";
}
// toast("test position = "+index+";卡片"+orientation);
}
Expand Down
19 changes: 10 additions & 9 deletions app/src/main/java/com/huxq17/example/http/HttpSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* Created by huxq17 on 2015/11/16.
Expand All @@ -27,7 +28,7 @@ public static HttpSender instance() {


public void post(final String url,
LinkedHashMap<String, String> headers, final String params,
Map<String, String> headers, final String params,
final LoadListener listener, Object... tag) {
HttpRequest.Builder builder = new HttpRequest.Builder();
builder.url(url);
Expand All @@ -41,7 +42,7 @@ public void post(final String url,
mHttpBase.post(request, listener, tag);
}

public void post(final String url, LinkedHashMap<String, String> headers, LinkedHashMap<String, Object> params,
public void post(final String url, Map<String, String> headers, Map<String, Object> params,
LoadListener listener, Object... tag) {
HttpRequest.Builder builder = new HttpRequest.Builder();
builder.url(url);
Expand All @@ -51,7 +52,7 @@ public void post(final String url, LinkedHashMap<String, String> headers, Linked
mHttpBase.post(request, listener, tag);
}

public HttpResponse postSync(final String url, LinkedHashMap<String, String> headers, LinkedHashMap<String, Object> params,
public HttpResponse postSync(final String url, Map<String, String> headers, Map<String, Object> params,
Object... tag) {
HttpRequest.Builder builder = new HttpRequest.Builder();
builder.url(url);
Expand All @@ -61,7 +62,7 @@ public HttpResponse postSync(final String url, LinkedHashMap<String, String> hea
return mHttpBase.post(request, null, tag);
}

public void get(String url, LinkedHashMap<String, String> headers, String params,
public void get(String url, Map<String, String> headers, String params,
final LoadListener listener, Object... tag) {
if (!TextUtils.isEmpty(params)) {
url = url + "?" + params;
Expand All @@ -73,7 +74,7 @@ public void get(String url, LinkedHashMap<String, String> headers, String params
mHttpBase.get(builder.build(), listener, tag);
}

public HttpResponse getInputStreamSync(String url, LinkedHashMap<String, String> headers, String params, Object... tag) {
public HttpResponse getInputStreamSync(String url, Map<String, String> headers, String params, Object... tag) {
if (!TextUtils.isEmpty(params)) {
url = url + "?" + params;
}
Expand All @@ -82,7 +83,7 @@ public HttpResponse getInputStreamSync(String url, LinkedHashMap<String, String>
addHeaders(builder, headers);
return mHttpBase.get(builder.build(), null, tag);
}
public HttpResponse getSync(String url, LinkedHashMap<String, String> headers, String params, Object... tag){
public HttpResponse getSync(String url, Map<String, String> headers, String params, Object... tag){
if (!TextUtils.isEmpty(params)) {
url = url + "?" + params;
}
Expand Down Expand Up @@ -111,7 +112,7 @@ public HttpResponse headerSync(String url, Object... tag) {
return response;
}

public void upload(String url, LinkedHashMap<String, String> headers, File[] files, LinkedHashMap<String, Object> params, LoadListener listener, Object tag) {
public void upload(String url, Map<String, String> headers, File[] files, Map<String, Object> params, LoadListener listener, Object tag) {
HttpRequest.Builder builder = new HttpRequest.Builder();
builder.url(url).setParams(params);
addHeaders(builder, headers);
Expand All @@ -121,7 +122,7 @@ public void upload(String url, LinkedHashMap<String, String> headers, File[] fil
mHttpBase.post(builder.build(), listener, tag);
}

public void upload(String url, LinkedHashMap<String, String> headers, File[] files, LoadListener listener, Object tag) {
public void upload(String url, Map<String, String> headers, File[] files, LoadListener listener, Object tag) {
upload(url, headers, files, null, listener, tag);
}

Expand All @@ -137,7 +138,7 @@ public void upload(String url, LinkedHashMap<String, String> headers, File[] fil
// TaskPool.getInstance().execute(new DownLoadTask(info,context,listener,tag));
// }

private void addHeaders(HttpRequest.Builder builder, LinkedHashMap<String, String> headers) {
private void addHeaders(HttpRequest.Builder builder, Map<String, String> headers) {
if (headers != null && headers.size() > 0) {
builder.setHeader(headers);
}
Expand Down
78 changes: 36 additions & 42 deletions app/src/main/java/com/huxq17/example/http/OKHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
Expand All @@ -36,6 +38,7 @@
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.huxq17.example.http.response.ResponseType.*;

/**
* Created by xiaoqian.hu on 2015/10/15.
Expand Down Expand Up @@ -148,7 +151,7 @@ private RequestBody buildRequestBody(RequestParams requestParams) {
String contentType = requestParams.getContentType();
String charset = requestParams.getCharSet();
String params = requestParams.toString();
LinkedHashMap<String, Object> paramsHashmap = requestParams.getmParams();
Map<String, Object> paramsHashmap = requestParams.getmParams();
if (params == null || TextUtils.isEmpty(contentType) || TextUtils.isEmpty(charset)) {
throw new RuntimeException("params is null");
}
Expand Down Expand Up @@ -182,7 +185,7 @@ private RequestBody buildRequestBody(RequestParams requestParams) {
}

private void addHeader(Request.Builder builder, HttpHeader header) {
HashMap<String, String> headers = header.getHeaders();
Map<String, String> headers = header.getHeaders();
if (headers != null && headers.size() > 0) {
for (HashMap.Entry<String, String> map :
headers.entrySet()) {
Expand Down Expand Up @@ -225,20 +228,17 @@ private HttpResponse execute(ResponseType type, Request request, boolean synchro
httpResponse.setResponseType(type);
Response response = call.execute();
String string = null;
switch (type) {
case String:
try {
string = response.body().string();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
httpResponse.setString(string);
if (type == String) {
try {
string = response.body().string();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
httpResponse.setString(string);
// LogUtils.d("okresult: " + string);
break;
case InputStream:
} else if(type == InputStream) {
httpResponse.setInputStream(response.body().byteStream());
break;
}
httpResponse.setContentLength(response.body().contentLength());
} catch (Exception e) {
Expand Down Expand Up @@ -275,20 +275,17 @@ private void execute() {
String string = null;
httpResponse.setContentLength(response.body().contentLength());
httpResponse.setResponseType(mType);
switch (mType) {
case String:
try {
string = response.body().string();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
httpResponse.setString(string);
LogUtils.d("okresult: " + string + ";contentLength=" + response.body().contentLength());
break;
case InputStream:
httpResponse.setInputStream(response.body().byteStream());
break;
if (mType == String) {
try {
string = response.body().string();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
httpResponse.setString(string);
LogUtils.d("okresult: " + string + ";contentLength=" + response.body().contentLength());
} else if(mType == InputStream) {
httpResponse.setInputStream(response.body().byteStream());
}
notifySuccess(httpResponse);
} catch (Exception e) {
Expand Down Expand Up @@ -317,20 +314,17 @@ public void onResponse(Response response) throws IOException {
synchronized (NetWorkTask.this) {
HttpResponse httpResponse = new HttpResponse();
String string = null;
switch (mType) {
case String:
try {
string = response.body().string();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
httpResponse.setString(string);
LogUtils.d("okresult: " + string);
break;
case InputStream:
httpResponse.setInputStream(response.body().byteStream());
break;
if (mType == String) {
try {
string = response.body().string();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
httpResponse.setString(string);
LogUtils.d("okresult: " + string);
} else if(mType == InputStream) {
httpResponse.setInputStream(response.body().byteStream());
}
httpResponse.setString(string);
httpResponse.setContentLength(response.body().contentLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public final class HttpHeader {
private HashMap<String, String> mHeader;
private Map<String, String> mHeader;

public HttpHeader() {
mHeader = new HashMap<>();
Expand All @@ -16,14 +17,14 @@ public HttpHeader() {
public void addHeader(String name,String value){
mHeader.put(name,value);
}
public void setHeader(LinkedHashMap<String,String> header){
public void setHeader(Map<String,String> header){
this.mHeader = header;
}

public void removeHeader(String name){
mHeader.remove(name);
}
public HashMap<String,String> getHeaders(){
public Map<String,String> getHeaders(){
return mHeader;
}
public void clear(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* Created by huxq17 on 2015/11/24.
Expand Down Expand Up @@ -96,7 +97,7 @@ public Builder synchron() {
return this;
}

public Builder setHeader(LinkedHashMap<String, String> header) {
public Builder setHeader(Map<String, String> header) {
this.header.setHeader(header);
return this;
}
Expand All @@ -106,7 +107,7 @@ public Builder removeHeader(String name) {
return this;
}

public Builder setParams(LinkedHashMap<String, Object> params) {
public Builder setParams(Map<String, Object> params) {
if (params == null) {
throw new RuntimeException("params==null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


/**
Expand All @@ -19,7 +20,7 @@ public class RequestParams {
private String charSet = "utf-8";
private String stringParams;

private LinkedHashMap<String, Object> mParams;
private Map<String, Object> mParams;
private List<FileBody> mFiles;

public RequestParams() {
Expand All @@ -29,7 +30,7 @@ public RequestParams() {

public boolean isEmpty() {
return TextUtils.isEmpty(stringParams) &&
(mParams == null || mParams != null && mParams.size() == 0) && (mFiles == null || mFiles != null && mFiles.size() == 0);
(mParams == null || mParams.size() == 0) && (mFiles == null || mFiles.size() == 0);
}

/**
Expand All @@ -42,7 +43,7 @@ public void addParams(String name, Object params) {
mParams.put(name, params);
}

public void setParams(LinkedHashMap<String, Object> params) {
public void setParams(Map<String, Object> params) {
mParams = params;
}

Expand Down Expand Up @@ -98,7 +99,7 @@ public void clear() {
mFiles.clear();
}

public LinkedHashMap<String, Object> getmParams() {
public Map<String, Object> getmParams() {
return mParams;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.InputStream;
import java.io.Serializable;

import static com.huxq17.example.http.response.ResponseType.*;

/**
* Created by huxq17 on 2015/11/28.
*/
Expand All @@ -26,13 +28,10 @@ private void check(ResponseType requstType) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("response type mismatch,you need type is ").append(requstType)
.append(" ,but your configuration is ").append(type).append(" ,so you should config responseType like this:");
switch (requstType) {
case String:
stringBuffer.append(" builder.setResponseType(ResponseType.String);");
break;
case InputStream:
stringBuffer.append(" builder.setResponseType(ResponseType.InputStream);");
break;
if (requstType == String) {
stringBuffer.append(" builder.setResponseType(ResponseType.String);");
} else if (requstType == InputStream) {
stringBuffer.append(" builder.setResponseType(ResponseType.InputStream);");
}
throw new RuntimeException(stringBuffer.toString());
}
Expand Down