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
4258e95f
Commit
4258e95f
authored
Feb 08, 2016
by
Max Lv
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #568 from Mygod/layout
Refine layout of StatusPreference
parents
fbdf2dbf
cd5c2ef8
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
127 additions
and
138 deletions
+127
-138
build.sbt
build.sbt
+1
-0
src/main/res/drawable-anydpi-v21/ic_cloud.xml
src/main/res/drawable-anydpi-v21/ic_cloud.xml
+0
-9
src/main/res/drawable-anydpi-v21/ic_cloud_off.xml
src/main/res/drawable-anydpi-v21/ic_cloud_off.xml
+0
-9
src/main/res/drawable-anydpi-v21/ic_cloud_queue.xml
src/main/res/drawable-anydpi-v21/ic_cloud_queue.xml
+0
-9
src/main/res/layout/status_pref.xml
src/main/res/layout/status_pref.xml
+67
-51
src/main/res/values-zh/strings.xml
src/main/res/values-zh/strings.xml
+0
-1
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+0
-1
src/main/res/xml/pref_all.xml
src/main/res/xml/pref_all.xml
+1
-1
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+15
-34
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
...in/scala/com/github/shadowsocks/ShadowsocksSettings.scala
+20
-16
src/main/scala/com/github/shadowsocks/preferences/StatusPreference.scala
...com/github/shadowsocks/preferences/StatusPreference.scala
+23
-7
No files found.
build.sbt
View file @
4258e95f
...
...
@@ -37,6 +37,7 @@ libraryDependencies ++= Seq(
"com.google.android.gms"
%
"play-services-ads"
%
"8.4.0"
,
"com.google.android.gms"
%
"play-services-analytics"
%
"8.4.0"
,
"com.android.support"
%
"design"
%
"23.1.1"
,
"com.android.support"
%
"gridlayout-v7"
%
"23.1.1"
,
"com.github.jorgecastilloprz"
%
"fabprogresscircle"
%
"1.01"
,
"com.j256.ormlite"
%
"ormlite-core"
%
"4.48"
,
"com.j256.ormlite"
%
"ormlite-android"
%
"4.48"
,
...
...
src/main/res/drawable-anydpi-v21/ic_cloud.xml
deleted
100644 → 0
View file @
fbdf2dbf
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:width=
"24dp"
android:height=
"24dp"
android:viewportWidth=
"24.0"
android:viewportHeight=
"24.0"
>
<path
android:fillColor=
"#FFFFFFFF"
android:pathData=
"M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96z"
/>
</vector>
src/main/res/drawable-anydpi-v21/ic_cloud_off.xml
deleted
100644 → 0
View file @
fbdf2dbf
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:width=
"24dp"
android:height=
"24dp"
android:viewportWidth=
"24.0"
android:viewportHeight=
"24.0"
>
<path
android:fillColor=
"#FFFFFFFF"
android:pathData=
"M19.35,10.04C18.67,6.59 15.64,4 12,4c-1.48,0 -2.85,0.43 -4.01,1.17l1.46,1.46C10.21,6.23 11.08,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3 0,1.13 -0.64,2.11 -1.56,2.62l1.45,1.45C23.16,18.16 24,16.68 24,15c0,-2.64 -2.05,-4.78 -4.65,-4.96zM3,5.27l2.75,2.74C2.56,8.15 0,10.77 0,14c0,3.31 2.69,6 6,6h11.73l2,2L21,20.73 4.27,4 3,5.27zM7.73,10l8,8H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h1.73z"
/>
</vector>
src/main/res/drawable-anydpi-v21/ic_cloud_queue.xml
deleted
100644 → 0
View file @
fbdf2dbf
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:width=
"24dp"
android:height=
"24dp"
android:viewportWidth=
"24.0"
android:viewportHeight=
"24.0"
>
<path
android:fillColor=
"#FFFFFFFF"
android:pathData=
"M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM19,18H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h0.71C7.37,7.69 9.48,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3s-1.34,3 -3,3z"
/>
</vector>
src/main/res/layout/status_pref.xml
View file @
4258e95f
...
...
@@ -4,33 +4,23 @@
android:layout_height=
"wrap_content"
android:minHeight=
"?android:attr/listPreferredItemHeight"
android:gravity=
"center_vertical"
android:paddingEnd=
"?android:attr/scrollbarSize"
android:paddingLeft=
"15dip"
android:paddingRight=
"15dip"
android:paddingTop=
"6dip"
android:paddingBottom=
"6dip"
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"
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
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:layout_width=
"
0dp
"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
/>
<TextView
android:id=
"@android:id/summary"
android:textSize=
"14sp"
android:textColor=
"?android:attr/textColorSecondary"
...
...
@@ -38,71 +28,97 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"end"
/>
</TableRow>
</LinearLayout>
<android.support.v7.widget.GridLayout
xmlns:app=
"http://schemas.android.com/apk/res-auto"
app:columnCount=
"4"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TableRow
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
a
ndroid
:layout_column=
"0"
a
pp
: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:layout_marginEnd=
"24dp"
android:gravity=
"end"
android:text=
"@string/sent"
/>
<TextView
a
ndroid
:layout_column=
"1"
a
pp
:layout_column=
"1"
android:id=
"@+id/tx"
style=
"@style/TextAppearance.AppCompat.Caption"
android:textSize=
"14sp"
android:textColor=
"?android:attr/textColorSecondary"
android:ellipsize=
"marquee"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
app:layout_columnWeight=
"1"
app:layout_gravity=
"fill_horizontal"
/>
<TextView
app:layout_column=
"2"
android:textSize=
"14sp"
android:textColor=
"?android:attr/textColorSecondary"
android:ellipsize=
"marquee"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"end"
android:text=
"0 Byte"
/>
android:text=
"▲"
/>
<TextView
a
ndroid
:layout_column=
"3"
a
pp
:layout_column=
"3"
android:id=
"@+id/txRate"
style=
"@style/TextAppearance.AppCompat.Caption"
android:textSize=
"14sp"
android:textColor=
"?android:attr/textColorSecondary"
android:ellipsize=
"marquee"
android:layout_width=
"
match_parent
"
android:layout_width=
"
0dp
"
android:layout_height=
"wrap_content"
a
ndroid:gravity=
"end
"
a
ndroid:text=
"▲ 0 B/s"
/>
</TableRow
>
a
pp:layout_columnWeight=
"1
"
a
pp:layout_gravity=
"fill_horizontal"
android:gravity=
"end"
/
>
<TableRow
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
android:layout_column=
"0"
app:layout_row=
"1"
app: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:layout_marginEnd=
"24dp"
android:gravity=
"end"
android:text=
"@string/received"
/>
<TextView
android:layout_column=
"1"
app:layout_row=
"1"
app:layout_column=
"1"
android:id=
"@+id/rx"
style=
"@style/TextAppearance.AppCompat.Caption"
android:textSize=
"14sp"
android:textColor=
"?android:attr/textColorSecondary"
android:ellipsize=
"marquee"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
app:layout_columnWeight=
"1"
app:layout_gravity=
"fill_horizontal"
/>
<TextView
app:layout_row=
"1"
app:layout_column=
"2"
android:textSize=
"14sp"
android:textColor=
"?android:attr/textColorSecondary"
android:ellipsize=
"marquee"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"end"
android:text=
"0 Byte"
/>
android:text=
"▼"
/>
<TextView
android:layout_column=
"3"
app:layout_row=
"1"
app:layout_column=
"3"
android:id=
"@+id/rxRate"
style=
"@style/TextAppearance.AppCompat.Caption"
android:textSize=
"14sp"
android:textColor=
"?android:attr/textColorSecondary"
android:ellipsize=
"marquee"
android:layout_width=
"
match_parent
"
android:layout_width=
"
0dp
"
android:layout_height=
"wrap_content"
a
ndroid:gravity=
"end
"
a
ndroid:text=
"▼ 0 B/s"
/>
</TableRow
>
a
pp:layout_columnWeight=
"1
"
a
pp:layout_gravity=
"fill_horizontal"
android:gravity=
"end"
/
>
</
Table
Layout>
</
android.support.v7.widget.Grid
Layout>
</LinearLayout>
src/main/res/values-zh/strings.xml
View file @
4258e95f
...
...
@@ -116,6 +116,5 @@
<!-- status -->
<string
name=
"sent"
>
发送:
</string>
<string
name=
"received"
>
接收:
</string>
<string
name=
"check_connectivity"
>
检查网络连接
</string>
</resources>
src/main/res/values/strings.xml
View file @
4258e95f
...
...
@@ -124,5 +124,4 @@
<!-- 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 @
4258e95f
...
...
@@ -10,7 +10,7 @@
<com.github.shadowsocks.preferences.StatusPreference
android:key=
"stat"
android:summary=
"@string/c
heck_connectivity
"
android:summary=
"@string/c
onnection_test_pending
"
android:title=
"@string/stat"
/>
</PreferenceCategory>
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
4258e95f
...
...
@@ -58,7 +58,6 @@ 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
}
...
...
@@ -107,9 +106,6 @@ class Shadowsocks
var
state
=
State
.
STOPPED
var
currentProfile
=
new
Profile
var
vpnEnabled
=
-
1
var
trafficCache
:
Array
[
String
]
=
_
var
connectionTestResult
:
String
=
_
var
connectionTestSuccess
:
Boolean
=
true
// Services
var
currentServiceName
=
classOf
[
ShadowsocksNatService
].
getName
...
...
@@ -158,28 +154,13 @@ class Shadowsocks
})
}
def
trafficUpdated
(
txRate
:
Long
,
rxRate
:
Long
,
txTotal
:
Long
,
rxTotal
:
Long
)
{
trafficCache
=
Array
(
"▲ "
+
TrafficMonitor
.
formatTraffic
(
txRate
)
+
"/s"
,
"▼ "
+
TrafficMonitor
.
formatTraffic
(
rxRate
)
+
"/s"
,
TrafficMonitor
.
formatTraffic
(
txTotal
),
TrafficMonitor
.
formatTraffic
(
rxTotal
))
handler
.
post
(
updateTraffic
)
handler
.
post
(()
=>
updateTraffic
(
txRate
,
rxRate
,
txTotal
,
rxTotal
))
}
}
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
(
""
)
}
else
{
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
updateTraffic
(
txRate
:
Long
,
rxRate
:
Long
,
txTotal
:
Long
,
rxTotal
:
Long
)
=
preferences
.
stat
.
setRate
(
TrafficMonitor
.
formatTraffic
(
txTotal
),
TrafficMonitor
.
formatTraffic
(
rxTotal
),
TrafficMonitor
.
formatTraffic
(
txRate
)
+
"/s"
,
TrafficMonitor
.
formatTraffic
(
rxRate
)
+
"/s"
)
def
attachService
:
Unit
=
attachService
(
callback
)
...
...
@@ -263,7 +244,7 @@ class Shadowsocks
}
else
{
in
=
assetManager
.
open
(
file
)
}
out
=
new
FileOutputStream
(
getApplicationInfo
()
.
dataDir
+
"/"
+
file
)
out
=
new
FileOutputStream
(
getApplicationInfo
.
dataDir
+
"/"
+
file
)
copyFile
(
in
,
out
)
in
.
close
()
in
=
null
...
...
@@ -293,8 +274,8 @@ class Shadowsocks
val
cmd
=
new
ArrayBuffer
[
String
]()
for
(
task
<-
Array
(
"ss-local"
,
"ss-tunnel"
,
"pdnsd"
,
"redsocks"
,
"tun2socks"
))
{
cmd
.
append
(
"chmod 666 %s/%s-nat.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
()
.
dataDir
,
task
))
cmd
.
append
(
"chmod 666 %s/%s-vpn.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
()
.
dataDir
,
task
))
cmd
.
append
(
"chmod 666 %s/%s-nat.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
cmd
.
append
(
"chmod 666 %s/%s-vpn.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
}
if
(
ShadowsocksApplication
.
isVpnEnabled
)
{
...
...
@@ -307,8 +288,8 @@ class Shadowsocks
for
(
task
<-
Array
(
"ss-local"
,
"ss-tunnel"
,
"pdnsd"
,
"redsocks"
,
"tun2socks"
))
{
try
{
val
pid_nat
=
scala
.
io
.
Source
.
fromFile
(
getApplicationInfo
()
.
dataDir
+
"/"
+
task
+
"-nat.pid"
).
mkString
.
trim
.
toInt
val
pid_vpn
=
scala
.
io
.
Source
.
fromFile
(
getApplicationInfo
()
.
dataDir
+
"/"
+
task
+
"-vpn.pid"
).
mkString
.
trim
.
toInt
val
pid_nat
=
scala
.
io
.
Source
.
fromFile
(
getApplicationInfo
.
dataDir
+
"/"
+
task
+
"-nat.pid"
).
mkString
.
trim
.
toInt
val
pid_vpn
=
scala
.
io
.
Source
.
fromFile
(
getApplicationInfo
.
dataDir
+
"/"
+
task
+
"-vpn.pid"
).
mkString
.
trim
.
toInt
cmd
.
append
(
"kill -9 %d"
.
formatLocal
(
Locale
.
ENGLISH
,
pid_nat
))
cmd
.
append
(
"kill -9 %d"
.
formatLocal
(
Locale
.
ENGLISH
,
pid_vpn
))
Process
.
killProcess
(
pid_nat
)
...
...
@@ -316,10 +297,10 @@ class Shadowsocks
}
catch
{
case
e
:
Throwable
=>
// Ignore
}
cmd
.
append
(
"rm -f %s/%s-nat.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
()
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-nat.conf"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
()
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-vpn.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
()
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-vpn.conf"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
()
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-nat.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-nat.conf"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-vpn.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-vpn.conf"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
}
if
(
ShadowsocksApplication
.
isVpnEnabled
)
Console
.
runCommand
(
cmd
.
toArray
)
else
{
Console
.
runRootCommand
(
cmd
.
toArray
)
...
...
@@ -389,6 +370,7 @@ class Shadowsocks
Toast
.
LENGTH_SHORT
),
fab
,
getWindow
,
0
,
Utils
.
dpToPx
(
this
,
8
)).
show
true
})
updateTraffic
(
0
,
0
,
0
,
0
)
// Bind to the service
handler
.
post
(()
=>
attachService
)
...
...
@@ -461,7 +443,6 @@ class Shadowsocks
// Check if current profile changed
if
(
ShadowsocksApplication
.
profileId
!=
currentProfile
.
id
)
reloadProfile
()
updateTraffic
()
updateState
()
}
...
...
@@ -503,7 +484,7 @@ class Shadowsocks
val
ab
=
new
ArrayBuffer
[
String
]
for
(
executable
<-
Shadowsocks
.
EXECUTABLES
)
{
ab
.
append
(
"chmod 755 "
+
getApplicationInfo
()
.
dataDir
+
"/"
+
executable
)
ab
.
append
(
"chmod 755 "
+
getApplicationInfo
.
dataDir
+
"/"
+
executable
)
}
Console
.
runCommand
(
ab
.
toArray
)
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
View file @
4258e95f
...
...
@@ -9,10 +9,11 @@ import android.content.{DialogInterface, Intent, SharedPreferences}
import
android.net.Uri
import
android.os.
{
Build
,
Bundle
}
import
android.preference.
{
Preference
,
PreferenceFragment
,
SwitchPreference
}
import
android.support.design.widget.Snackbar
import
android.support.v7.app.AlertDialog
import
android.webkit.
{
WebView
,
WebViewClient
}
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.preferences.
{
DropDownPreference
,
NumberPickerPreference
,
PasswordEditTextPreference
,
SummaryEditTextPreference
}
import
com.github.shadowsocks.preferences.
_
import
com.github.shadowsocks.utils.CloseUtils._
import
com.github.shadowsocks.utils.
{
Key
,
Utils
}
...
...
@@ -68,7 +69,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
private
def
activity
=
getActivity
.
asInstanceOf
[
Shadowsocks
]
lazy
val
natSwitch
=
findPreference
(
Key
.
isNAT
).
asInstanceOf
[
SwitchPreference
]
var
stat
:
Preference
=
_
var
stat
:
Status
Preference
=
_
private
var
isProxyApps
:
SwitchPreference
=
_
private
var
testCount
:
Int
=
_
...
...
@@ -78,13 +79,11 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
addPreferencesFromResource
(
R
.
xml
.
pref_all
)
getPreferenceManager
.
getSharedPreferences
.
registerOnSharedPreferenceChangeListener
(
this
)
stat
=
findPreference
(
Key
.
stat
)
stat
=
findPreference
(
Key
.
stat
).
asInstanceOf
[
StatusPreference
]
stat
.
setOnPreferenceClickListener
(
_
=>
{
val
id
=
synchronized
{
testCount
+=
1
activity
.
connectionTestResult
=
getString
(
R
.
string
.
connection_test_testing
)
activity
.
connectionTestSuccess
=
true
activity
.
updateTraffic
()
activity
.
handler
.
post
(()
=>
stat
.
setSummary
(
R
.
string
.
connection_test_testing
))
testCount
}
ThrowableFuture
{
...
...
@@ -97,7 +96,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
conn
.
setUseCaches
(
false
)
if
(
testCount
==
id
)
{
var
result
:
String
=
null
var
success
:
Boolean
=
true
var
success
=
true
try
{
val
start
=
currentTimeMillis
conn
.
getInputStream
...
...
@@ -107,21 +106,24 @@ 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
=>
{
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
)
if
(
ShadowsocksApplication
.
isVpnEnabled
)
activity
.
handler
.
post
(()
=>
{
if
(
success
)
stat
.
setSummary
(
result
)
else
{
stat
.
setSummary
(
R
.
string
.
connection_test_fail
)
Snackbar
.
make
(
activity
.
findViewById
(
android
.
R
.
id
.
content
),
result
,
Snackbar
.
LENGTH_LONG
).
show
}
})
})
}
}
}
true
})
stat
.
setSummary
(
if
(
ShadowsocksApplication
.
isVpnEnabled
)
getString
(
R
.
string
.
connection_test_pending
)
else
null
)
isProxyApps
=
findPreference
(
Key
.
isProxyApps
).
asInstanceOf
[
SwitchPreference
]
isProxyApps
.
setOnPreferenceClickListener
((
preference
:
Preference
)
=>
{
...
...
@@ -182,10 +184,12 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
}
def
onSharedPreferenceChanged
(
sharedPreferences
:
SharedPreferences
,
key
:
String
)
=
key
match
{
case
Key
.
isNAT
=>
activity
.
handler
.
post
(()
=>
{
activity
.
deattachService
activity
.
attachService
})
case
Key
.
isNAT
=>
activity
.
handler
.
post
(()
=>
{
activity
.
deattachService
activity
.
attachService
})
stat
.
setSummary
(
if
(
ShadowsocksApplication
.
isVpnEnabled
)
getString
(
R
.
string
.
connection_test_pending
)
else
null
)
case
_
=>
}
...
...
src/main/scala/com/github/shadowsocks/preferences/StatusPreference.scala
View file @
4258e95f
...
...
@@ -2,8 +2,8 @@ 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.view.
{
LayoutInflater
,
View
,
ViewGroup
}
import
android.widget.TextView
import
com.github.shadowsocks.R
...
...
@@ -12,14 +12,18 @@ import com.github.shadowsocks.R
*/
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
var
tx
:
String
=
_
var
rx
:
String
=
_
var
txRate
:
String
=
_
var
rxRate
:
String
=
_
var
txView
:
TextView
=
_
var
rxView
:
TextView
=
_
var
txRateView
:
TextView
=
_
var
rxRateView
:
TextView
=
_
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
)
val
view
=
getContext
.
getSystemService
(
Context
.
LAYOUT_INFLATER_SERVICE
).
asInstanceOf
[
LayoutInflater
]
.
inflate
(
R
.
layout
.
status_pref
,
parent
,
false
)
txView
=
view
.
findViewById
(
R
.
id
.
tx
).
asInstanceOf
[
TextView
]
rxView
=
view
.
findViewById
(
R
.
id
.
rx
).
asInstanceOf
[
TextView
]
...
...
@@ -29,16 +33,28 @@ final class StatusPreference(context: Context, attrs: AttributeSet = null)
view
}
override
def
onBindView
(
view
:
View
)
=
{
super
.
onBindView
(
view
)
txView
.
setText
(
tx
)
rxView
.
setText
(
rx
)
txRateView
.
setText
(
txRate
)
rxRateView
.
setText
(
rxRate
)
}
def
setRate
(
tx
:
String
,
rx
:
String
,
txRate
:
String
,
rxRate
:
String
)
{
this
.
tx
=
tx
if
(
txView
!=
null
)
{
txView
.
setText
(
tx
)
}
this
.
rx
=
rx
if
(
rxView
!=
null
)
{
rxView
.
setText
(
rx
)
}
this
.
txRate
=
txRate
if
(
txRateView
!=
null
)
{
txRateView
.
setText
(
txRate
)
}
this
.
rxRate
=
rxRate
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