Traffic is shown in the main UI

This commit is contained in:
Sathyanarayanan Gunasekaran 2011-07-03 17:11:11 +05:30 committed by n8fr8
parent f181f26d4e
commit a2981152a7
2 changed files with 32 additions and 26 deletions

View File

@ -47,8 +47,6 @@ import android.widget.TextView;
public class Orbot extends Activity implements TorConstants, OnLongClickListener public class Orbot extends Activity implements TorConstants, OnLongClickListener
{ {
private static final int VISIBLE = 0;
/* 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 ImageView imgStatus = null; //the main touchable image for activating Orbot
@ -615,21 +613,20 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up)); msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up));
mHandler.sendMessage(msg); mHandler.sendMessage(msg);
trafficRow.setVisibility(VISIBLE); trafficRow.setVisibility(RelativeLayout.VISIBLE);
} }
//now we stop Tor! amazing! //now we stop Tor! amazing!
private void stopTor () throws RemoteException private void stopTor () throws RemoteException
{ {
//if the service is bound, then turn it off, using the same "PROFILE_" technique
if (mService != null) if (mService != null)
{ {
mService.setProfile(TorServiceConstants.PROFILE_OFF); 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); Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
mHandler.sendMessage(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 : 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)); downloadText.setText(formatCount(datacount.Download));
uploadText.setText(formatCount(datacount.Upload)); uploadText.setText(formatCount(datacount.Upload));
downloadText.invalidate();
uploadText.invalidate();
break; break;
@ -911,15 +908,16 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
public long Upload; public long Upload;
// data downloaded // data downloaded
public long Download; public long Download;
DataCount(long Upload, long Download){
this.Upload = Upload;
this.Download = Download;
}
} }
private String formatCount(long count) { private String formatCount(long count) {
// Converts the supplied argument into a string.
// Under 2Mb, returns "xxx.xKb" return count+" kB";
// 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");
} }
} }

View File

@ -41,9 +41,11 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.Parcelable;
import android.os.RemoteCallbackList; import android.os.RemoteCallbackList;
import android.os.RemoteException; import android.os.RemoteException;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -1125,10 +1127,16 @@ public class TorService extends Service implements TorServiceConstants, TorConst
datacount.Download = read/1000; datacount.Download = read/1000;
datacount.Upload = written/1000; datacount.Upload = written/1000;
Message message = Message.obtain(); Message msg = Message.obtain();
message.what = MESSAGE_TRAFFIC_COUNT; msg.what = MESSAGE_TRAFFIC_COUNT;
message.obj = datacount; //msg.obj = datacount;
Orbot.currentInstance.mHandler.sendMessage(message); Bundle data = new Bundle();
data.putLong("upload", datacount.Upload);
data.putLong("download", datacount.Download);
msg.setData(data);
Orbot.currentInstance.mHandler.sendMessage(msg);
//sendCallbackStatusMessage(message); //sendCallbackStatusMessage(message);