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

[tor-commits] [orbot/master] user interface updates - "log" drawer with up/down stats



commit abebfd565edda58fff5f8aac4b38c7bc9acd641e
Author: n8fr8 <nathan@xxxxxxxxxxx>
Date:   Mon Oct 1 12:35:48 2012 +0530

    user interface updates - "log" drawer with up/down stats
---
 src/org/torproject/android/AnimatedBlockView.java  |  135 ------------------
 src/org/torproject/android/ImageProgressView.java  |   78 +++++++++++
 src/org/torproject/android/Orbot.java              |  143 +++++++++++++-------
 .../torproject/android/RandomColorCircleView.java  |  132 ++++++++++++++++++
 .../torproject/android/settings/AppManager.java    |    2 +-
 src/org/torproject/android/wizard/Permissions.java |    6 +-
 6 files changed, 310 insertions(+), 186 deletions(-)

diff --git a/src/org/torproject/android/AnimatedBlockView.java b/src/org/torproject/android/AnimatedBlockView.java
deleted file mode 100644
index 7ba4e63..0000000
--- a/src/org/torproject/android/AnimatedBlockView.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package org.torproject.android;
-
-import java.util.Random;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.View.MeasureSpec;
-
-public class AnimatedBlockView extends View
-{
-
-	  private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
-
-	  private float initX, initY, radius;
-	  private boolean drawing = false;
-
-		Random rand = new Random();
-		
-
-	public AnimatedBlockView(Context context) {
-	 super(context);
-	 // TODO Auto-generated constructor stub
-	 init();
-	 
-	}
-
-	public AnimatedBlockView(Context context, AttributeSet attrs) {
-	 super(context, attrs);
-	 init();
-	}
-
-	public AnimatedBlockView(Context context, AttributeSet attrs, int defStyle) {
-	 super(context, attrs, defStyle);
-	 
-	 init();
-	}
-
-	private void init(){
-	 paint.setStyle(Paint.Style.FILL);
-	 paint.setColor(Color.WHITE);
-	 paint.setAntiAlias(true);
-
-	}
-
-	@Override
-	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-	   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
-	   
-	   setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
-	   MeasureSpec.getSize(heightMeasureSpec));
-	 
-	}
-
-	int a1 = 30;
-	int a2 = 255;
-	
-	@Override
-	protected void onDraw(Canvas canvas) {
-
-		super.onDraw(canvas);
-		
-		for (int i = 0; i < 20; i++)
-		{
-			float r = rand.nextFloat()*255f;
-			float g = rand.nextFloat()*255f;
-			float b = rand.nextFloat()*255f;
-	
-			paint.setARGB(a1,(int)r,(int)g,(int)b);
-		
-			float x = rand.nextFloat() * getWidth();
-			float y = rand.nextFloat() * getHeight();
-
-			float w = rand.nextFloat() * getWidth();
-			float h = rand.nextFloat() * getHeight();
-			
-			canvas.drawCircle(x, y, w/2, paint);
-			
-			
-		}
-		
-	}
-	
-	int a1mod = 1;
-	
-	public void updateAlpha ()
-	{
-		a1 += a1mod;
-		
-		if (a1 > 255 || a1 < 0)
-			a1mod *= -1;
-		
-
-	}
-
-	@Override
-	public boolean onTouchEvent(MotionEvent event) {
-	 
-
-	 int action = event.getAction();
-	 if (action==MotionEvent.ACTION_MOVE){
-	  float x = event.getX();
-	  float y = event.getY();
-
-	 // radius = (float) Math.sqrt(Math.pow(x-initX, 2) + Math.pow(y-initY, 2));
-	  //updateAlpha();
-	  
-	     a1 = (int)(255*(y/((float)getHeight())));
-	  
-	 }
-	 else if (action==MotionEvent.ACTION_DOWN){
-	  initX = event.getX();
-	  initY = event.getY();
-	  radius = 1;
-	  drawing = true;
-	 
-	  
-	 }
-	 else if (action==MotionEvent.ACTION_UP){
-	  drawing = false;
-	 
-	  
-	 }
-	 
-	 return true;
-	 
-	}
-
-}
\ No newline at end of file
diff --git a/src/org/torproject/android/ImageProgressView.java b/src/org/torproject/android/ImageProgressView.java
new file mode 100644
index 0000000..6e813eb
--- /dev/null
+++ b/src/org/torproject/android/ImageProgressView.java
@@ -0,0 +1,78 @@
+package org.torproject.android;
+
+import java.util.Random;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.ImageView;
+
+public class ImageProgressView extends ImageView
+{
+
+	  private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+
+	  private float progress = 0f; // 0 to 1
+	  
+	  private RectF circle;
+	  
+	public ImageProgressView(Context context) {
+	 super(context);
+	 // TODO Auto-generated constructor stub
+	 init();
+	 
+	}
+
+	public ImageProgressView(Context context, AttributeSet attrs) {
+	 super(context, attrs);
+	 init();
+	}
+
+	public ImageProgressView(Context context, AttributeSet attrs, int defStyle) {
+	 super(context, attrs, defStyle);
+	 
+	 init();
+	}
+
+	private void init(){
+	 paint.setStyle(Paint.Style.STROKE);
+	 paint.setColor(Color.GREEN);
+	 paint.setAntiAlias(true);
+	 paint.setStrokeWidth(20);
+	 
+	}
+
+	@Override
+	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+	   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+	   
+	   setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
+	   MeasureSpec.getSize(heightMeasureSpec));
+	 
+	}
+
+	@Override
+	protected void onDraw(Canvas canvas) {
+
+		super.onDraw(canvas);
+		
+		if (circle == null)
+		{
+		circle = new RectF(getWidth()/2,getHeight()/2+getHeight()/8, getWidth()/3,getHeight()/3);
+		}
+		
+		float sweepAngle = 360f * progress;
+		
+		canvas.drawArc(circle, 0, sweepAngle, true, paint);
+		
+	}
+	
+	
+
+	
+}
\ No newline at end of file
diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index d952cc4..f95ff45 100644
--- a/src/org/torproject/android/Orbot.java
+++ b/src/org/torproject/android/Orbot.java
@@ -11,12 +11,10 @@ import org.torproject.android.service.TorServiceConstants;
 import org.torproject.android.settings.ProcessSettingsAsyncTask;
 import org.torproject.android.settings.SettingsPreferences;
 import org.torproject.android.wizard.ChooseLocaleWizardActivity;
