summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java54
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java20
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java6
-rwxr-xr-xmain/src/main/res/values/strings.xml13
5 files changed, 63 insertions, 32 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java b/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
index c7760a0e..7b5946a3 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
@@ -103,7 +103,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
if (windowtraffic < TRAFFIC_LIMIT) {
screen = connectState.DISCONNECTED;
VpnStatus.logInfo(R.string.screenoff_pause,
- OpenVPNService.humanReadableByteCount(TRAFFIC_LIMIT, false), TRAFFIC_WINDOW);
+ "64 kB", TRAFFIC_WINDOW);
mManagement.pause(getPauseReason());
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index a4c66e9d..753ef0ab 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -19,6 +19,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutManager;
import android.content.res.Configuration;
+import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.VpnService;
import android.os.Binder;
@@ -117,19 +118,42 @@ 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 mbit) {
- if (mbit)
+ public static String humanReadableByteCount(long bytes, boolean speed, Resources res) {
+ if (speed)
bytes = bytes * 8;
- int unit = mbit ? 1000 : 1024;
- if (bytes < unit)
- return bytes + (mbit ? "\u2009bit" : "\u2009B");
-
- int exp = (int) (Math.log(bytes) / Math.log(unit));
- String pre = (mbit ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (mbit ? "" : "");
- if (mbit)
- return String.format(Locale.getDefault(), "%.1f %sbit", bytes / Math.pow(unit, exp), pre);
+ int unit = speed ? 1000 : 1024;
+
+
+ int exp = Math.min((int) (Math.log(bytes) / Math.log(unit)), 3);
+
+ float bytesUnit = Math.round(bytes / Math.pow(unit, exp));
+
+ if (speed)
+ switch (exp) {
+ case 0:
+ return res.getString(R.string.bits_per_second, bytesUnit);
+ case 1:
+ return res.getString(R.string.kbits_per_second, bytesUnit);
+ case 2:
+ return res.getString(R.string.mbits_per_second, bytesUnit);
+ default:
+ return res.getString(R.string.gbits_per_second, bytesUnit);
+ }
else
- return String.format(Locale.getDefault(), "%.1f %sB", bytes / Math.pow(unit, exp), pre);
+ switch (exp) {
+ case 0:
+ return res.getString(R.string.volume_byte, bytesUnit);
+ case 1:
+ return res.getString(R.string.volume_kbyte, bytesUnit);
+ case 2:
+ return res.getString(R.string.volume_mbyte, bytesUnit);
+ default:
+ return res.getString(R.string.volume_gbyte, bytesUnit);
+
+ }
+
+
+
}
@Override
@@ -1051,10 +1075,10 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
public void updateByteCount(long in, long out, long diffIn, long diffOut) {
if (mDisplayBytecount) {
String netstat = String.format(getString(R.string.statusline_bytecount),
- humanReadableByteCount(in, false),
- humanReadableByteCount(diffIn / OpenVPNManagement.mBytecountInterval, true),
- humanReadableByteCount(out, false),
- humanReadableByteCount(diffOut / OpenVPNManagement.mBytecountInterval, true));
+ humanReadableByteCount(in, false, getResources()),
+ humanReadableByteCount(diffIn / OpenVPNManagement.mBytecountInterval, true, getResources()),
+ humanReadableByteCount(out, false, getResources()),
+ humanReadableByteCount(diffOut / OpenVPNManagement.mBytecountInterval, true, getResources()));
int priority = mNotificationAlwaysVisible ? PRIORITY_DEFAULT : PRIORITY_MIN;
showNotification(netstat, null, priority, mConnecttime, LEVEL_CONNECTED);
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java b/main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java
index e9e6fa47..8273ca9b 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/GraphFragment.java
@@ -7,6 +7,7 @@ package de.blinkt.openvpn.fragments;
import android.app.Fragment;
import android.content.Context;
+import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
@@ -135,12 +136,13 @@ public class GraphFragment extends Fragment implements VpnStatus.ByteCountListen
long now = (System.currentTimeMillis() / 100) - firstTs;
int interval = OpenVPNManagement.mBytecountInterval * 10;
+ Resources res = getActivity().getResources();
final String netstat = String.format(getString(R.string.statusline_bytecount),
- humanReadableByteCount(in, false),
- humanReadableByteCount(diffIn / OpenVPNManagement.mBytecountInterval, true),
- humanReadableByteCount(out, false),
- humanReadableByteCount(diffOut / OpenVPNManagement.mBytecountInterval, true));
+ humanReadableByteCount(in, false, res),
+ humanReadableByteCount(diffIn / OpenVPNManagement.mBytecountInterval, true, res),
+ humanReadableByteCount(out, false, res),
+ humanReadableByteCount(diffOut / OpenVPNManagement.mBytecountInterval, true, res));
getActivity().runOnUiThread(new Runnable() {
@Override
@@ -225,6 +227,7 @@ public class GraphFragment extends Fragment implements VpnStatus.ByteCountListen
YAxis yAxis = holder.chart.getAxisLeft();
yAxis.setLabelCount(5, false);
+ final Resources res = getActivity().getResources();
yAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
@@ -233,7 +236,7 @@ public class GraphFragment extends Fragment implements VpnStatus.ByteCountListen
if (mLogScale)
value = (float) Math.pow(10, value)/8;
- return humanReadableByteCount((long) value, true) + "/s";
+ return humanReadableByteCount((long) value, true, res);
}
});
@@ -265,13 +268,6 @@ public class GraphFragment extends Fragment implements VpnStatus.ByteCountListen
return convertView;
}
-
- public void getAverageForGraphList(boolean in, int timeperiod) {
-
-
-
- }
-
private LineData getDataSet(int timeperiod) {
LinkedList<Entry> dataIn = new LinkedList<>();
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
index 7962aac5..30f922ae 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java
@@ -16,6 +16,7 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.res.Resources;
import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -117,8 +118,9 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
@Override
public void updateByteCount(long in, long out, long diffIn, long diffOut) {
//%2$s/s %1$s - ↑%4$s/s %3$s
- final String down = String.format("%2$s/s %1$s", humanReadableByteCount(in, false), humanReadableByteCount(diffIn / OpenVPNManagement.mBytecountInterval, true));
- final String up = String.format("%2$s/s %1$s", humanReadableByteCount(out, false), humanReadableByteCount(diffOut / OpenVPNManagement.mBytecountInterval, true));
+ Resources res = getActivity().getResources();
+ final String down = String.format("%2$s %1$s", humanReadableByteCount(in, false, res), humanReadableByteCount(diffIn / OpenVPNManagement.mBytecountInterval, true, res));
+ final String up = String.format("%2$s %1$s", humanReadableByteCount(out, false, res), humanReadableByteCount(diffOut / OpenVPNManagement.mBytecountInterval, true, res));
if (mUpStatus != null && mDownStatus != null) {
if (getActivity() != null) {
diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml
index c450a00a..c20d1fe4 100755
--- a/main/src/main/res/values/strings.xml
+++ b/main/src/main/res/values/strings.xml
@@ -250,7 +250,7 @@
<string name="state_tcp_connect">Connecting (TCP)</string>
<string name="state_auth_failed">Authentication failed</string>
<string name="state_nonetwork">Waiting for usable network</string>
- <string name="statusline_bytecount">↓%2$s/s %1$s - ↑%4$s/s %3$s</string>
+ <string name="statusline_bytecount">↓%2$s %1$s - ↑%4$s %3$s</string>
<string name="notifcation_title_notconnect">Not connected</string>
<string name="start_vpn_title">Connecting to VPN %s</string>
<string name="start_vpn_ticker">Connecting to VPN %s</string>
@@ -408,7 +408,7 @@
<string name="novpn_selected">No VPN selected.</string>
<string name="defaultvpn">Default VPN</string>
<string name="defaultvpnsummary">VPN used in places where a default VPN needed. These are currently on boot, for Always-On and the Quick Settings Tile.</string>
- <string name="vpnselected">Currently slected VPN: \'%s\'</string>
+ <string name="vpnselected">Currently selected VPN: \'%s\'</string>
<string name="reconnect">Reconnect</string>
<string name="qs_title">Toggle VPN</string>
<string name="qs_connect">Connect to %s</string>
@@ -432,5 +432,14 @@
<string name="last5minutes">Last 5 minutes</string>
<string name="data_in">In</string>
<string name="data_out">Out</string>
+ <string name="bits_per_second">%.0f bit/s</string>
+ <string name="kbits_per_second">%.1f kbit/s</string>
+ <string name="mbits_per_second">%.1f Mbit/s</string>
+ <string name="gbits_per_second">%.1f Gbit/s</string>
+
+ <string name="volume_byte">%.0f B</string>
+ <string name="volume_kbyte">%.1f kB</string>
+ <string name="volume_mbyte">%.1f MB</string>
+ <string name="volume_gbyte">%.1f GB</string>
</resources>