Skip to content

Commit c94ccc6

Browse files
authored
Merge pull request #21 from Manabu-GT/develop
Develop
2 parents 602f97c + dbc9e4e commit c94ccc6

File tree

18 files changed

+254
-20
lines changed

18 files changed

+254
-20
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## Version 1.1.3 *(2017-09-24)*
4+
5+
* Add a NetStatsModule as an extension module
6+
* Support Library 26.0.1 -> 26.1.0
7+
38
## Version 1.1.2 *(2017-09-09)*
49

510
* Add a TimberModule as an extension module

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ API Level 16 (Android 4.1) and above.
1919

2020
Setup
2121
------
22-
The library is pushed to Maven Central as an AAR,
22+
The library is pushed to Maven Central as an AAR,
2323
so you just need to add the followings to your ***build.gradle*** file:
2424

2525
```groovy
2626
dependencies {
27-
debugCompile 'com.ms-square:debugoverlay:1.1.2'
28-
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.2'
29-
testCompile 'com.ms-square:debugoverlay-no-op:1.1.2'
27+
debugCompile 'com.ms-square:debugoverlay:1.1.3'
28+
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
29+
testCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
3030
}
3131
```
3232

33-
Please note that `com.ms-square:debugoverlay:1.1.2` will add `android.permission.SYSTEM_ALERT_WINDOW` to your app.
33+
Please note that `com.ms-square:debugoverlay:1.1.3` will add `android.permission.SYSTEM_ALERT_WINDOW` to your app.
3434
Threfore, you should avoid to use that dependency for your release build.
3535

