Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
509a4e79
Commit
509a4e79
authored
Nov 18, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add network traffic display in profile selector
parent
f4401f8b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
17 deletions
+39
-17
src/main/res/values-zh/strings.xml
src/main/res/values-zh/strings.xml
+4
-0
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+5
-0
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
...scala/com/github/shadowsocks/ProfileManagerActivity.scala
+16
-3
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
...n/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
+14
-14
No files found.
src/main/res/values-zh/strings.xml
View file @
509a4e79
...
...
@@ -74,6 +74,10 @@
<string
name=
"stat"
>
网络流量
</string>
<string
name=
"stat_summary"
>
发送:\t%1$s\t|\t接收:\t%2$s\n上传:\t%3$s\t|\t下载:\t%4$s
</string>
<string
name=
"stat_profiles"
>
\n发送:\t%1$s\t|\t接收:\t%2$s
</string>
<plurals
name=
"bytes"
>
<item
quantity=
"other"
>
字节
</item>
</plurals>
<!-- profile -->
<string
name=
"add_profile_dialog"
>
为影梭添加此配置文件?
</string>
...
...
src/main/res/values/strings.xml
View file @
509a4e79
...
...
@@ -14,6 +14,11 @@
<string
name=
"nat_summary_no_root"
>
NAT mode is disabled without root
</string>
<string
name=
"stat"
>
Network Traffic
</string>
<string
name=
"stat_summary"
>
Send: \t%1$s\t|\tReceive: \t%2$s\nUpload: \t%3$s\t|\tDownload: \t%4$s
</string>
<string
name=
"stat_profiles"
>
\nSend: \t%1$s\t|\tReceive: \t%2$s
</string>
<plurals
name=
"bytes"
>
<item
quantity=
"one"
>
Byte
</item>
<item
quantity=
"other"
>
Bytes
</item>
</plurals>
<!-- proxy category -->
<string
name=
"proxy_cat"
>
Server Settings
</string>
...
...
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
View file @
509a4e79
...
...
@@ -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
)
=
{
...
...
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
View file @
509a4e79
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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment