├── .gitignore ├── LICENSE ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ ├── data.sql │ ├── devices.db.1.sql │ ├── devices.db.2.sql │ ├── devices.db.3.sql │ └── response.json │ ├── java │ └── me │ │ └── adamstroud │ │ └── devicedatabase │ │ ├── DeviceDatabaseApplication.java │ │ ├── api │ │ ├── retrofit │ │ │ ├── DeviceService.java │ │ │ ├── ManufacturersAndDevicesResponse.java │ │ │ └── WebServiceClient.java │ │ └── volley │ │ │ ├── GetManufacturersAndDevicesRequest.java │ │ │ ├── JacksonRequest.java │ │ │ └── VolleyApiClient.java │ │ ├── device │ │ ├── AddDeviceActivity.java │ │ ├── DeviceDetailActivity.java │ │ ├── DeviceListActivity.java │ │ └── NetworkCallAsyncTask.java │ │ ├── manufacturer │ │ ├── AddManufacturerActivity.java │ │ └── ManufacturerListActivity.java │ │ ├── model │ │ ├── Device.java │ │ └── Manufacturer.java │ │ ├── provider │ │ ├── DevicesContract.java │ │ ├── DevicesOpenHelper.java │ │ └── DevicesProvider.java │ │ └── sync │ │ ├── Authenticator.java │ │ ├── AuthenticatorService.java │ │ ├── SyncAdapter.java │ │ ├── SyncManager.java │ │ └── SyncService.java │ └── res │ ├── drawable-hdpi │ ├── ic_add_white_24dp.png │ ├── ic_done_white_24dp.png │ ├── ic_search_white_24dp.png │ └── ic_share_white_24dp.png │ ├── drawable-mdpi │ ├── ic_add_white_24dp.png │ ├── ic_done_white_24dp.png │ ├── ic_search_white_24dp.png │ └── ic_share_white_24dp.png │ ├── drawable-xhdpi │ ├── ic_add_white_24dp.png │ ├── ic_done_white_24dp.png │ ├── ic_search_white_24dp.png │ └── ic_share_white_24dp.png │ ├── drawable-xxhdpi │ ├── ic_add_white_24dp.png │ ├── ic_done_white_24dp.png │ ├── ic_search_white_24dp.png │ └── ic_share_white_24dp.png │ ├── drawable-xxxhdpi │ ├── ic_add_white_24dp.png │ ├── ic_done_white_24dp.png │ ├── ic_search_white_24dp.png │ └── ic_share_white_24dp.png │ ├── layout │ ├── activity_add_device.xml │ ├── activity_add_manufacturer.xml │ ├── activity_device_detail.xml │ ├── activity_device_list.xml │ ├── activity_manufacturer_list.xml │ ├── appbar.xml │ ├── list_item_device.xml │ └── list_item_manufacturer.xml │ ├── menu │ ├── activity_add_device.xml │ ├── activity_add_manufacturer.xml │ ├── activity_device_detail.xml │ └── activity_device_list.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-v21 │ └── styles.xml │ ├── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ ├── authenticator.xml │ └── syncadapter.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── thirdParty └── volley ├── .gitignore ├── Android.mk ├── README ├── build.gradle ├── build.xml ├── custom_rules.xml ├── pom.xml ├── proguard-project.txt ├── proguard.cfg ├── rules.gradle └── src ├── main ├── AndroidManifest.xml └── java │ └── com │ └── android │ └── volley │ ├── AuthFailureError.java │ ├── Cache.java │ ├── CacheDispatcher.java │ ├── DefaultRetryPolicy.java │ ├── ExecutorDelivery.java │ ├── Network.java │ ├── NetworkDispatcher.java │ ├── NetworkError.java │ ├── NetworkResponse.java │ ├── NoConnectionError.java │ ├── ParseError.java │ ├── Request.java │ ├── RequestQueue.java │ ├── Response.java │ ├── ResponseDelivery.java │ ├── RetryPolicy.java │ ├── ServerError.java │ ├── TimeoutError.java │ ├── VolleyError.java │ ├── VolleyLog.java │ └── toolbox │ ├── AndroidAuthenticator.java │ ├── Authenticator.java │ ├── BasicNetwork.java │ ├── ByteArrayPool.java │ ├── ClearCacheRequest.java │ ├── DiskBasedCache.java │ ├── HttpClientStack.java │ ├── HttpHeaderParser.java │ ├── HttpStack.java │ ├── HurlStack.java │ ├── ImageLoader.java │ ├── ImageRequest.java │ ├── JsonArrayRequest.java │ ├── JsonObjectRequest.java │ ├── JsonRequest.java │ ├── NetworkImageView.java │ ├── NoCache.java │ ├── PoolingByteArrayOutputStream.java │ ├── RequestFuture.java │ ├── StringRequest.java │ └── Volley.java └── test ├── java └── com │ └── android │ └── volley │ ├── CacheDispatcherTest.java │ ├── NetworkDispatcherTest.java │ ├── RequestQueueIntegrationTest.java │ ├── RequestQueueTest.java │ ├── RequestTest.java │ ├── ResponseDeliveryTest.java │ ├── mock │ ├── MockCache.java │ ├── MockHttpClient.java │ ├── MockHttpStack.java │ ├── MockHttpURLConnection.java │ ├── MockNetwork.java │ ├── MockRequest.java │ ├── MockResponseDelivery.java │ ├── ShadowSystemClock.java │ ├── TestRequest.java │ └── WaitableQueue.java │ ├── toolbox │ ├── AndroidAuthenticatorTest.java │ ├── BasicNetworkTest.java │ ├── ByteArrayPoolTest.java │ ├── CacheTest.java │ ├── DiskBasedCacheTest.java │ ├── HttpClientStackTest.java │ ├── HttpHeaderParserTest.java │ ├── HurlStackTest.java │ ├── ImageLoaderTest.java │ ├── ImageRequestTest.java │ ├── JsonRequestCharsetTest.java │ ├── JsonRequestTest.java │ ├── NetworkImageViewTest.java │ ├── PoolingByteArrayOutputStreamTest.java │ ├── RequestFutureTest.java │ ├── RequestQueueTest.java │ ├── RequestTest.java │ ├── ResponseTest.java │ └── StringRequestTest.java │ └── utils │ ├── CacheTestUtils.java │ └── ImmediateResponseDelivery.java └── resources └── org.robolectric.Config.properties /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # IntelliJ/Android Studio project files 30 | .idea/ 31 | *.iml 32 | *.ipr 33 | *.iws 34 | captures/ 35 | 36 | # Eclipse project files 37 | .settings/ 38 | .project 39 | .classpath 40 | 41 | # Mac OS files 42 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android™ Database Best Practices 2 | 3 | This repository contains the source code that was discussed in 4 | [Android™ Database Best Practices](https://www.pearsonhighered.com/program/Stroud-Android-Database-Best-Practices/PGM332735.html). 5 | The code resides in a [Gradle](http://www.gradle.org) project that can be imported into 6 | [Android™ Studio](https://developer.android.com/studio/index.html) and run on a device. 7 | 8 | ## Description 9 | 10 | **Battle-Tested Strategies for Storing, Managing, and Sharing Android Data** 11 | 12 | This is the first guide to focus on one of the most critical aspects of Android development: how to 13 | efficiently store, retrieve, manage, and share information from your app’s internal database. 14 | Through real-world code examples, which you can use in your own apps, you’ll learn how to take full 15 | advantage of Android’s SQLite database and related classes. 16 | 17 | The newest title in Addison-Wesley’s [Android™ Deep Dive](https://www.pearsonhighered.com/series/Android-Deep-Dive/4146853.html) 18 | series for experienced Android developers, [Android™ Database Best Practices](https://www.pearsonhighered.com/program/Stroud-Android-Database-Best-Practices/PGM332735.html) 19 | draws on Adam Stroud’s extensive experience leading cutting-edge app projects. 20 | 21 | First, Stroud reviews the core database theory and SQL techniques you need to efficiently build, 22 | manipulate, and read SQLite databases. Next, he explores SQLite in detail, illuminates Android’s 23 | APIs for database interaction, and shares modern best practices for working with databases in the 24 | Android environment. 25 | 26 | Through a complete case study, you’ll learn how to design your data access layer to simplify all 27 | facets of data management and avoid unwanted technical debt. You’ll also find detailed solutions for 28 | common challenges in building data-enabled Android apps, including issues associated with threading, 29 | remote data access, and showing data to users. 30 | 31 | With this indispensable guide, you will: 32 | + Discover how Android’s lightweight SQLite database differs from other relational databases 33 | + Use SQL DDL to add structure to a database, and use DML to manipulate data 34 | + Define and work with SQLite data types 35 | + Persist highly structured data for fast, efficient access 36 | + Master Android classes for create, read, update, and delete (CRUD) operations and database queries 37 | + Share data within or between apps via content providers 38 | + Master efficient UI strategies for displaying data, while accounting for threading issues 39 | + Use Android’s Intents API to pass data between activities when starting a new activity or service 40 | + Achieve two-way communication between apps and remote web APIs 41 | + Manage the complexities of app-to-server communication, and avoid common problems 42 | + Use Android’s new Data Binding API to write less code and improve performance 43 | 44 | 45 | ## Contact 46 | + [Email](mailto:adam.stroud@gmail.com) 47 | 48 | ## License 49 | 50 | All the code is licensed under the Apache 2.0 license. See [LICENSE.txt](https://github.com/android-database-best-practices/device-database/blob/master/LICENSE) for license details. -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 | apply plugin: 'com.android.application' 18 | 19 | android { 20 | compileSdkVersion rootProject.ext.compileSdkVersion 21 | buildToolsVersion rootProject.ext.buildToolsVersion 22 | 23 | defaultConfig { 24 | applicationId "me.adamstroud.devicedatabase" 25 | minSdkVersion 15 26 | targetSdkVersion 24 27 | versionCode 1 28 | versionName "1.1-SNAPSHOT" 29 | } 30 | buildTypes { 31 | release { 32 | minifyEnabled false 33 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 34 | } 35 | } 36 | packagingOptions { 37 | exclude 'META-INF/NOTICE' 38 | exclude 'META-INF/LICENSE' 39 | } 40 | 41 | dataBinding { 42 | enabled = true 43 | } 44 | } 45 | 46 | dependencies { 47 | compile fileTree(dir: 'libs', include: ['*.jar']) 48 | compile project(':thirdParty:volley') 49 | 50 | testCompile 'junit:junit:4.12' 51 | 52 | compile rootProject.ext.supportLibraryDependencies.appCompat 53 | compile rootProject.ext.supportLibraryDependencies.design 54 | compile rootProject.ext.supportLibraryDependencies.recyclerView 55 | compile rootProject.ext.supportLibraryDependencies.cardView 56 | 57 | final RETROFIT_VERSION = '2.0.0' 58 | compile "com.squareup.retrofit2:retrofit:${RETROFIT_VERSION}" 59 | compile "com.squareup.retrofit2:converter-gson:${RETROFIT_VERSION}" 60 | compile "com.squareup.okhttp3:logging-interceptor:3.2.0" 61 | compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0' 62 | compile "com.squareup.retrofit2:adapter-rxjava:${RETROFIT_VERSION}" 63 | 64 | compile 'io.reactivex:rxandroid:1.1.0' 65 | // Because RxAndroid releases are few and far between, it is 66 | // recommended you also explicitly depend on RxJava's latest version 67 | // for bug fixes and new features. 68 | compile 'io.reactivex:rxjava:1.1.3' 69 | 70 | compile 'com.facebook.stetho:stetho:1.3.1' 71 | compile 'com.facebook.stetho:stetho-okhttp3:1.3.1' 72 | } 73 | -------------------------------------------------------------------------------- /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/adstro/Applications/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 | 19 | # ################################################################################################## 20 | # Retrofit2 (https://square.github.io/retrofit/) 21 | # ################################################################################################## 22 | -dontwarn retrofit2.** 23 | -keep class retrofit2.** { *; } 24 | -keepattributes Signature 25 | -keepattributes Exceptions -------------------------------------------------------------------------------- /app/src/main/assets/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO manufacturer (short_name, long_name) 2 | VALUES ('HTC', 'HTC Corporation'); 3 | 4 | INSERT INTO manufacturer (short_name, long_name) 5 | VALUES ('Samsung', 'Samsung Electronics'); 6 | 7 | INSERT INTO manufacturer (short_name, long_name) 8 | VALUES ('LG', 'LG Electronics'); 9 | 10 | INSERT INTO device (model, nickname, display_size_inches, manufacturer_id) 11 | VALUES ('Nexus One', 'Passion', 3.7, (SELECT _id 12 | FROM manufacturer 13 | WHERE short_name = 'HTC')); 14 | 15 | INSERT INTO device (model, nickname, display_size_inches, manufacturer_id) 16 | VALUES ('Nexus S', 'Crespo', 4.0, (SELECT _id 17 | FROM manufacturer 18 | WHERE short_name = 'Samsung')); 19 | 20 | INSERT INTO device (model, nickname, display_size_inches, manufacturer_id) 21 | VALUES ('Galaxy Nexus', 'Toro', 4.65, (SELECT _id 22 | FROM manufacturer 23 | WHERE short_name = 'Samsung')); 24 | 25 | INSERT INTO device (model, nickname, display_size_inches, manufacturer_id) 26 | VALUES ('Nexus 4', 'Mako', 4.7, (SELECT _id 27 | FROM manufacturer 28 | WHERE short_name = 'LG')); -------------------------------------------------------------------------------- /app/src/main/assets/devices.db.1.sql: -------------------------------------------------------------------------------- 1 | -- device table 2 | CREATE TABLE device (_id INTEGER PRIMARY KEY AUTOINCREMENT, 3 | model TEXT NOT NULL, 4 | nickname TEXT, 5 | memory_mb REAL, 6 | display_size_inches REAL, 7 | manufacturer_id INTEGER REFERENCES manufacturer(_id) ON DELETE CASCADE); 8 | CREATE INDEX idx_device_model ON device(model); 9 | 10 | -- manufacturer table 11 | CREATE TABLE manufacturer(_id INTEGER PRIMARY KEY AUTOINCREMENT, 12 | short_name TEXT, 13 | long_name); -------------------------------------------------------------------------------- /app/src/main/assets/devices.db.2.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE table_2 (_id INTEGER PRIMARY KEY AUTOINCREMENT); -------------------------------------------------------------------------------- /app/src/main/assets/devices.db.3.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE table_3 (_id INTEGER PRIMARY KEY AUTOINCREMENT); -------------------------------------------------------------------------------- /app/src/main/assets/response.json: -------------------------------------------------------------------------------- 1 | { 2 | "manufacturers": [ 3 | { 4 | "short_name": "Samsung", 5 | "long_name": "Samsung Electronics", 6 | "devices": [ 7 | { 8 | "model": "Nexus S", 9 | "nickname": "Crespo", 10 | "display_size_inches": 4.0 11 | }, 12 | { 13 | "model": "Galaxy Nexus", 14 | "nickname": "Toro", 15 | "display_size_inches": 4.65 16 | } 17 | ] 18 | }, 19 | { 20 | "short_name": "LG", 21 | "long_name": "LG Electronics", 22 | "devices": [ 23 | { 24 | "model": "Nexus 4", 25 | "nickname": "Mako", 26 | "display_size_inches": 4.7 27 | } 28 | ] 29 | }, 30 | { 31 | "short_name": "HTC", 32 | "long_name": "HTC Corporation", 33 | "devices": [ 34 | { 35 | "model": "Nexus One", 36 | "nickname": "Passion", 37 | "display_size_inches": 3.7 38 | } 39 | ] 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/DeviceDatabaseApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase; 18 | 19 | import android.app.Application; 20 | 21 | import com.facebook.stetho.Stetho; 22 | 23 | /** 24 | * The application for the class 25 | * 26 | * @author Adam Stroud <adam.stroud@gmail.com> 27 | */ 28 | public class DeviceDatabaseApplication extends Application { 29 | @Override 30 | public void onCreate() { 31 | super.onCreate(); 32 | 33 | if (BuildConfig.DEBUG) { 34 | Stetho.initializeWithDefaults(this); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/api/retrofit/DeviceService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.api.retrofit; 18 | 19 | import retrofit2.Call; 20 | import retrofit2.http.GET; 21 | import rx.Observable; 22 | 23 | /** 24 | * The interface for the web API. 25 | * 26 | * @author Adam Stroud <adam.stroud@gmail.com> 27 | */ 28 | public interface DeviceService { 29 | @GET("v2/570bbaf6110000b003d17e3a") 30 | Call getManufacturersAndDevices(); 31 | 32 | @GET("v2/570bbaf6110000b003d17e3a") 33 | Observable rxGetManufacturersAndDevices(); 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/api/retrofit/ManufacturersAndDevicesResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.api.retrofit; 18 | 19 | import java.util.List; 20 | 21 | import me.adamstroud.devicedatabase.model.Manufacturer; 22 | 23 | /** 24 | * The response to the {@link me.adamstroud.devicedatabase.api.volley.GetManufacturersAndDevicesRequest} request. 25 | * 26 | * @author Adam Stroud <adam.stroud@gmail.com> 27 | */ 28 | public class ManufacturersAndDevicesResponse { 29 | private List manufacturers; 30 | 31 | public List getManufacturers() { 32 | return manufacturers; 33 | } 34 | 35 | public void setManufacturers(List manufacturers) { 36 | this.manufacturers = manufacturers; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/api/retrofit/WebServiceClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.api.retrofit; 18 | 19 | import android.util.Log; 20 | 21 | import com.google.gson.FieldNamingPolicy; 22 | import com.google.gson.Gson; 23 | import com.google.gson.GsonBuilder; 24 | 25 | import me.adamstroud.devicedatabase.BuildConfig; 26 | import okhttp3.OkHttpClient; 27 | import okhttp3.logging.HttpLoggingInterceptor; 28 | import retrofit2.Retrofit; 29 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 30 | import retrofit2.converter.gson.GsonConverterFactory; 31 | 32 | /** 33 | * The singleton for the web API client. 34 | * 35 | * @author Adam Stroud <adam.stroud@gmail.com> 36 | */ 37 | public class WebServiceClient { 38 | private static final String TAG = 39 | WebServiceClient.class.getSimpleName(); 40 | 41 | private static WebServiceClient instance = new WebServiceClient(); 42 | 43 | private final DeviceService service; 44 | 45 | public static WebServiceClient getInstance() { 46 | return instance; 47 | } 48 | 49 | private WebServiceClient() { 50 | final Gson gson = new GsonBuilder() 51 | .setFieldNamingPolicy(FieldNamingPolicy 52 | .LOWER_CASE_WITH_UNDERSCORES) 53 | .create(); 54 | 55 | Retrofit.Builder retrofitBuilder = new Retrofit.Builder() 56 | .baseUrl("http://www.mocky.io") 57 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 58 | .addConverterFactory(GsonConverterFactory.create(gson)); 59 | 60 | if (BuildConfig.DEBUG) { 61 | final HttpLoggingInterceptor loggingInterceptor = 62 | new HttpLoggingInterceptor(new HttpLoggingInterceptor 63 | .Logger() { 64 | @Override 65 | public void log(String message) { 66 | Log.d(TAG, message); 67 | } 68 | }); 69 | 70 | retrofitBuilder.callFactory(new OkHttpClient 71 | .Builder() 72 | .addNetworkInterceptor(loggingInterceptor) 73 | .build()); 74 | 75 | loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 76 | } 77 | 78 | service = retrofitBuilder.build().create(DeviceService.class); 79 | } 80 | 81 | public DeviceService getService() { 82 | return service; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/api/volley/GetManufacturersAndDevicesRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.api.volley; 18 | 19 | import com.android.volley.Response.ErrorListener; 20 | import com.android.volley.Response.Listener; 21 | 22 | import java.util.List; 23 | 24 | import me.adamstroud.devicedatabase.model.Manufacturer; 25 | 26 | /** 27 | * Returns the manufacturer/device list. 28 | * 29 | * @author Adam Stroud <adam.stroud@gmail.com> 30 | */ 31 | public class GetManufacturersAndDevicesRequest 32 | extends JacksonRequest { 33 | public GetManufacturersAndDevicesRequest(Object tag, 34 | Listener listener, 35 | ErrorListener errorListener) { 36 | super(Method.GET, 37 | "http://www.mocky.io/v2/570bbaf6110000b003d17e3a", 38 | Response.class, 39 | listener, 40 | errorListener); 41 | 42 | this.setTag(tag); 43 | } 44 | 45 | public static class Response { 46 | private List manufacturers; 47 | 48 | public List getManufacturers() { 49 | return manufacturers; 50 | } 51 | 52 | public void setManufacturers(List manufacturers) { 53 | this.manufacturers = manufacturers; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/api/volley/JacksonRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.api.volley; 18 | 19 | import com.android.volley.NetworkResponse; 20 | import com.android.volley.ParseError; 21 | import com.android.volley.Request; 22 | import com.android.volley.Response; 23 | import com.android.volley.toolbox.HttpHeaderParser; 24 | import com.fasterxml.jackson.annotation.JsonInclude; 25 | import com.fasterxml.jackson.databind.ObjectMapper; 26 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * Processes a JSON request using the Jackson JSON parser. 32 | * 33 | * @author Adam Stroud <adam.stroud@gmail.com> 34 | */ 35 | public class JacksonRequest extends Request { 36 | private static final ObjectMapper objectMapper = new ObjectMapper() 37 | .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE) 38 | .setSerializationInclusion(JsonInclude.Include.NON_NULL); 39 | 40 | private final Response.Listener listener; 41 | private final Class clazz; 42 | 43 | public JacksonRequest(int method, 44 | String url, 45 | Class clazz, 46 | Response.Listener listener, 47 | Response.ErrorListener errorListener) { 48 | super(method, url, errorListener); 49 | 50 | this.listener = listener; 51 | this.clazz = clazz; 52 | } 53 | 54 | @Override 55 | protected Response parseNetworkResponse(NetworkResponse response) { 56 | T responsePayload; 57 | 58 | try { 59 | responsePayload = objectMapper.readValue(response.data, 60 | clazz); 61 | 62 | return Response.success(responsePayload, 63 | HttpHeaderParser.parseCacheHeaders(response)); 64 | } catch (IOException e) { 65 | return Response.error(new ParseError(e)); 66 | } 67 | } 68 | 69 | @Override 70 | protected void deliverResponse(T response) { 71 | listener.onResponse(response); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/api/volley/VolleyApiClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.api.volley; 18 | 19 | import android.content.Context; 20 | 21 | import com.android.volley.Request; 22 | import com.android.volley.RequestQueue; 23 | import com.android.volley.toolbox.Volley; 24 | 25 | /** 26 | * The Volley web API client. 27 | * 28 | * @author Adam Stroud <adam.stroud@gmail.com> 29 | */ 30 | public class VolleyApiClient { 31 | private static VolleyApiClient instance; 32 | 33 | private RequestQueue requestQueue; 34 | 35 | public static synchronized VolleyApiClient getInstance(Context ctx) { 36 | if (instance == null) { 37 | instance = new VolleyApiClient(ctx); 38 | } 39 | 40 | return instance; 41 | } 42 | 43 | private VolleyApiClient(Context context) { 44 | requestQueue = 45 | Volley.newRequestQueue(context.getApplicationContext()); 46 | } 47 | 48 | public Request add(Request request) { 49 | return requestQueue.add(request); 50 | } 51 | 52 | public void cancelAll(Object tag) { 53 | requestQueue.cancelAll(tag); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/manufacturer/AddManufacturerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.manufacturer; 18 | 19 | import android.content.AsyncQueryHandler; 20 | import android.content.ContentUris; 21 | import android.content.ContentValues; 22 | import android.net.Uri; 23 | import android.os.Bundle; 24 | import android.support.design.widget.CoordinatorLayout; 25 | import android.support.design.widget.FloatingActionButton; 26 | import android.support.design.widget.Snackbar; 27 | import android.support.design.widget.TextInputLayout; 28 | import android.support.v7.app.AppCompatActivity; 29 | import android.support.v7.widget.Toolbar; 30 | import android.view.MenuItem; 31 | import android.view.View; 32 | 33 | import me.adamstroud.devicedatabase.R; 34 | import me.adamstroud.devicedatabase.provider.DevicesContract; 35 | 36 | public class AddManufacturerActivity extends AppCompatActivity { 37 | private CoordinatorLayout root; 38 | private TextInputLayout shortNameView; 39 | private TextInputLayout longNameView; 40 | private AddManufacturerAsyncQueryHandler queryHandler; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.activity_add_manufacturer); 46 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 47 | setSupportActionBar(toolbar); 48 | 49 | root = (CoordinatorLayout) findViewById(R.id.root); 50 | shortNameView = (TextInputLayout) findViewById(R.id.short_name); 51 | longNameView = (TextInputLayout) findViewById(R.id.long_name); 52 | queryHandler = new AddManufacturerAsyncQueryHandler(); 53 | 54 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 55 | fab.setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View view) { 58 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 59 | .setAction("Action", null).show(); 60 | } 61 | }); 62 | 63 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 64 | } 65 | 66 | public void onActionDoneClick(MenuItem menuItem) { 67 | final ContentValues contentValues = new ContentValues(); 68 | contentValues.put(DevicesContract.Manufacturer.SHORT_NAME, shortNameView.getEditText().getText().toString()); 69 | contentValues.put(DevicesContract.Manufacturer.LONG_NAME, longNameView.getEditText().getText().toString()); 70 | 71 | queryHandler.startInsert(1, null, DevicesContract.Manufacturer.CONTENT_URI, contentValues); 72 | } 73 | 74 | private class AddManufacturerAsyncQueryHandler extends AsyncQueryHandler { 75 | public AddManufacturerAsyncQueryHandler() { 76 | super(getContentResolver()); 77 | } 78 | 79 | @Override 80 | protected void onInsertComplete(int token, Object cookie, Uri uri) { 81 | super.onInsertComplete(token, cookie, uri); 82 | Snackbar.make(root, getString(R.string.device_saved_message, ContentUris.parseId(uri)), Snackbar.LENGTH_SHORT).show(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/model/Device.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.model; 18 | 19 | /** 20 | * A device. 21 | * 22 | * @author Adam Stroud <adam.stroud@gmail.com> 23 | */ 24 | public class Device { 25 | private String model; 26 | private String nickname; 27 | private float memoryMb; 28 | private float displaySizeInches; 29 | 30 | public String getModel() { 31 | return model; 32 | } 33 | 34 | public void setModel(String model) { 35 | this.model = model; 36 | } 37 | 38 | public String getNickname() { 39 | return nickname; 40 | } 41 | 42 | public void setNickname(String nickname) { 43 | this.nickname = nickname; 44 | } 45 | 46 | public float getMemoryMb() { 47 | return memoryMb; 48 | } 49 | 50 | public void setMemoryMb(float memoryMb) { 51 | this.memoryMb = memoryMb; 52 | } 53 | 54 | public float getDisplaySizeInches() { 55 | return displaySizeInches; 56 | } 57 | 58 | public void setDisplaySizeInches(float displaySizeInches) { 59 | this.displaySizeInches = displaySizeInches; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/model/Manufacturer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.model; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * A Device manufacturer. 23 | * 24 | * @author Adam Stroud <adam.stroud@gmail.com> 25 | */ 26 | public class Manufacturer { 27 | private String shortName; 28 | private String longName; 29 | private List devices; 30 | 31 | public String getShortName() { 32 | return shortName; 33 | } 34 | 35 | public void setShortName(String shortName) { 36 | this.shortName = shortName; 37 | } 38 | 39 | public String getLongName() { 40 | return longName; 41 | } 42 | 43 | public void setLongName(String longName) { 44 | this.longName = longName; 45 | } 46 | 47 | public List getDevices() { 48 | return devices; 49 | } 50 | 51 | public void setDevices(List devices) { 52 | this.devices = devices; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/provider/DevicesContract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.provider; 18 | 19 | import android.content.ContentResolver; 20 | import android.net.Uri; 21 | import android.provider.BaseColumns; 22 | 23 | import me.adamstroud.devicedatabase.BuildConfig; 24 | 25 | /** 26 | * Defines the API for {@link DevicesProvider}. 27 | * 28 | * @author Adam Stroud <adam.stroud@gmail.com> 29 | */ 30 | public final class DevicesContract { 31 | public static final String AUTHORITY = 32 | String.format("%s.provider", BuildConfig.APPLICATION_ID); 33 | 34 | public static final Uri AUTHORITY_URI = new Uri.Builder() 35 | .scheme(ContentResolver.SCHEME_CONTENT) 36 | .authority(AUTHORITY) 37 | .build(); 38 | 39 | public interface Device extends BaseColumns { 40 | /* default */ static final String PATH = "device"; 41 | public static final String MODEL = "model"; 42 | public static final String NICKNAME = "nickname"; 43 | public static final String MEMORY_MB = "memory_mb"; 44 | 45 | public static final String DISPLAY_SIZE_INCHES = 46 | "display_size_inches"; 47 | 48 | public static final String MANUFACTURER_ID = "manufacturer_id"; 49 | 50 | public static final Uri CONTENT_URI = 51 | Uri.withAppendedPath(AUTHORITY_URI, PATH); 52 | } 53 | 54 | public interface Manufacturer extends BaseColumns { 55 | /* default */ static final String PATH = "manufacturer"; 56 | public static final String SHORT_NAME = "short_name"; 57 | public static final String LONG_NAME = "long_name"; 58 | 59 | public static final Uri CONTENT_URI = 60 | Uri.withAppendedPath(AUTHORITY_URI, PATH); 61 | } 62 | 63 | public interface DeviceManufacturer extends Device, Manufacturer { 64 | /* default */ static final String PATH = "device-manufacturer"; 65 | public static final String DEVICE_ID = "device_id"; 66 | public static final String MANUFACTURER_ID = "manufacturer_id"; 67 | 68 | public static final Uri CONTENT_URI = 69 | Uri.withAppendedPath(AUTHORITY_URI, PATH); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/sync/Authenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.sync; 18 | 19 | import android.accounts.AbstractAccountAuthenticator; 20 | import android.accounts.Account; 21 | import android.accounts.AccountAuthenticatorResponse; 22 | import android.accounts.NetworkErrorException; 23 | import android.content.Context; 24 | import android.os.Bundle; 25 | 26 | /** 27 | * Stub Authenticator for use with the SyncAdapter. 28 | * 29 | * @author Adam Stroud <adam.stroud@gmail.com> 30 | */ 31 | public class Authenticator extends AbstractAccountAuthenticator { 32 | public Authenticator(Context context) { 33 | super(context); 34 | } 35 | 36 | @Override 37 | public Bundle editProperties(AccountAuthenticatorResponse response, 38 | String accountType) { 39 | throw new UnsupportedOperationException("Not yet implemented"); 40 | } 41 | 42 | @Override 43 | public Bundle addAccount(AccountAuthenticatorResponse response, 44 | String accountType, 45 | String authTokenType, 46 | String[] requiredFeatures, 47 | Bundle options) throws NetworkErrorException { 48 | throw new UnsupportedOperationException("Not yet implemented"); 49 | } 50 | 51 | @Override 52 | public Bundle confirmCredentials(AccountAuthenticatorResponse response, 53 | Account account, 54 | Bundle options) 55 | throws NetworkErrorException { 56 | throw new UnsupportedOperationException("Not yet implemented"); 57 | } 58 | 59 | @Override 60 | public Bundle getAuthToken(AccountAuthenticatorResponse response, 61 | Account account, 62 | String authTokenType, 63 | Bundle options) 64 | throws NetworkErrorException { 65 | throw new UnsupportedOperationException("Not yet implemented"); 66 | } 67 | 68 | @Override 69 | public String getAuthTokenLabel(String authTokenType) { 70 | throw new UnsupportedOperationException("Not yet implemented"); 71 | } 72 | 73 | @Override 74 | public Bundle updateCredentials(AccountAuthenticatorResponse response, 75 | Account account, 76 | String authTokenType, 77 | Bundle options) 78 | throws NetworkErrorException { 79 | throw new UnsupportedOperationException("Not yet implemented"); 80 | } 81 | 82 | @Override 83 | public Bundle hasFeatures(AccountAuthenticatorResponse response, 84 | Account account, 85 | String[] features) 86 | throws NetworkErrorException { 87 | throw new UnsupportedOperationException("Not yet implemented"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/sync/AuthenticatorService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.sync; 18 | 19 | import android.app.Service; 20 | import android.content.Intent; 21 | import android.os.IBinder; 22 | 23 | public class AuthenticatorService extends Service { 24 | private Authenticator authenticator; 25 | 26 | public AuthenticatorService() { 27 | } 28 | 29 | @Override 30 | public void onCreate() { 31 | super.onCreate(); 32 | authenticator = new Authenticator(this); 33 | } 34 | 35 | @Override 36 | public IBinder onBind(Intent intent) { 37 | return authenticator.getIBinder(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/me/adamstroud/devicedatabase/sync/SyncService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Adam Stroud 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 me.adamstroud.devicedatabase.sync; 18 | 19 | import android.app.Service; 20 | import android.content.Intent; 21 | import android.os.IBinder; 22 | import android.support.annotation.Nullable; 23 | 24 | /** 25 | * Binds the {@link SyncAdapter} to the sync framework. 26 | * 27 | * @author Adam Stroud <adam.stroud@gmail.com> 28 | */ 29 | public class SyncService extends Service { 30 | private static SyncAdapter syncAdapter = null; 31 | 32 | @Override 33 | public void onCreate() { 34 | super.onCreate(); 35 | 36 | synchronized (SyncService.class) { 37 | syncAdapter = new SyncAdapter(getApplicationContext(), true); 38 | } 39 | } 40 | 41 | @Nullable 42 | @Override 43 | public IBinder onBind(Intent intent) { 44 | return syncAdapter.getSyncAdapterBinder(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_add_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-hdpi/ic_add_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-hdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-hdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_share_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-hdpi/ic_share_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_add_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-mdpi/ic_add_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-mdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-mdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_share_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-mdpi/ic_share_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_add_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xhdpi/ic_add_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xhdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xhdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_share_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xhdpi/ic_share_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xxhdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xxhdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_share_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xxhdpi/ic_share_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_add_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xxxhdpi/ic_add_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xxxhdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xxxhdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_share_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/drawable-xxxhdpi/ic_share_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_add_device.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | 23 | 29 | 33 | 34 | 35 | 36 | 41 | 44 | 45 | 46 | 51 | 54 | 55 | 56 | 61 | 65 | 66 | 67 | 72 | 76 | 77 | 78 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_add_manufacturer.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 27 | 28 | 29 | 30 | 35 | 39 | 40 | 41 | 46 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_device_detail.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 22 | 23 | 30 | 34 | 35 | 36 | 40 | 41 | 45 | 46 | 50 | 51 | 55 | 56 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_device_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 26 | 27 | 28 | 29 | 36 | 37 | 43 | 44 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_manufacturer_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 26 | 27 | 28 | 29 | 36 | 37 | 43 | 44 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/appbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 24 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_item_device.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 27 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_item_manufacturer.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 22 | 23 | 28 | 29 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_add_device.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_add_manufacturer.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_device_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_device_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 25 | 26 | 29 | 30 | 33 | 34 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | > 18 | 19 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #3F51B5 20 | #303F9F 21 | #FF4081 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 16dp 20 | 200dp 21 | 22 | 16dp 23 | 16dp 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | Device Database 19 | Devices 20 | Device Detail 21 | Edit Device 22 | Manufacturers 23 | Model 24 | Nickname 25 | Select Device Manufacturer 26 | Enter RAM in MB 27 | Enter display size in inches 28 | Done 29 | Search 30 | Share 31 | Device (%1$d) Saved 32 | Add Retrofit Data 33 | Add Volley Data 34 | Perform Sync 35 | %1$s %2$s(_id:%3$d) 36 | Allows apps to read device information 37 | Allows apps to read device information 38 | Allows apps to write device information 39 | No devices found. Click the \"+\" button to add one. 40 | No manufacturers found. Click the \"+\" button to add one. 41 | AddManufacturerActivity 42 | Enter Short Name 43 | Enter Long Name 44 | Memory: %1$.2f MB 45 | Display Size: %1$.2f inches 46 | Model: %s 47 | Nickname: %s 48 | Id: %d 49 | 50 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/xml/authenticator.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/xml/syncadapter.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | ext { 4 | compileSdkVersion = 24 5 | buildToolsVersion = "24.0.2" 6 | 7 | // Support Library 8 | supportLibraryVersion = '24.2.1' 9 | supportLibraryDependencies = [ 10 | appCompat : "com.android.support:appcompat-v7:${supportLibraryVersion}", 11 | design : "com.android.support:design:${supportLibraryVersion}", 12 | recyclerView : "com.android.support:recyclerview-v7:${supportLibraryVersion}", 13 | cardView : "com.android.support:cardview-v7:${supportLibraryVersion}" 14 | ] 15 | } 16 | 17 | buildscript { 18 | repositories { 19 | jcenter() 20 | } 21 | dependencies { 22 | classpath 'com.android.tools.build:gradle:2.2.0' 23 | 24 | // NOTE: Do not place your application dependencies here; they belong 25 | // in the individual module build.gradle files 26 | } 27 | } 28 | 29 | allprojects { 30 | repositories { 31 | jcenter() 32 | } 33 | } 34 | 35 | task clean(type: Delete) { 36 | delete rootProject.buildDir 37 | } 38 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android-database-best-practices/device-database/3423589b8d0810b253fa7829e3c25b132cc0f74c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Sep 27 21:17:19 EDT 2016 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.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':thirdParty:volley' 2 | -------------------------------------------------------------------------------- /thirdParty/volley/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | gen 3 | .gradle 4 | build 5 | .settings 6 | target 7 | *.iml 8 | .idea 9 | local.properties 10 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/README: -------------------------------------------------------------------------------- 1 | URL: https://android.googlesource.com/platform/frameworks/volley/+/f0bc25d83ddceccd61c2c11a4fa71b9157290363 2 | 3 | Version: f0bc25d83ddceccd61c2c11a4fa71b9157290363 4 | License: Apache 2.0 5 | License File: LICENSE 6 | 7 | Description: 8 | 9 | Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Volley is available through the open AOSP repository. 10 | 11 | Volley offers the following benefits: 12 | 13 | * Automatic scheduling of network requests. 14 | * Multiple concurrent network connections. 15 | * Transparent disk and memory response caching with standard HTTP cache coherence. 16 | * Support for request prioritization. 17 | * Cancellation request API. You can cancel a single request, or you can set blocks or scopes of requests to cancel. 18 | * Ease of customization, for example, for retry and backoff. 19 | * Strong ordering that makes it easy to correctly populate your UI with data fetched asynchronously from the network. 20 | * Debugging and tracing tools. 21 | 22 | Local Modifications: 23 | * Updated build.gradle to work with environment -------------------------------------------------------------------------------- /thirdParty/volley/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 | // Most users should just add this line to settings.gradle: 10 | // include(":volley") 11 | // 12 | // If you have a more complicated Gradle setup you can choose to use 13 | // this instead: 14 | // include(":volley") 15 | // project(':volley').buildFileName = 'rules.gradle' 16 | 17 | buildscript { 18 | repositories { 19 | jcenter() 20 | } 21 | dependencies { 22 | classpath 'com.android.tools.build:gradle:2.2.0' 23 | } 24 | } 25 | 26 | apply plugin: 'com.android.library' 27 | 28 | repositories { 29 | jcenter() 30 | } 31 | 32 | android { 33 | compileSdkVersion rootProject.ext.compileSdkVersion 34 | buildToolsVersion rootProject.ext.buildToolsVersion 35 | useLibrary 'org.apache.http.legacy' 36 | } 37 | 38 | apply from: 'rules.gradle' 39 | -------------------------------------------------------------------------------- /thirdParty/volley/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /thirdParty/volley/custom_rules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/rules.gradle: -------------------------------------------------------------------------------- 1 | // See build.gradle for an explanation of what this file is. 2 | 3 | apply plugin: 'com.android.library' 4 | 5 | // Check if the android plugin version supports unit testing. 6 | if (configurations.findByName("testCompile")) { 7 | dependencies { 8 | testCompile "junit:junit:4.10" 9 | testCompile "org.mockito:mockito-core:1.9.5" 10 | testCompile "org.robolectric:robolectric:3.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/Cache.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 java.util.Collections; 20 | import java.util.Map; 21 | 22 | /** 23 | * An interface for a cache keyed by a String with a byte array as data. 24 | */ 25 | public interface Cache { 26 | /** 27 | * Retrieves an entry from the cache. 28 | * @param key Cache key 29 | * @return An {@link Entry} or null in the event of a cache miss 30 | */ 31 | public Entry get(String key); 32 | 33 | /** 34 | * Adds or replaces an entry to the cache. 35 | * @param key Cache key 36 | * @param entry Data to store and metadata for cache coherency, TTL, etc. 37 | */ 38 | public void put(String key, Entry entry); 39 | 40 | /** 41 | * Performs any potentially long-running actions needed to initialize the cache; 42 | * will be called from a worker thread. 43 | */ 44 | public void initialize(); 45 | 46 | /** 47 | * Invalidates an entry in the cache. 48 | * @param key Cache key 49 | * @param fullExpire True to fully expire the entry, false to soft expire 50 | */ 51 | public void invalidate(String key, boolean fullExpire); 52 | 53 | /** 54 | * Removes an entry from the cache. 55 | * @param key Cache key 56 | */ 57 | public void remove(String key); 58 | 59 | /** 60 | * Empties the cache. 61 | */ 62 | public void clear(); 63 | 64 | /** 65 | * Data and metadata for an entry returned by the cache. 66 | */ 67 | public static class Entry { 68 | /** The data returned from cache. */ 69 | public byte[] data; 70 | 71 | /** ETag for cache coherency. */ 72 | public String etag; 73 | 74 | /** Date of this response as reported by the server. */ 75 | public long serverDate; 76 | 77 | /** The last modified date for the requested object. */ 78 | public long lastModified; 79 | 80 | /** TTL for this record. */ 81 | public long ttl; 82 | 83 | /** Soft TTL for this record. */ 84 | public long softTtl; 85 | 86 | /** Immutable response headers as received from server; must be non-null. */ 87 | public Map responseHeaders = Collections.emptyMap(); 88 | 89 | /** True if the entry is expired. */ 90 | public boolean isExpired() { 91 | return this.ttl < System.currentTimeMillis(); 92 | } 93 | 94 | /** True if a refresh is needed from the original data source. */ 95 | public boolean refreshNeeded() { 96 | return this.softTtl < System.currentTimeMillis(); 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/DefaultRetryPolicy.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 | * Default retry policy for requests. 21 | */ 22 | public class DefaultRetryPolicy implements RetryPolicy { 23 | /** The current timeout in milliseconds. */ 24 | private int mCurrentTimeoutMs; 25 | 26 | /** The current retry count. */ 27 | private int mCurrentRetryCount; 28 | 29 | /** The maximum number of attempts. */ 30 | private final int mMaxNumRetries; 31 | 32 | /** The backoff multiplier for the policy. */ 33 | private final float mBackoffMultiplier; 34 | 35 | /** The default socket timeout in milliseconds */ 36 | public static final int DEFAULT_TIMEOUT_MS = 2500; 37 | 38 | /** The default number of retries */ 39 | public static final int DEFAULT_MAX_RETRIES = 1; 40 | 41 | /** The default backoff multiplier */ 42 | public static final float DEFAULT_BACKOFF_MULT = 1f; 43 | 44 | /** 45 | * Constructs a new retry policy using the default timeouts. 46 | */ 47 | public DefaultRetryPolicy() { 48 | this(DEFAULT_TIMEOUT_MS, DEFAULT_MAX_RETRIES, DEFAULT_BACKOFF_MULT); 49 | } 50 | 51 | /** 52 | * Constructs a new retry policy. 53 | * @param initialTimeoutMs The initial timeout for the policy. 54 | * @param maxNumRetries The maximum number of retries. 55 | * @param backoffMultiplier Backoff multiplier for the policy. 56 | */ 57 | public DefaultRetryPolicy(int initialTimeoutMs, int maxNumRetries, float backoffMultiplier) { 58 | mCurrentTimeoutMs = initialTimeoutMs; 59 | mMaxNumRetries = maxNumRetries; 60 | mBackoffMultiplier = backoffMultiplier; 61 | } 62 | 63 | /** 64 | * Returns the current timeout. 65 | */ 66 | @Override 67 | public int getCurrentTimeout() { 68 | return mCurrentTimeoutMs; 69 | } 70 | 71 | /** 72 | * Returns the current retry count. 73 | */ 74 | @Override 75 | public int getCurrentRetryCount() { 76 | return mCurrentRetryCount; 77 | } 78 | 79 | /** 80 | * Returns the backoff multiplier for the policy. 81 | */ 82 | public float getBackoffMultiplier() { 83 | return mBackoffMultiplier; 84 | } 85 | 86 | /** 87 | * Prepares for the next retry by applying a backoff to the timeout. 88 | * @param error The error code of the last attempt. 89 | */ 90 | @Override 91 | public void retry(VolleyError error) throws VolleyError { 92 | mCurrentRetryCount++; 93 | mCurrentTimeoutMs += (mCurrentTimeoutMs * mBackoffMultiplier); 94 | if (!hasAttemptRemaining()) { 95 | throw error; 96 | } 97 | } 98 | 99 | /** 100 | * Returns true if this policy has attempts remaining, false otherwise. 101 | */ 102 | protected boolean hasAttemptRemaining() { 103 | return mCurrentRetryCount <= mMaxNumRetries; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/ExecutorDelivery.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.os.Handler; 20 | 21 | import java.util.concurrent.Executor; 22 | 23 | /** 24 | * Delivers responses and errors. 25 | */ 26 | public class ExecutorDelivery implements ResponseDelivery { 27 | /** Used for posting responses, typically to the main thread. */ 28 | private final Executor mResponsePoster; 29 | 30 | /** 31 | * Creates a new response delivery interface. 32 | * @param handler {@link Handler} to post responses on 33 | */ 34 | public ExecutorDelivery(final Handler handler) { 35 | // Make an Executor that just wraps the handler. 36 | mResponsePoster = new Executor() { 37 | @Override 38 | public void execute(Runnable command) { 39 | handler.post(command); 40 | } 41 | }; 42 | } 43 | 44 | /** 45 | * Creates a new response delivery interface, mockable version 46 | * for testing. 47 | * @param executor For running delivery tasks 48 | */ 49 | public ExecutorDelivery(Executor executor) { 50 | mResponsePoster = executor; 51 | } 52 | 53 | @Override 54 | public void postResponse(Request> request, Response> response) { 55 | postResponse(request, response, null); 56 | } 57 | 58 | @Override 59 | public void postResponse(Request> request, Response> response, Runnable runnable) { 60 | request.markDelivered(); 61 | request.addMarker("post-response"); 62 | mResponsePoster.execute(new ResponseDeliveryRunnable(request, response, runnable)); 63 | } 64 | 65 | @Override 66 | public void postError(Request> request, VolleyError error) { 67 | request.addMarker("post-error"); 68 | Response> response = Response.error(error); 69 | mResponsePoster.execute(new ResponseDeliveryRunnable(request, response, null)); 70 | } 71 | 72 | /** 73 | * A Runnable used for delivering network responses to a listener on the 74 | * main thread. 75 | */ 76 | @SuppressWarnings("rawtypes") 77 | private class ResponseDeliveryRunnable implements Runnable { 78 | private final Request mRequest; 79 | private final Response mResponse; 80 | private final Runnable mRunnable; 81 | 82 | public ResponseDeliveryRunnable(Request request, Response response, Runnable runnable) { 83 | mRequest = request; 84 | mResponse = response; 85 | mRunnable = runnable; 86 | } 87 | 88 | @SuppressWarnings("unchecked") 89 | @Override 90 | public void run() { 91 | // If this request has canceled, finish it and don't deliver. 92 | if (mRequest.isCanceled()) { 93 | mRequest.finish("canceled-at-delivery"); 94 | return; 95 | } 96 | 97 | // Deliver a normal response or error, depending. 98 | if (mResponse.isSuccess()) { 99 | mRequest.deliverResponse(mResponse.result); 100 | } else { 101 | mRequest.deliverError(mResponse.error); 102 | } 103 | 104 | // If this is an intermediate response, add a marker, otherwise we're done 105 | // and the request can be finished. 106 | if (mResponse.intermediate) { 107 | mRequest.addMarker("intermediate-response"); 108 | } else { 109 | mRequest.finish("done"); 110 | } 111 | 112 | // If we have been provided a post-delivery runnable, run it. 113 | if (mRunnable != null) { 114 | mRunnable.run(); 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/NetworkResponse.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 org.apache.http.HttpStatus; 20 | 21 | import java.util.Collections; 22 | import java.util.Map; 23 | 24 | /** 25 | * Data and headers returned from {@link Network#performRequest(Request)}. 26 | */ 27 | public class NetworkResponse { 28 | /** 29 | * Creates a new network response. 30 | * @param statusCode the HTTP status code 31 | * @param data Response body 32 | * @param headers Headers returned with this response, or null for none 33 | * @param notModified True if the server returned a 304 and the data was already in cache 34 | * @param networkTimeMs Round-trip network time to receive network response 35 | */ 36 | public NetworkResponse(int statusCode, byte[] data, Map headers, 37 | boolean notModified, long networkTimeMs) { 38 | this.statusCode = statusCode; 39 | this.data = data; 40 | this.headers = headers; 41 | this.notModified = notModified; 42 | this.networkTimeMs = networkTimeMs; 43 | } 44 | 45 | public NetworkResponse(int statusCode, byte[] data, Map headers, 46 | boolean notModified) { 47 | this(statusCode, data, headers, notModified, 0); 48 | } 49 | 50 | public NetworkResponse(byte[] data) { 51 | this(HttpStatus.SC_OK, data, Collections.emptyMap(), false, 0); 52 | } 53 | 54 | public NetworkResponse(byte[] data, Map headers) { 55 | this(HttpStatus.SC_OK, data, headers, false, 0); 56 | } 57 | 58 | /** The HTTP status code. */ 59 | public final int statusCode; 60 | 61 | /** Raw data from this response. */ 62 | public final byte[] data; 63 | 64 | /** Response headers. */ 65 | public final Map headers; 66 | 67 | /** True if the server returned a 304 (Not Modified). */ 68 | public final boolean notModified; 69 | 70 | /** Network roundtrip time in milliseconds. */ 71 | public final long networkTimeMs; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/Response.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 | * Encapsulates a parsed response for delivery. 21 | * 22 | * @param Parsed type of this response 23 | */ 24 | public class Response { 25 | 26 | /** Callback interface for delivering parsed responses. */ 27 | public interface Listener { 28 | /** Called when a response is received. */ 29 | public void onResponse(T response); 30 | } 31 | 32 | /** Callback interface for delivering error responses. */ 33 | public interface ErrorListener { 34 | /** 35 | * Callback method that an error has been occurred with the 36 | * provided error code and optional user-readable message. 37 | */ 38 | public void onErrorResponse(VolleyError error); 39 | } 40 | 41 | /** Returns a successful response containing the parsed result. */ 42 | public static Response success(T result, Cache.Entry cacheEntry) { 43 | return new Response(result, cacheEntry); 44 | } 45 | 46 | /** 47 | * Returns a failed response containing the given error code and an optional 48 | * localized message displayed to the user. 49 | */ 50 | public static Response error(VolleyError error) { 51 | return new Response(error); 52 | } 53 | 54 | /** Parsed response, or null in the case of error. */ 55 | public final T result; 56 | 57 | /** Cache metadata for this response, or null in the case of error. */ 58 | public final Cache.Entry cacheEntry; 59 | 60 | /** Detailed error information if errorCode != OK. */ 61 | public final VolleyError error; 62 | 63 | /** True if this response was a soft-expired one and a second one MAY be coming. */ 64 | public boolean intermediate = false; 65 | 66 | /** 67 | * Returns whether this response is considered successful. 68 | */ 69 | public boolean isSuccess() { 70 | return error == null; 71 | } 72 | 73 | 74 | private Response(T result, Cache.Entry cacheEntry) { 75 | this.result = result; 76 | this.cacheEntry = cacheEntry; 77 | this.error = null; 78 | } 79 | 80 | private Response(VolleyError error) { 81 | this.result = null; 82 | this.cacheEntry = null; 83 | this.error = error; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/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 { 31 | private final Cache mCache; 32 | private final Runnable mCallback; 33 | 34 | /** 35 | * Creates a synthetic request for clearing the cache. 36 | * @param cache Cache to clear 37 | * @param callback Callback to make on the main thread once the cache is clear, 38 | * or null for none 39 | */ 40 | public ClearCacheRequest(Cache cache, Runnable callback) { 41 | super(Method.GET, null, null); 42 | mCache = cache; 43 | mCallback = callback; 44 | } 45 | 46 | @Override 47 | public boolean isCanceled() { 48 | // This is a little bit of a hack, but hey, why not. 49 | mCache.clear(); 50 | if (mCallback != null) { 51 | Handler handler = new Handler(Looper.getMainLooper()); 52 | handler.postAtFrontOfQueue(mCallback); 53 | } 54 | return true; 55 | } 56 | 57 | @Override 58 | public Priority getPriority() { 59 | return Priority.IMMEDIATE; 60 | } 61 | 62 | @Override 63 | protected Response parseNetworkResponse(NetworkResponse response) { 64 | return null; 65 | } 66 | 67 | @Override 68 | protected void deliverResponse(Object response) { 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/toolbox/JsonArrayRequest.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.NetworkResponse; 20 | import com.android.volley.ParseError; 21 | import com.android.volley.Response; 22 | import com.android.volley.Response.ErrorListener; 23 | import com.android.volley.Response.Listener; 24 | 25 | import org.json.JSONArray; 26 | import org.json.JSONException; 27 | 28 | import java.io.UnsupportedEncodingException; 29 | 30 | /** 31 | * A request for retrieving a {@link JSONArray} response body at a given URL. 32 | */ 33 | public class JsonArrayRequest extends JsonRequest { 34 | 35 | /** 36 | * Creates a new request. 37 | * @param url URL to fetch the JSON from 38 | * @param listener Listener to receive the JSON response 39 | * @param errorListener Error listener, or null to ignore errors. 40 | */ 41 | public JsonArrayRequest(String url, Listener listener, ErrorListener errorListener) { 42 | super(Method.GET, url, null, listener, errorListener); 43 | } 44 | 45 | /** 46 | * Creates a new request. 47 | * @param method the HTTP method to use 48 | * @param url URL to fetch the JSON from 49 | * @param jsonRequest A {@link JSONArray} to post with the request. Null is allowed and 50 | * indicates no parameters will be posted along with request. 51 | * @param listener Listener to receive the JSON response 52 | * @param errorListener Error listener, or null to ignore errors. 53 | */ 54 | public JsonArrayRequest(int method, String url, JSONArray jsonRequest, 55 | Listener listener, ErrorListener errorListener) { 56 | super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener, 57 | errorListener); 58 | } 59 | 60 | @Override 61 | protected Response parseNetworkResponse(NetworkResponse response) { 62 | try { 63 | String jsonString = new String(response.data, 64 | HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET)); 65 | return Response.success(new JSONArray(jsonString), 66 | HttpHeaderParser.parseCacheHeaders(response)); 67 | } catch (UnsupportedEncodingException e) { 68 | return Response.error(new ParseError(e)); 69 | } catch (JSONException je) { 70 | return Response.error(new ParseError(je)); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/toolbox/JsonObjectRequest.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.NetworkResponse; 20 | import com.android.volley.ParseError; 21 | import com.android.volley.Response; 22 | import com.android.volley.Response.ErrorListener; 23 | import com.android.volley.Response.Listener; 24 | 25 | import org.json.JSONException; 26 | import org.json.JSONObject; 27 | 28 | import java.io.UnsupportedEncodingException; 29 | 30 | /** 31 | * A request for retrieving a {@link JSONObject} response body at a given URL, allowing for an 32 | * optional {@link JSONObject} to be passed in as part of the request body. 33 | */ 34 | public class JsonObjectRequest extends JsonRequest { 35 | 36 | /** 37 | * Creates a new request. 38 | * @param method the HTTP method to use 39 | * @param url URL to fetch the JSON from 40 | * @param jsonRequest A {@link JSONObject} to post with the request. Null is allowed and 41 | * indicates no parameters will be posted along with request. 42 | * @param listener Listener to receive the JSON response 43 | * @param errorListener Error listener, or null to ignore errors. 44 | */ 45 | public JsonObjectRequest(int method, String url, JSONObject jsonRequest, 46 | Listener listener, ErrorListener errorListener) { 47 | super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener, 48 | errorListener); 49 | } 50 | 51 | /** 52 | * Constructor which defaults to GET if jsonRequest is 53 | * null, POST otherwise. 54 | * 55 | * @see #JsonObjectRequest(int, String, JSONObject, Listener, ErrorListener) 56 | */ 57 | public JsonObjectRequest(String url, JSONObject jsonRequest, Listener listener, 58 | ErrorListener errorListener) { 59 | this(jsonRequest == null ? Method.GET : Method.POST, url, jsonRequest, 60 | listener, errorListener); 61 | } 62 | 63 | @Override 64 | protected Response parseNetworkResponse(NetworkResponse response) { 65 | try { 66 | String jsonString = new String(response.data, 67 | HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET)); 68 | return Response.success(new JSONObject(jsonString), 69 | HttpHeaderParser.parseCacheHeaders(response)); 70 | } catch (UnsupportedEncodingException e) { 71 | return Response.error(new ParseError(e)); 72 | } catch (JSONException je) { 73 | return Response.error(new ParseError(je)); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/toolbox/JsonRequest.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.NetworkResponse; 20 | import com.android.volley.Request; 21 | import com.android.volley.Response; 22 | import com.android.volley.Response.ErrorListener; 23 | import com.android.volley.Response.Listener; 24 | import com.android.volley.VolleyLog; 25 | 26 | import java.io.UnsupportedEncodingException; 27 | 28 | /** 29 | * A request for retrieving a T type response body at a given URL that also 30 | * optionally sends along a JSON body in the request specified. 31 | * 32 | * @param JSON type of response expected 33 | */ 34 | public abstract class JsonRequest extends Request { 35 | /** Default charset for JSON request. */ 36 | protected static final String PROTOCOL_CHARSET = "utf-8"; 37 | 38 | /** Content type for request. */ 39 | private static final String PROTOCOL_CONTENT_TYPE = 40 | String.format("application/json; charset=%s", PROTOCOL_CHARSET); 41 | 42 | private final Listener mListener; 43 | private final String mRequestBody; 44 | 45 | /** 46 | * Deprecated constructor for a JsonRequest which defaults to GET unless {@link #getPostBody()} 47 | * or {@link #getPostParams()} is overridden (which defaults to POST). 48 | * 49 | * @deprecated Use {@link #JsonRequest(int, String, String, Listener, ErrorListener)}. 50 | */ 51 | public JsonRequest(String url, String requestBody, Listener listener, 52 | ErrorListener errorListener) { 53 | this(Method.DEPRECATED_GET_OR_POST, url, requestBody, listener, errorListener); 54 | } 55 | 56 | public JsonRequest(int method, String url, String requestBody, Listener listener, 57 | ErrorListener errorListener) { 58 | super(method, url, errorListener); 59 | mListener = listener; 60 | mRequestBody = requestBody; 61 | } 62 | 63 | @Override 64 | protected void deliverResponse(T response) { 65 | mListener.onResponse(response); 66 | } 67 | 68 | @Override 69 | abstract protected Response parseNetworkResponse(NetworkResponse response); 70 | 71 | /** 72 | * @deprecated Use {@link #getBodyContentType()}. 73 | */ 74 | @Override 75 | public String getPostBodyContentType() { 76 | return getBodyContentType(); 77 | } 78 | 79 | /** 80 | * @deprecated Use {@link #getBody()}. 81 | */ 82 | @Override 83 | public byte[] getPostBody() { 84 | return getBody(); 85 | } 86 | 87 | @Override 88 | public String getBodyContentType() { 89 | return PROTOCOL_CONTENT_TYPE; 90 | } 91 | 92 | @Override 93 | public byte[] getBody() { 94 | try { 95 | return mRequestBody == null ? null : mRequestBody.getBytes(PROTOCOL_CHARSET); 96 | } catch (UnsupportedEncodingException uee) { 97 | VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", 98 | mRequestBody, PROTOCOL_CHARSET); 99 | return null; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /thirdParty/volley/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 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/toolbox/PoolingByteArrayOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 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 java.io.ByteArrayOutputStream; 20 | import java.io.IOException; 21 | 22 | /** 23 | * A variation of {@link java.io.ByteArrayOutputStream} that uses a pool of byte[] buffers instead 24 | * of always allocating them fresh, saving on heap churn. 25 | */ 26 | public class PoolingByteArrayOutputStream extends ByteArrayOutputStream { 27 | /** 28 | * If the {@link #PoolingByteArrayOutputStream(ByteArrayPool)} constructor is called, this is 29 | * the default size to which the underlying byte array is initialized. 30 | */ 31 | private static final int DEFAULT_SIZE = 256; 32 | 33 | private final ByteArrayPool mPool; 34 | 35 | /** 36 | * Constructs a new PoolingByteArrayOutputStream with a default size. If more bytes are written 37 | * to this instance, the underlying byte array will expand. 38 | */ 39 | public PoolingByteArrayOutputStream(ByteArrayPool pool) { 40 | this(pool, DEFAULT_SIZE); 41 | } 42 | 43 | /** 44 | * Constructs a new {@code ByteArrayOutputStream} with a default size of {@code size} bytes. If 45 | * more than {@code size} bytes are written to this instance, the underlying byte array will 46 | * expand. 47 | * 48 | * @param size initial size for the underlying byte array. The value will be pinned to a default 49 | * minimum size. 50 | */ 51 | public PoolingByteArrayOutputStream(ByteArrayPool pool, int size) { 52 | mPool = pool; 53 | buf = mPool.getBuf(Math.max(size, DEFAULT_SIZE)); 54 | } 55 | 56 | @Override 57 | public void close() throws IOException { 58 | mPool.returnBuf(buf); 59 | buf = null; 60 | super.close(); 61 | } 62 | 63 | @Override 64 | public void finalize() { 65 | mPool.returnBuf(buf); 66 | } 67 | 68 | /** 69 | * Ensures there is enough space in the buffer for the given number of additional bytes. 70 | */ 71 | private void expand(int i) { 72 | /* Can the buffer handle @i more bytes, if not expand it */ 73 | if (count + i <= buf.length) { 74 | return; 75 | } 76 | byte[] newbuf = mPool.getBuf((count + i) * 2); 77 | System.arraycopy(buf, 0, newbuf, 0, count); 78 | mPool.returnBuf(buf); 79 | buf = newbuf; 80 | } 81 | 82 | @Override 83 | public synchronized void write(byte[] buffer, int offset, int len) { 84 | expand(len); 85 | super.write(buffer, offset, len); 86 | } 87 | 88 | @Override 89 | public synchronized void write(int oneByte) { 90 | expand(1); 91 | super.write(oneByte); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/toolbox/StringRequest.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.NetworkResponse; 20 | import com.android.volley.Request; 21 | import com.android.volley.Response; 22 | import com.android.volley.Response.ErrorListener; 23 | import com.android.volley.Response.Listener; 24 | 25 | import java.io.UnsupportedEncodingException; 26 | 27 | /** 28 | * A canned request for retrieving the response body at a given URL as a String. 29 | */ 30 | public class StringRequest extends Request { 31 | private final Listener mListener; 32 | 33 | /** 34 | * Creates a new request with the given method. 35 | * 36 | * @param method the request {@link Method} to use 37 | * @param url URL to fetch the string at 38 | * @param listener Listener to receive the String response 39 | * @param errorListener Error listener, or null to ignore errors 40 | */ 41 | public StringRequest(int method, String url, Listener listener, 42 | ErrorListener errorListener) { 43 | super(method, url, errorListener); 44 | mListener = listener; 45 | } 46 | 47 | /** 48 | * Creates a new GET request. 49 | * 50 | * @param url URL to fetch the string at 51 | * @param listener Listener to receive the String response 52 | * @param errorListener Error listener, or null to ignore errors 53 | */ 54 | public StringRequest(String url, Listener listener, ErrorListener errorListener) { 55 | this(Method.GET, url, listener, errorListener); 56 | } 57 | 58 | @Override 59 | protected void deliverResponse(String response) { 60 | mListener.onResponse(response); 61 | } 62 | 63 | @Override 64 | protected Response parseNetworkResponse(NetworkResponse response) { 65 | String parsed; 66 | try { 67 | parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); 68 | } catch (UnsupportedEncodingException e) { 69 | parsed = new String(response.data); 70 | } 71 | return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /thirdParty/volley/src/main/java/com/android/volley/toolbox/Volley.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 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 android.content.Context; 20 | import android.content.pm.PackageInfo; 21 | import android.content.pm.PackageManager.NameNotFoundException; 22 | import android.net.http.AndroidHttpClient; 23 | import android.os.Build; 24 | 25 | import com.android.volley.Network; 26 | import com.android.volley.RequestQueue; 27 | 28 | import java.io.File; 29 | 30 | public class Volley { 31 | 32 | /** Default on-disk cache directory. */ 33 | private static final String DEFAULT_CACHE_DIR = "volley"; 34 | 35 | /** 36 | * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. 37 | * 38 | * @param context A {@link Context} to use for creating the cache dir. 39 | * @param stack An {@link HttpStack} to use for the network, or null for default. 40 | * @return A started {@link RequestQueue} instance. 41 | */ 42 | public static RequestQueue newRequestQueue(Context context, HttpStack stack) { 43 | File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); 44 | 45 | String userAgent = "volley/0"; 46 | try { 47 | String packageName = context.getPackageName(); 48 | PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); 49 | userAgent = packageName + "/" + info.versionCode; 50 | } catch (NameNotFoundException e) { 51 | } 52 | 53 | if (stack == null) { 54 | if (Build.VERSION.SDK_INT >= 9) { 55 | stack = new HurlStack(); 56 | } else { 57 | // Prior to Gingerbread, HttpUrlConnection was unreliable. 58 | // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html 59 | stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); 60 | } 61 | } 62 | 63 | Network network = new BasicNetwork(stack); 64 | 65 | RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); 66 | queue.start(); 67 | 68 | return queue; 69 | } 70 | 71 | /** 72 | * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. 73 | * 74 | * @param context A {@link Context} to use for creating the cache dir. 75 | * @return A started {@link RequestQueue} instance. 76 | */ 77 | public static RequestQueue newRequestQueue(Context context) { 78 | return newRequestQueue(context, null); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/NetworkDispatcherTest.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 com.android.volley.mock.MockCache; 20 | import com.android.volley.mock.MockNetwork; 21 | import com.android.volley.mock.MockRequest; 22 | import com.android.volley.mock.MockResponseDelivery; 23 | import com.android.volley.mock.WaitableQueue; 24 | import org.junit.After; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.junit.runner.RunWith; 28 | import org.robolectric.RobolectricTestRunner; 29 | 30 | import java.util.Arrays; 31 | 32 | import static org.junit.Assert.*; 33 | 34 | @RunWith(RobolectricTestRunner.class) 35 | public class NetworkDispatcherTest { 36 | private NetworkDispatcher mDispatcher; 37 | private MockResponseDelivery mDelivery; 38 | private WaitableQueue mNetworkQueue; 39 | private MockNetwork mNetwork; 40 | private MockCache mCache; 41 | private MockRequest mRequest; 42 | 43 | private static final byte[] CANNED_DATA = "Ceci n'est pas une vraie reponse".getBytes(); 44 | private static final long TIMEOUT_MILLIS = 5000; 45 | 46 | @Before public void setUp() throws Exception { 47 | mDelivery = new MockResponseDelivery(); 48 | mNetworkQueue = new WaitableQueue(); 49 | mNetwork = new MockNetwork(); 50 | mCache = new MockCache(); 51 | mRequest = new MockRequest(); 52 | mDispatcher = new NetworkDispatcher(mNetworkQueue, mNetwork, mCache, mDelivery); 53 | mDispatcher.start(); 54 | } 55 | 56 | @After public void tearDown() throws Exception { 57 | mDispatcher.quit(); 58 | mDispatcher.join(); 59 | } 60 | 61 | @Test public void successPostsResponse() throws Exception { 62 | mNetwork.setDataToReturn(CANNED_DATA); 63 | mNetwork.setNumExceptionsToThrow(0); 64 | mNetworkQueue.add(mRequest); 65 | mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS); 66 | assertFalse(mDelivery.postError_called); 67 | assertTrue(mDelivery.postResponse_called); 68 | Response> response = mDelivery.responsePosted; 69 | assertNotNull(response); 70 | assertTrue(response.isSuccess()); 71 | assertTrue(Arrays.equals((byte[])response.result, CANNED_DATA)); 72 | } 73 | 74 | @Test public void exceptionPostsError() throws Exception { 75 | mNetwork.setNumExceptionsToThrow(MockNetwork.ALWAYS_THROW_EXCEPTIONS); 76 | mNetworkQueue.add(mRequest); 77 | mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS); 78 | assertFalse(mDelivery.postResponse_called); 79 | assertTrue(mDelivery.postError_called); 80 | } 81 | 82 | @Test public void shouldCacheFalse() throws Exception { 83 | mRequest.setShouldCache(false); 84 | mNetworkQueue.add(mRequest); 85 | mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS); 86 | assertFalse(mCache.putCalled); 87 | } 88 | 89 | @Test public void shouldCacheTrue() throws Exception { 90 | mNetwork.setDataToReturn(CANNED_DATA); 91 | mRequest.setShouldCache(true); 92 | mRequest.setCacheKey("bananaphone"); 93 | mNetworkQueue.add(mRequest); 94 | mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS); 95 | assertTrue(mCache.putCalled); 96 | assertNotNull(mCache.entryPut); 97 | assertTrue(Arrays.equals(mCache.entryPut.data, CANNED_DATA)); 98 | assertEquals("bananaphone", mCache.keyPut); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/RequestQueueTest.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 com.android.volley.mock.ShadowSystemClock; 20 | import com.android.volley.toolbox.NoCache; 21 | import com.android.volley.utils.ImmediateResponseDelivery; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | import org.mockito.Mock; 26 | import org.robolectric.RobolectricTestRunner; 27 | import org.robolectric.annotation.Config; 28 | 29 | import static org.junit.Assert.*; 30 | import static org.mockito.Mockito.*; 31 | import static org.mockito.MockitoAnnotations.initMocks; 32 | 33 | /** 34 | * Unit tests for RequestQueue, with all dependencies mocked out 35 | */ 36 | @RunWith(RobolectricTestRunner.class) 37 | @Config(shadows = {ShadowSystemClock.class}) 38 | public class RequestQueueTest { 39 | 40 | private ResponseDelivery mDelivery; 41 | @Mock private Network mMockNetwork; 42 | 43 | @Before public void setUp() throws Exception { 44 | mDelivery = new ImmediateResponseDelivery(); 45 | initMocks(this); 46 | } 47 | 48 | @Test public void cancelAll_onlyCorrectTag() throws Exception { 49 | RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 0, mDelivery); 50 | Object tagA = new Object(); 51 | Object tagB = new Object(); 52 | Request req1 = mock(Request.class); 53 | when(req1.getTag()).thenReturn(tagA); 54 | Request req2 = mock(Request.class); 55 | when(req2.getTag()).thenReturn(tagB); 56 | Request req3 = mock(Request.class); 57 | when(req3.getTag()).thenReturn(tagA); 58 | Request req4 = mock(Request.class); 59 | when(req4.getTag()).thenReturn(tagA); 60 | 61 | queue.add(req1); // A 62 | queue.add(req2); // B 63 | queue.add(req3); // A 64 | queue.cancelAll(tagA); 65 | queue.add(req4); // A 66 | 67 | verify(req1).cancel(); // A cancelled 68 | verify(req3).cancel(); // A cancelled 69 | verify(req2, never()).cancel(); // B not cancelled 70 | verify(req4, never()).cancel(); // A added after cancel not cancelled 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/RequestTest.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 com.android.volley.Request.Priority; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.robolectric.RobolectricTestRunner; 23 | 24 | import static org.junit.Assert.*; 25 | 26 | @RunWith(RobolectricTestRunner.class) 27 | public class RequestTest { 28 | 29 | @Test public void compareTo() { 30 | int sequence = 0; 31 | TestRequest low = new TestRequest(Priority.LOW); 32 | low.setSequence(sequence++); 33 | TestRequest low2 = new TestRequest(Priority.LOW); 34 | low2.setSequence(sequence++); 35 | TestRequest high = new TestRequest(Priority.HIGH); 36 | high.setSequence(sequence++); 37 | TestRequest immediate = new TestRequest(Priority.IMMEDIATE); 38 | immediate.setSequence(sequence++); 39 | 40 | // "Low" should sort higher because it's really processing order. 41 | assertTrue(low.compareTo(high) > 0); 42 | assertTrue(high.compareTo(low) < 0); 43 | assertTrue(low.compareTo(low2) < 0); 44 | assertTrue(low.compareTo(immediate) > 0); 45 | assertTrue(immediate.compareTo(high) < 0); 46 | } 47 | 48 | private class TestRequest extends Request { 49 | private Priority mPriority = Priority.NORMAL; 50 | public TestRequest(Priority priority) { 51 | super(Request.Method.GET, "", null); 52 | mPriority = priority; 53 | } 54 | 55 | @Override 56 | public Priority getPriority() { 57 | return mPriority; 58 | } 59 | 60 | @Override 61 | protected void deliverResponse(Object response) { 62 | } 63 | 64 | @Override 65 | protected Response parseNetworkResponse(NetworkResponse response) { 66 | return null; 67 | } 68 | } 69 | 70 | @Test public void urlParsing() { 71 | UrlParseRequest nullUrl = new UrlParseRequest(null); 72 | assertEquals(0, nullUrl.getTrafficStatsTag()); 73 | UrlParseRequest emptyUrl = new UrlParseRequest(""); 74 | assertEquals(0, emptyUrl.getTrafficStatsTag()); 75 | UrlParseRequest noHost = new UrlParseRequest("http:///"); 76 | assertEquals(0, noHost.getTrafficStatsTag()); 77 | UrlParseRequest badProtocol = new UrlParseRequest("bad:http://foo"); 78 | assertEquals(0, badProtocol.getTrafficStatsTag()); 79 | UrlParseRequest goodProtocol = new UrlParseRequest("http://foo"); 80 | assertFalse(0 == goodProtocol.getTrafficStatsTag()); 81 | } 82 | 83 | private class UrlParseRequest extends Request { 84 | public UrlParseRequest(String url) { 85 | super(Request.Method.GET, url, null); 86 | } 87 | 88 | @Override 89 | protected void deliverResponse(Object response) { 90 | } 91 | 92 | @Override 93 | protected Response parseNetworkResponse(NetworkResponse response) { 94 | return null; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/ResponseDeliveryTest.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 com.android.volley.mock.MockRequest; 20 | import com.android.volley.utils.CacheTestUtils; 21 | import com.android.volley.utils.ImmediateResponseDelivery; 22 | 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.robolectric.RobolectricTestRunner; 28 | 29 | import static org.junit.Assert.*; 30 | 31 | @RunWith(RobolectricTestRunner.class) 32 | public class ResponseDeliveryTest { 33 | 34 | private ExecutorDelivery mDelivery; 35 | private MockRequest mRequest; 36 | private Response mSuccessResponse; 37 | 38 | @Before public void setUp() throws Exception { 39 | // Make the delivery just run its posted responses immediately. 40 | mDelivery = new ImmediateResponseDelivery(); 41 | mRequest = new MockRequest(); 42 | mRequest.setSequence(1); 43 | byte[] data = new byte[16]; 44 | Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data); 45 | mSuccessResponse = Response.success(data, cacheEntry); 46 | } 47 | 48 | @Test public void postResponseCallsDeliverResponse() { 49 | mDelivery.postResponse(mRequest, mSuccessResponse); 50 | assertTrue(mRequest.deliverResponse_called); 51 | assertFalse(mRequest.deliverError_called); 52 | } 53 | 54 | @Test public void postResponseSuppressesCanceled() { 55 | mRequest.cancel(); 56 | mDelivery.postResponse(mRequest, mSuccessResponse); 57 | assertFalse(mRequest.deliverResponse_called); 58 | assertFalse(mRequest.deliverError_called); 59 | } 60 | 61 | @Test public void postErrorCallsDeliverError() { 62 | Response errorResponse = Response.error(new ServerError()); 63 | 64 | mDelivery.postResponse(mRequest, errorResponse); 65 | assertTrue(mRequest.deliverError_called); 66 | assertFalse(mRequest.deliverResponse_called); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/MockCache.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.mock; 18 | 19 | import com.android.volley.Cache; 20 | 21 | public class MockCache implements Cache { 22 | 23 | public boolean clearCalled = false; 24 | @Override 25 | public void clear() { 26 | clearCalled = true; 27 | } 28 | 29 | public boolean getCalled = false; 30 | private Entry mFakeEntry = null; 31 | 32 | public void setEntryToReturn(Entry entry) { 33 | mFakeEntry = entry; 34 | } 35 | 36 | @Override 37 | public Entry get(String key) { 38 | getCalled = true; 39 | return mFakeEntry; 40 | } 41 | 42 | public boolean putCalled = false; 43 | public String keyPut = null; 44 | public Entry entryPut = null; 45 | 46 | @Override 47 | public void put(String key, Entry entry) { 48 | putCalled = true; 49 | keyPut = key; 50 | entryPut = entry; 51 | } 52 | 53 | @Override 54 | public void invalidate(String key, boolean fullExpire) { 55 | } 56 | 57 | @Override 58 | public void remove(String key) { 59 | } 60 | 61 | @Override 62 | public void initialize() { 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/MockHttpClient.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.mock; 18 | 19 | import org.apache.http.HttpEntity; 20 | import org.apache.http.HttpHost; 21 | import org.apache.http.HttpRequest; 22 | import org.apache.http.HttpResponse; 23 | import org.apache.http.HttpStatus; 24 | import org.apache.http.ProtocolVersion; 25 | import org.apache.http.StatusLine; 26 | import org.apache.http.client.HttpClient; 27 | import org.apache.http.client.ResponseHandler; 28 | import org.apache.http.client.methods.HttpUriRequest; 29 | import org.apache.http.conn.ClientConnectionManager; 30 | import org.apache.http.message.BasicHttpResponse; 31 | import org.apache.http.message.BasicStatusLine; 32 | import org.apache.http.params.HttpParams; 33 | import org.apache.http.protocol.HttpContext; 34 | 35 | 36 | public class MockHttpClient implements HttpClient { 37 | private int mStatusCode = HttpStatus.SC_OK; 38 | private HttpEntity mResponseEntity = null; 39 | 40 | public void setResponseData(HttpEntity entity) { 41 | mStatusCode = HttpStatus.SC_OK; 42 | mResponseEntity = entity; 43 | } 44 | 45 | public void setErrorCode(int statusCode) { 46 | if (statusCode == HttpStatus.SC_OK) { 47 | throw new IllegalArgumentException("statusCode cannot be 200 for an error"); 48 | } 49 | mStatusCode = statusCode; 50 | } 51 | 52 | public HttpUriRequest requestExecuted = null; 53 | 54 | // This is the only one we actually use. 55 | @Override 56 | public HttpResponse execute(HttpUriRequest request, HttpContext context) { 57 | requestExecuted = request; 58 | StatusLine statusLine = new BasicStatusLine( 59 | new ProtocolVersion("HTTP", 1, 1), mStatusCode, ""); 60 | HttpResponse response = new BasicHttpResponse(statusLine); 61 | response.setEntity(mResponseEntity); 62 | 63 | return response; 64 | } 65 | 66 | 67 | // Unimplemented methods ahoy 68 | 69 | @Override 70 | public HttpResponse execute(HttpUriRequest request) { 71 | throw new UnsupportedOperationException(); 72 | } 73 | 74 | @Override 75 | public HttpResponse execute(HttpHost target, HttpRequest request) { 76 | throw new UnsupportedOperationException(); 77 | } 78 | 79 | @Override 80 | public T execute(HttpUriRequest arg0, ResponseHandler extends T> arg1) { 81 | throw new UnsupportedOperationException(); 82 | } 83 | 84 | @Override 85 | public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) { 86 | throw new UnsupportedOperationException(); 87 | } 88 | 89 | @Override 90 | public T execute(HttpUriRequest arg0, ResponseHandler extends T> arg1, HttpContext arg2) { 91 | throw new UnsupportedOperationException(); 92 | } 93 | 94 | @Override 95 | public T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler extends T> arg2) { 96 | throw new UnsupportedOperationException(); 97 | } 98 | 99 | @Override 100 | public T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler extends T> arg2, 101 | HttpContext arg3) { 102 | throw new UnsupportedOperationException(); 103 | } 104 | 105 | @Override 106 | public ClientConnectionManager getConnectionManager() { 107 | throw new UnsupportedOperationException(); 108 | } 109 | 110 | @Override 111 | public HttpParams getParams() { 112 | throw new UnsupportedOperationException(); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/MockHttpStack.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.mock; 18 | 19 | import com.android.volley.AuthFailureError; 20 | import com.android.volley.Request; 21 | import com.android.volley.toolbox.HttpStack; 22 | 23 | import org.apache.http.HttpResponse; 24 | 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | public class MockHttpStack implements HttpStack { 29 | 30 | private HttpResponse mResponseToReturn; 31 | 32 | private String mLastUrl; 33 | 34 | private Map mLastHeaders; 35 | 36 | private byte[] mLastPostBody; 37 | 38 | public String getLastUrl() { 39 | return mLastUrl; 40 | } 41 | 42 | public Map getLastHeaders() { 43 | return mLastHeaders; 44 | } 45 | 46 | public byte[] getLastPostBody() { 47 | return mLastPostBody; 48 | } 49 | 50 | public void setResponseToReturn(HttpResponse response) { 51 | mResponseToReturn = response; 52 | } 53 | 54 | @Override 55 | public HttpResponse performRequest(Request> request, Map additionalHeaders) 56 | throws AuthFailureError { 57 | mLastUrl = request.getUrl(); 58 | mLastHeaders = new HashMap(); 59 | if (request.getHeaders() != null) { 60 | mLastHeaders.putAll(request.getHeaders()); 61 | } 62 | if (additionalHeaders != null) { 63 | mLastHeaders.putAll(additionalHeaders); 64 | } 65 | try { 66 | mLastPostBody = request.getBody(); 67 | } catch (AuthFailureError e) { 68 | mLastPostBody = null; 69 | } 70 | return mResponseToReturn; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/MockHttpURLConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 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.mock; 18 | 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.IOException; 21 | import java.io.OutputStream; 22 | import java.net.HttpURLConnection; 23 | import java.net.MalformedURLException; 24 | import java.net.URL; 25 | 26 | public class MockHttpURLConnection extends HttpURLConnection { 27 | 28 | private boolean mDoOutput; 29 | private String mRequestMethod; 30 | private OutputStream mOutputStream; 31 | 32 | public MockHttpURLConnection() throws MalformedURLException { 33 | super(new URL("http://foo.com")); 34 | mDoOutput = false; 35 | mRequestMethod = "GET"; 36 | mOutputStream = new ByteArrayOutputStream(); 37 | } 38 | 39 | @Override 40 | public void setDoOutput(boolean flag) { 41 | mDoOutput = flag; 42 | } 43 | 44 | @Override 45 | public boolean getDoOutput() { 46 | return mDoOutput; 47 | } 48 | 49 | @Override 50 | public void setRequestMethod(String method) { 51 | mRequestMethod = method; 52 | } 53 | 54 | @Override 55 | public String getRequestMethod() { 56 | return mRequestMethod; 57 | } 58 | 59 | @Override 60 | public OutputStream getOutputStream() { 61 | return mOutputStream; 62 | } 63 | 64 | @Override 65 | public void disconnect() { 66 | } 67 | 68 | @Override 69 | public boolean usingProxy() { 70 | return false; 71 | } 72 | 73 | @Override 74 | public void connect() throws IOException { 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/MockNetwork.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.mock; 18 | 19 | import com.android.volley.Network; 20 | import com.android.volley.NetworkResponse; 21 | import com.android.volley.Request; 22 | import com.android.volley.ServerError; 23 | import com.android.volley.VolleyError; 24 | 25 | public class MockNetwork implements Network { 26 | public final static int ALWAYS_THROW_EXCEPTIONS = -1; 27 | 28 | private int mNumExceptionsToThrow = 0; 29 | private byte[] mDataToReturn = null; 30 | 31 | /** 32 | * @param numExceptionsToThrow number of times to throw an exception or 33 | * {@link #ALWAYS_THROW_EXCEPTIONS} 34 | */ 35 | public void setNumExceptionsToThrow(int numExceptionsToThrow) { 36 | mNumExceptionsToThrow = numExceptionsToThrow; 37 | } 38 | 39 | public void setDataToReturn(byte[] data) { 40 | mDataToReturn = data; 41 | } 42 | 43 | public Request> requestHandled = null; 44 | 45 | @Override 46 | public NetworkResponse performRequest(Request> request) throws VolleyError { 47 | if (mNumExceptionsToThrow > 0 || mNumExceptionsToThrow == ALWAYS_THROW_EXCEPTIONS) { 48 | if (mNumExceptionsToThrow != ALWAYS_THROW_EXCEPTIONS) { 49 | mNumExceptionsToThrow--; 50 | } 51 | throw new ServerError(); 52 | } 53 | 54 | requestHandled = request; 55 | return new NetworkResponse(mDataToReturn); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/MockRequest.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.mock; 18 | 19 | import com.android.volley.NetworkResponse; 20 | import com.android.volley.Request; 21 | import com.android.volley.Response; 22 | import com.android.volley.Response.ErrorListener; 23 | import com.android.volley.VolleyError; 24 | import com.android.volley.utils.CacheTestUtils; 25 | 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | 29 | public class MockRequest extends Request { 30 | public MockRequest() { 31 | super(Request.Method.GET, "http://foo.com", null); 32 | } 33 | 34 | public MockRequest(String url, ErrorListener listener) { 35 | super(Request.Method.GET, url, listener); 36 | } 37 | 38 | private Map mPostParams = new HashMap(); 39 | 40 | public void setPostParams(Map postParams) { 41 | mPostParams = postParams; 42 | } 43 | 44 | @Override 45 | public Map getPostParams() { 46 | return mPostParams; 47 | } 48 | 49 | private String mCacheKey = super.getCacheKey(); 50 | 51 | public void setCacheKey(String cacheKey) { 52 | mCacheKey = cacheKey; 53 | } 54 | 55 | @Override 56 | public String getCacheKey() { 57 | return mCacheKey; 58 | } 59 | 60 | public boolean deliverResponse_called = false; 61 | public boolean parseResponse_called = false; 62 | 63 | @Override 64 | protected void deliverResponse(byte[] response) { 65 | deliverResponse_called = true; 66 | } 67 | 68 | public boolean deliverError_called = false; 69 | 70 | @Override 71 | public void deliverError(VolleyError error) { 72 | super.deliverError(error); 73 | deliverError_called = true; 74 | } 75 | 76 | public boolean cancel_called = false; 77 | 78 | @Override 79 | public void cancel() { 80 | cancel_called = true; 81 | super.cancel(); 82 | } 83 | 84 | private Priority mPriority = super.getPriority(); 85 | 86 | public void setPriority(Priority priority) { 87 | mPriority = priority; 88 | } 89 | 90 | @Override 91 | public Priority getPriority() { 92 | return mPriority; 93 | } 94 | 95 | @Override 96 | protected Response parseNetworkResponse(NetworkResponse response) { 97 | parseResponse_called = true; 98 | return Response.success(response.data, CacheTestUtils.makeRandomCacheEntry(response.data)); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/MockResponseDelivery.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.mock; 18 | 19 | import com.android.volley.Request; 20 | import com.android.volley.Response; 21 | import com.android.volley.ResponseDelivery; 22 | import com.android.volley.VolleyError; 23 | 24 | public class MockResponseDelivery implements ResponseDelivery { 25 | 26 | public boolean postResponse_called = false; 27 | public boolean postError_called = false; 28 | 29 | public boolean wasEitherResponseCalled() { 30 | return postResponse_called || postError_called; 31 | } 32 | 33 | public Response> responsePosted = null; 34 | @Override 35 | public void postResponse(Request> request, Response> response) { 36 | postResponse_called = true; 37 | responsePosted = response; 38 | } 39 | 40 | @Override 41 | public void postResponse(Request> request, Response> response, Runnable runnable) { 42 | postResponse_called = true; 43 | responsePosted = response; 44 | runnable.run(); 45 | } 46 | 47 | @Override 48 | public void postError(Request> request, VolleyError error) { 49 | postError_called = true; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/ShadowSystemClock.java: -------------------------------------------------------------------------------- 1 | package com.android.volley.mock; 2 | 3 | import android.os.SystemClock; 4 | import org.robolectric.annotation.Implements; 5 | 6 | @Implements(value = SystemClock.class, callThroughByDefault = true) 7 | public class ShadowSystemClock { 8 | public static long elapsedRealtime() { 9 | return 0; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/mock/WaitableQueue.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.mock; 18 | 19 | import com.android.volley.NetworkResponse; 20 | import com.android.volley.Request; 21 | import com.android.volley.Response; 22 | 23 | import java.util.concurrent.PriorityBlockingQueue; 24 | import java.util.concurrent.Semaphore; 25 | import java.util.concurrent.TimeUnit; 26 | import java.util.concurrent.TimeoutException; 27 | 28 | // TODO: the name of this class sucks 29 | @SuppressWarnings("serial") 30 | public class WaitableQueue extends PriorityBlockingQueue> { 31 | private final Request> mStopRequest = new MagicStopRequest(); 32 | private final Semaphore mStopEvent = new Semaphore(0); 33 | 34 | // TODO: this isn't really "until empty" it's "until next call to take() after empty" 35 | public void waitUntilEmpty(long timeoutMillis) 36 | throws TimeoutException, InterruptedException { 37 | add(mStopRequest); 38 | if (!mStopEvent.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS)) { 39 | throw new TimeoutException(); 40 | } 41 | } 42 | 43 | @Override 44 | public Request> take() throws InterruptedException { 45 | Request> item = super.take(); 46 | if (item == mStopRequest) { 47 | mStopEvent.release(); 48 | return take(); 49 | } 50 | return item; 51 | } 52 | 53 | private static class MagicStopRequest extends Request { 54 | public MagicStopRequest() { 55 | super(Request.Method.GET, "", null); 56 | } 57 | 58 | @Override 59 | public Priority getPriority() { 60 | return Priority.LOW; 61 | } 62 | 63 | @Override 64 | protected Response parseNetworkResponse(NetworkResponse response) { 65 | return null; 66 | } 67 | 68 | @Override 69 | protected void deliverResponse(Object response) { 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/BasicNetworkTest.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.NetworkResponse; 20 | import com.android.volley.Request; 21 | import com.android.volley.Response; 22 | import com.android.volley.mock.MockHttpStack; 23 | 24 | import org.apache.http.ProtocolVersion; 25 | import org.apache.http.entity.StringEntity; 26 | import org.apache.http.message.BasicHttpResponse; 27 | 28 | import org.junit.After; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | import org.junit.runner.RunWith; 32 | import org.robolectric.RobolectricTestRunner; 33 | 34 | import static org.junit.Assert.*; 35 | 36 | import java.util.HashMap; 37 | import java.util.Map; 38 | 39 | @RunWith(RobolectricTestRunner.class) 40 | public class BasicNetworkTest { 41 | 42 | @Test public void headersAndPostParams() throws Exception { 43 | MockHttpStack mockHttpStack = new MockHttpStack(); 44 | BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 45 | 200, "OK"); 46 | fakeResponse.setEntity(new StringEntity("foobar")); 47 | mockHttpStack.setResponseToReturn(fakeResponse); 48 | BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack); 49 | Request request = new Request(Request.Method.GET, "http://foo", null) { 50 | 51 | @Override 52 | protected Response parseNetworkResponse(NetworkResponse response) { 53 | return null; 54 | } 55 | 56 | @Override 57 | protected void deliverResponse(String response) { 58 | } 59 | 60 | @Override 61 | public Map getHeaders() { 62 | Map result = new HashMap(); 63 | result.put("requestheader", "foo"); 64 | return result; 65 | } 66 | 67 | @Override 68 | public Map getParams() { 69 | Map result = new HashMap(); 70 | result.put("requestpost", "foo"); 71 | return result; 72 | } 73 | }; 74 | httpNetwork.performRequest(request); 75 | assertEquals("foo", mockHttpStack.getLastHeaders().get("requestheader")); 76 | assertEquals("requestpost=foo&", new String(mockHttpStack.getLastPostBody())); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/ByteArrayPoolTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 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 org.junit.After; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | 24 | import static org.junit.Assert.*; 25 | 26 | public class ByteArrayPoolTest { 27 | @Test public void reusesBuffer() { 28 | ByteArrayPool pool = new ByteArrayPool(32); 29 | 30 | byte[] buf1 = pool.getBuf(16); 31 | byte[] buf2 = pool.getBuf(16); 32 | 33 | pool.returnBuf(buf1); 34 | pool.returnBuf(buf2); 35 | 36 | byte[] buf3 = pool.getBuf(16); 37 | byte[] buf4 = pool.getBuf(16); 38 | assertTrue(buf3 == buf1 || buf3 == buf2); 39 | assertTrue(buf4 == buf1 || buf4 == buf2); 40 | assertTrue(buf3 != buf4); 41 | } 42 | 43 | @Test public void obeysSizeLimit() { 44 | ByteArrayPool pool = new ByteArrayPool(32); 45 | 46 | byte[] buf1 = pool.getBuf(16); 47 | byte[] buf2 = pool.getBuf(16); 48 | byte[] buf3 = pool.getBuf(16); 49 | 50 | pool.returnBuf(buf1); 51 | pool.returnBuf(buf2); 52 | pool.returnBuf(buf3); 53 | 54 | byte[] buf4 = pool.getBuf(16); 55 | byte[] buf5 = pool.getBuf(16); 56 | byte[] buf6 = pool.getBuf(16); 57 | 58 | assertTrue(buf4 == buf2 || buf4 == buf3); 59 | assertTrue(buf5 == buf2 || buf5 == buf3); 60 | assertTrue(buf4 != buf5); 61 | assertTrue(buf6 != buf1 && buf6 != buf2 && buf6 != buf3); 62 | } 63 | 64 | @Test public void returnsBufferWithRightSize() { 65 | ByteArrayPool pool = new ByteArrayPool(32); 66 | 67 | byte[] buf1 = pool.getBuf(16); 68 | pool.returnBuf(buf1); 69 | 70 | byte[] buf2 = pool.getBuf(17); 71 | assertNotSame(buf2, buf1); 72 | 73 | byte[] buf3 = pool.getBuf(15); 74 | assertSame(buf3, buf1); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/CacheTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.robolectric.RobolectricTestRunner; 23 | 24 | import static org.junit.Assert.assertNotNull; 25 | 26 | @RunWith(RobolectricTestRunner.class) 27 | public class CacheTest { 28 | 29 | @Test 30 | public void publicMethods() throws Exception { 31 | // Catch-all test to find API-breaking changes. 32 | assertNotNull(Cache.class.getMethod("get", String.class)); 33 | assertNotNull(Cache.class.getMethod("put", String.class, Cache.Entry.class)); 34 | assertNotNull(Cache.class.getMethod("initialize")); 35 | assertNotNull(Cache.class.getMethod("invalidate", String.class, boolean.class)); 36 | assertNotNull(Cache.class.getMethod("remove", String.class)); 37 | assertNotNull(Cache.class.getMethod("clear")); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/JsonRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.Response; 20 | import org.json.JSONArray; 21 | import org.json.JSONObject; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.robolectric.RobolectricTestRunner; 25 | 26 | import static org.junit.Assert.assertNotNull; 27 | 28 | @RunWith(RobolectricTestRunner.class) 29 | public class JsonRequestTest { 30 | 31 | @Test 32 | public void publicMethods() throws Exception { 33 | // Catch-all test to find API-breaking changes. 34 | assertNotNull(JsonRequest.class.getConstructor(String.class, String.class, 35 | Response.Listener.class, Response.ErrorListener.class)); 36 | assertNotNull(JsonRequest.class.getConstructor(int.class, String.class, String.class, 37 | Response.Listener.class, Response.ErrorListener.class)); 38 | 39 | assertNotNull(JsonArrayRequest.class.getConstructor(String.class, 40 | Response.Listener.class, Response.ErrorListener.class)); 41 | assertNotNull(JsonArrayRequest.class.getConstructor(int.class, String.class, JSONArray.class, 42 | Response.Listener.class, Response.ErrorListener.class)); 43 | 44 | assertNotNull(JsonObjectRequest.class.getConstructor(String.class, JSONObject.class, 45 | Response.Listener.class, Response.ErrorListener.class)); 46 | assertNotNull(JsonObjectRequest.class.getConstructor(int.class, String.class, 47 | JSONObject.class, Response.Listener.class, Response.ErrorListener.class)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java: -------------------------------------------------------------------------------- 1 | package com.android.volley.toolbox; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.ViewGroup.LayoutParams; 6 | import android.widget.ImageView.ScaleType; 7 | 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.robolectric.RuntimeEnvironment; 12 | import org.robolectric.RobolectricTestRunner; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | @RunWith(RobolectricTestRunner.class) 17 | public class NetworkImageViewTest { 18 | private NetworkImageView mNIV; 19 | private MockImageLoader mMockImageLoader; 20 | 21 | @Before public void setUp() throws Exception { 22 | mMockImageLoader = new MockImageLoader(); 23 | mNIV = new NetworkImageView(RuntimeEnvironment.application); 24 | } 25 | 26 | @Test public void setImageUrl_requestsImage() { 27 | mNIV.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 28 | mNIV.setImageUrl("http://foo", mMockImageLoader); 29 | assertEquals("http://foo", mMockImageLoader.lastRequestUrl); 30 | assertEquals(0, mMockImageLoader.lastMaxWidth); 31 | assertEquals(0, mMockImageLoader.lastMaxHeight); 32 | } 33 | 34 | // public void testSetImageUrl_setsMaxSize() { 35 | // // TODO: Not sure how to make getWidth() return something from an 36 | // // instrumentation test. Write this test once it's figured out. 37 | // } 38 | 39 | private class MockImageLoader extends ImageLoader { 40 | public MockImageLoader() { 41 | super(null, null); 42 | } 43 | 44 | public String lastRequestUrl; 45 | public int lastMaxWidth; 46 | public int lastMaxHeight; 47 | 48 | public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth, 49 | int maxHeight, ScaleType scaleType) { 50 | lastRequestUrl = requestUrl; 51 | lastMaxWidth = maxWidth; 52 | lastMaxHeight = maxHeight; 53 | return null; 54 | } 55 | } 56 | 57 | @Test 58 | public void publicMethods() throws Exception { 59 | // Catch-all test to find API-breaking changes. 60 | assertNotNull(NetworkImageView.class.getConstructor(Context.class)); 61 | assertNotNull(NetworkImageView.class.getConstructor(Context.class, AttributeSet.class)); 62 | assertNotNull(NetworkImageView.class.getConstructor(Context.class, AttributeSet.class, 63 | int.class)); 64 | 65 | assertNotNull(NetworkImageView.class.getMethod("setImageUrl", String.class, ImageLoader.class)); 66 | assertNotNull(NetworkImageView.class.getMethod("setDefaultImageResId", int.class)); 67 | assertNotNull(NetworkImageView.class.getMethod("setErrorImageResId", int.class)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/PoolingByteArrayOutputStreamTest.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 java.io.IOException; 20 | import java.util.Arrays; 21 | 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.*; 25 | 26 | public class PoolingByteArrayOutputStreamTest { 27 | @Test public void pooledOneBuffer() throws IOException { 28 | ByteArrayPool pool = new ByteArrayPool(32768); 29 | writeOneBuffer(pool); 30 | writeOneBuffer(pool); 31 | writeOneBuffer(pool); 32 | } 33 | 34 | @Test public void pooledIndividualWrites() throws IOException { 35 | ByteArrayPool pool = new ByteArrayPool(32768); 36 | writeBytesIndividually(pool); 37 | writeBytesIndividually(pool); 38 | writeBytesIndividually(pool); 39 | } 40 | 41 | @Test public void unpooled() throws IOException { 42 | ByteArrayPool pool = new ByteArrayPool(0); 43 | writeOneBuffer(pool); 44 | writeOneBuffer(pool); 45 | writeOneBuffer(pool); 46 | } 47 | 48 | @Test public void unpooledIndividualWrites() throws IOException { 49 | ByteArrayPool pool = new ByteArrayPool(0); 50 | writeBytesIndividually(pool); 51 | writeBytesIndividually(pool); 52 | writeBytesIndividually(pool); 53 | } 54 | 55 | private void writeOneBuffer(ByteArrayPool pool) throws IOException { 56 | byte[] data = new byte[16384]; 57 | for (int i = 0; i < data.length; i++) { 58 | data[i] = (byte) (i & 0xff); 59 | } 60 | PoolingByteArrayOutputStream os = new PoolingByteArrayOutputStream(pool); 61 | os.write(data); 62 | 63 | assertTrue(Arrays.equals(data, os.toByteArray())); 64 | } 65 | 66 | private void writeBytesIndividually(ByteArrayPool pool) { 67 | byte[] data = new byte[16384]; 68 | for (int i = 0; i < data.length; i++) { 69 | data[i] = (byte) (i & 0xff); 70 | } 71 | PoolingByteArrayOutputStream os = new PoolingByteArrayOutputStream(pool); 72 | for (int i = 0; i < data.length; i++) { 73 | os.write(data[i]); 74 | } 75 | 76 | assertTrue(Arrays.equals(data, os.toByteArray())); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/RequestFutureTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.Request; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.robolectric.RobolectricTestRunner; 23 | 24 | import static org.junit.Assert.assertNotNull; 25 | 26 | @RunWith(RobolectricTestRunner.class) 27 | public class RequestFutureTest { 28 | 29 | @Test 30 | public void publicMethods() throws Exception { 31 | // Catch-all test to find API-breaking changes. 32 | assertNotNull(RequestFuture.class.getMethod("newFuture")); 33 | assertNotNull(RequestFuture.class.getMethod("setRequest", Request.class)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/RequestQueueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.*; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.robolectric.RobolectricTestRunner; 23 | 24 | import static org.junit.Assert.assertNotNull; 25 | 26 | @RunWith(RobolectricTestRunner.class) 27 | public class RequestQueueTest { 28 | 29 | @Test 30 | public void publicMethods() throws Exception { 31 | // Catch-all test to find API-breaking changes. 32 | assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class, 33 | ResponseDelivery.class)); 34 | assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class)); 35 | assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class)); 36 | 37 | assertNotNull(RequestQueue.class.getMethod("start")); 38 | assertNotNull(RequestQueue.class.getMethod("stop")); 39 | assertNotNull(RequestQueue.class.getMethod("getSequenceNumber")); 40 | assertNotNull(RequestQueue.class.getMethod("getCache")); 41 | assertNotNull(RequestQueue.class.getMethod("cancelAll", RequestQueue.RequestFilter.class)); 42 | assertNotNull(RequestQueue.class.getMethod("cancelAll", Object.class)); 43 | assertNotNull(RequestQueue.class.getMethod("add", Request.class)); 44 | assertNotNull(RequestQueue.class.getDeclaredMethod("finish", Request.class)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/RequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.*; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.robolectric.RobolectricTestRunner; 23 | 24 | import static org.junit.Assert.assertNotNull; 25 | 26 | @RunWith(RobolectricTestRunner.class) 27 | public class RequestTest { 28 | 29 | @Test 30 | public void publicMethods() throws Exception { 31 | // Catch-all test to find API-breaking changes. 32 | assertNotNull(Request.class.getConstructor(int.class, String.class, 33 | Response.ErrorListener.class)); 34 | 35 | assertNotNull(Request.class.getMethod("getMethod")); 36 | assertNotNull(Request.class.getMethod("setTag", Object.class)); 37 | assertNotNull(Request.class.getMethod("getTag")); 38 | assertNotNull(Request.class.getMethod("getErrorListener")); 39 | assertNotNull(Request.class.getMethod("getTrafficStatsTag")); 40 | assertNotNull(Request.class.getMethod("setRetryPolicy", RetryPolicy.class)); 41 | assertNotNull(Request.class.getMethod("addMarker", String.class)); 42 | assertNotNull(Request.class.getDeclaredMethod("finish", String.class)); 43 | assertNotNull(Request.class.getMethod("setRequestQueue", RequestQueue.class)); 44 | assertNotNull(Request.class.getMethod("setSequence", int.class)); 45 | assertNotNull(Request.class.getMethod("getSequence")); 46 | assertNotNull(Request.class.getMethod("getUrl")); 47 | assertNotNull(Request.class.getMethod("getCacheKey")); 48 | assertNotNull(Request.class.getMethod("setCacheEntry", Cache.Entry.class)); 49 | assertNotNull(Request.class.getMethod("getCacheEntry")); 50 | assertNotNull(Request.class.getMethod("cancel")); 51 | assertNotNull(Request.class.getMethod("isCanceled")); 52 | assertNotNull(Request.class.getMethod("getHeaders")); 53 | assertNotNull(Request.class.getDeclaredMethod("getParams")); 54 | assertNotNull(Request.class.getDeclaredMethod("getParamsEncoding")); 55 | assertNotNull(Request.class.getMethod("getBodyContentType")); 56 | assertNotNull(Request.class.getMethod("getBody")); 57 | assertNotNull(Request.class.getMethod("setShouldCache", boolean.class)); 58 | assertNotNull(Request.class.getMethod("shouldCache")); 59 | assertNotNull(Request.class.getMethod("getPriority")); 60 | assertNotNull(Request.class.getMethod("getTimeoutMs")); 61 | assertNotNull(Request.class.getMethod("getRetryPolicy")); 62 | assertNotNull(Request.class.getMethod("markDelivered")); 63 | assertNotNull(Request.class.getMethod("hasHadResponseDelivered")); 64 | assertNotNull(Request.class.getDeclaredMethod("parseNetworkResponse", NetworkResponse.class)); 65 | assertNotNull(Request.class.getDeclaredMethod("parseNetworkError", VolleyError.class)); 66 | assertNotNull(Request.class.getDeclaredMethod("deliverResponse", Object.class)); 67 | assertNotNull(Request.class.getMethod("deliverError", VolleyError.class)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/ResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.Response; 22 | import com.android.volley.VolleyError; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | import org.robolectric.RobolectricTestRunner; 26 | 27 | import java.util.Map; 28 | 29 | import static org.junit.Assert.assertNotNull; 30 | 31 | @RunWith(RobolectricTestRunner.class) 32 | public class ResponseTest { 33 | 34 | @Test 35 | public void publicMethods() throws Exception { 36 | // Catch-all test to find API-breaking changes. 37 | assertNotNull(Response.class.getMethod("success", Object.class, Cache.Entry.class)); 38 | assertNotNull(Response.class.getMethod("error", VolleyError.class)); 39 | assertNotNull(Response.class.getMethod("isSuccess")); 40 | 41 | assertNotNull(Response.Listener.class.getDeclaredMethod("onResponse", Object.class)); 42 | 43 | assertNotNull(Response.ErrorListener.class.getDeclaredMethod("onErrorResponse", 44 | VolleyError.class)); 45 | 46 | assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class, 47 | boolean.class, long.class)); 48 | assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class, 49 | boolean.class)); 50 | assertNotNull(NetworkResponse.class.getConstructor(byte[].class)); 51 | assertNotNull(NetworkResponse.class.getConstructor(byte[].class, Map.class)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/toolbox/StringRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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.Response; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.robolectric.RobolectricTestRunner; 23 | 24 | import static org.junit.Assert.assertNotNull; 25 | 26 | @RunWith(RobolectricTestRunner.class) 27 | public class StringRequestTest { 28 | 29 | @Test 30 | public void publicMethods() throws Exception { 31 | // Catch-all test to find API-breaking changes. 32 | assertNotNull(StringRequest.class.getConstructor(String.class, Response.Listener.class, 33 | Response.ErrorListener.class)); 34 | assertNotNull(StringRequest.class.getConstructor(int.class, String.class, 35 | Response.Listener.class, Response.ErrorListener.class)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/utils/CacheTestUtils.java: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | 3 | package com.android.volley.utils; 4 | 5 | import com.android.volley.Cache; 6 | 7 | import java.util.Random; 8 | 9 | public class CacheTestUtils { 10 | 11 | /** 12 | * Makes a random cache entry. 13 | * @param data Data to use, or null to use random data 14 | * @param isExpired Whether the TTLs should be set such that this entry is expired 15 | * @param needsRefresh Whether the TTLs should be set such that this entry needs refresh 16 | */ 17 | public static Cache.Entry makeRandomCacheEntry( 18 | byte[] data, boolean isExpired, boolean needsRefresh) { 19 | Random random = new Random(); 20 | Cache.Entry entry = new Cache.Entry(); 21 | if (data != null) { 22 | entry.data = data; 23 | } else { 24 | entry.data = new byte[random.nextInt(1024)]; 25 | } 26 | entry.etag = String.valueOf(random.nextLong()); 27 | entry.lastModified = random.nextLong(); 28 | entry.ttl = isExpired ? 0 : Long.MAX_VALUE; 29 | entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE; 30 | return entry; 31 | } 32 | 33 | /** 34 | * Like {@link #makeRandomCacheEntry(byte[], boolean, boolean)} but 35 | * defaults to an unexpired entry. 36 | */ 37 | public static Cache.Entry makeRandomCacheEntry(byte[] data) { 38 | return makeRandomCacheEntry(data, false, false); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/java/com/android/volley/utils/ImmediateResponseDelivery.java: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All rights reserved. 2 | 3 | package com.android.volley.utils; 4 | 5 | import com.android.volley.ExecutorDelivery; 6 | 7 | import java.util.concurrent.Executor; 8 | 9 | /** 10 | * A ResponseDelivery for testing that immediately delivers responses 11 | * instead of posting back to the main thread. 12 | */ 13 | public class ImmediateResponseDelivery extends ExecutorDelivery { 14 | 15 | public ImmediateResponseDelivery() { 16 | super(new Executor() { 17 | @Override 18 | public void execute(Runnable command) { 19 | command.run(); 20 | } 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /thirdParty/volley/src/test/resources/org.robolectric.Config.properties: -------------------------------------------------------------------------------- 1 | manifest=src/main/AndroidManifest.xml 2 | --------------------------------------------------------------------------------
errorCode != OK
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().
GET
jsonRequest
null
POST