Network Connection Class


Source link: https://github.com/facebook/network-connection-class

Network Connection Class

Network Connection Class is an Android library that allows you to figure out the quality of the current user's internet connection. The connection gets classified into several "Connection Classes" that make it easy to develop against. The library does this by listening to the existing internet traffic done by your app and notifying you when the user's connection quality changes. Developers can then use this Connection Class information and adjust the application's behaviour (request lower quality images or video, throttle type-ahead, etc).

Network Connection Class currently only measures the user's downstream bandwidth. Latency is also an important factor, but in our tests, we've found that bandwidth is a good proxy for both.

The Network Connection Class library takes care of spikes using a moving average of the incoming samples, and also applies some hysteresis (both with a minimum number of samples and amount the average has to cross a boundary before triggering a bucket change):

Integration

Download

Download the latest JARs or grab via Gradle:

compile 'com.facebook.network.connectionclass:connectionclass:1.0.1'

or Maven:

<dependency>
<groupId>com.facebook.network.connectionclass</groupId>
<artifactId>connectionclass</artifactId>
<version>1.0.1</version> </dependency>

Calculate Connection Class

Connection Class provides an interface for classes to add themselves as listeners for when the network's connection quality changes. In the subscriber class, implement ConnectionClassStateChangeListener:

public interface ConnectionClassStateChangeListener {

public void onBandwidthStateChange(ConnectionQuality bandwidthState);
 
}

and subscribe with the listener:

ConnectionClassManager.getInstance().register(mListener);

Alternatively, you can manually query for the current connection quality bucket with getCurrentBandwidthQuality().

ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();

The main way to provide the ConnectionClassManager data is to use the DeviceBandwidthSampler. The DeviceBandwidthSampler samples the device's underlying network stats when you tell it you're performing some sort of network activity (downloading photos, playing a video, etc).

// Override ConnectionClassStateChangeListener ConnectionClassManager.getInstance().register(mListener);
 DeviceBandwidthSampler.getInstance().startSampling();
 // Do some downloading tasks DeviceBandwidthSampler.getInstance().stopSampling();

If the application is aware of the bandwidth downloaded in a certain time frame, data can be added to the moving average using:

ConnectionClassManager.addBandwidth(bandwidth, time);

See the connectionclass-sample project for more details.

Improve Connection Class!

See the CONTRIBUTING.md file for how to help out.

License

Connection Class is BSD-licensed. We also provide an additional patent grant.

Resources

Kotlin Adaptor for RxJava.

Kotlin has support for SAM (Single Abstract Method) Interfaces as Functions (i.e. Java 8 Lambdas). So you could use Kotlin in RxJava without this adaptor

The gradle plugin to add proguard snippets to your proguard setting file quickly.

This plugin pulls the proguard information from the krschultz/android-proguard-snippets.
If you wanna add the snippets, PR to android-proguard-snippets!

Android UI logger library.

Main features:

  • Always on the screen, even if app is paused. It can be destroyed after direct command call.
  • You can drag it to the any place of the screen.
  • Font and background colors can be changed by double tap.
  • You can re-size main log window by dragging down right corner * of the log window.
  • Clear the screen by clicking on the right upper corner.
  • Easy use. Only three API methods.
  • Easy link with Gradle.

Wizard encapsulates navigation operations between fragments of an activity using BackStack.

ExceptionWear is very simple library to solve problem of not passing exceptions from Android Wear devices to the phone. So if you release an app for smart-watches to Google Play and it will crash (and it will) you won't get any information about it.

ASignature is a library for drawing smooth signatures. It uses variable width Bézier curve interpolation based on Smoother Signatures. It works from API 8+ and doesn't depend on any external libraries.

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