3636
FYI, the following table describes the total number of method/field references in this library's release aar.
3737
This data is acquired by using [Dexcount Gradle Plugin](https://github.com/KeepSafe/dexcount-gradle-plugin).
3838

3939
| library | methods | fields |
4040
|:------------- |:-------------|:-------------|
41-
|com.ms-square:debugoverlay:1.1.2|566|252|
42-
|com.ms-square:debugoverlay-no-op:1.1.2|141|37|
41+
|com.ms-square:debugoverlay:1.1.3|566|252|
42+
|com.ms-square:debugoverlay-no-op:1.1.3|141|37|
4343

4444
Due to the extensibility of this library, no-op version unfortunately has more than a few methods.
45-
If you want to eliminate such method count in your release build, consider having separate `Application` class only for your debug build which uses this library and just specify `debugCompile 'com.ms-square:debugoverlay:1.1.2'` in the dependencies section of build.gradle.
45+
If you want to eliminate such method count in your release build, consider having separate `Application` class only for your debug build which uses this library and just specify `debugCompile 'com.ms-square:debugoverlay:1.1.3'` in the dependencies section of build.gradle.
4646

4747
Usage
4848
------
@@ -96,7 +96,7 @@ new DebugOverlay.Builder(this)
9696
9797
* bgColor - [color]
9898
>Color used for the background of the overlay. Default is `25% Black`.
99-
99+
100100
* textColor - [color]
101101
>Color used for text on the overlay. Default is `White`.
102102
@@ -110,9 +110,9 @@ new DebugOverlay.Builder(this)
110110
>If true, it adds the overlay window on Android's system window layer; in Android 7.1.1 and after, it will ask you for the overlay permission by taking you to the Android's settings screen when you first set up. If set to false, it will automatically add the overlay on each application window. In most cases, you want to set this to `true`.
111111
Default is `true`.
112112

113-
* notification - [boolean, string(optional)]
113+
* notification - [boolean, string(optional)]
114114
> *applicable only when allowSystemLayer is set to true*
115-
>
115+
>
116116
> When set to true, it will show notification which allows you to show/hide the overlay window.
117117
Default is `true`.
118118
You can optionally supply string which must be your *activity's class name*.
@@ -159,6 +159,12 @@ Extension Modules (available separately)
159159
160160
For details, please check out [debugoverlay-ext-timber](https://github.com/Manabu-GT/DebugOverlay-Android/tree/develop/debugoverlay-ext-timber).
161161

162+
#### NetStatsModule
163+
`optional`
164+
> An extension module which shows the total network usage of the application. The stats include all network interfaces, and both TCP and UDP usage.
165+
166+
For details, please check out [debugoverlay-ext-netstats](https://github.com/Manabu-GT/DebugOverlay-Android/tree/develop/debugoverlay-ext-netstats).
167+
162168
Customization
163169
------
164170

22.7 KB
Loading

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ext {
3434
minSdkVersion = 16
3535
targetSdkVersion = 26
3636

37-
supportLibraryVersion = "26.0.1"
37+
supportLibraryVersion = "26.1.0"
3838

3939
// http://tools.android.com/tech-docs/new-build-system/tips
4040
// this is for faster build on CI servers since it does not perform preDex

debugoverlay-ext-netstats/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

debugoverlay-ext-netstats/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Network Statistics Extension Module
2+
===================================
3+
4+
**NetStatsModule** is an extension module which shows the total network usage of the application.
5+
The stats include all network interfaces, and both TCP and UDP usage.
6+
7+
<img src="../art/overlay_with_netstats_module_small.png" width="50%" alt="DebugOverlay Screen Capture">
8+
9+
Setup
10+
-----
11+
12+
Gradle:
13+
14+
```groovy
15+
dependencies {
16+
debugCompile 'com.ms-square:debugoverlay:1.1.3'
17+
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
18+
testCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
19+
20+
compile ('com.ms-square:debugoverlay-ext-netstats:1.1.3') {
21+
exclude module: 'debugoverlay'
22+
}
23+
}
24+
```
25+
26+
or
27+
28+
```groovy
29+
dependencies {
30+
// this will use a full debugoverlay lib even in the test/release build
31+
compile 'com.ms-square:debugoverlay-ext-netstats:1.1.3'
32+
}
33+
```
34+
35+
Usage
36+
-----
37+
38+
### Simple Example
39+
40+
In your `Application` class:
41+
42+
```java
43+
public class ExampleApplication extends Application {
44+
45+
@Override public void onCreate() {
46+
super.onCreate();
47+
new DebugOverlay.Builder(this)
48+
.modules(new CpuUsageModule(),
49+
new MemInfoModule(this),
50+
new FpsModule(),
51+
new NetStatsModule())
52+
.build()
53+
.install();
54+
// Normal app init code...
55+
}
56+
}
57+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion rootProject.ext.compileSdkVersion
5+
buildToolsVersion rootProject.ext.buildToolsVersion
6+
7+
defaultConfig {
8+
minSdkVersion rootProject.ext.minSdkVersion
9+
targetSdkVersion rootProject.ext.targetSdkVersion
10+
}
11+
}
12+
13+
dependencies {
14+
compile project(':debugoverlay')
15+
testCompile deps.junit
16+
}
17+
18+
// for maven central deployment
19+
apply from: 'https://raw.githubusercontent.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# For maven central
2+
POM_ARTIFACT_ID=debugoverlay-ext-netstats
3+
POM_NAME=Network Statistics DebugOverlay extension for Android
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<manifest package="com.ms_square.debugoverlay_ext_netstats" />
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.ms_square.debugoverlay_ext_netstats;
2+
3+
import android.net.TrafficStats;
4+
import android.os.Handler;
5+
import android.os.Looper;
6+
import android.util.Log;
7+
8+
import com.ms_square.debugoverlay.modules.BaseDataModule;
9+
10+
import java.util.Locale;
11+
12+
class NetStatsDataModule extends BaseDataModule<String> {
13+
14+
private static final String TAG = "NetStatsDataModule";
15+
16+
private static final double BYTES_PER_GIGABYTE = 1000000000f;
17+
18+
private static final double BYTES_PER_MEGABYTE = 1000000f;
19+
20+
private static final double BYTES_PER_KILOBYTE = 1000f;
21+
22+
private static final String HEADER = "Received: %8s/s\nSent: %12s/s";
23+
24+
private final Handler handler = new Handler(Looper.getMainLooper());
25+
26+
private final Runnable networkStatisticsQueryRunnable = new Runnable() {
27+
28+
@Override
29+
public void run() {
30+
31+
double totalBytesReceived = TrafficStats.getUidRxBytes(uid);
32+
double totalBytesSent = TrafficStats.getUidTxBytes(uid);
33+
34+
if (totalBytesReceived == TrafficStats.UNSUPPORTED || totalBytesSent == TrafficStats.UNSUPPORTED) {
35+
Log.w(TAG, "The use of TrafficStats is not supported on this device.");
36+
return;
37+
}
38+
39+
if (previousReceived >= 0 && previousSent >= 0) {
40+
received = (totalBytesReceived - previousReceived) / intervalSeconds;
41+
sent = (totalBytesSent - previousSent) / intervalSeconds;
42+
notifyObservers();
43+
}
44+
previousReceived = totalBytesReceived;
45+
previousSent = totalBytesSent;
46+
47+
handler.postDelayed(this, intervalMilliseconds);
48+
}
49+
};
50+
51+
private final int intervalMilliseconds;
52+
private final int uid;
53+
private final double intervalSeconds;
54+
55+
private double previousReceived;
56+
private double previousSent;
57+
private double received;
58+
private double sent;
59+
60+
public NetStatsDataModule(int intervalMilliseconds) {
61+
this.uid = android.os.Process.myUid();
62+
this.intervalMilliseconds = intervalMilliseconds;
63+
this.intervalSeconds = intervalMilliseconds * 0.001;
64+
}
65+
66+
@Override
67+
protected String getLatestData() {
68+
return String.format(
69+
Locale.US, HEADER, bytesToPrettyString(received), bytesToPrettyString(sent));
70+
}
71+
72+
@Override
73+
public void start() {
74+
previousReceived = -1f;
75+
previousSent = -1f;
76+
handler.post(networkStatisticsQueryRunnable);
77+
}
78+
79+
@Override
80+
public void stop() {
81+
handler.removeCallbacks(networkStatisticsQueryRunnable);
82+
}
83+
84+
private String bytesToPrettyString(double bytes) {
85+
if (bytes >= BYTES_PER_GIGABYTE) {
86+
return String.format(Locale.US, "%.1f GB", bytes / BYTES_PER_GIGABYTE);
87+
} else if (bytes >= BYTES_PER_MEGABYTE) {
88+
return String.format(Locale.US, "%.1f MB", bytes / BYTES_PER_MEGABYTE);
89+
} else if (bytes >= BYTES_PER_KILOBYTE) {
90+
return String.format(Locale.US, "%.1f kB", bytes / BYTES_PER_KILOBYTE);
91+
} else {
92+
return String.format(Locale.US, "%.1f B", bytes);
93+
}
94+
}
95+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.ms_square.debugoverlay_ext_netstats;
2+
3+
import com.ms_square.debugoverlay.OverlayModule;
4+
import com.ms_square.debugoverlay.modules.SimpleViewModule;
5+
6+
public class NetStatsModule extends OverlayModule<String> {
7+
8+
private static final int DEFAULT_INTERVAL = 1000; // ms
9+
10+
public NetStatsModule() {
11+
this(DEFAULT_INTERVAL);
12+
}
13+
14+
public NetStatsModule(int interval) {
15+
super(new NetStatsDataModule(interval), new SimpleViewModule(R.layout.debugoverlay_netstats));
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@id/debugoverlay_overlay_text"
4+
style="@style/debugoverlay_OverlayText"
5+
android:layout_width="wrap_content"
6+
android:layout_height="wrap_content"
7+
android:maxLines="2">
8+
</TextView>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.ms_square.debugoverlay_ext_netstats;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() throws Exception {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

debugoverlay-ext-timber/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Gradle:
1212

1313
```groovy
1414
dependencies {
15-
debugCompile 'com.ms-square:debugoverlay:1.1.2'
16-
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.2'
17-
testCompile 'com.ms-square:debugoverlay-no-op:1.1.2'
15+
debugCompile 'com.ms-square:debugoverlay:1.1.3'
16+
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
17+
testCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
1818
19-
compile ('com.ms-square:debugoverlay-ext-timber:1.1.2') {
19+
compile ('com.ms-square:debugoverlay-ext-timber:1.1.3') {
2020
exclude module: 'debugoverlay'
2121
}
2222
}
@@ -27,7 +27,7 @@ or
2727
```groovy
2828
dependencies {
2929
// this will use a full debugoverlay lib even in the test/release build
30-
compile 'com.ms-square:debugoverlay-ext-timber:1.1.2'
30+
compile 'com.ms-square:debugoverlay-ext-timber:1.1.3'
3131
}
3232
```
3333

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ android.enableBuildCache=true
2626

2727
# For maven central
2828
GROUP=com.ms-square
29-
VERSION_NAME=1.1.2
30-
VERSION_CODE=5
29+
VERSION_NAME=1.1.3
30+
VERSION_CODE=6
3131
POM_PACKAGING=aar
3232
POM_DESCRIPTION=Android library to display various debugging information in an overlay window
3333

sample/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ dependencies {
7171
exclude module: 'debugoverlay'
7272
}
7373

74+
compile(project(':debugoverlay-ext-netstats')) {
75+
exclude module: 'debugoverlay'
76+
}
77+
7478
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
7579
compile "com.android.support:design:${supportLibraryVersion}"
7680

sample/src/main/java/com/ms_square/debugoverlay/sample/DebugOverlaySampleApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public void onCreate() {
4646
// new MemInfoModule(this),
4747
// new FpsModule(),
4848
// new IPAddressModule(this),
49+
// new NetStatsModule(),
4950
// new TimberModule(BuildConfig.DEBUG))
5051
// .build()
5152
// .install();

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':sample', ':debugoverlay', ':debugoverlay-no-op', ':debugoverlay-ext-timber'
1+
include ':sample', ':debugoverlay', ':debugoverlay-no-op', ':debugoverlay-ext-timber', ':debugoverlay-ext-netstats'

0 commit comments

Comments
 (0)