-import org.torproject.android.wizard.LotsaText;
 
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.NotificationManager;
-import android.app.ProgressDialog;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -33,28 +31,40 @@ import android.os.IBinder;
 import android.os.Message;
 import android.os.RemoteException;
 import android.preference.PreferenceManager;
+import android.text.ClipboardManager;
+import android.text.method.ScrollingMovementMethod;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.View.OnLongClickListener;
+import android.view.View.OnTouchListener;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.RelativeLayout;
+import android.widget.SlidingDrawer;
+import android.widget.SlidingDrawer.OnDrawerCloseListener;
+import android.widget.SlidingDrawer.OnDrawerOpenListener;
 import android.widget.TextView;
+import android.widget.Toast;
 
 public class Orbot extends Activity implements TorConstants, OnLongClickListener
 {
 	/* Useful UI bits */
 	private TextView lblStatus = null; //the main text display widget
-	private ImageView imgStatus = null; //the main touchable image for activating Orbot
-	private ProgressDialog progressDialog;
+	private ImageProgressView imgStatus = null; //the main touchable image for activating Orbot
+//	private ProgressDialog progressDialog;
 	private MenuItem mItemOnOff = null;
     private RelativeLayout trafficRow = null; // the row showing the traffic
     private TextView downloadText = null;
     private TextView uploadText = null;
+    private TextView mTxtOrbotLog = null;
+    private SlidingDrawer mDrawer = null;
+    private boolean mDrawerOpen = false;
 
 	/* Some tracking bits */
 	private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
@@ -92,14 +102,46 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
 		
     	lblStatus = (TextView)findViewById(R.id.lblStatus);
 		lblStatus.setOnLongClickListener(this);
-    	imgStatus = (ImageView)findViewById(R.id.imgStatus);
+    	imgStatus = (ImageProgressView)findViewById(R.id.imgStatus);
     	imgStatus.setOnLongClickListener(this);
     	trafficRow = (RelativeLayout)findViewById(R.id.trafficRow);
     	downloadText = (TextView)findViewById(R.id.trafficDown);
         uploadText = (TextView)findViewById(R.id.trafficUp);
+        mTxtOrbotLog = (TextView)findViewById(R.id.orbotLog);
         
+        mDrawer = ((SlidingDrawer)findViewById(R.id.SlidingDrawer));
+    	Button slideButton = (Button)findViewById(R.id.slideButton);
+    	slideButton.setOnTouchListener(new OnTouchListener (){
+
+			@Override
+			public boolean onTouch(View v, MotionEvent event) {
+
+				if (event.equals(MotionEvent.ACTION_DOWN))
+				{
+					mDrawerOpen = !mDrawerOpen;
+					mTxtOrbotLog.setEnabled(mDrawerOpen);				
+				}
+				return false;
+			}
+    		
+    	});
+    	
+        mTxtOrbotLog.setMovementMethod(new ScrollingMovementMethod());
+        mTxtOrbotLog.setOnLongClickListener(new View.OnLongClickListener() {
+         
 
-
+			@Override
+			public boolean onLongClick(View v) {
+				  ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
+	                cm.setText(mTxtOrbotLog.getText());
+	                Toast.makeText(Orbot.this, "LOG COPIED TO CLIPBOARD. PLEASE EMAIL TO help@xxxxxxxxxxxxxxxxxxxx TO DEBUG PROBLEM", Toast.LENGTH_SHORT).show();
+	            return true;
+			}
+        });
+        
+		downloadText.setText(formatCount(0) + " / " + formatTotal(0));
+		uploadText.setText(formatCount(0) + " / " + formatTotal(0));
+	
     }
     
    /*
@@ -249,7 +291,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
 		
 		unbindService();
 		
-		hideProgressDialog();
+		//hideProgressDialog();
 
 		if (aDialog != null)
 			aDialog.dismiss();
@@ -315,8 +357,6 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
 	protected void onResume() {
 		super.onResume();
 		
-//		setLocale();
-
     	bindService();
 		
 		if (getIntent() == null)
@@ -405,7 +445,6 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
 
 	@Override
 	public void onConfigurationChanged(Configuration newConfig) {
-		// TODO Auto-generated method stub
 		super.onConfigurationChanged(newConfig);
 	}
 
@@ -526,7 +565,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
                             {
                                     imgStatus.setImageResource(R.drawable.toron);
 
-                                    hideProgressDialog();
+                           //         hideProgressDialog();
                                     
                                     String lblMsg = getString(R.string.status_activated);
                                      
@@ -534,8 +573,8 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
                                     
                                     if (torServiceMsg != null && torServiceMsg.length() > 0)
                                     {
-                                    //        showAlert("Update", torServiceMsg, false);
-                                    	lblStatus.setText(torServiceMsg);
+                                    //        showAlert("Update", torServiceMsg,xte
+                                    	mTxtOrbotLog.append(torServiceMsg + "\n");
                                     }
                                     
                                     boolean showFirstTime = prefs.getBoolean("connect_first_time",true);
@@ -563,8 +602,10 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
                                     
                                     imgStatus.setImageResource(R.drawable.torstarting);
                                     
-                                    if (progressDialog != null)
-                                            progressDialog.setMessage(torServiceMsg);
+                                  //  if (progressDialog != null)
+                                    //        progressDialog.setMessage(torServiceMsg);
+                                    
+                                    mTxtOrbotLog.append(torServiceMsg + '\n');
                                     
                                     if (mItemOnOff != null)
                                             mItemOnOff.setTitle(R.string.menu_stop);
@@ -574,7 +615,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
                             {
 
 
-                                    hideProgressDialog();
+                                  //  hideProgressDialog();
                                     
                                     imgStatus.setImageResource(R.drawable.toroff);
                                     lblStatus.setText(getString(R.string.status_disabled) + "\n" + getString(R.string.press_to_start));
@@ -599,6 +640,9 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
     private void startTor () throws RemoteException
     {
             
+
+			mTxtOrbotLog.setText("");
+		
             // this is a bit of a strange/old/borrowed code/design i used to change the service state
             // not sure it really makes sense when what we want to say is just "startTor"
             mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on
@@ -624,8 +668,9 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
     		mService.setProfile(TorServiceConstants.PROFILE_OFF);
     		Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
     		mHandler.sendMessage(msg);
-            trafficRow.setVisibility(RelativeLayout.GONE);
+            //trafficRow.setVisibility(RelativeLayout.GONE);
 
+            
     	}
     	
      
@@ -637,32 +682,35 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
      */
         public boolean onLongClick(View view) {
                 
-                
-            try
-            {
-                    
-                if (mService != null && mService.getStatus() == TorServiceConstants.STATUS_OFF)
-                {
-                        
-                        createProgressDialog(getString(R.string.status_starting_up));
-
-                        startTor();
-                }
-                else
-                {
-                        
-                        stopTor();
-                        
-                }
-                
-                return true;
-                    
-            }
-            catch (Exception e)
-            {
-                    Log.d(TAG,"error onclick",e);
-            }
-            
+        	if (!mDrawerOpen)
+        	{
+	            try
+	            {
+	                    
+	                if (mService != null && mService.getStatus() == TorServiceConstants.STATUS_OFF)
+	                {
+	                        
+	                       // createProgressDialog(getString(R.string.status_starting_up));
+	
+	                        startTor();
+	                }
+	                else
+	                {
+	                        
+	                        stopTor();
+	                        
+	                }
+	                
+	                return true;
+	                    
+	            }
+	            catch (Exception e)
+	            {
+	                    Log.d(TAG,"error onclick",e);
+	            }
+
+        	}
+        	
             return false;
                     
         }
