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
...
@@ -336,8 +336,8 @@ class Shadowsocks
.
show
()
.
show
()
switchButton
.
setEnabled
(
false
)
switchButton
.
setEnabled
(
false
)
}
}
switchButton
.
setChecked
(
true
)
changeSwitch
(
checked
=
true
)
onStateChanged
(
State
.
CONNECTED
,
null
)
onStateChanged
(
bgService
.
getState
,
null
)
setPreferenceEnabled
(
enabled
=
false
)
setPreferenceEnabled
(
enabled
=
false
)
}
}
// set the listener
// set the listener
...
@@ -370,6 +370,16 @@ class Shadowsocks
...
@@ -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
=
{
private
def
showProgress
(
msg
:
String
)
:
Handler
=
{
clearDialog
()
clearDialog
()
progressDialog
=
ProgressDialog
.
show
(
this
,
""
,
msg
,
true
,
false
)
progressDialog
=
ProgressDialog
.
show
(
this
,
""
,
msg
,
true
,
false
)
...
@@ -458,14 +468,23 @@ class Shadowsocks
...
@@ -458,14 +468,23 @@ class Shadowsocks
version
version
}
}
private
def
isTextEmpty
(
s
:
String
,
msg
:
String
)
:
Boolean
=
{
def
isTextEmpty
(
s
:
String
,
msg
:
String
)
:
Boolean
=
{
if
(
s
==
null
||
s
.
length
<=
0
)
{
if
(
s
==
null
||
s
.
length
<=
0
)
{
showDialog
(
msg
)
Crouton
.
makeText
(
this
,
msg
,
Style
.
ALERT
).
show
(
)
return
true
return
true
}
}
false
false
}
}
def
cancelStart
()
{
handler
.
postDelayed
(
new
Runnable
{
override
def
run
()
{
clearDialog
()
changeSwitch
(
checked
=
false
)
}
},
1000
)
}
def
prepareStartService
()
{
def
prepareStartService
()
{
showProgress
(
getString
(
R
.
string
.
connecting
))
showProgress
(
getString
(
R
.
string
.
connecting
))
spawn
{
spawn
{
...
@@ -478,7 +497,7 @@ class Shadowsocks
...
@@ -478,7 +497,7 @@ class Shadowsocks
}
}
}
else
{
}
else
{
if
(!
serviceStart
)
{
if
(!
serviceStart
)
{
switchButton
.
setChecked
(
false
)
cancelStart
(
)
}
}
}
}
}
}
...
@@ -492,6 +511,12 @@ class Shadowsocks
...
@@ -492,6 +511,12 @@ class Shadowsocks
case
false
=>
case
false
=>
serviceStop
()
serviceStop
()
}
}
if
(
switchButton
.
isEnabled
)
{
switchButton
.
setEnabled
(
false
)
handler
.
postDelayed
(
new
Runnable
{
override
def
run
()
{
switchButton
.
setEnabled
(
true
)
}
},
1000
)
}
}
}
}
}
...
@@ -920,11 +945,10 @@ class Shadowsocks
...
@@ -920,11 +945,10 @@ class Shadowsocks
case
Activity
.
RESULT_OK
=>
case
Activity
.
RESULT_OK
=>
prepared
=
true
prepared
=
true
if
(!
serviceStart
)
{
if
(!
serviceStart
)
{
switchButton
.
setChecked
(
false
)
cancelStart
(
)
}
}
case
_
=>
case
_
=>
clearDialog
()
cancelStart
()
switchButton
.
setChecked
(
false
)
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
}
}
}
}
...
@@ -946,24 +970,35 @@ class Shadowsocks
...
@@ -946,24 +970,35 @@ class Shadowsocks
if
(
bgService
!=
null
)
bgService
.
stop
()
if
(
bgService
!=
null
)
bgService
.
stop
()
}
}
/** Called when connect button is clicked. */
def
checkText
(
key
:
String
)
:
Boolean
=
{
def
serviceStart
:
Boolean
=
{
val
text
=
settings
.
getString
(
key
,
""
)
!
isTextEmpty
(
text
,
getString
(
R
.
string
.
proxy_empty
))
}
val
proxy
=
settings
.
getString
(
Key
.
proxy
,
""
)
def
checkNumber
(
key
:
String
)
:
Boolean
=
{
if
(
isTextEmpty
(
proxy
,
getString
(
R
.
string
.
proxy_empty
)))
return
false
val
text
=
settings
.
getString
(
key
,
""
)
val
portText
=
settings
.
getString
(
Key
.
localPort
,
""
)
if
(
isTextEmpty
(
text
,
getString
(
R
.
string
.
port_empty
)))
return
false
if
(
isTextEmpty
(
portText
,
getString
(
R
.
string
.
port_empty
)))
return
false
try
{
try
{
val
port
:
Int
=
Integer
.
valueOf
(
portT
ext
)
val
port
:
Int
=
Integer
.
valueOf
(
t
ext
)
if
(
port
<=
1024
)
{
if
(
port
<=
1024
)
{
this
.
showDialog
(
getString
(
R
.
string
.
port_alert
)
)
Crouton
.
makeText
(
this
,
R
.
string
.
port_alert
,
Style
.
ALERT
).
show
(
)
return
false
return
false
}
}
}
catch
{
}
catch
{
case
ex
:
Exception
=>
case
ex
:
Exception
=>
this
.
showDialog
(
getString
(
R
.
string
.
port_alert
)
)
Crouton
.
makeText
(
this
,
R
.
string
.
port_alert
,
Style
.
ALERT
).
show
(
)
return
false
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
if
(
bgService
==
null
)
return
false
...
@@ -973,7 +1008,7 @@ class Shadowsocks
...
@@ -973,7 +1008,7 @@ class Shadowsocks
val
style
=
new
Style
.
Builder
().
setBackgroundColorValue
(
Style
.
holoBlueLight
).
build
()
val
style
=
new
Style
.
Builder
().
setBackgroundColorValue
(
Style
.
holoBlueLight
).
build
()
val
config
=
new
Configuration
.
Builder
().
setDuration
(
Configuration
.
DURATION_LONG
).
build
()
val
config
=
new
Configuration
.
Builder
().
setDuration
(
Configuration
.
DURATION_LONG
).
build
()
Crouton
.
makeText
(
Shadowsocks
.
this
,
R
.
string
.
vpn_status
,
style
).
setConfiguration
(
config
).
show
()
Crouton
.
makeText
(
Shadowsocks
.
this
,
R
.
string
.
vpn_status
,
style
).
setConfiguration
(
config
).
show
()
switchButton
.
setEnabled
(
false
)
changeSwitch
(
checked
=
false
)
}
}
true
true
}
}
...
@@ -1010,20 +1045,6 @@ class Shadowsocks
...
@@ -1010,20 +1045,6 @@ class Shadowsocks
.
show
()
.
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
()
{
def
clearDialog
()
{
if
(
progressDialog
!=
null
)
{
if
(
progressDialog
!=
null
)
{
progressDialog
.
dismiss
()
progressDialog
.
dismiss
()
...
@@ -1045,13 +1066,13 @@ class Shadowsocks
...
@@ -1045,13 +1066,13 @@ class Shadowsocks
setPreferenceEnabled
(
enabled
=
false
)
setPreferenceEnabled
(
enabled
=
false
)
case
State
.
CONNECTED
=>
case
State
.
CONNECTED
=>
clearDialog
()
clearDialog
()
if
(!
switchButton
.
isChecked
)
switchButton
.
setChecked
(
true
)
if
(!
switchButton
.
isChecked
)
changeSwitch
(
checked
=
true
)
setPreferenceEnabled
(
enabled
=
false
)
setPreferenceEnabled
(
enabled
=
false
)
case
State
.
STOPPED
=>
case
State
.
STOPPED
=>
clearDialog
()
clearDialog
()
if
(
switchButton
.
isChecked
)
{
if
(
switchButton
.
isChecked
)
{
switchButton
.
setEnabled
(
true
)
switchButton
.
setEnabled
(
true
)
switchButton
.
setChecked
(
false
)
changeSwitch
(
checked
=
false
)
Crouton
.
cancelAllCroutons
()
Crouton
.
cancelAllCroutons
()
}
}
if
(
m
!=
null
)
{
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