Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit 20525ff

Browse files
committed
Initial commit
0 parents  commit 20525ff

39 files changed

+2107
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.gradle
2+
/local.properties
3+
/.idea
4+
*.iml
5+
.DS_Store
6+
/build

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Change Log
2+
==========
3+
4+
## Version 1.0.0
5+
6+
_2015-03-25_
7+
8+
* Initial release.

CONTRIBUTING.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Contributing to Network Connection Class
2+
We want to make contributing to this project as easy and transparent as
3+
possible.
4+
5+
## Our Development Process
6+
We work directly in the github project and provide versioned releases
7+
appropriate for major milestones and minor bug fixes or improvements. GitHub
8+
is used directly for issues and pull requests and the developers actively
9+
respond to requests.
10+
11+
## Pull Requests
12+
We actively welcome your pull requests.
13+
1. Fork the repo and create your branch from `master`.
14+
2. If you've added code that should be tested, add tests
15+
3. If you've changed APIs, update the documentation.
16+
4. Ensure the test suite passes.
17+
5. Make sure your code lints.
18+
6. If you haven't already, complete the Contributor License Agreement ("CLA").
19+
20+
## Contributor License Agreement ("CLA")
21+
In order to accept your pull request, we need you to submit a CLA. You only need
22+
to do this once to work on any of Facebook's open source projects.
23+
24+
Complete your CLA here: <https://code.facebook.com/cla>
25+
26+
## Issues
27+
We use GitHub issues to track public bugs. Please ensure your description is
28+
clear and has sufficient instructions to be able to reproduce the issue.
29+
30+
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
31+
disclosure of security bugs. In those cases, please go through the process
32+
outlined on that page and do not file a public issue.
33+
34+
## Coding Style
35+
* 2 spaces for indentation rather than tabs
36+
* Line wrapping indents 4 spaces
37+
* 100 character line length
38+
* One parameter per line when line wrapping is required
39+
* Use the `m` member variable prefix for private fields
40+
* Opening braces to appear on the same line as code
41+
42+
## License
43+
By contributing to Network Connection Class, you agree that your contributions will be licensed
44+
under its BSD license.

LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
BSD License
2+
3+
For Network Connection Class software
4+
5+
Copyright (c) 2015, Facebook, Inc. All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
* Neither the name Facebook nor the names of its contributors may be used to
18+
endorse or promote products derived from this software without specific
19+
prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PATENTS

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Additional Grant of Patent Rights
2+
3+
"Software" means the Network Connection Class software distributed by Facebook,
4+
Inc.
5+
6+
Facebook hereby grants you a perpetual, worldwide, royalty-free, non-exclusive,
7+
irrevocable (subject to the termination provision below) license under any
8+
rights in any patent claims owned by Facebook, to make, have made, use, sell,
9+
offer to sell, import, and otherwise transfer the Software. For avoidance of
10+
doubt, no license is granted under Facebook’s rights in any patent claims that
11+
are infringed by (i) modifications to the Software made by you or a third party,
12+
or (ii) the Software in combination with any software or other technology
13+
provided by you or a third party.
14+
15+
The license granted hereunder will terminate, automatically and without notice,
16+
for anyone that makes any claim (including by filing any lawsuit, assertion or
17+
other action) alleging (a) direct, indirect, or contributory infringement or
18+
inducement to infringe any patent: (i) by Facebook or any of its subsidiaries or
19+
affiliates, whether or not such claim is related to the Software, (ii) by any
20+
party if such claim arises in whole or in part from any software, product or
21+
service of Facebook or any of its subsidiaries or affiliates, whether or not
22+
such claim is related to the Software, or (iii) by any party relating to the
23+
Software; or (b) that any right in any patent claim of Facebook is invalid or
24+
unenforceable.

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Network Connection Class
2+
3+
Network Connection Class is an Android library that allows you to figure out
4+
the quality of the current user's internet connection. The connection gets
5+
classified into several "Connection Classes" that make it easy to develop
6+
against. The library does this by listening to the existing internet traffic
7+
done by your app and notifying you when the user's connection quality changes.
8+
Developers can then use this Connection Class information and adjust the application's
9+
behaviour (request lower quality images or video, throttle type-ahead, etc).
10+
11+
## Integration
12+
13+
### Download
14+
Download [the latest JARs](https://github.com/facebook/network-connection-class/releases/latest) or grab via Gradle:
15+
```groovy
16+
compile 'com.facebook.network.connectionclass:connectionclass:1.0.0'
17+
```
18+
or Maven:
19+
```xml
20+
<dependency>
21+
<groupId>com.facebook.network.connectionclass</groupId>
22+
<artifactId>connectionclass</artifactId>
23+
<version>1.0.0</version>
24+
</dependency>
25+
```
26+
27+
### Calculate Connection Class
28+
Connection Class provides an interface for classes to add themselves as
29+
listeners for when the network's connection quality changes. In the subscriber
30+
class, implement `ConnectionClassStateChangeListener`:
31+
32+
```java
33+
public interface ConnectionClassStateChangeListener {
34+
public void onBandwidthStateChange(ConnectionQuality bandwidthState);
35+
}
36+
```
37+
38+
and subscribe with the listener:
39+
40+
```java
41+
ConnectionClassManager.getInstance().register(mListener);
42+
```
43+
44+
Alternatively, you can manually query for the connection quality bucket with
45+
`getCurrentBandwidthQuality()`.
46+
47+
```java
48+
ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();
49+
```
50+
51+
The main way to provide the ConnectionClassManager data is to use the DownloadBandwidthSampler.
52+
The DownloadBandwidthSampler samples the device's underlying network stats when you tell it
53+
you're performing some sort of network activity (downloading photos, playing a video, etc).
54+
55+
```java
56+
// Override ConnectionClassStateChangeListener
57+
ConnectionClassManager.getInstance().register(mListener);
58+
DownloadBandwidthSampler.getInstance().startSampling();
59+
// Do some downloading tasks
60+
DownloadBandwidthSampler.getInstance().stopSampling();
61+
```
62+
63+
If the application is aware of the bandwidth downloaded in a certain time frame,
64+
data can be added to the moving average using:
65+
66+
```java
67+
ConnectionClassManager.addBandwidth(bandwidth, time);
68+
```
69+
70+
See the `connectionclass-sample` project for more details.
71+
72+
## Improve Connection Class!
73+
See the CONTRIBUTING.md file for how to help out.
74+
75+
## License
76+
Connection Class is BSD-licensed. We also provide an additional patent grant.

build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath 'com.android.tools.build:gradle:1.0.0'
7+
classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
8+
}
9+
}
10+
allprojects {
11+
repositories {
12+
jcenter()
13+
}
14+
}

connectionclass-sample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apply plugin: 'com.android.application'
2+
3+
repositories {
4+
jcenter()
5+
}
6+
7+
android {
8+
compileSdkVersion 21
9+
buildToolsVersion "21.1.2"
10+
11+
defaultConfig {
12+
applicationId "com.facebook.network.connectionclass.sample"
13+
minSdkVersion 9
14+
targetSdkVersion 21
15+
versionCode 1
16+
versionName "1.0"
17+
}
18+
}
19+
20+
dependencies {
21+
compile project (":connectionclass")
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.facebook.network.connectionclass.sample" >
4+
5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@drawable/ic_launcher"
10+
android:label="@string/app_name">
11+
<activity
12+
android:name=".MainActivity"
13+
android:label="@string/app_name" >
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN"/>
16+
<category android:name="android.intent.category.LAUNCHER"/>
17+
<category android:name="android.intent.category.DEFAULT"/>
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>

0 commit comments

Comments
 (0)