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

[tor-commits] [orbot/master] Traffic is shown in the main UI



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

    Traffic is shown in the main UI
---
 src/org/torproject/android/Orbot.java              |   42 +++++++++----------
 src/org/torproject/android/service/TorService.java |   16 ++++++--
 2 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index fd0ace0..93cec94 100644
--- a/src/org/torproject/android/Orbot.java
+++ b/src/org/torproject/android/Orbot.java
@@ -47,8 +47,6 @@ import android.widget.TextView;
 
 public class Orbot extends Activity implements TorConstants, OnLongClickListener
 {
-
-	private static final int VISIBLE = 0;
 	/* Useful UI bits */
 	private TextView lblStatus = null; //the main text display widget
 	private ImageView imgStatus = null; //the main touchable image for activating Orbot
@@ -615,23 +613,22 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
             msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up));
             mHandler.sendMessage(msg);
             
-        trafficRow.setVisibility(VISIBLE);
+        trafficRow.setVisibility(RelativeLayout.VISIBLE);
     	
     }
     
     //now we stop Tor! amazing!
     private void stopTor () throws RemoteException
     {
-        //if the service is bound, then turn it off, using the same "PROFILE_" technique
-            if (mService != null)
-            {
-                    mService.setProfile(TorServiceConstants.PROFILE_OFF);
-                    
-                    //again this is related to the progress dialog or some other threaded UI object
-                    Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
-                    mHandler.sendMessage(msg);
-            }
-            
+    	if (mService != null)
+    	{
+    		mService.setProfile(TorServiceConstants.PROFILE_OFF);
+    		Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
+    		mHandler.sendMessage(msg);
+            trafficRow.setVisibility(RelativeLayout.GONE);
+
+    	}
+    	
      
     }
     
@@ -748,11 +745,11 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
 
             	case TorServiceConstants.MESSAGE_TRAFFIC_COUNT :
             		
-            		DataCount datacount =  (DataCount) msg.obj;            		
+            		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();
+            		
             		
             		break;
                 		
@@ -911,15 +908,16 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
    		public long Upload;
    		// data downloaded
    		public long Download;
+   		
+   		DataCount(long Upload, long Download){
+   			this.Upload = Upload;
+   			this.Download = Download;
+   		}
    	}
    	
    	private String formatCount(long count) {
-		// 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 4aaf2b0..0115146 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -41,9 +41,11 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
+import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
+import android.os.Parcelable;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
 import android.preference.PreferenceManager;
@@ -1125,10 +1127,16 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 	        datacount.Download = read/1000;
 	        datacount.Upload = written/1000;
 	        
-			Message message = Message.obtain();
-			message.what = MESSAGE_TRAFFIC_COUNT;
-			message.obj = datacount;
-			Orbot.currentInstance.mHandler.sendMessage(message); 
+			Message msg = Message.obtain();
+			msg.what = MESSAGE_TRAFFIC_COUNT;
+			//msg.obj = datacount;
+			Bundle data = new Bundle();
+			data.putLong("upload", datacount.Upload);
+			data.putLong("download", datacount.Download);
+			
+			msg.setData(data);
+			
+			Orbot.currentInstance.mHandler.sendMessage(msg); 
 
 			//sendCallbackStatusMessage(message); 
 			



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