From e114be51d005e00f470f1bb870e6bcaa0ee295f7 Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Sun, 3 Jul 2011 17:41:43 +0530 Subject: [PATCH] Improved Formatting Now shows the data with upto 2 decimal places. If under 2Mb, shows "xxx.xKb", else shows "xxx.xxMb" --- src/org/torproject/android/Orbot.java | 13 ++++++++++--- src/org/torproject/android/service/TorService.java | 11 +++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 93cec946..6eaa124f 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -749,7 +749,8 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download")); downloadText.setText(formatCount(datacount.Download)); uploadText.setText(formatCount(datacount.Upload)); - + downloadText.invalidate(); + uploadText.invalidate(); break; @@ -916,8 +917,14 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener } private String formatCount(long count) { - - return count+" kB"; + // Converts the supplied argument into a string. + // Under 2Mb, returns "xxx.xKb" + // Over 2Mb, returns "xxx.xxMb" + if (count < 1e6 * 2) + return ((float)((int)(count*10/1024))/10 + "kB"); + return ((float)((int)(count*100/1024/1024))/100 + "MB"); + + //return count+" kB"; } } diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 01151460..e9fc2248 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -1122,10 +1122,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst sb.append("kb written"); logNotice(sb.toString()); - DataCount datacount = new DataCount(); - - datacount.Download = read/1000; - datacount.Upload = written/1000; + DataCount datacount = new DataCount(written,read); Message msg = Message.obtain(); msg.what = MESSAGE_TRAFFIC_COUNT; @@ -1149,6 +1146,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst public long Upload; // data downloaded public long Download; + + + DataCount(long Upload, long Download){ + this.Upload = Upload; + this.Download = Download; + } } public void circuitStatus(String status, String circID, String path) {