@@ -730,6 +778,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
         public void handleMessage(Message msg) {
             switch (msg.what) {
                 case TorServiceConstants.STATUS_MSG:
+                case TorServiceConstants.LOG_MSG:
 
                         String torServiceMsg = (String)msg.getData().getString(HANDLER_TOR_MSG);
                         
@@ -741,10 +790,6 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
                         }
                         
                     break;
-                case TorServiceConstants.LOG_MSG:
-                        
-                        
-                    break;
                 case TorServiceConstants.ENABLE_TOR_MSG:
                         
                         
@@ -760,7 +805,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
 
             	case TorServiceConstants.MESSAGE_TRAFFIC_COUNT :
                     
-            		trafficRow.setVisibility(RelativeLayout.VISIBLE);
+            		//trafficRow.setVisibility(RelativeLayout.VISIBLE);
             		Bundle data = msg.getData();
             		DataCount datacount =  new DataCount(data.getLong("upload"),data.getLong("download"));     
             		String TotalUpload = "";
@@ -897,6 +942,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
         }
     }
         
+    /*
     private void createProgressDialog (String msg)
     {
             if (progressDialog != null && progressDialog.isShowing())
@@ -920,6 +966,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
         }
                 
     }
+    */
     
     private void setLocale ()
     {
diff --git a/src/org/torproject/android/RandomColorCircleView.java b/src/org/torproject/android/RandomColorCircleView.java
new file mode 100644
index 0000000..aa25339
--- /dev/null
+++ b/src/org/torproject/android/RandomColorCircleView.java
@@ -0,0 +1,132 @@
+package org.torproject.android;
+
+import java.util.Random;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+
+public class RandomColorCircleView extends View
+{
+
+	  private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+
+	  private float initX, initY, radius;
+	  private boolean drawing = false;
+
+		Random rand = new Random();
+		
+
+	public RandomColorCircleView(Context context) {
+	 super(context);
+	 // TODO Auto-generated constructor stub
+	 init();
+	 
+	}
+
+	public RandomColorCircleView(Context context, AttributeSet attrs) {
+	 super(context, attrs);
+	 init();
+	}
+
+	public RandomColorCircleView(Context context, AttributeSet attrs, int defStyle) {
+	 super(context, attrs, defStyle);
+	 
+	 init();
+	}
+
+	private void init(){
+	 paint.setStyle(Paint.Style.FILL);
+	 paint.setColor(Color.WHITE);
+	 paint.setAntiAlias(true);
+
+	}
+
+	@Override
+	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+	   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+	   
+	   setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
+	   MeasureSpec.getSize(heightMeasureSpec));
+	 
+	}
+
+	int a1 = 30;
+	int a2 = 255;
+	
+	@Override
+	protected void onDraw(Canvas canvas) {
+
+		super.onDraw(canvas);
+		
+		for (int i = 0; i < 20; i++)
+		{
+			float r = rand.nextFloat()*255f;
+			float g = rand.nextFloat()*255f;
+			float b = rand.nextFloat()*255f;
+	
+			paint.setARGB(a1,(int)r,(int)g,(int)b);
+		
+			float x = rand.nextFloat() * getWidth();
+			float y = rand.nextFloat() * getHeight();
+
+			float w = rand.nextFloat() * getWidth();
+			float h = rand.nextFloat() * getHeight();
+			
+			canvas.drawCircle(x, y, w/2, paint);
+			
+			
+		}
+		
+	}
+	
+	int a1mod = 1;
+	
+	public void updateAlpha ()
+	{
+		a1 += a1mod;
+		
+		if (a1 > 255 || a1 < 0)
+			a1mod *= -1;
+		
+
+	}
+
+	@Override
+	public boolean onTouchEvent(MotionEvent event) {
+	 
+
+	 int action = event.getAction();
+	 if (action==MotionEvent.ACTION_MOVE){
+	  float x = event.getX();
+	  float y = event.getY();
+
+	 // radius = (float) Math.sqrt(Math.pow(x-initX, 2) + Math.pow(y-initY, 2));
+	  //updateAlpha();
+	  
+	     a1 = (int)(255*(y/((float)getHeight())));
+	  
+	 }
+	 else if (action==MotionEvent.ACTION_DOWN){
+	  initX = event.getX();
+	  initY = event.getY();
+	  radius = 1;
+	  drawing = true;
+	 
+	  
+	 }
+	 else if (action==MotionEvent.ACTION_UP){
+	  drawing = false;
+	 
+	  
+	 }
+	 
+	 return true;
+	 
+	}
+
+}
\ No newline at end of file
diff --git a/src/org/torproject/android/settings/AppManager.java b/src/org/torproject/android/settings/AppManager.java
index 0733030..46b33f1 100644
--- a/src/org/torproject/android/settings/AppManager.java
+++ b/src/org/torproject/android/settings/AppManager.java
@@ -212,7 +212,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
 			try {
 				PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS);
 				
-				if (pInfo != null && pInfo.permissions != null)
+				if (pInfo != null && pInfo.requestedPermissions != null)
 				{
 					for (String permInfo:pInfo.requestedPermissions)
 					{
diff --git a/src/org/torproject/android/wizard/Permissions.java b/src/org/torproject/android/wizard/Permissions.java
index a593c12..3b64b04 100644
--- a/src/org/torproject/android/wizard/Permissions.java
+++ b/src/org/torproject/android/wizard/Permissions.java
@@ -162,9 +162,11 @@ public class Permissions extends Activity implements TorConstants {
 				if (hasRoot)
 				{
 					try {
-						int resp = new TorTransProxy().testOwnerModule(context);
+						TorTransProxy ttProxy = new TorTransProxy();
 						
-						if (resp < 0)
+						int resp = ttProxy.testOwnerModule(context,ttProxy.getIpTablesPath(context));
+						
+						if (resp != 0)
 						{
 							hasRoot = false;
 							Toast.makeText(context, "ERROR: IPTables OWNER module not available", Toast.LENGTH_LONG).show();



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