From e8c3fdc1edbeda9fc1f002ffb51a62a1fbe8874b Mon Sep 17 00:00:00 2001 From: n8fr8 Date: Sun, 30 Sep 2012 18:37:37 +0530 Subject: [PATCH] add total display to data transfer UI --- res/layout/layout_main.xml | 15 +++++----- res/values/strings.xml | 4 +-- src/org/torproject/android/Orbot.java | 40 +++++++++++++++++---------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/res/layout/layout_main.xml b/res/layout/layout_main.xml index a9444e1f..f73d79cc 100644 --- a/res/layout/layout_main.xml +++ b/res/layout/layout_main.xml @@ -60,14 +60,15 @@ About Wizard -Download -Upload +Download (speed/total) +Upload (speed/total) Help Close diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index c51b1047..59112dae 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -763,22 +763,23 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener trafficRow.setVisibility(RelativeLayout.VISIBLE); Bundle data = msg.getData(); - DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download")); - downloadText.setText(formatCount(datacount.Download)); - uploadText.setText(formatCount(datacount.Upload)); - downloadText.invalidate(); - uploadText.invalidate(); - + DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download")); + String TotalUpload = ""; + String TotalDownload = ""; + try { - String TotalUpload = mService.getInfo("traffic/written"); - String TotalDownload = mService.getInfo("traffic/read"); - StringBuilder sb = new StringBuilder(); - sb.append("Total Upload " + TotalUpload); - sb.append("Total Download" + TotalDownload); - Log.d(TAG,sb.toString()); + TotalUpload = mService.getInfo("traffic/written"); + TotalDownload = mService.getInfo("traffic/read"); + } catch (RemoteException e) { Log.d(TAG,"Total bandwidth error"+e.getMessage()); } + + downloadText.setText(formatCount(datacount.Download) + " / " + formatTotal(Long.parseLong(TotalDownload))); + uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(Long.parseLong(TotalUpload))); + + downloadText.invalidate(); + uploadText.invalidate(); break; @@ -949,8 +950,19 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener // Under 2Mb, returns "xxx.xKb" // Over 2Mb, returns "xxx.xxMb" if (count < 1e6 * 2) - return ((float)((int)(count*10/1024))/10 + " kbps"); - return ((float)((int)(count*100/1024/1024))/100 + " mbps"); + return ((float)((int)(count*10/1024))/10 + "kbps"); + return ((float)((int)(count*100/1024/1024))/100 + "mbps"); + + //return count+" kB"; + } + + private String formatTotal(long count) { + // Converts the supplied argument into a string. + // Under 2Mb, returns "xxx.xKb" + // Over 2Mb, returns "xxx.xxMb" + if (count < 1e6) + return ((float)((int)(count*10/1024))/10 + "KB"); + return ((float)((int)(count*100/1024/1024))/100 + "MB"); //return count+" kB"; }