add total display to data transfer UI

This commit is contained in:
n8fr8 2012-09-30 18:37:37 +05:30
parent eceede30f9
commit e8c3fdc1ed
3 changed files with 36 additions and 23 deletions

View File

@ -60,14 +60,15 @@
<RelativeLayout android:id="@+id/trafficRow"
android:gravity="bottom"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:visibility="invisible"
android:layout_height="80dp"
android:layout_height="wrap_content"
android:padding="6dp"
android:layout_marginTop="6dp"
android:background="#A0909090">
<TextView
android:id="@+id/trafficDownLabel"
android:textColor="#FFFFFFFF"
android:layout_width="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="16sp"
@ -77,7 +78,7 @@
<TextView
android:id="@+id/trafficUpLabel"
android:textColor="#FFFFFFFF"
android:layout_width="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/main_layout_upload"
@ -87,7 +88,7 @@
<TextView
android:id="@+id/trafficDown"
android:textColor="#FF00B627"
android:layout_width="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/trafficDownLabel"
@ -96,8 +97,8 @@
android:textStyle="bold" />
<TextView
android:id="@+id/trafficUp"
android:textColor="#FFFF2211"
android:layout_width="150dp"
android:textColor="#FF00B627"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/trafficUpLabel"

View File

@ -31,8 +31,8 @@
<string name="menu_about">About</string>
<string name="menu_wizard">Wizard</string>
<string name="main_layout_download">Download</string>
<string name="main_layout_upload">Upload</string>
<string name="main_layout_download">Download (speed/total)</string>
<string name="main_layout_upload">Upload (speed/total)</string>
<string name="button_help">Help</string>
<string name="button_close">Close</string>

View File

@ -764,22 +764,23 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
trafficRow.setVisibility(RelativeLayout.VISIBLE);
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();
String TotalUpload = "";
String TotalDownload = "";
try {
String TotalUpload = mService.getInfo("traffic/written");
String TotalDownload = mService.getInfo("traffic/read");
StringBuilder sb = new StringBuilder();
sb.append("Total Upload " + TotalUpload);
sb.append("Total Download" + TotalDownload);
Log.d(TAG,sb.toString());
TotalUpload = mService.getInfo("traffic/written");
TotalDownload = mService.getInfo("traffic/read");
} catch (RemoteException e) {
Log.d(TAG,"Total bandwidth error"+e.getMessage());
}
downloadText.setText(formatCount(datacount.Download) + " / " + formatTotal(Long.parseLong(TotalDownload)));
uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(Long.parseLong(TotalUpload)));
downloadText.invalidate();
uploadText.invalidate();
break;
default:
@ -955,4 +956,15 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
//return count+" kB";
}
private String formatTotal(long count) {
// Converts the supplied argument into a string.
// Under 2Mb, returns "xxx.xKb"
// Over 2Mb, returns "xxx.xxMb"
if (count < 1e6)
return ((float)((int)(count*10/1024))/10 + "KB");
return ((float)((int)(count*100/1024/1024))/100 + "MB");
//return count+" kB";
}
}