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
ba8b5162
Commit
ba8b5162
authored
Feb 09, 2014
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refine the switch button
parent
36cdcdac
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
34 deletions
+55
-34
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+55
-34
No files found.
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
ba8b5162
...
...
@@ -336,8 +336,8 @@ class Shadowsocks
.
show
()
switchButton
.
setEnabled
(
false
)
}
switchButton
.
setChecked
(
true
)
onStateChanged
(
State
.
CONNECTED
,
null
)
changeSwitch
(
checked
=
true
)
onStateChanged
(
bgService
.
getState
,
null
)
setPreferenceEnabled
(
enabled
=
false
)
}
// set the listener
...
...
@@ -370,6 +370,16 @@ class Shadowsocks
}
}
private
def
changeSwitch
(
checked
:
Boolean
)
{
switchButton
.
setChecked
(
checked
)
if
(
switchButton
.
isEnabled
)
{
switchButton
.
setEnabled
(
false
)
handler
.
postDelayed
(
new
Runnable
{
override
def
run
()
{
switchButton
.
setEnabled
(
true
)
}
},
1000
)
}
}
private
def
showProgress
(
msg
:
String
)
:
Handler
=
{
clearDialog
()
progressDialog
=
ProgressDialog
.
show
(
this
,
""
,
msg
,
true
,
false
)
...
...
@@ -458,14 +468,23 @@ class Shadowsocks
version
}
private
def
isTextEmpty
(
s
:
String
,
msg
:
String
)
:
Boolean
=
{
def
isTextEmpty
(
s
:
String
,
msg
:
String
)
:
Boolean
=
{
if
(
s
==
null
||
s
.
length
<=
0
)
{
showDialog
(
msg
)
Crouton
.
makeText
(
this
,
msg
,
Style
.
ALERT
).
show
(
)
return
true
}
false
}
def
cancelStart
()
{
handler
.
postDelayed
(
new
Runnable
{
override
def
run
()
{
clearDialog
()
changeSwitch
(
checked
=
false
)
}
},
1000
)
}
def
prepareStartService
()
{
showProgress
(
getString
(
R
.
string
.
connecting
))
spawn
{
...
...
@@ -478,7 +497,7 @@ class Shadowsocks
}
}
else
{
if
(!
serviceStart
)
{
switchButton
.
setChecked
(
false
)
cancelStart
(
)
}
}
}
...
...
@@ -492,6 +511,12 @@ class Shadowsocks
case
false
=>
serviceStop
()
}
if
(
switchButton
.
isEnabled
)
{
switchButton
.
setEnabled
(
false
)
handler
.
postDelayed
(
new
Runnable
{
override
def
run
()
{
switchButton
.
setEnabled
(
true
)
}
},
1000
)
}
}
}
...
...
@@ -920,11 +945,10 @@ class Shadowsocks
case
Activity
.
RESULT_OK
=>
prepared
=
true
if
(!
serviceStart
)
{
switchButton
.
setChecked
(
false
)
cancelStart
(
)
}
case
_
=>
clearDialog
()
switchButton
.
setChecked
(
false
)
cancelStart
()
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
}
}
...
...
@@ -946,24 +970,35 @@ class Shadowsocks
if
(
bgService
!=
null
)
bgService
.
stop
()
}
/** Called when connect button is clicked. */
def
serviceStart
:
Boolean
=
{
def
checkText
(
key
:
String
)
:
Boolean
=
{
val
text
=
settings
.
getString
(
key
,
""
)
!
isTextEmpty
(
text
,
getString
(
R
.
string
.
proxy_empty
))
}
val
proxy
=
settings
.
getString
(
Key
.
proxy
,
""
)
if
(
isTextEmpty
(
proxy
,
getString
(
R
.
string
.
proxy_empty
)))
return
false
val
portText
=
settings
.
getString
(
Key
.
localPort
,
""
)
if
(
isTextEmpty
(
portText
,
getString
(
R
.
string
.
port_empty
)))
return
false
def
checkNumber
(
key
:
String
)
:
Boolean
=
{
val
text
=
settings
.
getString
(
key
,
""
)
if
(
isTextEmpty
(
text
,
getString
(
R
.
string
.
port_empty
)))
return
false
try
{
val
port
:
Int
=
Integer
.
valueOf
(
portT
ext
)
val
port
:
Int
=
Integer
.
valueOf
(
t
ext
)
if
(
port
<=
1024
)
{
this
.
showDialog
(
getString
(
R
.
string
.
port_alert
)
)
Crouton
.
makeText
(
this
,
R
.
string
.
port_alert
,
Style
.
ALERT
).
show
(
)
return
false
}
}
catch
{
case
ex
:
Exception
=>
this
.
showDialog
(
getString
(
R
.
string
.
port_alert
)
)
Crouton
.
makeText
(
this
,
R
.
string
.
port_alert
,
Style
.
ALERT
).
show
(
)
return
false
}
true
}
/** Called when connect button is clicked. */
def
serviceStart
:
Boolean
=
{
if
(!
checkText
(
Key
.
proxy
))
return
false
if
(!
checkText
(
Key
.
sitekey
))
return
false
if
(!
checkNumber
(
Key
.
localPort
))
return
false
if
(!
checkNumber
(
Key
.
remotePort
))
return
false
if
(
bgService
==
null
)
return
false
...
...
@@ -973,7 +1008,7 @@ class Shadowsocks
val
style
=
new
Style
.
Builder
().
setBackgroundColorValue
(
Style
.
holoBlueLight
).
build
()
val
config
=
new
Configuration
.
Builder
().
setDuration
(
Configuration
.
DURATION_LONG
).
build
()
Crouton
.
makeText
(
Shadowsocks
.
this
,
R
.
string
.
vpn_status
,
style
).
setConfiguration
(
config
).
show
()
switchButton
.
setEnabled
(
false
)
changeSwitch
(
checked
=
false
)
}
true
}
...
...
@@ -1010,20 +1045,6 @@ class Shadowsocks
.
show
()
}
private
def
showDialog
(
msg
:
String
)
{
val
builder
:
AlertDialog.Builder
=
new
AlertDialog
.
Builder
(
this
)
builder
.
setMessage
(
msg
)
.
setCancelable
(
false
)
.
setNegativeButton
(
getString
(
R
.
string
.
ok_iknow
),
new
DialogInterface
.
OnClickListener
{
def
onClick
(
dialog
:
DialogInterface
,
id
:
Int
)
{
dialog
.
cancel
()
}
})
val
alert
:
AlertDialog
=
builder
.
create
alert
.
show
()
}
def
clearDialog
()
{
if
(
progressDialog
!=
null
)
{
progressDialog
.
dismiss
()
...
...
@@ -1045,13 +1066,13 @@ class Shadowsocks
setPreferenceEnabled
(
enabled
=
false
)
case
State
.
CONNECTED
=>
clearDialog
()
if
(!
switchButton
.
isChecked
)
switchButton
.
setChecked
(
true
)
if
(!
switchButton
.
isChecked
)
changeSwitch
(
checked
=
true
)
setPreferenceEnabled
(
enabled
=
false
)
case
State
.
STOPPED
=>
clearDialog
()
if
(
switchButton
.
isChecked
)
{
switchButton
.
setEnabled
(
true
)
switchButton
.
setChecked
(
false
)
changeSwitch
(
checked
=
false
)
Crouton
.
cancelAllCroutons
()
}
if
(
m
!=
null
)
{
...
...
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