HttpResponseCache


Source link: https://github.com/candrews/HttpResponseCache

HttpResponseCache

The HttpResponseCache library provides transparent and automatic caching of HTTP and HTTPS requests that use the java.net.HttpUrlConnection classes.

For information on how to use HttpUrlConnection, refer to the (Android documentation)[ https://developer.android.com/reference/java/net/HttpURLConnection.html] - don't worry, the information also applies to non-Android Java.

Requirements

This library will work on Java 5 and later, and (theoretically) any version of Android (it has only been tested back to 1.5).

Usage

When using Maven (or any of the dependency management systems that use Maven's library, such as Ivy), simply add the dependency reference. The library, and its dependencies, are in Maven Central: http://mvnrepository.com/artifact/com.integralblue/httpresponsecache For example, for a Maven pom.xml:

<dependency>
<groupId>com.integralblue</groupId>
<artifactId>httpresponsecache</artifactId>
<version>1.3</version> </dependency>

If Maven is not in use, such as when using a non-Maven Android project, include the httpresponsecache jar and its dependency, DiskLruCache.

In the application, before making any HTTP(s) requests, simply call:

com.integralblue.httpresponsecache.HttpResponseCache.install(File directory, long maxSize);

Where directory is the directory to hold cache data, and maxSize is the maximum size of the cache in bytes.

On Android, it may be desirable to use Android 4.0 and higher's built in HttpResponseCache and fall back to this library on older versions of Android. This code would do that:

final long httpCacheSize = 10 * 1024 * 1024; // 10 MiB final File httpCacheDir = new File(getCacheDir(), "http");
 try {

  Class.forName("android.net.http.HttpResponseCache")

.getMethod("install", File.class, long.class)

.invoke(null, httpCacheDir, httpCacheSize);
 
}
 catch (Exception httpResponseCacheNotAvailable) {

  Ln.d(httpResponseCacheNotAvailable, "android.net.http.HttpResponseCache not available, probably because we're running on a pre-ICS version of Android. Using com.integralblue.httpresponsecache.HttpHttpResponseCache.");

  try{

com.integralblue.httpresponsecache.HttpResponseCache.install(httpCacheDir, httpCacheSize);

  
}
catch(Exception e){

Ln.e(e, "Failed to set up com.integralblue.httpresponsecache.HttpResponseCache");

  
}
 
}

Note that this library may be more up to date and have more bug fixes / features / performance improvements than the version included with the Android platform being targeted. For example, this library includes some performance improvements that are in Jelly Bean (4.1) but not in ICS (4.0). So if you want users on ICS to get these performance improvements, always use this library, and do not conditionally use the one from Android. In other words, you may want to always simply use:

com.integralblue.httpresponsecache.HttpResponseCache.install(httpCacheDir, httpCacheSize);

and not use the conditional code above.

License

This library is licensed under the terms of the Apache License, Version 2.0. You may obtain a copy of the license at http://www.apache.org/licenses/LICENSE-2.0

Origin/Contributors

This library consists of code copied from the Android Open Source Project (AOSP). android.net.http.HttpResponseCache was copied, along with all of its non-standard-Java dependencies, to a new namespace and then modified to work under standard Java. Special thanks for Jesse Wilson for writing android.net.http.HttpResponseCache and assisting in the creation of this library. Also special thanks to Jake Wharton for porting DiskLruCache from AOSP, greatly reducing the amount of work necessary to create this library.

Resources

CatLog is a free and open-source log reader for Android.

It shows a scrolling (tailed) view of the Android "Logcat" system log, hence the goofy name. It also allows you to record logs in real time, send logs via email, and filter using a variety of criteria.

Simply pass a url to play youtube video on new activity. It supports screen orientation, media volume control and etc.

The design goals of this project are as follows:

  • Provide an on-device view of explicit log output during app development.
  • Do not disrupt the normal lifecycle of the app (no app switching).
  • Transparent implementation (using the same API as android.util.Log, easily disabled).
  • Minimal setup.

Android simple listview by using linearlayout. Behavior is the same except no scrollable, thus you can use it freely in scrollview. It is very basic implementation, you should not use for the huge list.

Paginize is a light-weight application framework for Android.

An ImageView that supports different kind of cropping rather than the only Android is currently supporting: centerCrop

Using this library, you can crop your desired image by sides described below:

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes