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
a2848ce5
Commit
a2848ce5
authored
Sep 29, 2013
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update UI
parent
6f55861d
Changes
12
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
375 additions
and
120 deletions
+375
-120
src/main/res/layout/layout_switch.xml
src/main/res/layout/layout_switch.xml
+2
-1
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+3
-0
src/main/res/xml/pref_proxy.xml
src/main/res/xml/pref_proxy.xml
+6
-0
src/main/scala/com/github/shadowsocks/AppManager.scala
src/main/scala/com/github/shadowsocks/AppManager.scala
+2
-3
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+193
-67
src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala
...scala/com/github/shadowsocks/ShadowsocksApplication.scala
+0
-1
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
...ain/scala/com/github/shadowsocks/ShadowsocksService.scala
+2
-12
src/main/scala/com/github/shadowsocks/Utils.scala
src/main/scala/com/github/shadowsocks/Utils.scala
+46
-3
src/main/scala/com/github/shadowsocks/database/DBHelper.scala
...main/scala/com/github/shadowsocks/database/DBHelper.scala
+1
-1
src/main/scala/com/github/shadowsocks/database/MenuAdapter.scala
...n/scala/com/github/shadowsocks/database/MenuAdapter.scala
+31
-17
src/main/scala/com/github/shadowsocks/database/Profile.scala
src/main/scala/com/github/shadowsocks/database/Profile.scala
+14
-8
src/main/scala/com/github/shadowsocks/database/ProfileManager.scala
...cala/com/github/shadowsocks/database/ProfileManager.scala
+75
-7
No files found.
src/main/res/layout/layout_switch.xml
View file @
a2848ce5
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"center_vertical"
android:gravity=
"center_vertical"
android:textSize=
"2
2
sp"
android:textSize=
"2
4
sp"
android:textColor=
"@color/title"
android:textColor=
"@color/title"
android:text=
"@string/app_name"
android:text=
"@string/app_name"
android:layout_alignParentLeft=
"true"
android:layout_alignParentLeft=
"true"
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentRight=
"true"
android:layout_alignParentRight=
"true"
android:layout_marginRight =
"10dp"
android:layout_centerVertical=
"true"
/>
android:layout_centerVertical=
"true"
/>
</RelativeLayout>
</RelativeLayout>
src/main/res/values/strings.xml
View file @
a2848ce5
...
@@ -10,6 +10,8 @@
...
@@ -10,6 +10,8 @@
<!-- proxy category -->
<!-- proxy category -->
<string
name=
"proxy_cat"
>
Server Settings
</string>
<string
name=
"proxy_cat"
>
Server Settings
</string>
<string
name=
"profile"
>
Profile
</string>
<string
name=
"profile_summary"
>
Profile name
</string>
<string
name=
"proxy"
>
Server
</string>
<string
name=
"proxy"
>
Server
</string>
<string
name=
"proxy_summary"
>
Hostname or IP Address of your Shadowsocks server
</string>
<string
name=
"proxy_summary"
>
Hostname or IP Address of your Shadowsocks server
</string>
<string
name=
"remote_port"
>
Remote Port
</string>
<string
name=
"remote_port"
>
Remote Port
</string>
...
@@ -73,5 +75,6 @@
...
@@ -73,5 +75,6 @@
<string
name=
"about_title"
>
Shadowsocks %s
</string>
<string
name=
"about_title"
>
Shadowsocks %s
</string>
<string
name=
"flush_dnscache"
>
Flush DNS Cache
</string>
<string
name=
"flush_dnscache"
>
Flush DNS Cache
</string>
<string
name=
"flushing"
>
Flushing
</string>
<string
name=
"flushing"
>
Flushing
</string>
<string
name=
"add_profile"
>
Add Profile
</string>
</resources>
</resources>
src/main/res/xml/pref_proxy.xml
View file @
a2848ce5
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<PreferenceScreen
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<com.github.shadowsocks.preferences.SummaryEditTextPreference
android:defaultValue=
"Default"
android:key=
"profileName"
android:summary=
"@string/profile_summary"
android:title=
"@string/profile"
>
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
<com.github.shadowsocks.preferences.SummaryEditTextPreference
<com.github.shadowsocks.preferences.SummaryEditTextPreference
android:defaultValue=
"198.199.101.152"
android:defaultValue=
"198.199.101.152"
android:key=
"proxy"
android:key=
"proxy"
...
...
src/main/scala/com/github/shadowsocks/AppManager.scala
View file @
a2848ce5
...
@@ -109,7 +109,6 @@ class AppManager extends SherlockActivity with OnCheckedChangeListener with OnCl
...
@@ -109,7 +109,6 @@ class AppManager extends SherlockActivity with OnCheckedChangeListener with OnCl
val
MSG_LOAD_START
=
1
val
MSG_LOAD_START
=
1
val
MSG_LOAD_FINISH
=
2
val
MSG_LOAD_FINISH
=
2
val
SCHEME
=
"app://"
val
STUB
=
android
.
R
.
drawable
.
sym_def_app_icon
val
STUB
=
android
.
R
.
drawable
.
sym_def_app_icon
implicit
def
anyrefarray_tools
[
T
<:
AnyRef
](
a
:
Array
[
T
])
=
new
ObjectArrayTools
(
a
)
implicit
def
anyrefarray_tools
[
T
<:
AnyRef
](
a
:
Array
[
T
])
=
new
ObjectArrayTools
(
a
)
...
@@ -184,7 +183,7 @@ class AppManager extends SherlockActivity with OnCheckedChangeListener with OnCl
...
@@ -184,7 +183,7 @@ class AppManager extends SherlockActivity with OnCheckedChangeListener with OnCl
.
cacheOnDisc
()
.
cacheOnDisc
()
.
displayer
(
new
FadeInBitmapDisplayer
(
300
))
.
displayer
(
new
FadeInBitmapDisplayer
(
300
))
.
build
()
.
build
()
ImageLoader
.
getInstance
().
displayImage
(
"app://"
+
app
.
uid
,
entry
.
icon
,
options
)
ImageLoader
.
getInstance
().
displayImage
(
Scheme
.
APP
+
app
.
uid
,
entry
.
icon
,
options
)
entry
.
text
.
setText
(
app
.
name
)
entry
.
text
.
setText
(
app
.
name
)
val
box
:
CheckBox
=
entry
.
box
val
box
:
CheckBox
=
entry
.
box
...
@@ -327,7 +326,7 @@ class AppManager extends SherlockActivity with OnCheckedChangeListener with OnCl
...
@@ -327,7 +326,7 @@ class AppManager extends SherlockActivity with OnCheckedChangeListener with OnCl
}
}
override
def
getStreamFromOtherSource
(
imageUri
:
String
,
extra
:
AnyRef
)
:
InputStream
=
{
override
def
getStreamFromOtherSource
(
imageUri
:
String
,
extra
:
AnyRef
)
:
InputStream
=
{
val
uid
=
imageUri
.
substring
(
S
CHEME
.
length
).
toInt
val
uid
=
imageUri
.
substring
(
S
cheme
.
APP
.
length
).
toInt
val
drawable
=
Utils
.
getAppIcon
(
getBaseContext
,
uid
)
val
drawable
=
Utils
.
getAppIcon
(
getBaseContext
,
uid
)
val
bitmap
=
Utils
.
drawableToBitmap
(
drawable
)
val
bitmap
=
Utils
.
drawableToBitmap
(
drawable
)
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
a2848ce5
This diff is collapsed.
Click to expand it.
src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala
View file @
a2848ce5
...
@@ -44,7 +44,6 @@ import com.github.shadowsocks.database.{ProfileManager, DBHelper}
...
@@ -44,7 +44,6 @@ import com.github.shadowsocks.database.{ProfileManager, DBHelper}
class
ShadowsocksApplication
extends
Application
{
class
ShadowsocksApplication
extends
Application
{
lazy
val
dbHelper
=
new
DBHelper
(
this
)
lazy
val
dbHelper
=
new
DBHelper
(
this
)
lazy
val
profileManager
=
new
ProfileManager
(
dbHelper
)
override
def
onCreate
()
{
override
def
onCreate
()
{
EasyTracker
.
getInstance
.
setContext
(
this
)
EasyTracker
.
getInstance
.
setContext
(
this
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
View file @
a2848ce5
...
@@ -324,18 +324,8 @@ class ShadowsocksService extends Service {
...
@@ -324,18 +324,8 @@ class ShadowsocksService extends Service {
val
icon
=
getResources
.
getDrawable
(
R
.
drawable
.
ic_stat_shadowsocks
)
val
icon
=
getResources
.
getDrawable
(
R
.
drawable
.
ic_stat_shadowsocks
)
if
(
rate
>=
0
)
{
if
(
rate
>=
0
)
{
val
bitmap
=
Bitmap
.
createBitmap
(
icon
.
getIntrinsicWidth
*
4
,
val
bitmap
=
Utils
.
getBitmap
(
rate
.
toString
,
icon
.
getIntrinsicWidth
*
4
,
icon
.
getIntrinsicHeight
*
4
,
Bitmap
.
Config
.
ARGB_8888
)
icon
.
getIntrinsicHeight
*
4
,
Color
.
TRANSPARENT
)
val
r
=
rate
.
toString
val
size
=
bitmap
.
getHeight
/
4
val
canvas
=
new
Canvas
(
bitmap
)
val
paint
=
new
Paint
()
paint
.
setColor
(
Color
.
WHITE
)
paint
.
setTextSize
(
size
)
val
bounds
=
new
Rect
()
paint
.
getTextBounds
(
r
,
0
,
r
.
length
,
bounds
)
canvas
.
drawText
(
r
,
(
bitmap
.
getWidth
-
bounds
.
width
())
/
2
,
bitmap
.
getHeight
-
(
bitmap
.
getHeight
-
bounds
.
height
())
/
2
,
paint
)
builder
.
setLargeIcon
(
bitmap
)
builder
.
setLargeIcon
(
bitmap
)
if
(
rate
<
1000
)
{
if
(
rate
<
1000
)
{
...
...
src/main/scala/com/github/shadowsocks/Utils.scala
View file @
a2848ce5
...
@@ -49,10 +49,11 @@ import org.apache.http.conn.util.InetAddressUtils
...
@@ -49,10 +49,11 @@ import org.apache.http.conn.util.InetAddressUtils
import
scala.collection.mutable.ArrayBuffer
import
scala.collection.mutable.ArrayBuffer
import
org.xbill.DNS._
import
org.xbill.DNS._
import
scala.Some
import
scala.Some
import
android.graphics.
{
Canvas
,
Bitmap
}
import
android.graphics.
_
import
android.app.ActivityManager
import
android.app.ActivityManager
import
android.os.Build
import
android.os.Build
import
android.provider.Settings
import
android.provider.Settings
import
scala.Some
object
Config
{
object
Config
{
val
SHADOWSOCKS
=
"{\"server\": [%s], \"server_port\": %d, \"local_port\": %d, \"password\": %s, \"timeout\": %d}"
val
SHADOWSOCKS
=
"{\"server\": [%s], \"server_port\": %d, \"local_port\": %d, \"password\": %s, \"timeout\": %d}"
...
@@ -112,10 +113,13 @@ object Config {
...
@@ -112,10 +113,13 @@ object Config {
}
}
case
class
Config
(
isGlobalProxy
:
Boolean
,
isGFWList
:
Boolean
,
isBypassApps
:
Boolean
,
isTrafficStat
:
Boolean
,
case
class
Config
(
isGlobalProxy
:
Boolean
,
isGFWList
:
Boolean
,
isBypassApps
:
Boolean
,
isTrafficStat
:
Boolean
,
var
proxy
:
String
,
sitekey
:
String
,
encMethod
:
String
,
remotePort
:
Int
,
profileName
:
String
,
var
proxy
:
String
,
sitekey
:
String
,
encMethod
:
String
,
remotePort
:
Int
,
localPort
:
Int
,
proxiedAppString
:
String
)
localPort
:
Int
,
proxiedAppString
:
String
)
object
Key
{
object
Key
{
val
profileId
=
"profileId"
val
profileName
=
"profileName"
val
proxied
=
"Proxyed"
val
proxied
=
"Proxyed"
val
isRoot
=
"isRoot"
val
isRoot
=
"isRoot"
...
@@ -137,6 +141,11 @@ object Key {
...
@@ -137,6 +141,11 @@ object Key {
val
localPort
=
"port"
val
localPort
=
"port"
}
}
object
Scheme
{
val
APP
=
"app://"
val
PROFILE
=
"profile://"
}
object
State
{
object
State
{
val
INIT
=
0
val
INIT
=
0
val
CONNECTING
=
1
val
CONNECTING
=
1
...
@@ -162,6 +171,7 @@ object Extra {
...
@@ -162,6 +171,7 @@ object Extra {
edit
.
putBoolean
(
Key
.
isBypassApps
,
config
.
isBypassApps
)
edit
.
putBoolean
(
Key
.
isBypassApps
,
config
.
isBypassApps
)
edit
.
putBoolean
(
Key
.
isTrafficStat
,
config
.
isTrafficStat
)
edit
.
putBoolean
(
Key
.
isTrafficStat
,
config
.
isTrafficStat
)
edit
.
putString
(
Key
.
profileName
,
config
.
profileName
)
edit
.
putString
(
Key
.
proxy
,
config
.
proxy
)
edit
.
putString
(
Key
.
proxy
,
config
.
proxy
)
edit
.
putString
(
Key
.
sitekey
,
config
.
sitekey
)
edit
.
putString
(
Key
.
sitekey
,
config
.
sitekey
)
edit
.
putString
(
Key
.
encMethod
,
config
.
encMethod
)
edit
.
putString
(
Key
.
encMethod
,
config
.
encMethod
)
...
@@ -177,6 +187,7 @@ object Extra {
...
@@ -177,6 +187,7 @@ object Extra {
val
isBypassApps
=
intent
.
getBooleanExtra
(
Key
.
isBypassApps
,
false
)
val
isBypassApps
=
intent
.
getBooleanExtra
(
Key
.
isBypassApps
,
false
)
val
isTrafficStat
=
intent
.
getBooleanExtra
(
Key
.
isTrafficStat
,
false
)
val
isTrafficStat
=
intent
.
getBooleanExtra
(
Key
.
isTrafficStat
,
false
)
val
profileName
=
intent
.
getStringExtra
(
Key
.
profileName
)
val
proxy
=
intent
.
getStringExtra
(
Key
.
proxy
)
val
proxy
=
intent
.
getStringExtra
(
Key
.
proxy
)
val
sitekey
=
intent
.
getStringExtra
(
Key
.
sitekey
)
val
sitekey
=
intent
.
getStringExtra
(
Key
.
sitekey
)
val
encMethod
=
intent
.
getStringExtra
(
Key
.
encMethod
)
val
encMethod
=
intent
.
getStringExtra
(
Key
.
encMethod
)
...
@@ -184,7 +195,7 @@ object Extra {
...
@@ -184,7 +195,7 @@ object Extra {
val
localPort
=
intent
.
getIntExtra
(
Key
.
localPort
,
1984
)
val
localPort
=
intent
.
getIntExtra
(
Key
.
localPort
,
1984
)
val
proxiedString
=
intent
.
getStringExtra
(
Key
.
proxied
)
val
proxiedString
=
intent
.
getStringExtra
(
Key
.
proxied
)
new
Config
(
isGlobalProxy
,
isGFWList
,
isBypassApps
,
isTrafficStat
,
proxy
,
sitekey
,
encMethod
,
remotePort
,
new
Config
(
isGlobalProxy
,
isGFWList
,
isBypassApps
,
isTrafficStat
,
pro
fileName
,
pro
xy
,
sitekey
,
encMethod
,
remotePort
,
localPort
,
proxiedString
)
localPort
,
proxiedString
)
}
}
...
@@ -194,6 +205,7 @@ object Extra {
...
@@ -194,6 +205,7 @@ object Extra {
val
isBypassApps
=
settings
.
getBoolean
(
Key
.
isBypassApps
,
false
)
val
isBypassApps
=
settings
.
getBoolean
(
Key
.
isBypassApps
,
false
)
val
isTrafficStat
=
settings
.
getBoolean
(
Key
.
isTrafficStat
,
false
)
val
isTrafficStat
=
settings
.
getBoolean
(
Key
.
isTrafficStat
,
false
)
val
profileName
=
settings
.
getString
(
Key
.
profileName
,
"default"
)
val
proxy
=
settings
.
getString
(
Key
.
proxy
,
"127.0.0.1"
)
match
{
val
proxy
=
settings
.
getString
(
Key
.
proxy
,
"127.0.0.1"
)
match
{
case
"198.199.101.152"
=>
BuildConfig
.
SERVER
case
"198.199.101.152"
=>
BuildConfig
.
SERVER
case
s
:
String
=>
s
case
s
:
String
=>
s
...
@@ -232,6 +244,7 @@ object Extra {
...
@@ -232,6 +244,7 @@ object Extra {
intent
.
putExtra
(
Key
.
isBypassApps
,
isBypassApps
)
intent
.
putExtra
(
Key
.
isBypassApps
,
isBypassApps
)
intent
.
putExtra
(
Key
.
isTrafficStat
,
isTrafficStat
)
intent
.
putExtra
(
Key
.
isTrafficStat
,
isTrafficStat
)
intent
.
putExtra
(
Key
.
profileName
,
profileName
)
intent
.
putExtra
(
Key
.
proxy
,
proxy
)
intent
.
putExtra
(
Key
.
proxy
,
proxy
)
intent
.
putExtra
(
Key
.
sitekey
,
sitekey
)
intent
.
putExtra
(
Key
.
sitekey
,
sitekey
)
intent
.
putExtra
(
Key
.
encMethod
,
encMethod
)
intent
.
putExtra
(
Key
.
encMethod
,
encMethod
)
...
@@ -265,6 +278,36 @@ object Utils {
...
@@ -265,6 +278,36 @@ object Utils {
var
data_path
:
String
=
null
var
data_path
:
String
=
null
var
rootTries
=
0
var
rootTries
=
0
/*
* round or floor depending on whether you are using offsets(floor) or
* widths(round)
*/
def
dpToPx
(
context
:
Context
,
dp
:
Float
)
:
Float
=
{
val
density
=
context
.
getResources
.
getDisplayMetrics
.
density
dp
*
density
}
def
pxToDp
(
context
:
Context
,
px
:
Float
)
:
Float
=
{
val
density
=
context
.
getResources
.
getDisplayMetrics
.
density
px
/
density
}
def
getBitmap
(
text
:
String
,
width
:
Int
,
height
:
Int
,
background
:
Int
)
:
Bitmap
=
{
val
bitmap
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_8888
)
val
size
=
bitmap
.
getHeight
/
4
val
canvas
=
new
Canvas
(
bitmap
)
canvas
.
drawColor
(
background
)
val
paint
=
new
Paint
()
paint
.
setColor
(
Color
.
WHITE
)
paint
.
setTextSize
(
size
)
val
bounds
=
new
Rect
()
paint
.
getTextBounds
(
text
,
0
,
text
.
length
,
bounds
)
canvas
.
drawText
(
text
,
(
bitmap
.
getWidth
-
bounds
.
width
())
/
2
,
bitmap
.
getHeight
-
(
bitmap
.
getHeight
-
bounds
.
height
())
/
2
,
paint
)
bitmap
}
// Blocked > 3 seconds
// Blocked > 3 seconds
def
toggleAirplaneMode
(
context
:
Context
)
{
def
toggleAirplaneMode
(
context
:
Context
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
17
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
17
)
{
...
...
src/main/scala/com/github/shadowsocks/database/DBHelper.scala
View file @
a2848ce5
...
@@ -46,7 +46,7 @@ import com.j256.ormlite.support.ConnectionSource
...
@@ -46,7 +46,7 @@ import com.j256.ormlite.support.ConnectionSource
import
com.j256.ormlite.table.TableUtils
import
com.j256.ormlite.table.TableUtils
import
com.j256.ormlite.dao.Dao
import
com.j256.ormlite.dao.Dao
class
DBHelper
(
val
context
:
Context
)
extends
OrmLiteSqliteOpenHelper
(
context
,
"profile.db"
,
null
,
3
)
{
class
DBHelper
(
val
context
:
Context
)
extends
OrmLiteSqliteOpenHelper
(
context
,
"profile.db"
,
null
,
7
)
{
lazy
val
profileDao
:
Dao
[
Profile
,
Int
]
=
getDao
(
classOf
[
Profile
])
lazy
val
profileDao
:
Dao
[
Profile
,
Int
]
=
getDao
(
classOf
[
Profile
])
...
...
src/main/scala/com/github/shadowsocks/database/MenuAdapter.scala
View file @
a2848ce5
...
@@ -39,39 +39,39 @@
...
@@ -39,39 +39,39 @@
package
com.github.shadowsocks.database
package
com.github.shadowsocks.database
import
android.content.
{
DialogInterface
,
Context
}
import
android.content.
Context
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.BaseAdapter
import
android.widget.BaseAdapter
import
android.widget.TextView
import
android.widget.TextView
import
com.github.shadowsocks.
R
import
com.github.shadowsocks.
{
Shadowsocks
,
R
}
import
android.view.View.
OnClickListener
import
android.view.View.
{
OnLongClickListener
,
OnClickListener
}
case
class
Item
(
id
:
Int
,
title
:
String
,
iconRes
:
Int
,
action
:
Int
=>
Unit
)
case
class
Item
(
id
:
Int
,
title
:
String
,
iconRes
:
Int
,
click
:
Int
=>
Unit
,
longClick
:
Int
=>
Boolean
=
_
=>
false
)
case
class
Category
(
title
:
String
)
case
class
Category
(
title
:
String
)
object
MenuAdapter
{
object
MenuAdapter
{
trait
MenuListener
{
trait
MenuListener
{
def
onActiveViewChanged
(
v
:
View
)
def
onActiveViewChanged
(
v
:
View
,
pos
:
Int
)
}
}
val
UNDEFINED
=
-
1
val
UNDEFINED
=
-
1
val
CATEGORY
=
0
val
CATEGORY
=
0
val
ITEM
=
1
val
ITEM
=
1
}
}
class
MenuAdapter
(
context
:
Context
,
var
items
:
List
[
Any
])
extends
BaseAdapter
{
class
MenuAdapter
(
context
:
Context
,
var
items
:
List
[
Any
])
extends
BaseAdapter
{
def
setListener
(
listener
:
MenuAdapter.MenuListener
)
{
def
setListener
(
listener
:
MenuAdapter.MenuListener
)
{
mL
istener
=
listener
this
.
l
istener
=
listener
}
}
def
setActivePosition
(
activePosition
:
Int
)
{
def
setActivePosition
(
activePosition
:
Int
)
{
mA
ctivePosition
=
activePosition
this
.
a
ctivePosition
=
activePosition
}
}
@Override
def
getCount
:
Int
=
{
@Override
def
getCount
:
Int
=
{
...
@@ -121,32 +121,46 @@ class MenuAdapter (context: Context, var items: List[Any]) extends BaseAdapter {
...
@@ -121,32 +121,46 @@ class MenuAdapter (context: Context, var items: List[Any]) extends BaseAdapter {
}
}
val
tv
:
TextView
=
v
.
asInstanceOf
[
TextView
]
val
tv
:
TextView
=
v
.
asInstanceOf
[
TextView
]
tv
.
setText
(
value
.
title
)
tv
.
setText
(
value
.
title
)
if
(
value
.
iconRes
!=
-
1
)
{
tv
.
setCompoundDrawablesWithIntrinsicBounds
(
value
.
iconRes
,
0
,
0
,
0
)
tv
.
setCompoundDrawablesWithIntrinsicBounds
(
value
.
iconRes
,
0
,
0
,
0
)
}
tv
.
setOnClickListener
(
new
OnClickListener
{
tv
.
setOnClickListener
(
new
OnClickListener
{
def
onClick
(
view
:
View
)
{
def
onClick
(
view
:
View
)
{
val
item
=
view
.
getTag
(
R
.
id
.
mdItem
).
asInstanceOf
[
Item
]
val
item
=
view
.
getTag
(
R
.
id
.
mdItem
).
asInstanceOf
[
Item
]
item
.
action
(
item
.
id
)
item
.
click
(
item
.
id
)
}
})
tv
.
setOnLongClickListener
(
new
OnLongClickListener
{
def
onLongClick
(
view
:
View
)
:
Boolean
=
{
val
item
=
view
.
getTag
(
R
.
id
.
mdItem
).
asInstanceOf
[
Item
]
item
.
longClick
(
item
.
id
)
}
}
})
})
v
.
setTag
(
R
.
id
.
mdItem
,
value
)
v
.
setTag
(
R
.
id
.
mdItem
,
value
)
case
_
=>
case
_
=>
}
}
v
.
setTag
(
R
.
id
.
mdActiveViewPosition
,
position
)
v
.
setTag
(
R
.
id
.
mdActiveViewPosition
,
position
)
if
(
position
==
mA
ctivePosition
)
{
if
(
position
==
a
ctivePosition
)
{
if
(
mListener
!=
null
)
mListener
.
onActiveViewChanged
(
v
)
if
(
listener
!=
null
)
listener
.
onActiveViewChanged
(
v
,
position
)
}
}
v
v
}
}
def
updateList
(
list
:
List
[
Any
])
{
def
updateList
(
list
:
List
[
Any
]
,
activeId
:
Int
)
{
items
=
list
items
=
list
activePosition
=
items
.
indexWhere
{
case
item
:
Item
=>
item
.
id
==
activeId
case
_
=>
false
}
notifyDataSetChanged
()
notifyDataSetChanged
()
}
}
private
var
mL
istener
:
MenuAdapter.MenuListener
=
null
private
var
l
istener
:
MenuAdapter.MenuListener
=
null
private
var
mActivePosition
:
Int
=
0
private
var
activePosition
:
Int
=
-
1
}
}
src/main/scala/com/github/shadowsocks/database/Profile.scala
View file @
a2848ce5
...
@@ -42,14 +42,14 @@ package com.github.shadowsocks.database
...
@@ -42,14 +42,14 @@ package com.github.shadowsocks.database
import
com.j256.ormlite.field.
{
DataType
,
DatabaseField
}
import
com.j256.ormlite.field.
{
DataType
,
DatabaseField
}
class
Profile
{
class
Profile
{
@DatabaseField
(
i
d
=
true
)
@DatabaseField
(
generatedI
d
=
true
)
var
id
:
Int
=
0
var
id
:
Int
=
0
@DatabaseField
@DatabaseField
var
name
:
String
=
null
var
name
:
String
=
"Untitled"
@DatabaseField
@DatabaseField
var
host
:
String
=
null
var
host
:
String
=
""
@DatabaseField
@DatabaseField
var
localPort
:
Int
=
0
var
localPort
:
Int
=
0
...
@@ -58,13 +58,13 @@ class Profile {
...
@@ -58,13 +58,13 @@ class Profile {
var
remotePort
:
Int
=
0
var
remotePort
:
Int
=
0
@DatabaseField
@DatabaseField
var
password
:
String
=
null
var
password
:
String
=
""
@DatabaseField
@DatabaseField
var
method
:
String
=
null
var
method
:
String
=
""
@DatabaseField
@DatabaseField
var
date
:
String
=
null
var
date
:
String
=
""
@DatabaseField
@DatabaseField
var
upload
:
Int
=
0
var
upload
:
Int
=
0
...
@@ -78,9 +78,15 @@ class Profile {
...
@@ -78,9 +78,15 @@ class Profile {
@DatabaseField
@DatabaseField
var
global
:
Boolean
=
false
var
global
:
Boolean
=
false
@DatabaseField
var
bypass
:
Boolean
=
false
@DatabaseField
var
traffic
:
Boolean
=
false
@DatabaseField
(
dataType
=
DataType
.
LONG_STRING
)
@DatabaseField
(
dataType
=
DataType
.
LONG_STRING
)
var
individual
:
String
=
null
var
individual
:
String
=
""
@DatabaseField
(
dataType
=
DataType
.
LONG_STRING
)
@DatabaseField
(
dataType
=
DataType
.
LONG_STRING
)
var
description
:
String
=
null
var
description
:
String
=
""
}
}
src/main/scala/com/github/shadowsocks/database/ProfileManager.scala
View file @
a2848ce5
...
@@ -40,18 +40,20 @@
...
@@ -40,18 +40,20 @@
package
com.github.shadowsocks.database
package
com.github.shadowsocks.database
import
android.util.Log
import
android.util.Log
import
com.github.shadowsocks.Shadowsocks
import
com.github.shadowsocks._
import
android.content.
{
SharedPreferences
,
Context
}
class
ProfileManager
(
dbHelper
:
DBHelper
)
{
class
ProfileManager
(
settings
:
SharedPreferences
,
dbHelper
:
DBHelper
)
{
def
addProfile
(
profile
:
Profile
)
:
Boolean
=
{
def
createOrUpdateProfile
(
profile
:
Profile
)
:
Boolean
=
{
try
{
try
{
dbHelper
.
profileDao
.
createOrUpdate
(
profile
)
dbHelper
.
profileDao
.
createOrUpdate
(
profile
)
true
}
catch
{
}
catch
{
case
ex
:
Exception
=>
case
ex
:
Exception
=>
Log
.
e
(
Shadowsocks
.
TAG
,
"addProfile"
,
ex
)
Log
.
e
(
Shadowsocks
.
TAG
,
"addProfile"
,
ex
)
return
false
false
}
}
true
}
}
def
getProfile
(
id
:
Int
)
:
Option
[
Profile
]
=
{
def
getProfile
(
id
:
Int
)
:
Option
[
Profile
]
=
{
...
@@ -70,12 +72,12 @@ class ProfileManager(dbHelper: DBHelper) {
...
@@ -70,12 +72,12 @@ class ProfileManager(dbHelper: DBHelper) {
def
delProfile
(
id
:
Int
)
:
Boolean
=
{
def
delProfile
(
id
:
Int
)
:
Boolean
=
{
try
{
try
{
dbHelper
.
profileDao
.
deleteById
(
id
)
dbHelper
.
profileDao
.
deleteById
(
id
)
true
}
catch
{
}
catch
{
case
ex
:
Exception
=>
case
ex
:
Exception
=>
Log
.
e
(
Shadowsocks
.
TAG
,
"delProfile"
,
ex
)
Log
.
e
(
Shadowsocks
.
TAG
,
"delProfile"
,
ex
)
return
false
false
}
}
true
}
}
def
getAllProfiles
:
Option
[
List
[
Profile
]]
=
{
def
getAllProfiles
:
Option
[
List
[
Profile
]]
=
{
...
@@ -88,4 +90,70 @@ class ProfileManager(dbHelper: DBHelper) {
...
@@ -88,4 +90,70 @@ class ProfileManager(dbHelper: DBHelper) {
None
None
}
}
}
}
def
load
(
id
:
Int
)
:
Profile
=
{
Log
.
d
(
Shadowsocks
.
TAG
,
id
+
" "
)
save
()
val
profile
=
getProfile
(
id
)
getOrElse
{
val
p
=
new
Profile
()
createOrUpdateProfile
(
p
)
p
}
Log
.
d
(
Shadowsocks
.
TAG
,
"load "
+
profile
.
id
+
" "
+
profile
.
name
)
val
edit
=
settings
.
edit
()
edit
.
putBoolean
(
Key
.
isGlobalProxy
,
profile
.
global
)
edit
.
putBoolean
(
Key
.
isGFWList
,
profile
.
chnroute
)
edit
.
putBoolean
(
Key
.
isBypassApps
,
profile
.
bypass
)
edit
.
putBoolean
(
Key
.
isTrafficStat
,
profile
.
traffic
)
edit
.
putString
(
Key
.
profileName
,
profile
.
name
)
edit
.
putString
(
Key
.
proxy
,
profile
.
host
)
edit
.
putString
(
Key
.
sitekey
,
profile
.
password
)
edit
.
putString
(
Key
.
encMethod
,
profile
.
method
)
edit
.
putString
(
Key
.
remotePort
,
profile
.
remotePort
.
toString
)
edit
.
putString
(
Key
.
localPort
,
profile
.
localPort
.
toString
)
edit
.
putString
(
Key
.
proxied
,
profile
.
individual
)
edit
.
putInt
(
Key
.
profileId
,
profile
.
id
)
edit
.
commit
()
profile
}
def
save
()
{
val
profile
=
new
Profile
()
profile
.
global
=
settings
.
getBoolean
(
Key
.
isGlobalProxy
,
false
)
profile
.
chnroute
=
settings
.
getBoolean
(
Key
.
isGFWList
,
false
)
profile
.
bypass
=
settings
.
getBoolean
(
Key
.
isBypassApps
,
false
)
profile
.
traffic
=
settings
.
getBoolean
(
Key
.
isTrafficStat
,
false
)
profile
.
name
=
settings
.
getString
(
Key
.
profileName
,
"default"
)
profile
.
host
=
settings
.
getString
(
Key
.
proxy
,
"127.0.0.1"
)
profile
.
password
=
settings
.
getString
(
Key
.
sitekey
,
"default"
)
profile
.
method
=
settings
.
getString
(
Key
.
encMethod
,
"table"
)
profile
.
remotePort
=
try
{
Integer
.
valueOf
(
settings
.
getString
(
Key
.
remotePort
,
"1984"
))
}
catch
{
case
ex
:
NumberFormatException
=>
{
1984
}
}
profile
.
localPort
=
try
{
Integer
.
valueOf
(
settings
.
getString
(
Key
.
localPort
,
"1984"
))
}
catch
{
case
ex
:
NumberFormatException
=>
{
1984
}
}
profile
.
individual
=
settings
.
getString
(
Key
.
proxied
,
""
)
profile
.
id
=
settings
.
getInt
(
Key
.
profileId
,
-
1
)
Log
.
d
(
Shadowsocks
.
TAG
,
"save "
+
profile
.
id
+
" "
+
profile
.
name
)
createOrUpdateProfile
(
profile
)
}
}
}
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