├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── xwdz │ │ │ └── httpsimple │ │ │ ├── APISignatureIntercept.java │ │ │ ├── AppendGlobalParamsIntercept.java │ │ │ ├── App.java │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── xwdz │ │ │ └── httpsimple │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── xwdz │ │ └── httpsimple │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── mylibrary ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── xwdz │ │ │ └── http │ │ │ ├── callback │ │ │ ├── InterceptRequest.java │ │ │ ├── IBaseEasyCallback.java │ │ │ ├── StringEasyCallbackImpl.java │ │ │ ├── BaseEasyCallbackImpl.java │ │ │ └── FileEasyCallbackImpl.java │ │ │ ├── core │ │ │ ├── EasyCall.java │ │ │ ├── EasyRequestManager.java │ │ │ ├── HttpUrlConnection.java │ │ │ └── Request.java │ │ │ ├── error │ │ │ └── EasyHTTPException.java │ │ │ ├── thread │ │ │ ├── EasyThreadPools.java │ │ │ └── RequestTaskProxy.java │ │ │ ├── EasyNetwork.java │ │ │ ├── EasyNetworkConfig.java │ │ │ └── Util.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── xwdz │ │ │ └── http │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── xwdz │ │ └── http │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── jpg └── logo.jpg ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── encodings.xml ├── vcs.xml ├── misc.xml ├── runConfigurations.xml ├── gradle.xml └── inspectionProfiles │ └── Project_Default.xml ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /mylibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':mylibrary' 2 | -------------------------------------------------------------------------------- /jpg/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/jpg/logo.jpg -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | httpSimple 3 | 4 | -------------------------------------------------------------------------------- /mylibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My Library 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /mylibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwdz/EasyNetwork/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu May 09 17:28:38 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /mylibrary/src/main/java/com/xwdz/http/callback/InterceptRequest.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http.callback; 2 | 3 | import com.xwdz.http.core.Request; 4 | 5 | /** 6 | * @author xingwei.huang (xwdz9989@gmail.com) 7 | * @since v1.0.0 8 | */ 9 | public interface InterceptRequest { 10 | 11 | Request onInterceptRequest(Request request); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /mylibrary/src/test/java/com/xwdz/http/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/test/java/com/xwdz/httpsimple/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.httpsimple; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /mylibrary/src/main/java/com/xwdz/http/callback/IBaseEasyCallback.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http.callback; 2 | 3 | import com.xwdz.http.core.EasyCall; 4 | 5 | import java.net.HttpURLConnection; 6 | 7 | /** 8 | * @author xingwei.huang (xwdz9989@gmail.com) 9 | * @since v1.0.0 10 | */ 11 | public interface IBaseEasyCallback { 12 | 13 | void onResponse(EasyCall call, HttpURLConnection httpURLConnection); 14 | 15 | void onFailure(EasyCall call, Throwable error); 16 | 17 | void onCancel(); 18 | } 19 | -------------------------------------------------------------------------------- /mylibrary/src/main/java/com/xwdz/http/core/EasyCall.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http.core; 2 | 3 | /** 4 | * @author xingwei.huang (xwdz9989@gmail.com) 5 | * @since v1.0.0 6 | */ 7 | public class EasyCall { 8 | 9 | private Request request; 10 | 11 | public EasyCall() { 12 | } 13 | 14 | public EasyCall(Request request) { 15 | this.request = request; 16 | } 17 | 18 | public Request getRequest() { 19 | return request; 20 | } 21 | 22 | public void setRequest(Request request) { 23 | this.request = request; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /mylibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /mylibrary/src/androidTest/java/com/xwdz/http/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.xwdz.http.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/xwdz/httpsimple/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.httpsimple; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.xwdz.httpsimple", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /mylibrary/src/main/java/com/xwdz/http/error/EasyHTTPException.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http.error; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author xingwei.huang (xwdz9989@gmail.com) 7 | * @since v1.0.0 8 | */ 9 | public class EasyHTTPException extends Throwable implements Serializable { 10 | 11 | private static final long serialVersionUID = -492948457991527824L; 12 | 13 | public static final class Error { 14 | public static final String CANCEL_REQUEST = "1004"; 15 | } 16 | 17 | 18 | public final String message; 19 | public final String code; 20 | 21 | 22 | public EasyHTTPException(String message, String code) { 23 | this.message = message; 24 | this.code = code; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "EasyHTTPException{" + 30 | "message='" + message + '\'' + 31 | ", code='" + code + '\'' + 32 | '}'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/xwdz/httpsimple/APISignatureIntercept.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.httpsimple; 2 | 3 | import android.util.Log; 4 | 5 | import com.xwdz.http.callback.InterceptRequest; 6 | import com.xwdz.http.core.Request; 7 | 8 | import java.util.HashMap; 9 | 10 | /** 11 | * @author xingwei.huang (xwdz9989@gmail.com) 12 | * @since v1.0.0 13 | */ 14 | public class APISignatureIntercept implements InterceptRequest { 15 | @Override 16 | public Request onInterceptRequest(Request request) { 17 | 18 | HashMap params = new HashMap<>(); 19 | HashMap headers = new HashMap<>(); 20 | 21 | // todo 统一加密 param or header or url 22 | Request realRequest = new Request.Builder() 23 | .url(request.url) 24 | .tag(request.tag) 25 | .addHeaders(headers) 26 | .addParams(params) 27 | .build(); 28 | 29 | Log.w("EasyHttp", "signature intercept:" + realRequest.toString()); 30 | return realRequest; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mylibrary/src/main/java/com/xwdz/http/core/EasyRequestManager.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http.core; 2 | 3 | import com.xwdz.http.EasyNetworkConfig; 4 | import com.xwdz.http.callback.IBaseEasyCallback; 5 | import com.xwdz.http.thread.RequestTaskProxy; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author xingwei.huang (xwdz9989@gmail.com) 12 | * @since v1.0.0 13 | */ 14 | public class EasyRequestManager { 15 | 16 | private HashMap mRequestHashMap; 17 | 18 | public EasyRequestManager() { 19 | mRequestHashMap = new HashMap<>(); 20 | } 21 | 22 | public void performRequest(EasyNetworkConfig config, Request request, IBaseEasyCallback baseEasyCallback) { 23 | final RequestTaskProxy task = new RequestTaskProxy(config, request, baseEasyCallback); 24 | task.start(); 25 | mRequestHashMap.put(task.getRequest().tag.toString(), task); 26 | 27 | } 28 | 29 | 30 | public void performCancelRequest(Object tag) { 31 | RequestTaskProxy requestWrapper = mRequestHashMap.get(tag.toString()); 32 | if (requestWrapper != null) { 33 | requestWrapper.cancel(); 34 | } 35 | } 36 | 37 | public void performCancelAll() { 38 | for (Map.Entry entry : mRequestHashMap.entrySet()) { 39 | entry.getValue().cancel(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/xwdz/httpsimple/AppendGlobalParamsIntercept.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.httpsimple; 2 | 3 | import com.xwdz.http.callback.InterceptRequest; 4 | import com.xwdz.http.core.Request; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * 添加所有请求公共参数 11 | * @author xingwei.huang (xwdz9989@gmail.com) 12 | * @since v1.0.0 13 | */ 14 | public class AppendGlobalParamsIntercept implements InterceptRequest { 15 | @Override 16 | public Request onInterceptRequest(Request request) { 17 | HashMap params = new HashMap<>(); 18 | HashMap headers = new HashMap<>(); 19 | 20 | headers.put("comm_global_custom_header1", "comm_custom_header1"); 21 | headers.put("comm_global_custom_header2", "comm_custom_header2"); 22 | 23 | params.put("comm_global_custom_params1", "comm_custom_params1"); 24 | params.put("comm_global_custom_params2", "comm_custom_params2"); 25 | 26 | for (Map.Entry old : request.params.entrySet()) { 27 | params.put(old.getKey(), old.getValue()); 28 | } 29 | 30 | for (Map.Entry old : request.headers.entrySet()) { 31 | headers.put(old.getKey(), old.getValue()); 32 | } 33 | 34 | Request clone = request.clone(); 35 | clone.params.putAll(params); 36 | clone.headers.putAll(headers); 37 | return clone; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mylibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | 4 | android { 5 | compileSdkVersion 28 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 16 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | 30 | implementation 'com.android.support:appcompat-v7:28.0.0' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | } 35 | 36 | def siteUrl = 'http://xwcc.fun' 37 | publish { 38 | userOrg = 'quinnhuang' 39 | repoName = 'widget' 40 | groupId = 'com.xwdz' 41 | artifactId = 'EasyNetwork' 42 | publishVersion = '1.0.3' 43 | desc = 'Android native Http'//描述,不重要 44 | website = siteUrl//项目主页 45 | } 46 | tasks.withType(Javadoc) {//防止编码问题 47 | options.addStringOption('Xdoclint:none', '-quiet') 48 | options.addStringOption('encoding', 'UTF-8') 49 | options.addStringOption('charSet', 'UTF-8') 50 | } -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.xwdz.httpsimple" 7 | minSdkVersion 19 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | def RETROFIT2 = '2.5.0' 22 | 23 | dependencies { 24 | implementation fileTree(include: ['*.jar'], dir: 'libs') 25 | implementation 'com.android.support:appcompat-v7:28.0.0' 26 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 27 | testImplementation 'junit:junit:4.12' 28 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 29 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 30 | implementation project(':mylibrary') 31 | // implementation 'com.xwdz:EasyNetwork:1.0.1-beta1' 32 | // implementation 'com.xwdz:SplashGlobally:0.0.1' 33 | 34 | implementation "com.squareup.retrofit2:retrofit:${RETROFIT2}" 35 | implementation "com.squareup.retrofit2:converter-gson:${RETROFIT2}" 36 | implementation "com.squareup.retrofit2:adapter-rxjava:${RETROFIT2}" 37 | implementation "io.reactivex:rxandroid:1.2.1" 38 | } 39 | -------------------------------------------------------------------------------- /mylibrary/src/main/java/com/xwdz/http/thread/EasyThreadPools.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http.thread; 2 | 3 | import java.util.concurrent.Callable; 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | import java.util.concurrent.Future; 7 | import java.util.concurrent.ThreadFactory; 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | 10 | /** 11 | * @author xingwei.huang (xwdz9989@gmail.com) 12 | * @since v1.0.0 13 | */ 14 | public class EasyThreadPools { 15 | 16 | private static ExecutorService sDefaultExecutorService; 17 | 18 | private static AtomicInteger sAtomicInteger = new AtomicInteger(); 19 | 20 | static { 21 | 22 | final ThreadFactory threadFactory = new ThreadFactory() { 23 | @Override 24 | public Thread newThread(Runnable r) { 25 | final Thread thread = new Thread(r); 26 | thread.setName("EasyNetwork#" + sAtomicInteger.getAndIncrement()); 27 | return thread; 28 | } 29 | }; 30 | sDefaultExecutorService = Executors.newCachedThreadPool(threadFactory); 31 | } 32 | 33 | public static void setDefaultExecutorService(ExecutorService defaultExecutorService) { 34 | sDefaultExecutorService = defaultExecutorService; 35 | } 36 | 37 | 38 | public static void executor(Runnable runnable) { 39 | sDefaultExecutorService.execute(runnable); 40 | } 41 | 42 | public static Future submit(Callable runnable) { 43 | return sDefaultExecutorService.submit(runnable); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/xwdz/httpsimple/App.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.httpsimple; 2 | 3 | import android.app.Application; 4 | 5 | import com.xwdz.http.EasyNetwork; 6 | import com.xwdz.http.EasyNetworkConfig; 7 | 8 | /** 9 | * @author xingwei.huang (xwdz9989@gmail.com) 10 | * @since v1.0.0 11 | */ 12 | public class App extends Application { 13 | 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | 18 | 19 | EasyNetworkConfig config = new EasyNetworkConfig(); 20 | config.addIntercepts(new AppendGlobalParamsIntercept()); 21 | config.setOpenRetry(true); 22 | config.setRetryIntervalMillis(3000); 23 | // config.addIntercepts(new APISignatureIntercept()); 24 | EasyNetwork.initializeConfig(config); 25 | 26 | 27 | // Retrofit retrofit = new Retrofit.Builder() 28 | // .baseUrl("11") 29 | // .client(okHttpClient) 30 | // .addConverterFactory(GsonConverterFactory.create()) 31 | // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 32 | // .build(); 33 | // 34 | // retrofit.create(FeedApi.class).request("0") 35 | // .enqueue(new Callback() { 36 | // @Override 37 | // public void onResponse(Call call, Response response) { 38 | // 39 | // } 40 | // 41 | // @Override 42 | // public void onFailure(Call call, Throwable t) { 43 | // 44 | // } 45 | // }); 46 | 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /mylibrary/src/main/java/com/xwdz/http/EasyNetwork.java: -------------------------------------------------------------------------------- 1 | package com.xwdz.http; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.xwdz.http.callback.IBaseEasyCallback; 6 | import com.xwdz.http.core.EasyRequestManager; 7 | import com.xwdz.http.core.Request; 8 | 9 | /** 10 | * @author xingwei.huang (xwdz9989@gmail.com) 11 | * @since v1.0.0 12 | */ 13 | public class EasyNetwork { 14 | 15 | 16 | private static EasyRequestManager sEasyRequestManager = new EasyRequestManager(); 17 | private static EasyNetworkConfig sConfig = new EasyNetworkConfig(); 18 | 19 | 20 | 21 | private EasyNetwork() { 22 | 23 | } 24 | 25 | public static void initializeConfig(EasyNetworkConfig config) { 26 | sConfig = config; 27 | } 28 | 29 | public static EasyNetworkConfig getConfig() { 30 | return sConfig; 31 | } 32 | 33 | public static void sendRequest(Request request, IBaseEasyCallback baseEasyCallback) { 34 | if (request == null) { 35 | throw new NullPointerException("request == null"); 36 | } 37 | 38 | if (TextUtils.isEmpty(request.url)) { 39 | throw new NullPointerException("url == null"); 40 | } 41 | 42 | request.tag = request.tag == null ? request.url : request.tag; 43 | 44 | 45 | sEasyRequestManager.performRequest(sConfig, request, baseEasyCallback); 46 | } 47 | 48 | public static void cancelRequest(Object tag) { 49 | sEasyRequestManager.performCancelRequest(tag); 50 | } 51 | 52 | public static void cancelAll() { 53 | sEasyRequestManager.performCancelAll(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 |