user interface updates - "log" drawer with up/down stats

This commit is contained in:
n8fr8 2012-10-01 12:35:48 +05:30
parent 331daa07b4
commit abebfd565e
5 changed files with 180 additions and 56 deletions

View File

@ -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);
}
}

View File

@ -11,12 +11,10 @@ import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.settings.ProcessSettingsAsyncTask; import org.torproject.android.settings.ProcessSettingsAsyncTask;
import org.torproject.android.settings.SettingsPreferences; import org.torproject.android.settings.SettingsPreferences;
import org.torproject.android.wizard.ChooseLocaleWizardActivity; import org.torproject.android.wizard.ChooseLocaleWizardActivity;
import org.torproject.android.wizard.LotsaText;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -33,28 +31,40 @@ import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.os.RemoteException; import android.os.RemoteException;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.ClipboardManager;
import android.text.method.ScrollingMovementMethod;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener; import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout; 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.TextView;
import android.widget.Toast;
public class Orbot extends Activity implements TorConstants, OnLongClickListener public class Orbot extends Activity implements TorConstants, OnLongClickListener
{ {
/* Useful UI bits */ /* Useful UI bits */
private TextView lblStatus = null; //the main text display widget private TextView lblStatus = null; //the main text display widget
private ImageView imgStatus = null; //the main touchable image for activating Orbot private ImageProgressView imgStatus = null; //the main touchable image for activating Orbot
private ProgressDialog progressDialog; // private ProgressDialog progressDialog;
private MenuItem mItemOnOff = null; private MenuItem mItemOnOff = null;
private RelativeLayout trafficRow = null; // the row showing the traffic private RelativeLayout trafficRow = null; // the row showing the traffic
private TextView downloadText = null; private TextView downloadText = null;
private TextView uploadText = null; private TextView uploadText = null;
private TextView mTxtOrbotLog = null;
private SlidingDrawer mDrawer = null;
private boolean mDrawerOpen = false;
/* Some tracking bits */ /* Some tracking bits */
private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
@ -92,13 +102,45 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
lblStatus = (TextView)findViewById(R.id.lblStatus); lblStatus = (TextView)findViewById(R.id.lblStatus);
lblStatus.setOnLongClickListener(this); lblStatus.setOnLongClickListener(this);
imgStatus = (ImageView)findViewById(R.id.imgStatus); imgStatus = (ImageProgressView)findViewById(R.id.imgStatus);
imgStatus.setOnLongClickListener(this); imgStatus.setOnLongClickListener(this);
trafficRow = (RelativeLayout)findViewById(R.id.trafficRow); trafficRow = (RelativeLayout)findViewById(R.id.trafficRow);
downloadText = (TextView)findViewById(R.id.trafficDown); downloadText = (TextView)findViewById(R.id.trafficDown);
uploadText = (TextView)findViewById(R.id.trafficUp); 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@guardianproject.info 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(); unbindService();
hideProgressDialog(); //hideProgressDialog();
if (aDialog != null) if (aDialog != null)
aDialog.dismiss(); aDialog.dismiss();
@ -315,8 +357,6 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
// setLocale();
bindService(); bindService();
if (getIntent() == null) if (getIntent() == null)
@ -405,7 +445,6 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
} }
@ -526,7 +565,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
{ {
imgStatus.setImageResource(R.drawable.toron); imgStatus.setImageResource(R.drawable.toron);
hideProgressDialog(); // hideProgressDialog();
String lblMsg = getString(R.string.status_activated); 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) if (torServiceMsg != null && torServiceMsg.length() > 0)
{ {
// showAlert("Update", torServiceMsg, false); // showAlert("Update", torServiceMsg,xte
lblStatus.setText(torServiceMsg); mTxtOrbotLog.append(torServiceMsg + "\n");
} }
boolean showFirstTime = prefs.getBoolean("connect_first_time",true); 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); imgStatus.setImageResource(R.drawable.torstarting);
if (progressDialog != null) // if (progressDialog != null)
progressDialog.setMessage(torServiceMsg); // progressDialog.setMessage(torServiceMsg);
mTxtOrbotLog.append(torServiceMsg + '\n');
if (mItemOnOff != null) if (mItemOnOff != null)
mItemOnOff.setTitle(R.string.menu_stop); 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); imgStatus.setImageResource(R.drawable.toroff);
lblStatus.setText(getString(R.string.status_disabled) + "\n" + getString(R.string.press_to_start)); 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 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 // 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" // not sure it really makes sense when what we want to say is just "startTor"
mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on
@ -624,7 +668,8 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
mService.setProfile(TorServiceConstants.PROFILE_OFF); mService.setProfile(TorServiceConstants.PROFILE_OFF);
Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG); Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
mHandler.sendMessage(msg); mHandler.sendMessage(msg);
trafficRow.setVisibility(RelativeLayout.GONE); //trafficRow.setVisibility(RelativeLayout.GONE);
} }
@ -637,14 +682,15 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
*/ */
public boolean onLongClick(View view) { public boolean onLongClick(View view) {
if (!mDrawerOpen)
{
try try
{ {
if (mService != null && mService.getStatus() == TorServiceConstants.STATUS_OFF) if (mService != null && mService.getStatus() == TorServiceConstants.STATUS_OFF)
{ {
createProgressDialog(getString(R.string.status_starting_up)); // createProgressDialog(getString(R.string.status_starting_up));
startTor(); startTor();
} }
@ -663,6 +709,8 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
Log.d(TAG,"error onclick",e); Log.d(TAG,"error onclick",e);
} }
}
return false; return false;
} }
@ -730,6 +778,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
switch (msg.what) { switch (msg.what) {
case TorServiceConstants.STATUS_MSG: case TorServiceConstants.STATUS_MSG:
case TorServiceConstants.LOG_MSG:
String torServiceMsg = (String)msg.getData().getString(HANDLER_TOR_MSG); String torServiceMsg = (String)msg.getData().getString(HANDLER_TOR_MSG);
@ -740,10 +789,6 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
lastServiceMsg = torServiceMsg; lastServiceMsg = torServiceMsg;
} }
break;
case TorServiceConstants.LOG_MSG:
break; break;
case TorServiceConstants.ENABLE_TOR_MSG: case TorServiceConstants.ENABLE_TOR_MSG:
@ -760,7 +805,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
case TorServiceConstants.MESSAGE_TRAFFIC_COUNT : case TorServiceConstants.MESSAGE_TRAFFIC_COUNT :
trafficRow.setVisibility(RelativeLayout.VISIBLE); //trafficRow.setVisibility(RelativeLayout.VISIBLE);
Bundle data = msg.getData(); Bundle data = msg.getData();
DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download")); DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download"));
String TotalUpload = ""; String TotalUpload = "";
@ -897,6 +942,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
} }
} }
/*
private void createProgressDialog (String msg) private void createProgressDialog (String msg)
{ {
if (progressDialog != null && progressDialog.isShowing()) if (progressDialog != null && progressDialog.isShowing())
@ -920,6 +966,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
} }
} }
*/
private void setLocale () private void setLocale ()
{ {

View File

@ -6,14 +6,11 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.MeasureSpec;
public class AnimatedBlockView extends View public class RandomColorCircleView extends View
{ {
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
@ -24,19 +21,19 @@ public class AnimatedBlockView extends View
Random rand = new Random(); Random rand = new Random();
public AnimatedBlockView(Context context) { public RandomColorCircleView(Context context) {
super(context); super(context);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
init(); init();
} }
public AnimatedBlockView(Context context, AttributeSet attrs) { public RandomColorCircleView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init(); init();
} }
public AnimatedBlockView(Context context, AttributeSet attrs, int defStyle) { public RandomColorCircleView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
init(); init();

View File

@ -212,7 +212,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
try { try {
PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS); 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) for (String permInfo:pInfo.requestedPermissions)
{ {

View File

@ -162,9 +162,11 @@ public class Permissions extends Activity implements TorConstants {
if (hasRoot) if (hasRoot)
{ {
try { 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; hasRoot = false;
Toast.makeText(context, "ERROR: IPTables OWNER module not available", Toast.LENGTH_LONG).show(); Toast.makeText(context, "ERROR: IPTables OWNER module not available", Toast.LENGTH_LONG).show();