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
713ff530
Commit
713ff530
authored
Jan 24, 2016
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine Traffic Stat
parent
35f17f53
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
204 additions
and
19 deletions
+204
-19
project/plugins.sbt
project/plugins.sbt
+4
-1
src/main/res/layout/status_pref.xml
src/main/res/layout/status_pref.xml
+108
-0
src/main/res/values-zh/strings.xml
src/main/res/values-zh/strings.xml
+10
-6
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+10
-4
src/main/res/xml/pref_all.xml
src/main/res/xml/pref_all.xml
+4
-1
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+14
-5
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
...in/scala/com/github/shadowsocks/ShadowsocksSettings.scala
+8
-2
src/main/scala/com/github/shadowsocks/preferences/StatusPreference.scala
...com/github/shadowsocks/preferences/StatusPreference.scala
+46
-0
No files found.
project/plugins.sbt
View file @
713ff530
resolvers
+=
Resolver
.
url
(
"scalasbt releases"
,
new
URL
(
"http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-snapshots"
))(
Resolver
.
ivyStylePatterns
)
addSbtPlugin
(
"com.hanhuy.sbt"
%
"android-sdk-plugin"
%
"1.5.13"
)
addSbtPlugin
(
"com.hanhuy.sbt"
%
"android-sdk-plugin"
%
"1.5.14"
)
resolvers
+=
"Sonatype snapshots"
at
"https://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin
(
"com.github.mpeltonen"
%
"sbt-idea"
%
"1.7.0-SNAPSHOT"
)
resolvers
+=
Resolver
.
url
(
"rtimush/sbt-plugin-snapshots"
,
new
URL
(
"https://dl.bintray.com/rtimush/sbt-plugin-snapshots/"
))(
Resolver
.
ivyStylePatterns
)
addSbtPlugin
(
"com.timushev.sbt"
%
"sbt-updates"
%
"0.1.9-6-g5a7705c"
)
src/main/res/layout/status_pref.xml
0 → 100644
View file @
713ff530
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@android:id/widget_frame"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:minHeight=
"?android:attr/listPreferredItemHeight"
android:gravity=
"center_vertical"
android:paddingEnd=
"?android:attr/scrollbarSize"
android:background=
"?android:attr/selectableItemBackground"
android:orientation=
"vertical"
>
<TableLayout
android:layout_marginLeft=
"15dip"
android:layout_marginRight=
"6dip"
android:layout_marginTop=
"6dip"
android:layout_marginBottom=
"6dip"
android:stretchColumns=
"3"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<TableRow
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
android:layout_column=
"0"
android:layout_span=
"2"
android:id=
"@android:id/title"
android:textSize=
"16sp"
android:textColor=
"?android:attr/textColorPrimary"
android:ellipsize=
"marquee"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:layout_column=
"3"
android:id=
"@android:id/summary"
android:textSize=
"14sp"
android:textColor=
"?android:attr/textColorSecondary"
android:ellipsize=
"marquee"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"end"
/>
</TableRow>
<TableRow
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
android:layout_column=
"0"
style=
"@style/TextAppearance.AppCompat.Body2"
android:ellipsize=
"marquee"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginRight=
"24dp"
android:gravity=
"end"
android:text=
"@string/sent"
/>
<TextView
android:layout_column=
"1"
android:id=
"@+id/tx"
style=
"@style/TextAppearance.AppCompat.Caption"
android:ellipsize=
"marquee"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"end"
android:text=
"0 Byte"
/>
<TextView
android:layout_column=
"3"
android:id=
"@+id/txRate"
style=
"@style/TextAppearance.AppCompat.Caption"
android:ellipsize=
"marquee"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"end"
android:text=
"▲ 0 B/s"
/>
</TableRow>
<TableRow
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
android:layout_column=
"0"
style=
"@style/TextAppearance.AppCompat.Body2"
android:ellipsize=
"marquee"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginRight=
"24dp"
android:gravity=
"end"
android:text=
"@string/received"
/>
<TextView
android:layout_column=
"1"
android:id=
"@+id/rx"
style=
"@style/TextAppearance.AppCompat.Caption"
android:ellipsize=
"marquee"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"end"
android:text=
"0 Byte"
/>
<TextView
android:layout_column=
"3"
android:id=
"@+id/rxRate"
style=
"@style/TextAppearance.AppCompat.Caption"
android:ellipsize=
"marquee"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"end"
android:text=
"▼ 0 B/s"
/>
</TableRow>
</TableLayout>
</LinearLayout>
src/main/res/values-zh/strings.xml
View file @
713ff530
...
...
@@ -75,14 +75,13 @@
<string
name=
"stat"
>
网络流量
</string>
<string
name=
"stat_summary"
>
发送: \t%3$s\t↑\t%1$s/s\n接收: \t%4$s\t↓\t%2$s/s
</string>
<plurals
name=
"bytes"
>
<item
quantity=
"other"
>
字节
</item>
</plurals>
<string
name=
"connection_test_pending"
>
点击检查是否接入互联网。
</string>
<string
name=
"connection_test_pending"
>
检查网络连接
</string>
<string
name=
"connection_test_testing"
>
测试中……
</string>
<string
name=
"connection_test_available"
>
已接入互联网。(延时:%d 毫秒)
</string>
<string
name=
"connection_test_available"
>
连接有效: 延时 %d 毫秒
</string>
<string
name=
"connection_test_fail"
>
无互联网连接
</string>
<string
name=
"connection_test_error"
>
失败:%s
</string>
<string
name=
"connection_test_error_status_code"
>
状态码无效
。
(#%d)
</string>
<string
name=
"connection_test_error_status_code"
>
状态码无效(#%d)
</string>
<!-- profile -->
<string
name=
"profile_manager_dialog"
>
配置文件
</string>
...
...
@@ -114,4 +113,9 @@
<string
name=
"stop_service"
>
切换到 %s
</string>
<string
name=
"profile_default"
>
使用当前配置
</string>
<!-- status -->
<string
name=
"sent"
>
发送:
</string>
<string
name=
"received"
>
接收:
</string>
<string
name=
"check_connectivity"
>
检查网络连接
</string>
</resources>
src/main/res/values/strings.xml
View file @
713ff530
...
...
@@ -19,11 +19,12 @@
<item
quantity=
"one"
>
Byte
</item>
<item
quantity=
"other"
>
Bytes
</item>
</plurals>
<string
name=
"connection_test_pending"
>
Tap to check Internet connection availability.
</string>
<string
name=
"connection_test_pending"
>
Check Connectivity
</string>
<string
name=
"connection_test_testing"
>
Testing…
</string>
<string
name=
"connection_test_available"
>
Internet connection available. (latency: %dms)
</string>
<string
name=
"connection_test_error"
>
Fail: %s
</string>
<string
name=
"connection_test_error_status_code"
>
Invalid status code. (#%d)
</string>
<string
name=
"connection_test_available"
>
Success: %dms latency to Internet
</string>
<string
name=
"connection_test_error"
>
Fail to detect internet connection: %s
</string>
<string
name=
"connection_test_fail"
>
Internet Unavailable
</string>
<string
name=
"connection_test_error_status_code"
>
Error code: #%d
</string>
<!-- proxy category -->
<string
name=
"proxy_cat"
>
Server Settings
</string>
...
...
@@ -119,4 +120,9 @@
<string
name=
"start_service"
>
Connect to %s
</string>
<string
name=
"stop_service"
>
Switch to %s
</string>
<string
name=
"profile_default"
>
Use the current profile
</string>
<!-- status -->
<string
name=
"sent"
>
Sent:
</string>
<string
name=
"received"
>
Received:
</string>
<string
name=
"check_connectivity"
>
Check Connectivity
</string>
</resources>
src/main/res/xml/pref_all.xml
View file @
713ff530
...
...
@@ -8,7 +8,10 @@
<intent
android:action=
"com.github.shadowsocks.ProfileManagerActivity"
/>
</Preference>
<Preference
android:key=
"stat"
android:title=
"@string/stat"
/>
<com.github.shadowsocks.preferences.StatusPreference
android:key=
"stat"
android:summary=
"@string/check_connectivity"
android:title=
"@string/stat"
/>
</PreferenceCategory>
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
713ff530
...
...
@@ -58,6 +58,7 @@ import android.view.{View, ViewGroup, ViewParent}
import
android.widget._
import
com.github.jorgecastilloprz.FABProgressCircle
import
com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import
com.github.shadowsocks.preferences._
import
com.github.shadowsocks.database._
import
com.github.shadowsocks.utils._
import
com.google.android.gms.ads.
{
AdRequest
,
AdSize
,
AdView
}
...
...
@@ -106,8 +107,9 @@ class Shadowsocks
var
state
=
State
.
STOPPED
var
currentProfile
=
new
Profile
var
vpnEnabled
=
-
1
var
trafficCache
:
String
=
_
var
trafficCache
:
Array
[
String
]
=
_
var
connectionTestResult
:
String
=
_
var
connectionTestSuccess
:
Boolean
=
true
// Services
var
currentServiceName
=
classOf
[
ShadowsocksNatService
].
getName
...
...
@@ -155,8 +157,9 @@ class Shadowsocks
})
}
def
trafficUpdated
(
txRate
:
Long
,
rxRate
:
Long
,
txTotal
:
Long
,
rxTotal
:
Long
)
{
trafficCache
=
getString
(
R
.
string
.
stat_summary
).
formatLocal
(
Locale
.
ENGLISH
,
TrafficMonitor
.
formatTraffic
(
txRate
),
TrafficMonitor
.
formatTraffic
(
rxRate
),
trafficCache
=
Array
(
"▲ "
+
TrafficMonitor
.
formatTraffic
(
txRate
)
+
"/s"
,
"▼ "
+
TrafficMonitor
.
formatTraffic
(
rxRate
)
+
"/s"
,
TrafficMonitor
.
formatTraffic
(
txTotal
),
TrafficMonitor
.
formatTraffic
(
rxTotal
))
handler
.
post
(
updateTraffic
)
}
...
...
@@ -165,10 +168,16 @@ class Shadowsocks
def
updateTraffic
()
:
Unit
=
if
(
trafficCache
==
null
)
callback
.
trafficUpdated
(
0
,
0
,
0
,
0
)
else
{
if
(
connectionTestResult
==
null
)
connectionTestResult
=
getString
(
R
.
string
.
connection_test_pending
)
if
(
preferences
.
natSwitch
.
isChecked
)
{
preferences
.
stat
.
setSummary
(
trafficCache
)
preferences
.
stat
.
setSummary
(
""
)
}
else
{
preferences
.
stat
.
setSummary
(
connectionTestResult
+
"\n"
+
trafficCache
)
if
(
connectionTestSuccess
)
{
preferences
.
stat
.
setSummary
(
connectionTestResult
)
}
else
{
preferences
.
stat
.
setSummary
(
getString
(
R
.
string
.
connection_test_fail
))
Snackbar
.
make
(
findViewById
(
android
.
R
.
id
.
content
),
connectionTestResult
,
Snackbar
.
LENGTH_LONG
).
show
}
}
preferences
.
stat
.
asInstanceOf
[
StatusPreference
].
setRate
(
trafficCache
(
2
),
trafficCache
(
3
),
trafficCache
(
0
),
trafficCache
(
1
))
}
def
attachService
:
Unit
=
attachService
(
callback
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
View file @
713ff530
...
...
@@ -78,11 +78,12 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
addPreferencesFromResource
(
R
.
xml
.
pref_all
)
getPreferenceManager
.
getSharedPreferences
.
registerOnSharedPreferenceChangeListener
(
this
)
stat
=
findPreference
(
Key
.
stat
)
stat
=
findPreference
(
Key
.
stat
)
stat
.
setOnPreferenceClickListener
(
_
=>
{
val
id
=
synchronized
{
testCount
+=
1
activity
.
connectionTestResult
=
getString
(
R
.
string
.
connection_test_testing
)
activity
.
connectionTestSuccess
=
true
activity
.
updateTraffic
()
testCount
}
...
...
@@ -96,6 +97,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
conn
.
setUseCaches
(
false
)
if
(
testCount
==
id
)
{
var
result
:
String
=
null
var
success
:
Boolean
=
true
try
{
val
start
=
currentTimeMillis
conn
.
getInputStream
...
...
@@ -105,9 +107,13 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
result
=
getString
(
R
.
string
.
connection_test_available
,
elapsed
:
java.lang.Long
)
else
throw
new
Exception
(
getString
(
R
.
string
.
connection_test_error_status_code
,
code
:
Integer
))
}
catch
{
case
e
:
Exception
=>
result
=
getString
(
R
.
string
.
connection_test_error
,
e
.
getMessage
)
case
e
:
Exception
=>
{
success
=
false
result
=
getString
(
R
.
string
.
connection_test_error
,
e
.
getMessage
)
}
}
synchronized
(
if
(
testCount
==
id
)
{
activity
.
connectionTestSuccess
=
success
activity
.
connectionTestResult
=
result
activity
.
handler
.
post
(
activity
.
updateTraffic
)
})
...
...
src/main/scala/com/github/shadowsocks/preferences/StatusPreference.scala
0 → 100644
View file @
713ff530
package
com.github.shadowsocks.preferences
import
android.content.Context
import
android.preference.Preference
import
android.view.
{
View
,
ViewGroup
,
LayoutInflater
}
import
android.util.AttributeSet
import
android.widget.TextView
import
com.github.shadowsocks.R
/**
* @author madeye
*/
final
class
StatusPreference
(
context
:
Context
,
attrs
:
AttributeSet
=
null
)
extends
Preference
(
context
,
attrs
)
{
var
txView
:
TextView
=
null
var
rxView
:
TextView
=
null
var
txRateView
:
TextView
=
null
var
rxRateView
:
TextView
=
null
override
def
onCreateView
(
parent
:
ViewGroup
)
:
View
=
{
val
li
=
getContext
().
getSystemService
(
Context
.
LAYOUT_INFLATER_SERVICE
).
asInstanceOf
[
LayoutInflater
]
val
view
=
li
.
inflate
(
R
.
layout
.
status_pref
,
parent
,
false
)
txView
=
view
.
findViewById
(
R
.
id
.
tx
).
asInstanceOf
[
TextView
]
rxView
=
view
.
findViewById
(
R
.
id
.
rx
).
asInstanceOf
[
TextView
]
txRateView
=
view
.
findViewById
(
R
.
id
.
txRate
).
asInstanceOf
[
TextView
]
rxRateView
=
view
.
findViewById
(
R
.
id
.
rxRate
).
asInstanceOf
[
TextView
]
view
}
def
setRate
(
tx
:
String
,
rx
:
String
,
txRate
:
String
,
rxRate
:
String
)
{
if
(
txView
!=
null
)
{
txView
.
setText
(
tx
)
}
if
(
rxView
!=
null
)
{
rxView
.
setText
(
rx
)
}
if
(
txRateView
!=
null
)
{
txRateView
.
setText
(
txRate
)
}
if
(
rxRateView
!=
null
)
{
rxRateView
.
setText
(
rxRate
)
}
}
}
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