Skip to content

Commit

Permalink
Merge pull request #21 from Manabu-GT/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Manabu-GT authored Sep 24, 2017
2 parents 602f97c + dbc9e4e commit c94ccc6
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## Version 1.1.3 *(2017-09-24)*

* Add a NetStatsModule as an extension module
* Support Library 26.0.1 -> 26.1.0

## Version 1.1.2 *(2017-09-09)*

* Add a TimberModule as an extension module
Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ API Level 16 (Android 4.1) and above.

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

```groovy
dependencies {
debugCompile 'com.ms-square:debugoverlay:1.1.2'
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.2'
testCompile 'com.ms-square:debugoverlay-no-op:1.1.2'
debugCompile 'com.ms-square:debugoverlay:1.1.3'
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
testCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
}
```

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

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

| library | methods | fields |
|:------------- |:-------------|:-------------|
|com.ms-square:debugoverlay:1.1.2|566|252|
|com.ms-square:debugoverlay-no-op:1.1.2|141|37|
|com.ms-square:debugoverlay:1.1.3|566|252|
|com.ms-square:debugoverlay-no-op:1.1.3|141|37|

Due to the extensibility of this library, no-op version unfortunately has more than a few methods.
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.
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.

Usage
------
Expand Down Expand Up @@ -96,7 +96,7 @@ new DebugOverlay.Builder(this)
* bgColor - [color]
>Color used for the background of the overlay. Default is `25% Black`.
* textColor - [color]
>Color used for text on the overlay. Default is `White`.
Expand All @@ -110,9 +110,9 @@ new DebugOverlay.Builder(this)
>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`.
Default is `true`.

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

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

Customization
------

Expand Down
Binary file added art/overlay_with_netstats_module_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ext {
minSdkVersion = 16
targetSdkVersion = 26

supportLibraryVersion = "26.0.1"
supportLibraryVersion = "26.1.0"

// http://tools.android.com/tech-docs/new-build-system/tips
// this is for faster build on CI servers since it does not perform preDex
Expand Down
1 change: 1 addition & 0 deletions debugoverlay-ext-netstats/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
57 changes: 57 additions & 0 deletions debugoverlay-ext-netstats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Network Statistics Extension Module
===================================

**NetStatsModule** is an extension module which shows the total network usage of the application.
The stats include all network interfaces, and both TCP and UDP usage.

<img src="../art/overlay_with_netstats_module_small.png" width="50%" alt="DebugOverlay Screen Capture">

Setup
-----

Gradle:

```groovy
dependencies {
debugCompile 'com.ms-square:debugoverlay:1.1.3'
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
testCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
compile ('com.ms-square:debugoverlay-ext-netstats:1.1.3') {
exclude module: 'debugoverlay'
}
}
```

or

```groovy
dependencies {
// this will use a full debugoverlay lib even in the test/release build
compile 'com.ms-square:debugoverlay-ext-netstats:1.1.3'
}
```

Usage
-----

### Simple Example

In your `Application` class:

```java
public class ExampleApplication extends Application {

@Override public void onCreate() {
super.onCreate();
new DebugOverlay.Builder(this)
.modules(new CpuUsageModule(),
new MemInfoModule(this),
new FpsModule(),
new NetStatsModule())
.build()
.install();
// Normal app init code...
}
}
```
19 changes: 19 additions & 0 deletions debugoverlay-ext-netstats/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
}
}

dependencies {
compile project(':debugoverlay')
testCompile deps.junit
}

// for maven central deployment
apply from: 'https://raw.githubusercontent.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
3 changes: 3 additions & 0 deletions debugoverlay-ext-netstats/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# For maven central
POM_ARTIFACT_ID=debugoverlay-ext-netstats
POM_NAME=Network Statistics DebugOverlay extension for Android
1 change: 1 addition & 0 deletions debugoverlay-ext-netstats/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.ms_square.debugoverlay_ext_netstats" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.ms_square.debugoverlay_ext_netstats;

import android.net.TrafficStats;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.ms_square.debugoverlay.modules.BaseDataModule;

import java.util.Locale;

class NetStatsDataModule extends BaseDataModule<String> {

private static final String TAG = "NetStatsDataModule";

private static final double BYTES_PER_GIGABYTE = 1000000000f;

private static final double BYTES_PER_MEGABYTE = 1000000f;

private static final double BYTES_PER_KILOBYTE = 1000f;

private static final String HEADER = "Received: %8s/s\nSent: %12s/s";

private final Handler handler = new Handler(Looper.getMainLooper());

private final Runnable networkStatisticsQueryRunnable = new Runnable() {

@Override
public void run() {

double totalBytesReceived = TrafficStats.getUidRxBytes(uid);
double totalBytesSent = TrafficStats.getUidTxBytes(uid);

if (totalBytesReceived == TrafficStats.UNSUPPORTED || totalBytesSent == TrafficStats.UNSUPPORTED) {
Log.w(TAG, "The use of TrafficStats is not supported on this device.");
return;
}

if (previousReceived >= 0 && previousSent >= 0) {
received = (totalBytesReceived - previousReceived) / intervalSeconds;
sent = (totalBytesSent - previousSent) / intervalSeconds;
notifyObservers();
}
previousReceived = totalBytesReceived;
previousSent = totalBytesSent;

handler.postDelayed(this, intervalMilliseconds);
}
};

private final int intervalMilliseconds;
private final int uid;
private final double intervalSeconds;

private double previousReceived;
private double previousSent;
private double received;
private double sent;

public NetStatsDataModule(int intervalMilliseconds) {
this.uid = android.os.Process.myUid();
this.intervalMilliseconds = intervalMilliseconds;
this.intervalSeconds = intervalMilliseconds * 0.001;
}

@Override
protected String getLatestData() {
return String.format(
Locale.US, HEADER, bytesToPrettyString(received), bytesToPrettyString(sent));
}

@Override
public void start() {
previousReceived = -1f;
previousSent = -1f;
handler.post(networkStatisticsQueryRunnable);
}

@Override
public void stop() {
handler.removeCallbacks(networkStatisticsQueryRunnable);
}

private String bytesToPrettyString(double bytes) {
if (bytes >= BYTES_PER_GIGABYTE) {
return String.format(Locale.US, "%.1f GB", bytes / BYTES_PER_GIGABYTE);
} else if (bytes >= BYTES_PER_MEGABYTE) {
return String.format(Locale.US, "%.1f MB", bytes / BYTES_PER_MEGABYTE);
} else if (bytes >= BYTES_PER_KILOBYTE) {
return String.format(Locale.US, "%.1f kB", bytes / BYTES_PER_KILOBYTE);
} else {
return String.format(Locale.US, "%.1f B", bytes);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ms_square.debugoverlay_ext_netstats;

import com.ms_square.debugoverlay.OverlayModule;
import com.ms_square.debugoverlay.modules.SimpleViewModule;

public class NetStatsModule extends OverlayModule<String> {

private static final int DEFAULT_INTERVAL = 1000; // ms

public NetStatsModule() {
this(DEFAULT_INTERVAL);
}

public NetStatsModule(int interval) {
super(new NetStatsDataModule(interval), new SimpleViewModule(R.layout.debugoverlay_netstats));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/debugoverlay_overlay_text"
style="@style/debugoverlay_OverlayText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2">
</TextView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ms_square.debugoverlay_ext_netstats;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
10 changes: 5 additions & 5 deletions debugoverlay-ext-timber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Gradle:

```groovy
dependencies {
debugCompile 'com.ms-square:debugoverlay:1.1.2'
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.2'
testCompile 'com.ms-square:debugoverlay-no-op:1.1.2'
debugCompile 'com.ms-square:debugoverlay:1.1.3'
releaseCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
testCompile 'com.ms-square:debugoverlay-no-op:1.1.3'
compile ('com.ms-square:debugoverlay-ext-timber:1.1.2') {
compile ('com.ms-square:debugoverlay-ext-timber:1.1.3') {
exclude module: 'debugoverlay'
}
}
Expand All @@ -27,7 +27,7 @@ or
```groovy
dependencies {
// this will use a full debugoverlay lib even in the test/release build
compile 'com.ms-square:debugoverlay-ext-timber:1.1.2'
compile 'com.ms-square:debugoverlay-ext-timber:1.1.3'
}
```

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android.enableBuildCache=true

# For maven central
GROUP=com.ms-square
VERSION_NAME=1.1.2
VERSION_CODE=5
VERSION_NAME=1.1.3
VERSION_CODE=6
POM_PACKAGING=aar
POM_DESCRIPTION=Android library to display various debugging information in an overlay window

Expand Down
4 changes: 4 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ dependencies {
exclude module: 'debugoverlay'
}

compile(project(':debugoverlay-ext-netstats')) {
exclude module: 'debugoverlay'
}

compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
compile "com.android.support:design:${supportLibraryVersion}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void onCreate() {
// new MemInfoModule(this),
// new FpsModule(),
// new IPAddressModule(this),
// new NetStatsModule(),
// new TimberModule(BuildConfig.DEBUG))
// .build()
// .install();
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':sample', ':debugoverlay', ':debugoverlay-no-op', ':debugoverlay-ext-timber'
include ':sample', ':debugoverlay', ':debugoverlay-no-op', ':debugoverlay-ext-timber', ':debugoverlay-ext-netstats'

0 comments on commit c94ccc6

Please sign in to comment.