├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── tsy12321
│ │ │ │ └── netdemo
│ │ │ │ ├── http
│ │ │ │ ├── lib
│ │ │ │ │ ├── LibVolleyResponseModel.java
│ │ │ │ │ ├── LibVolley.java
│ │ │ │ │ ├── LibOkHttp.java
│ │ │ │ │ ├── LibAsyncHttp.java
│ │ │ │ │ └── LibVolleyJsonObjectRequest.java
│ │ │ │ ├── MyHttpJsonResponseHandler.java
│ │ │ │ ├── MyHttpFileResponseHandler.java
│ │ │ │ ├── MyHttp.java
│ │ │ │ └── glue
│ │ │ │ │ ├── MyVolley.java
│ │ │ │ │ ├── MyOkHttp.java
│ │ │ │ │ └── MyAsyncHttp.java
│ │ │ │ ├── GlobalApp.java
│ │ │ │ ├── SharedPreferenceUtils.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── tsy12321
│ │ │ └── netdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── tsy12321
│ │ └── netdemo
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── volley-android-6.0.1_25
├── rules.gradle
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── android
│ │ └── volley
│ │ ├── TimeoutError.java
│ │ ├── ServerError.java
│ │ ├── NoConnectionError.java
│ │ ├── ParseError.java
│ │ ├── Network.java
│ │ ├── NetworkError.java
│ │ ├── toolbox
│ │ ├── Authenticator.java
│ │ ├── NoCache.java
│ │ ├── HttpStack.java
│ │ ├── ClearCacheRequest.java
│ │ ├── StringRequest.java
│ │ ├── JsonArrayRequest.java
│ │ ├── Volley.java
│ │ ├── JsonObjectRequest.java
│ │ ├── PoolingByteArrayOutputStream.java
│ │ ├── JsonRequest.java
│ │ ├── AndroidAuthenticator.java
│ │ ├── RequestFuture.java
│ │ ├── ByteArrayPool.java
│ │ ├── HttpHeaderParser.java
│ │ ├── HttpClientStack.java
│ │ ├── NetworkImageView.java
│ │ ├── HurlStack.java
│ │ └── ImageRequest.java
│ │ ├── ResponseDelivery.java
│ │ ├── RetryPolicy.java
│ │ ├── VolleyError.java
│ │ ├── AuthFailureError.java
│ │ ├── NetworkResponse.java
│ │ ├── Response.java
│ │ ├── Cache.java
│ │ ├── DefaultRetryPolicy.java
│ │ ├── ExecutorDelivery.java
│ │ ├── NetworkDispatcher.java
│ │ ├── CacheDispatcher.java
│ │ └── VolleyLog.java
├── custom_rules.xml
├── build.gradle
├── proguard-project.txt
├── Android.mk
├── proguard.cfg
├── build.xml
└── pom.xml
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':volley-android-6.0.1_25'
2 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/rules.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NetDemo
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsy12321/Android-Http-Example/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | gen
3 | .gradle
4 | build
5 | .settings
6 | target
7 | *.iml
8 | .idea
9 | local.properties
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsy12321/Android-Http-Example/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsy12321/Android-Http-Example/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsy12321/Android-Http-Example/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsy12321/Android-Http-Example/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tsy12321/Android-Http-Example/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/custom_rules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tsy12321/netdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tsy12321/netdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tsy12321/netdemo/http/lib/LibVolleyResponseModel.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo.http.lib;
2 |
3 | import org.json.JSONObject;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * volley response数据模型
9 | * Created by tsy on 16/5/23.
10 | */
11 | public class LibVolleyResponseModel {
12 | public Map headers; //response头
13 | public int status; //response status
14 | public JSONObject data; //response 数据
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tsy12321/netdemo/GlobalApp.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | /**
7 | * 全局 application
8 | * Created by tsy on 16/5/19.
9 | */
10 | public class GlobalApp extends Application {
11 |
12 | private static GlobalApp app;
13 | private Context context;
14 |
15 | @Override
16 | public void onCreate() {
17 | super.onCreate();
18 |
19 | app = this;
20 | context = getApplicationContext();
21 | }
22 |
23 | public static synchronized GlobalApp getInstance() {
24 | return app;
25 | }
26 |
27 | public Context getContext() {
28 | return context;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/tsy/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tsy12321/netdemo/http/MyHttpJsonResponseHandler.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo.http;
2 |
3 | import org.json.JSONObject;
4 |
5 | /**
6 | * MyHttpResponse回调 Json数据
7 | * Created by tsy on 16/5/17.
8 | */
9 | public abstract class MyHttpJsonResponseHandler {
10 |
11 | /**
12 | * 成功返回
13 | * @param statusCode
14 | * @param response
15 | */
16 | public abstract void onSuccess(int statusCode, JSONObject response);
17 |
18 | /**
19 | * 失败返回
20 | * @param statusCode
21 | * @param error_msg
22 | */
23 | public abstract void onFailure(int statusCode, String error_msg);
24 |
25 | /**
26 | * 请求被取消
27 | */
28 | public void onCancel() {
29 | //Log.v("myhttp", "request on cancel");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/build.gradle:
--------------------------------------------------------------------------------
1 | // NOTE: The only changes that belong in this file are the definitions
2 | // of tool versions (gradle plugin, compile SDK, build tools), so that
3 | // Volley can be built via gradle as a standalone project.
4 | //
5 | // Any other changes to the build config belong in rules.gradle, which
6 | // is used by projects that depend on Volley but define their own
7 | // tools versions across all dependencies to ensure a consistent build.
8 |
9 | buildscript {
10 | repositories {
11 | mavenCentral()
12 | }
13 | dependencies {
14 | classpath 'com.android.tools.build:gradle:2.1.2'
15 | }
16 | }
17 |
18 | apply plugin: 'com.android.library'
19 |
20 | android {
21 | compileSdkVersion 19
22 | buildToolsVersion = '23.0.2'
23 | }
24 |
25 | apply from: 'rules.gradle'
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Tue May 17 10:14:26 CST 2016
16 | systemProp.http.proxyHost=127.0.0.1
17 | systemProp.http.proxyPort=1080
18 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.tsy12321.netdemo"
9 | minSdkVersion 9
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.2.1'
26 | compile 'com.loopj.android:android-async-http:1.4.9'
27 | compile project(':volley-android-6.0.1_25')
28 | compile 'com.squareup.okhttp3:okhttp:3.2.0'
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tsy12321/netdemo/http/MyHttpFileResponseHandler.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo.http;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * 文件下载responseHandler
7 | * Created by tsy on 16/5/18.
8 | */
9 | public abstract class MyHttpFileResponseHandler {
10 | /**
11 | * 成功返回
12 | * @param statusCode
13 | */
14 | public abstract void onSuccess(int statusCode);
15 |
16 | /**
17 | * 失败返回
18 | * @param statusCode
19 | * @param error_msg
20 | */
21 | public abstract void onFailure(int statusCode, String error_msg);
22 |
23 | /**
24 | * 下载进度
25 | * @param bytesWritten 已经长传字节
26 | * @param totalSize 总字节
27 | */
28 | public abstract void onProgress(long bytesWritten, long totalSize);
29 |
30 | /**
31 | * 请求被取消
32 | */
33 | public void onCancel() {
34 | Log.v("myhttp", "request on cancel");
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/TimeoutError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Indicates that the connection or the socket timed out.
21 | */
22 | @SuppressWarnings("serial")
23 | public class TimeoutError extends VolleyError { }
24 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/ServerError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Indicates that the server responded with an error response.
21 | */
22 | @SuppressWarnings("serial")
23 | public class ServerError extends VolleyError {
24 | public ServerError(NetworkResponse networkResponse) {
25 | super(networkResponse);
26 | }
27 |
28 | public ServerError() {
29 | super();
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/NoConnectionError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Error indicating that no connection could be established when performing a Volley request.
21 | */
22 | @SuppressWarnings("serial")
23 | public class NoConnectionError extends NetworkError {
24 | public NoConnectionError() {
25 | super();
26 | }
27 |
28 | public NoConnectionError(Throwable reason) {
29 | super(reason);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/ParseError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Indicates that the server's response could not be parsed.
21 | */
22 | @SuppressWarnings("serial")
23 | public class ParseError extends VolleyError {
24 | public ParseError() { }
25 |
26 | public ParseError(NetworkResponse networkResponse) {
27 | super(networkResponse);
28 | }
29 |
30 | public ParseError(Throwable cause) {
31 | super(cause);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/Android.mk:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2011 The Android Open Source Project
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | LOCAL_PATH := $(call my-dir)
18 |
19 | include $(CLEAR_VARS)
20 |
21 | LOCAL_MODULE := volley
22 | LOCAL_SDK_VERSION := 17
23 | LOCAL_SRC_FILES := $(call all-java-files-under, src/main/java)
24 |
25 | include $(BUILD_STATIC_JAVA_LIBRARY)
26 |
27 | # Include this library in the build server's output directory
28 | # TODO: Not yet.
29 | #$(call dist-for-goals, dist_files, $(LOCAL_BUILT_MODULE):volley.jar)
30 |
31 | # Include build files in subdirectories
32 | include $(call all-makefiles-under,$(LOCAL_PATH))
33 |
34 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/Network.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * An interface for performing requests.
21 | */
22 | public interface Network {
23 | /**
24 | * Performs the specified request.
25 | * @param request Request to process
26 | * @return A {@link NetworkResponse} with data and caching metadata; will never be null
27 | * @throws VolleyError on errors
28 | */
29 | public NetworkResponse performRequest(Request> request) throws VolleyError;
30 | }
31 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/NetworkError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Indicates that there was a network error when performing a Volley request.
21 | */
22 | @SuppressWarnings("serial")
23 | public class NetworkError extends VolleyError {
24 | public NetworkError() {
25 | super();
26 | }
27 |
28 | public NetworkError(Throwable cause) {
29 | super(cause);
30 | }
31 |
32 | public NetworkError(NetworkResponse networkResponse) {
33 | super(networkResponse);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/toolbox/Authenticator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.AuthFailureError;
20 |
21 | /**
22 | * An interface for interacting with auth tokens.
23 | */
24 | public interface Authenticator {
25 | /**
26 | * Synchronously retrieves an auth token.
27 | *
28 | * @throws AuthFailureError If authentication did not succeed
29 | */
30 | public String getAuthToken() throws AuthFailureError;
31 |
32 | /**
33 | * Invalidates the provided auth token.
34 | */
35 | public void invalidateAuthToken(String authToken);
36 | }
37 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/ResponseDelivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | public interface ResponseDelivery {
20 | /**
21 | * Parses a response from the network or cache and delivers it.
22 | */
23 | public void postResponse(Request> request, Response> response);
24 |
25 | /**
26 | * Parses a response from the network or cache and delivers it. The provided
27 | * Runnable will be executed after delivery.
28 | */
29 | public void postResponse(Request> request, Response> response, Runnable runnable);
30 |
31 | /**
32 | * Posts an error for the given request.
33 | */
34 | public void postError(Request> request, VolleyError error);
35 | }
36 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/toolbox/NoCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Cache;
20 |
21 | /**
22 | * A cache that doesn't.
23 | */
24 | public class NoCache implements Cache {
25 | @Override
26 | public void clear() {
27 | }
28 |
29 | @Override
30 | public Entry get(String key) {
31 | return null;
32 | }
33 |
34 | @Override
35 | public void put(String key, Entry entry) {
36 | }
37 |
38 | @Override
39 | public void invalidate(String key, boolean fullExpire) {
40 | }
41 |
42 | @Override
43 | public void remove(String key) {
44 | }
45 |
46 | @Override
47 | public void initialize() {
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembers class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembers class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers class * extends android.app.Activity {
30 | public void *(android.view.View);
31 | }
32 |
33 | -keepclassmembers enum * {
34 | public static **[] values();
35 | public static ** valueOf(java.lang.String);
36 | }
37 |
38 | -keep class * implements android.os.Parcelable {
39 | public static final android.os.Parcelable$Creator *;
40 | }
41 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/RetryPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Retry policy for a request.
21 | */
22 | public interface RetryPolicy {
23 |
24 | /**
25 | * Returns the current timeout (used for logging).
26 | */
27 | public int getCurrentTimeout();
28 |
29 | /**
30 | * Returns the current retry count (used for logging).
31 | */
32 | public int getCurrentRetryCount();
33 |
34 | /**
35 | * Prepares for the next retry by applying a backoff to the timeout.
36 | * @param error The error code of the last attempt.
37 | * @throws VolleyError In the event that the retry could not be performed (for example if we
38 | * ran out of attempts), the passed in error is thrown.
39 | */
40 | public void retry(VolleyError error) throws VolleyError;
41 | }
42 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/toolbox/HttpStack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.AuthFailureError;
20 | import com.android.volley.Request;
21 |
22 | import org.apache.http.HttpResponse;
23 |
24 | import java.io.IOException;
25 | import java.util.Map;
26 |
27 | /**
28 | * An HTTP stack abstraction.
29 | */
30 | public interface HttpStack {
31 | /**
32 | * Performs an HTTP request with the given parameters.
33 | *
34 | *
A GET request is sent if request.getPostBody() == null. A POST request is sent otherwise,
35 | * and the Content-Type header is set to request.getPostBodyContentType().
36 | *
37 | * @param request the request to perform
38 | * @param additionalHeaders additional headers to be sent together with
39 | * {@link Request#getHeaders()}
40 | * @return the HTTP response
41 | */
42 | public HttpResponse performRequest(Request> request, Map additionalHeaders)
43 | throws IOException, AuthFailureError;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/VolleyError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | /**
20 | * Exception style class encapsulating Volley errors
21 | */
22 | @SuppressWarnings("serial")
23 | public class VolleyError extends Exception {
24 | public final NetworkResponse networkResponse;
25 | private long networkTimeMs;
26 |
27 | public VolleyError() {
28 | networkResponse = null;
29 | }
30 |
31 | public VolleyError(NetworkResponse response) {
32 | networkResponse = response;
33 | }
34 |
35 | public VolleyError(String exceptionMessage) {
36 | super(exceptionMessage);
37 | networkResponse = null;
38 | }
39 |
40 | public VolleyError(String exceptionMessage, Throwable reason) {
41 | super(exceptionMessage, reason);
42 | networkResponse = null;
43 | }
44 |
45 | public VolleyError(Throwable cause) {
46 | super(cause);
47 | networkResponse = null;
48 | }
49 |
50 | /* package */ void setNetworkTimeMs(long networkTimeMs) {
51 | this.networkTimeMs = networkTimeMs;
52 | }
53 |
54 | public long getNetworkTimeMs() {
55 | return networkTimeMs;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/AuthFailureError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley;
18 |
19 | import android.content.Intent;
20 |
21 | /**
22 | * Error indicating that there was an authentication failure when performing a Request.
23 | */
24 | @SuppressWarnings("serial")
25 | public class AuthFailureError extends VolleyError {
26 | /** An intent that can be used to resolve this exception. (Brings up the password dialog.) */
27 | private Intent mResolutionIntent;
28 |
29 | public AuthFailureError() { }
30 |
31 | public AuthFailureError(Intent intent) {
32 | mResolutionIntent = intent;
33 | }
34 |
35 | public AuthFailureError(NetworkResponse response) {
36 | super(response);
37 | }
38 |
39 | public AuthFailureError(String message) {
40 | super(message);
41 | }
42 |
43 | public AuthFailureError(String message, Exception reason) {
44 | super(message, reason);
45 | }
46 |
47 | public Intent getResolutionIntent() {
48 | return mResolutionIntent;
49 | }
50 |
51 | @Override
52 | public String getMessage() {
53 | if (mResolutionIntent != null) {
54 | return "User needs to (re)enter credentials.";
55 | }
56 | return super.getMessage();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tsy12321/netdemo/http/lib/LibVolley.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo.http.lib;
2 |
3 | import android.content.Context;
4 |
5 | import com.android.volley.Request;
6 | import com.android.volley.RequestQueue;
7 | import com.android.volley.Response;
8 | import com.android.volley.toolbox.Volley;
9 | import com.tsy12321.netdemo.GlobalApp;
10 |
11 | import java.util.Map;
12 |
13 | /**
14 | * 对volley的方法封装
15 | * Created by tsy on 16/5/23.
16 | */
17 | public class LibVolley {
18 | private static RequestQueue mRequestQueue;
19 |
20 | public static void post(Context context, String url, Map headers, Map params, Response.Listener listener, Response.ErrorListener err_listener) {
21 | if(mRequestQueue == null) {
22 | mRequestQueue = Volley.newRequestQueue(GlobalApp.getInstance().getContext());
23 | }
24 |
25 | LibVolleyJSONObjectRequest request = new LibVolleyJSONObjectRequest(Request.Method.POST, url
26 | , headers, params, listener, err_listener);
27 |
28 | request.setTag(context);
29 | mRequestQueue.add(request);
30 | }
31 |
32 | public static void get(Context context, String url, Map headers, Map params, Response.Listener listener, Response.ErrorListener err_listener) {
33 | if(mRequestQueue == null) {
34 | mRequestQueue = Volley.newRequestQueue(GlobalApp.getInstance().getContext());
35 | }
36 |
37 | LibVolleyJSONObjectRequest request = new LibVolleyJSONObjectRequest(Request.Method.GET, url
38 | , headers, params, listener, err_listener);
39 |
40 | request.setTag(context);
41 | mRequestQueue.add(request);
42 | }
43 |
44 | /**
45 | * 取消当前context的所有请求
46 | * @param context 当前所在context
47 | */
48 | public static void cancelRequest(Context context) {
49 | if(mRequestQueue != null && context != null) {
50 | mRequestQueue.cancelAll(context);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tsy12321/netdemo/SharedPreferenceUtils.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | /**
7 | * Created by tsy on 16/5/23.
8 | */
9 | public class SharedPreferenceUtils {
10 |
11 | //本地持久化存储name
12 | private static final String SHARED_PREFERENCES_NAME = "sharedpreference";
13 |
14 | /**
15 | * 本地持久化存储
16 | * 注:存储可用App本身存储
17 | */
18 | private static SharedPreferences.Editor mSharePreferenceEditor;
19 |
20 | /**
21 | * 保存数据
22 | * @param context 上下文
23 | * @param name key
24 | * @param data value
25 | */
26 | public static void saveSharedPreferences(Context context, String name, String data) {
27 | if (mSharePreferenceEditor == null) {
28 | SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
29 | mSharePreferenceEditor = sharedPreferences.edit();
30 | }
31 | mSharePreferenceEditor.putString(name, data);
32 | mSharePreferenceEditor.commit();
33 | }
34 |
35 | /**
36 | * 读取存储数据
37 | * @param context 上下文
38 | * @param name 读取的key
39 | * @return value
40 | */
41 | public static String readSharedPreferences(Context context, String name) {
42 | SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
43 | return sharedPreferences.getString(name, "");
44 | }
45 |
46 | /**
47 | * 移除指定name的信息
48 | * @param context
49 | * @param name
50 | */
51 | public static void removeSharedPreferences(Context context, String name) {
52 | if (mSharePreferenceEditor == null) {
53 | SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
54 | mSharePreferenceEditor = sharedPreferences.edit();
55 | }
56 | mSharePreferenceEditor.remove(name);
57 | mSharePreferenceEditor.commit();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tsy12321/netdemo/http/lib/LibOkHttp.java:
--------------------------------------------------------------------------------
1 | package com.tsy12321.netdemo.http.lib;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.Map;
6 |
7 | import okhttp3.Call;
8 | import okhttp3.Callback;
9 | import okhttp3.FormBody;
10 | import okhttp3.OkHttpClient;
11 | import okhttp3.Request;
12 |
13 | /**
14 | * Created by tsy on 16/5/23.
15 | */
16 | public class LibOkHttp {
17 | private static OkHttpClient client;
18 |
19 | public static void post(Context context, String url, Map params, Callback callback) {
20 | if(client == null) {
21 | client = new OkHttpClient();
22 | }
23 |
24 | FormBody.Builder builder = new FormBody.Builder();
25 | if(params != null && params.size() > 0) {
26 | for (Map.Entry entry : params.entrySet()) {
27 | builder.add(entry.getKey(), entry.getValue());
28 | }
29 | }
30 |
31 | Request request = new Request.Builder()
32 | .url(url)
33 | .post(builder.build())
34 | .tag(context)
35 | .build();
36 |
37 | client.newCall(request).enqueue(callback);
38 |
39 | }
40 |
41 | public static void get(Context context, String url, Callback callback) {
42 | if(client == null) {
43 | client = new OkHttpClient();
44 | }
45 |
46 | Request request = new Request.Builder()
47 | .url(url)
48 | .tag(context)
49 | .build();
50 |
51 | client.newCall(request).enqueue(callback);
52 | }
53 |
54 | /**
55 | * 取消当前context的所有请求
56 | * @param context 当前所在context
57 | */
58 | public static void cancelRequest(Context context) {
59 | if(client != null) {
60 | for(Call call : client.dispatcher().queuedCalls()) {
61 | if(call.request().tag().equals(context))
62 | call.cancel();
63 | }
64 | for(Call call : client.dispatcher().runningCalls()) {
65 | if(call.request().tag().equals(context))
66 | call.cancel();
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/volley-android-6.0.1_25/src/main/java/com/android/volley/toolbox/ClearCacheRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.volley.toolbox;
18 |
19 | import com.android.volley.Cache;
20 | import com.android.volley.NetworkResponse;
21 | import com.android.volley.Request;
22 | import com.android.volley.Response;
23 |
24 | import android.os.Handler;
25 | import android.os.Looper;
26 |
27 | /**
28 | * A synthetic request used for clearing the cache.
29 | */
30 | public class ClearCacheRequest extends Request