Improved Formatting

Now shows the data with upto 2 decimal places.
If under 2Mb, shows "xxx.xKb", else shows "xxx.xxMb"
This commit is contained in:
Sathyanarayanan Gunasekaran 2011-07-03 17:41:43 +05:30 committed by n8fr8
parent a2981152a7
commit e114be51d0
2 changed files with 17 additions and 7 deletions

View File

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

View File

@ -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) {