diff --git a/src/main/res/values-zh/strings.xml b/src/main/res/values-zh/strings.xml
index 02d6f29d..75a7070a 100755
--- a/src/main/res/values-zh/strings.xml
+++ b/src/main/res/values-zh/strings.xml
@@ -74,6 +74,10 @@
网络流量
发送:\t%1$s\t|\t接收:\t%2$s\n上传:\t%3$s\t|\t下载:\t%4$s
+ \n发送:\t%1$s\t|\t接收:\t%2$s
+
+ - 字节
+
为影梭添加此配置文件?
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 397155f6..888e211a 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -14,6 +14,11 @@
NAT mode is disabled without root
Network Traffic
Send: \t%1$s\t|\tReceive: \t%2$s\nUpload: \t%3$s\t|\tDownload: \t%4$s
+ \nSend: \t%1$s\t|\tReceive: \t%2$s
+
+ - Byte
+ - Bytes
+
Server Settings
diff --git a/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala b/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
index 5297827a..975a0a38 100644
--- a/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
+++ b/src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
@@ -10,11 +10,13 @@ import android.support.v7.widget.Toolbar.OnMenuItemClickListener
import android.support.v7.widget.helper.ItemTouchHelper
import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback
import android.support.v7.widget.{DefaultItemAnimator, LinearLayoutManager, RecyclerView, Toolbar}
+import android.text.style.TextAppearanceSpan
+import android.text.{Spanned, SpannableStringBuilder}
import android.view.View.{OnAttachStateChangeListener, OnClickListener}
import android.view.{LayoutInflater, MenuItem, View, ViewGroup}
import android.widget.{LinearLayout, ImageView, CheckedTextView, Toast}
import com.github.shadowsocks.database.Profile
-import com.github.shadowsocks.utils.{Parser, Utils}
+import com.github.shadowsocks.utils.{TrafficMonitor, Parser, Utils}
import com.google.zxing.integration.android.IntentIntegrator
import net.glxn.qrgen.android.QRCode
@@ -54,10 +56,21 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
})
}
+ def updateText() {
+ val builder = new SpannableStringBuilder
+ builder.append(item.name)
+ val start = builder.length
+ builder.append(getString(R.string.stat_profiles,
+ TrafficMonitor.formatTraffic(item.tx), TrafficMonitor.formatTraffic(item.rx)))
+ builder.setSpan(new TextAppearanceSpan(ProfileManagerActivity.this, android.R.style.TextAppearance_Small),
+ start + 1, builder.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+ text.setText(builder)
+ }
+
def bind(item: Profile) {
- text.setText(item.name)
- text.setChecked(item.id == ShadowsocksApplication.profileId)
this.item = item
+ updateText()
+ text.setChecked(item.id == ShadowsocksApplication.profileId)
}
def onClick(v: View) = {
diff --git a/src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala b/src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
index 00a737bf..3236a026 100644
--- a/src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
+++ b/src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
@@ -1,10 +1,11 @@
package com.github.shadowsocks.utils
import java.lang.{Math, System}
-import java.util.Locale
+import java.text.DecimalFormat
import android.net.TrafficStats
import android.os.Process
+import com.github.shadowsocks.{R, ShadowsocksApplication}
case class Traffic(tx: Long, rx: Long, timestamp: Long)
@@ -25,18 +26,17 @@ object TrafficMonitor {
Math.max(TrafficStats.getTotalRxBytes - TrafficStats.getUidRxBytes(uid), 0), System.currentTimeMillis())
}
- def formatTraffic(n: Long): String = {
- if (n <= 1024) {
- "%d KB".formatLocal(Locale.ENGLISH, n)
- } else if (n > 1024) {
- "%d MB".formatLocal(Locale.ENGLISH, n / 1024)
- } else if (n > 1024 * 1024) {
- "%d GB".formatLocal(Locale.ENGLISH, n / 1024 / 1024)
- } else if (n > 1024 * 1024 * 1024) {
- "%d TB".formatLocal(Locale.ENGLISH, n / 1024 / 1024 / 1024)
- } else {
- ">1024 TB"
+ private val units = Array("KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "BB", "NB", "DB", "CB")
+ private val numberFormat = new DecimalFormat("0.00")
+ def formatTraffic(size: Long): String = {
+ var n: Double = size
+ var i = -1
+ while (n >= 1024) {
+ n /= 1024
+ i = i + 1
}
+ if (i < 0) size + " " + ShadowsocksApplication.instance.getResources.getQuantityString(R.plurals.bytes, size.toInt)
+ else numberFormat.format(n) + ' ' + units(i)
}
def update() {
@@ -46,8 +46,8 @@ object TrafficMonitor {
txRate = (now.tx - last.tx) / delta
rxRate = (now.rx - last.rx) / delta
}
- txTotal += (now.tx - last.tx) / 1024
- rxTotal += (now.rx - last.rx) / 1024
+ txTotal += now.tx - last.tx
+ rxTotal += now.rx - last.rx
last = now
}