diff options
author | Arne Schwabe <arne@rfc2549.org> | 2013-02-11 15:53:43 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2013-02-11 15:53:43 +0100 |
commit | 24bdb287646f94b134d0073e2a2c4e90f09a5eb0 (patch) | |
tree | d02518971b44def496aac77d6b717a1f12e3e518 /src/de/blinkt | |
parent | 50299529d61e9c256e77cf220fa0ecc3f74a18bf (diff) |
Fix display of speed in the notification.
Diffstat (limited to 'src/de/blinkt')
-rw-r--r-- | src/de/blinkt/openvpn/OpenVPNMangement.java | 1 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVpnManagementThread.java | 4 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVpnService.java | 21 |
3 files changed, 16 insertions, 10 deletions
diff --git a/src/de/blinkt/openvpn/OpenVPNMangement.java b/src/de/blinkt/openvpn/OpenVPNMangement.java index 0c6d7163..85a3f784 100644 --- a/src/de/blinkt/openvpn/OpenVPNMangement.java +++ b/src/de/blinkt/openvpn/OpenVPNMangement.java @@ -1,6 +1,7 @@ package de.blinkt.openvpn; public interface OpenVPNMangement { + int mBytecountinterval=2; void reconnect(); diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java index 5cd70987..d17ed6c5 100644 --- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java +++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java @@ -25,7 +25,6 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNMangement { private VpnProfile mProfile;
private OpenVpnService mOpenVPNService;
private LinkedList<FileDescriptor> mFDList=new LinkedList<FileDescriptor>();
- private int mBytecountinterval=2;
private LocalServerSocket mServerSocket;
private boolean mReleaseHold=true;
private boolean mWaitingForRelease=false;
@@ -273,8 +272,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNMangement { long out = Long.parseLong(argument.substring(comma+1));
OpenVPN.updateByteCount(in,out);
-
-
+
}
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index cacbb85e..66ab9e30 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -565,9 +565,9 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac if(mDisplayBytecount) { String netstat = String.format(getString(R.string.statusline_bytecount), humanReadableByteCount(in, false), - humanReadableByteCount(diffin, false), + humanReadableByteCount(diffin/OpenVPNMangement.mBytecountinterval, true), humanReadableByteCount(out, false), - humanReadableByteCount(diffout, false)); + humanReadableByteCount(diffout/OpenVPNMangement.mBytecountinterval, true)); boolean lowpriority = !mNotificationalwaysVisible; showNotification(netstat,null,lowpriority,mConnecttime, OpenVPN.LEVEL_CONNECTED); @@ -576,12 +576,19 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac } // From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java - public static String humanReadableByteCount(long bytes, boolean si) { - int unit = si ? 1000 : 1024; - if (bytes < unit) return bytes + " B"; + public static String humanReadableByteCount(long bytes, boolean mbit) { + if(mbit) + bytes = bytes *8; + int unit = mbit ? 1000 : 1024; + if (bytes < unit) + return bytes + (mbit ? " bit" : " B"); + int exp = (int) (Math.log(bytes) / Math.log(unit)); - String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i"); - return String.format(Locale.getDefault(),"%.1f %sB", bytes / Math.pow(unit, exp), pre); + String pre = (mbit ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (mbit ? "" : ""); + if(mbit) + return String.format(Locale.getDefault(),"%.1f %sbit", bytes / Math.pow(unit, exp), pre); + else + return String.format(Locale.getDefault(),"%.1f %sB", bytes / Math.pow(unit, exp), pre); } @Override |