[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] Improved Formatting



commit e114be51d005e00f470f1bb870e6bcaa0ee295f7
Author: Sathyanarayanan Gunasekaran <gsathya.ceg@xxxxxxxxx>
Date:   Sun Jul 3 17:41:43 2011 +0530

    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 93cec94..6eaa124 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 0115146..e9fc224 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) {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits