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
04c86a53
Commit
04c86a53
authored
Dec 29, 2015
by
Max Lv
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #502 from Mygod/master
Fix dynamic traffic stat in profile selector
parents
5ddd8a16
f9667d76
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
51 deletions
+26
-51
src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksServiceCallback.aidl
.../github/shadowsocks/aidl/IShadowsocksServiceCallback.aidl
+1
-2
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+5
-6
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
...scala/com/github/shadowsocks/ProfileManagerActivity.scala
+7
-9
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+5
-4
src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala
...cala/com/github/shadowsocks/ShadowsocksNotification.scala
+8
-6
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
...n/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
+0
-24
No files found.
src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksServiceCallback.aidl
View file @
04c86a53
...
@@ -2,6 +2,5 @@ package com.github.shadowsocks.aidl;
...
@@ -2,6 +2,5 @@ package com.github.shadowsocks.aidl;
interface
IShadowsocksServiceCallback
{
interface
IShadowsocksServiceCallback
{
oneway
void
stateChanged
(
int
state
,
String
msg
);
oneway
void
stateChanged
(
int
state
,
String
msg
);
oneway
void
trafficUpdated
(
String
txRate
,
String
rxRate
,
oneway
void
trafficUpdated
(
long
txRate
,
long
rxRate
,
long
txTotal
,
long
rxTotal
);
String
txTotal
,
String
rxTotal
);
}
}
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
04c86a53
...
@@ -90,8 +90,7 @@ trait BaseService extends Service {
...
@@ -90,8 +90,7 @@ trait BaseService extends Service {
timer
.
schedule
(
task
,
1000
,
1000
)
timer
.
schedule
(
task
,
1000
,
1000
)
}
}
TrafficMonitor
.
updateRate
()
TrafficMonitor
.
updateRate
()
cb
.
trafficUpdated
(
TrafficMonitor
.
getTxRate
,
TrafficMonitor
.
getRxRate
,
cb
.
trafficUpdated
(
TrafficMonitor
.
txRate
,
TrafficMonitor
.
rxRate
,
TrafficMonitor
.
txTotal
,
TrafficMonitor
.
rxTotal
)
TrafficMonitor
.
getTxTotal
,
TrafficMonitor
.
getRxTotal
)
}
}
}
}
...
@@ -162,10 +161,10 @@ trait BaseService extends Service {
...
@@ -162,10 +161,10 @@ trait BaseService extends Service {
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
handler
.
post
(()
=>
{
handler
.
post
(()
=>
{
if
(
callbacksCount
>
0
)
{
if
(
callbacksCount
>
0
)
{
val
txRate
=
TrafficMonitor
.
getT
xRate
val
txRate
=
TrafficMonitor
.
t
xRate
val
rxRate
=
TrafficMonitor
.
getR
xRate
val
rxRate
=
TrafficMonitor
.
r
xRate
val
txTotal
=
TrafficMonitor
.
getT
xTotal
val
txTotal
=
TrafficMonitor
.
t
xTotal
val
rxTotal
=
TrafficMonitor
.
getR
xTotal
val
rxTotal
=
TrafficMonitor
.
r
xTotal
val
n
=
callbacks
.
beginBroadcast
()
val
n
=
callbacks
.
beginBroadcast
()
for
(
i
<-
0
until
n
)
{
for
(
i
<-
0
until
n
)
{
try
{
try
{
...
...
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
View file @
04c86a53
...
@@ -61,17 +61,15 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -61,17 +61,15 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
})
})
}
}
def
updateText
(
refetch
:
Boolean
=
false
)
{
def
updateText
(
txTotal
:
Long
=
0
,
rxTotal
:
Long
=
0
)
{
val
builder
=
new
SpannableStringBuilder
val
builder
=
new
SpannableStringBuilder
val
item
=
if
(
refetch
)
ShadowsocksApplication
.
profileManager
.
getProfile
(
this
.
item
.
id
)
match
{
val
tx
=
item
.
tx
+
txTotal
case
Some
(
profile
)
=>
profile
val
rx
=
item
.
rx
+
rxTotal
case
None
=>
return
}
else
this
.
item
builder
.
append
(
item
.
name
)
builder
.
append
(
item
.
name
)
if
(
item
.
tx
!=
0
||
item
.
rx
!=
0
)
{
if
(
tx
!=
0
||
rx
!=
0
)
{
val
start
=
builder
.
length
val
start
=
builder
.
length
builder
.
append
(
getString
(
R
.
string
.
stat_profiles
,
builder
.
append
(
getString
(
R
.
string
.
stat_profiles
,
TrafficMonitor
.
formatTraffic
(
item
.
tx
),
TrafficMonitor
.
formatTraffic
(
item
.
rx
)))
TrafficMonitor
.
formatTraffic
(
tx
),
TrafficMonitor
.
formatTraffic
(
rx
)))
builder
.
setSpan
(
new
TextAppearanceSpan
(
ProfileManagerActivity
.
this
,
android
.
R
.
style
.
TextAppearance_Small
),
builder
.
setSpan
(
new
TextAppearanceSpan
(
ProfileManagerActivity
.
this
,
android
.
R
.
style
.
TextAppearance_Small
),
start
+
1
,
builder
.
length
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
start
+
1
,
builder
.
length
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
...
@@ -207,8 +205,8 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -207,8 +205,8 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
attachService
(
new
IShadowsocksServiceCallback
.
Stub
{
attachService
(
new
IShadowsocksServiceCallback
.
Stub
{
def
stateChanged
(
state
:
Int
,
msg
:
String
)
=
()
// ignore
def
stateChanged
(
state
:
Int
,
msg
:
String
)
=
()
// ignore
def
trafficUpdated
(
txRate
:
String
,
rxRate
:
String
,
txTotal
:
String
,
rxTotal
:
Stri
ng
)
=
def
trafficUpdated
(
txRate
:
Long
,
rxRate
:
Long
,
txTotal
:
Long
,
rxTotal
:
Lo
ng
)
=
if
(
selectedItem
!=
null
)
selectedItem
.
updateText
(
t
rue
)
if
(
selectedItem
!=
null
)
selectedItem
.
updateText
(
t
xTotal
,
rxTotal
)
})
})
if
(
ShadowsocksApplication
.
settings
.
getBoolean
(
profileTip
,
true
))
{
if
(
ShadowsocksApplication
.
settings
.
getBoolean
(
profileTip
,
true
))
{
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
04c86a53
...
@@ -154,14 +154,15 @@ class Shadowsocks
...
@@ -154,14 +154,15 @@ class Shadowsocks
state
=
s
state
=
s
})
})
}
}
def
trafficUpdated
(
txRate
:
String
,
rxRate
:
String
,
txTotal
:
String
,
rxTotal
:
String
)
{
def
trafficUpdated
(
txRate
:
Long
,
rxRate
:
Long
,
txTotal
:
Long
,
rxTotal
:
Long
)
{
trafficCache
=
getString
(
R
.
string
.
stat_summary
).
formatLocal
(
Locale
.
ENGLISH
,
txRate
,
rxRate
,
txTotal
,
rxTotal
)
trafficCache
=
getString
(
R
.
string
.
stat_summary
).
formatLocal
(
Locale
.
ENGLISH
,
TrafficMonitor
.
formatTraffic
(
txRate
),
TrafficMonitor
.
formatTraffic
(
rxRate
),
TrafficMonitor
.
formatTraffic
(
txTotal
),
TrafficMonitor
.
formatTraffic
(
rxTotal
))
handler
.
post
(
updateTraffic
)
handler
.
post
(
updateTraffic
)
}
}
}
}
def
updateTraffic
()
:
Unit
=
if
(
trafficCache
==
null
)
callback
.
trafficUpdated
(
TrafficMonitor
.
getTxRate
,
def
updateTraffic
()
:
Unit
=
if
(
trafficCache
==
null
)
callback
.
trafficUpdated
(
0
,
0
,
0
,
0
)
else
{
TrafficMonitor
.
getRxRate
,
TrafficMonitor
.
getTxTotal
,
TrafficMonitor
.
getRxTotal
)
else
{
if
(
connectionTestResult
==
null
)
connectionTestResult
=
getString
(
R
.
string
.
connection_test_pending
)
if
(
connectionTestResult
==
null
)
connectionTestResult
=
getString
(
R
.
string
.
connection_test_pending
)
if
(
preferences
.
natSwitch
.
isChecked
)
{
if
(
preferences
.
natSwitch
.
isChecked
)
{
preferences
.
stat
.
setSummary
(
trafficCache
)
preferences
.
stat
.
setSummary
(
trafficCache
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala
View file @
04c86a53
...
@@ -9,20 +9,22 @@ import android.support.v4.app.NotificationCompat
...
@@ -9,20 +9,22 @@ import android.support.v4.app.NotificationCompat
import
android.support.v4.app.NotificationCompat.BigTextStyle
import
android.support.v4.app.NotificationCompat.BigTextStyle
import
android.support.v4.content.ContextCompat
import
android.support.v4.content.ContextCompat
import
com.github.shadowsocks.aidl.IShadowsocksServiceCallback.Stub
import
com.github.shadowsocks.aidl.IShadowsocksServiceCallback.Stub
import
com.github.shadowsocks.utils.
{
Action
,
State
,
Utils
}
import
com.github.shadowsocks.utils.
{
TrafficMonitor
,
Action
,
State
,
Utils
}
/**
/**
* @author Mygod
* @author Mygod
*/
*/
class
ShadowsocksNotification
(
private
val
service
:
BaseService
,
profileName
:
String
,
visible
:
Boolean
=
false
)
{
class
ShadowsocksNotification
(
private
val
service
:
BaseService
,
profileName
:
String
,
visible
:
Boolean
=
false
)
{
private
lazy
val
keyGuard
=
service
.
getSystemService
(
Context
.
KEYGUARD_SERVICE
).
asInstanceOf
[
KeyguardManager
]
private
val
keyGuard
=
service
.
getSystemService
(
Context
.
KEYGUARD_SERVICE
).
asInstanceOf
[
KeyguardManager
]
private
lazy
val
nm
=
service
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
).
asInstanceOf
[
NotificationManager
]
private
lazy
val
nm
=
service
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
).
asInstanceOf
[
NotificationManager
]
private
lazy
val
callback
=
new
Stub
{
private
lazy
val
callback
=
new
Stub
{
override
def
stateChanged
(
state
:
Int
,
msg
:
String
)
=
()
// ignore
override
def
stateChanged
(
state
:
Int
,
msg
:
String
)
=
()
// ignore
override
def
trafficUpdated
(
txRate
:
String
,
rxRate
:
String
,
txTotal
:
String
,
rxTotal
:
String
)
{
override
def
trafficUpdated
(
txRate
:
Long
,
rxRate
:
Long
,
txTotal
:
Long
,
rxTotal
:
Long
)
{
builder
.
setContentText
(
service
.
getString
(
R
.
string
.
traffic_summary
).
formatLocal
(
Locale
.
ENGLISH
,
txRate
,
rxRate
))
val
txr
=
TrafficMonitor
.
formatTraffic
(
txRate
)
style
.
bigText
(
service
.
getString
(
R
.
string
.
stat_summary
)
val
rxr
=
TrafficMonitor
.
formatTraffic
(
rxRate
)
.
formatLocal
(
Locale
.
ENGLISH
,
txRate
,
rxRate
,
txTotal
,
rxTotal
))
builder
.
setContentText
(
service
.
getString
(
R
.
string
.
traffic_summary
).
formatLocal
(
Locale
.
ENGLISH
,
txr
,
rxr
))
style
.
bigText
(
service
.
getString
(
R
.
string
.
stat_summary
).
formatLocal
(
Locale
.
ENGLISH
,
txr
,
rxr
,
TrafficMonitor
.
formatTraffic
(
txTotal
),
TrafficMonitor
.
formatTraffic
(
rxTotal
)))
show
()
show
()
}
}
}
}
...
...
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
View file @
04c86a53
...
@@ -80,29 +80,5 @@ object TrafficMonitor {
...
@@ -80,29 +80,5 @@ object TrafficMonitor {
rxLast
=
0
rxLast
=
0
dirty
=
true
dirty
=
true
}
}
def
getTxTotal
()
:
String
=
{
formatTraffic
(
txTotal
)
}
def
getRxTotal
()
:
String
=
{
formatTraffic
(
rxTotal
)
}
def
getTotal
()
:
String
=
{
formatTraffic
(
txTotal
+
rxTotal
)
}
def
getTxRate
()
:
String
=
{
formatTraffic
(
txRate
)
}
def
getRxRate
()
:
String
=
{
formatTraffic
(
rxRate
)
}
def
getRate
()
:
String
=
{
formatTraffic
(
txRate
+
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