Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
334b746
commit 72efff3
Showing
91 changed files
with
5,630 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
/build | ||
OkHttpFinal-OkHttpFinal.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Project-wide Gradle settings. | ||
|
||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
|
||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
|
||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
# Default value: -Xmx10248m -XX:MaxPermSize=256m | ||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | ||
|
||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true | ||
|
||
project_artifactId=okhttpfinal |
Empty file.
2 changes: 1 addition & 1 deletion
2
.../paojiao/okhttpfinal/ApplicationTest.java → ...inalteam/okhttpfinal/ApplicationTest.java
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="cn.paojiao.okhttpfinal"> | ||
|
||
<application android:allowBackup="true" | ||
android:label="@string/app_name" | ||
> | ||
|
||
</application> | ||
package="cn.finalteam.okhttpfinal"> | ||
|
||
</manifest> |
10 changes: 10 additions & 0 deletions
10
OkHttpFinal/src/main/java/cn/finalteam/okhttpfinal/ApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.finalteam.okhttpfinal; | ||
|
||
/** | ||
* Desction:接口响应基类 | ||
* Author:pengjianbo | ||
* Date:15/7/3 下午2:26 | ||
*/ | ||
public interface ApiResponse { | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
OkHttpFinal/src/main/java/cn/finalteam/okhttpfinal/BaseHttpRequestCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cn.finalteam.okhttpfinal; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* Desction:请求回调类 | ||
* Author:pengjianbo | ||
* Date:15/7/3 上午11:41 | ||
*/ | ||
public class BaseHttpRequestCallback<T extends ApiResponse> { | ||
|
||
public static final int ERROR_RESPONSE_NULL = 1001; | ||
public static final int ERROR_RESPONSE_JSON_EXCEPTION = 1002; | ||
public static final int ERROR_RESPONSE_UNKNOWN = 1003; | ||
public static final int ERROR_RESPONSE_TIMEOUT = 1004; | ||
|
||
public BaseHttpRequestCallback() { | ||
} | ||
|
||
public void onStart() { | ||
} | ||
|
||
public void onFinish() { | ||
} | ||
|
||
public void onSuccess(T t) { | ||
} | ||
|
||
public void onFailure(int errorCode, String msg) { | ||
} | ||
|
||
public Class getModelClazz() { | ||
return getGenericType(0); | ||
} | ||
|
||
private Class getGenericType(int index) { | ||
Type genType = getClass().getGenericSuperclass(); | ||
if (!(genType instanceof ParameterizedType)) { | ||
return Object.class; | ||
} | ||
Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); | ||
if (index >= params.length || index < 0) { | ||
throw new RuntimeException("Index outof bounds"); | ||
} | ||
if (!(params[index] instanceof Class)) { | ||
return Object.class; | ||
} | ||
return (Class) params[index]; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
OkHttpFinal/src/main/java/cn/finalteam/okhttpfinal/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cn.finalteam.okhttpfinal; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Desction: | ||
* Author:pengjianbo | ||
* Date:15/9/21 上午9:54 | ||
*/ | ||
public class Constants { | ||
protected static boolean DEBUG = BuildConfig.DEBUG; | ||
//下载管理目标文件夹 | ||
public static final String DM_TARGET_FOLDER = File.separator + "download" + File.separator; | ||
//Http请求超时时间 | ||
public static final int REQ_TIMEOUT = 30000; | ||
} |
32 changes: 32 additions & 0 deletions
32
OkHttpFinal/src/main/java/cn/finalteam/okhttpfinal/ContentType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package cn.finalteam.okhttpfinal; | ||
|
||
/** | ||
* Desction:文件内容类型 | ||
* Author:pengjianbo | ||
* Date:15/9/21 上午10:53 | ||
*/ | ||
public enum ContentType { | ||
TEXT("text/plain; charset=UTF-8"), | ||
PNG("image/png; charset=UTF-8"), | ||
JPEG("image/jpeg; charset=UTF-8"); | ||
|
||
private String contentType; | ||
|
||
private ContentType(String contentType){ | ||
this.contentType = contentType; | ||
} | ||
|
||
/** | ||
* @return the contentType | ||
*/ | ||
public String getContentType() { | ||
return contentType; | ||
} | ||
|
||
/** | ||
* @param contentType the contentType to set | ||
*/ | ||
public void setContentType(String contentType) { | ||
this.contentType = contentType; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
OkHttpFinal/src/main/java/cn/finalteam/okhttpfinal/HttpCycleContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.finalteam.okhttpfinal; | ||
|
||
/** | ||
* Desction: | ||
* Author:pengjianbo | ||
* Date:15/9/21 上午11:20 | ||
*/ | ||
public interface HttpCycleContext { | ||
String getHttpTaskKey(); | ||
} |
46 changes: 46 additions & 0 deletions
46
OkHttpFinal/src/main/java/cn/finalteam/okhttpfinal/HttpFileInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cn.finalteam.okhttpfinal; | ||
|
||
import java.io.InputStream; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* Desction:上传文件数据模型 | ||
* Author:pengjianbo | ||
* Date:15/7/3 上午11:10 | ||
*/ | ||
public class HttpFileInputStream implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
private InputStream inputStream; | ||
private String name; | ||
private long fileSize; | ||
|
||
public HttpFileInputStream(InputStream inputStream, String name, long fileSize) { | ||
this.inputStream = inputStream; | ||
this.name = name; | ||
this.fileSize = fileSize; | ||
} | ||
|
||
public InputStream getInputStream() { | ||
return inputStream; | ||
} | ||
|
||
public void setInputStream(InputStream inputStream) { | ||
this.inputStream = inputStream; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public long getFileSize() { | ||
return fileSize; | ||
} | ||
|
||
public void setFileSize(long fileSize) { | ||
this.fileSize = fileSize; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
OkHttpFinal/src/main/java/cn/finalteam/okhttpfinal/HttpRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cn.finalteam.okhttpfinal; | ||
|
||
/** | ||
* Desction:http请求类 | ||
* Author:pengjianbo | ||
* Date:15/9/22 下午10:17 | ||
*/ | ||
public class HttpRequest { | ||
|
||
public static void setDebug(boolean debug) { | ||
Constants.DEBUG = debug; | ||
} | ||
|
||
public static void get(String url) { | ||
get(url, null, null); | ||
} | ||
|
||
public static void get(String url, RequestParams params) { | ||
get(url, params, null); | ||
} | ||
|
||
public static void get(String url, BaseHttpRequestCallback callback) { | ||
get(url, null, callback); | ||
} | ||
|
||
public static void get(String url, RequestParams params, BaseHttpRequestCallback callback) { | ||
get(url, params, callback, Constants.REQ_TIMEOUT); | ||
} | ||
|
||
public static void get(String url, RequestParams params, BaseHttpRequestCallback callback, int timeOut) { | ||
executeRequest(url, params, callback, timeOut); | ||
} | ||
|
||
public static void post(String url) { | ||
post(url, null, null); | ||
} | ||
|
||
public static void post(String url, RequestParams params) { | ||
post(url, params, null); | ||
} | ||
|
||
public static void post(String url, BaseHttpRequestCallback callback) { | ||
post(url, null, callback); | ||
} | ||
|
||
public static void post(String url, RequestParams params, BaseHttpRequestCallback callback) { | ||
post(url, params, callback, Constants.REQ_TIMEOUT); | ||
} | ||
|
||
public static void post(String url, RequestParams params, BaseHttpRequestCallback callback, int timeOut) { | ||
executeRequest(url, params, callback, timeOut); | ||
} | ||
|
||
private static void executeRequest(String url, RequestParams params, BaseHttpRequestCallback callback, int timeout) { | ||
HttpTask task = new HttpTask(url, params, callback, timeout); | ||
task.execute(); | ||
} | ||
|
||
} |
Oops, something went wrong.