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
e5ce8fd0
Commit
e5ce8fd0
authored
Dec 02, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine Tasker features
parent
41b7da4b
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
106 additions
and
291 deletions
+106
-291
src/main/res/drawable-anydpi-v21/ic_check.xml
src/main/res/drawable-anydpi-v21/ic_check.xml
+0
-9
src/main/res/drawable-hdpi/ic_check.png
src/main/res/drawable-hdpi/ic_check.png
+0
-0
src/main/res/drawable-mdpi/ic_check.png
src/main/res/drawable-mdpi/ic_check.png
+0
-0
src/main/res/drawable-xhdpi/ic_check.png
src/main/res/drawable-xhdpi/ic_check.png
+0
-0
src/main/res/drawable-xxhdpi/ic_check.png
src/main/res/drawable-xxhdpi/ic_check.png
+0
-0
src/main/res/drawable-xxxhdpi/ic_check.png
src/main/res/drawable-xxxhdpi/ic_check.png
+0
-0
src/main/res/layout/layout_tasker.xml
src/main/res/layout/layout_tasker.xml
+18
-9
src/main/res/layout/layout_tasker_toggle_service.xml
src/main/res/layout/layout_tasker_toggle_service.xml
+0
-13
src/main/res/menu/tasker_menu.xml
src/main/res/menu/tasker_menu.xml
+0
-10
src/main/res/values-zh/strings.xml
src/main/res/values-zh/strings.xml
+5
-2
src/main/res/values/arrays.xml
src/main/res/values/arrays.xml
+0
-10
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+5
-8
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
...scala/com/github/shadowsocks/ProfileManagerActivity.scala
+1
-1
src/main/scala/com/github/shadowsocks/TaskerActivity.scala
src/main/scala/com/github/shadowsocks/TaskerActivity.scala
+52
-155
src/main/scala/com/github/shadowsocks/TaskerReceiver.scala
src/main/scala/com/github/shadowsocks/TaskerReceiver.scala
+8
-14
src/main/scala/com/github/shadowsocks/helper/TaskerSettings.scala
.../scala/com/github/shadowsocks/helper/TaskerSettings.scala
+17
-60
No files found.
src/main/res/drawable-anydpi-v21/ic_check.xml
deleted
100644 → 0
View file @
41b7da4b
<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=
"M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"
/>
</vector>
src/main/res/drawable-hdpi/ic_check.png
deleted
100644 → 0
View file @
41b7da4b
181 Bytes
src/main/res/drawable-mdpi/ic_check.png
deleted
100644 → 0
View file @
41b7da4b
137 Bytes
src/main/res/drawable-xhdpi/ic_check.png
deleted
100644 → 0
View file @
41b7da4b
199 Bytes
src/main/res/drawable-xxhdpi/ic_check.png
deleted
100644 → 0
View file @
41b7da4b
276 Bytes
src/main/res/drawable-xxxhdpi/ic_check.png
deleted
100644 → 0
View file @
41b7da4b
308 Bytes
src/main/res/layout/layout_tasker.xml
View file @
e5ce8fd0
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
>
<include
layout=
"@layout/toolbar_light_dark"
/>
<include
layout=
"@layout/toolbar_light_dark"
/>
<FrameLayout
<FrameLayout
android:layout_width=
"match_parent"
android:id=
"@+id/fragment"
android:layout_height=
"wrap_content"
android:layout_width=
"match_parent"
android:elevation=
"1dp"
android:layout_height=
"match_parent"
/>
android:background=
"@android:color/white"
>
<Switch
android:id=
"@+id/serviceSwitch"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/toggle_service_state"
android:textSize=
"18sp"
android:padding=
"16dp"
/>
</FrameLayout>
<android.support.v7.widget.RecyclerView
android:id=
"@+id/profilesList"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</LinearLayout>
</LinearLayout>
src/main/res/layout/layout_tasker_toggle_service.xml
deleted
100644 → 0
View file @
41b7da4b
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<Switch
android:id=
"@+id/service_switch"
android:checked=
"true"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/toggle_service_state"
android:textSize=
"18sp"
android:textColor=
"?android:attr/textColorSecondary"
android:padding=
"16dp"
/>
</FrameLayout>
src/main/res/menu/tasker_menu.xml
deleted
100644 → 0
View file @
41b7da4b
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<item
android:title=
"@string/save"
android:id=
"@+id/save"
android:icon=
"@drawable/ic_check"
android:alphabeticShortcut=
"s"
android:numericShortcut=
"0"
app:showAsAction=
"always"
/>
</menu>
\ No newline at end of file
src/main/res/values-zh/strings.xml
View file @
e5ce8fd0
...
@@ -97,7 +97,10 @@
...
@@ -97,7 +97,10 @@
<string
name=
"removed"
>
已删除
</string>
<string
name=
"removed"
>
已删除
</string>
<string
name=
"undo"
>
撤销
</string>
<string
name=
"undo"
>
撤销
</string>
<string
name=
"toggle_service_state"
>
切换服务状态
</string>
<string
name=
"toggle_service_state"
>
启动服务
</string>
<string
name=
"save"
>
保存
</string>
<string
name=
"start_service_default"
>
连接到当前服务器
</string>
<string
name=
"start_service"
>
连接到 %s
</string>
<string
name=
"stop_service"
>
切换到 %s
</string>
<string
name=
"profile_default"
>
使用当前配置
</string>
</resources>
</resources>
src/main/res/values/arrays.xml
View file @
e5ce8fd0
...
@@ -226,14 +226,4 @@
...
@@ -226,14 +226,4 @@
<item>
204.0.0.0/6
</item>
<item>
204.0.0.0/6
</item>
<item>
208.0.0.0/4
</item>
<item>
208.0.0.0/4
</item>
</string-array>
</string-array>
<string-array
name=
"tasker_action_name"
>
<item>
Toggle service
</item>
<item>
Switch profile
</item>
</string-array>
<string-array
name=
"tasker_action_value"
>
<item>
toggle_service
</item>
<item>
switch_profile
</item>
</string-array>
</resources>
</resources>
src/main/res/values/strings.xml
View file @
e5ce8fd0
...
@@ -103,12 +103,9 @@
...
@@ -103,12 +103,9 @@
<string
name=
"undo"
>
Undo
</string>
<string
name=
"undo"
>
Undo
</string>
<!-- tasker -->
<!-- tasker -->
<string
name=
"toggle_service_state"
>
Toggle service state
</string>
<string
name=
"toggle_service_state"
>
Start the service
</string>
<string
name=
"save"
>
Save
</string>
<string
name=
"start_service_default"
>
Connect to the current server
</string>
<string
name=
"turn_service_state"
>
Turn service %s
</string>
<string
name=
"start_service"
>
Connect to %s
</string>
<string
name=
"no_action_selected"
>
No action was selected
</string>
<string
name=
"stop_service"
>
Switch to %s
</string>
<string
name=
"no_profile_selected"
>
No profile was selected
</string>
<string
name=
"profile_default"
>
Use the current profile
</string>
<string
name=
"switch_profile_to"
>
Switch profile to %s
</string>
<string
name=
"state_on"
>
on
</string>
<string
name=
"state_off"
>
off
</string>
</resources>
</resources>
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
View file @
e5ce8fd0
...
@@ -93,7 +93,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -93,7 +93,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
private
class
ProfilesAdapter
extends
RecyclerView
.
Adapter
[
ProfileViewHolder
]
{
private
class
ProfilesAdapter
extends
RecyclerView
.
Adapter
[
ProfileViewHolder
]
{
private
val
recycleBin
=
new
ArrayBuffer
[(
Int
,
Profile
)]
private
val
recycleBin
=
new
ArrayBuffer
[(
Int
,
Profile
)]
private
var
profiles
=
new
ArrayBuffer
[
Profile
]
private
var
profiles
=
new
ArrayBuffer
[
Profile
]
profiles
++=
ShadowsocksApplication
.
profileManager
.
getAllProfiles
.
getOrElse
(
List
[
Profile
]()
)
profiles
++=
ShadowsocksApplication
.
profileManager
.
getAllProfiles
.
getOrElse
(
List
.
empty
[
Profile
]
)
def
getItemCount
=
profiles
.
length
def
getItemCount
=
profiles
.
length
...
...
src/main/scala/com/github/shadowsocks/TaskerActivity.scala
View file @
e5ce8fd0
...
@@ -39,183 +39,80 @@
...
@@ -39,183 +39,80 @@
package
com.github.shadowsocks
package
com.github.shadowsocks
import
android.app.Activity
import
android.app.Activity
import
android.content.Intent
import
android.content.res.Resources
import
android.os.Bundle
import
android.os.
{
Build
,
Bundle
}
import
android.support.v4.app.
{
Fragment
,
ListFragment
}
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.widget.Toolbar
import
android.support.v7.widget.
{
DefaultItemAnimator
,
LinearLayoutManager
,
RecyclerView
,
Toolbar
}
import
android.util.Log
import
android.view.
{
LayoutInflater
,
View
,
ViewGroup
}
import
android.view.
{
LayoutInflater
,
View
,
ViewGroup
}
import
android.widget.AdapterView.OnItemClickListener
import
android.widget.
{
Switch
,
CheckedTextView
}
import
android.widget._
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.helper.TaskerSettings
import
com.github.shadowsocks.helper.TaskerSettings
import
com.twofortyfouram.locale.api.
{
Intent
=>
ApiIntent
}
/**
/**
* @author CzBiX
* @author CzBiX
*/
*/
class
TaskerActivity
extends
AppCompatActivity
{
class
TaskerActivity
extends
AppCompatActivity
{
var
taskerOption
:
TaskerSettings
=
_
private
class
ProfileViewHolder
(
val
view
:
View
)
extends
RecyclerView
.
ViewHolder
(
view
)
with
View
.
OnClickListener
{
var
actionSelected
:
Boolean
=
false
{
val
typedArray
=
obtainStyledAttributes
(
Array
(
android
.
R
.
attr
.
selectableItemBackground
))
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
view
.
setBackgroundResource
(
typedArray
.
getResourceId
(
0
,
0
))
super
.
onCreate
(
savedInstanceState
)
typedArray
.
recycle
setContentView
(
R
.
layout
.
layout_tasker
)
val
toolbar
=
findViewById
(
R
.
id
.
toolbar
).
asInstanceOf
[
Toolbar
]
toolbar
.
setTitle
(
R
.
string
.
app_name
)
toolbar
.
setNavigationIcon
(
R
.
drawable
.
ic_close
)
toolbar
.
setNavigationOnClickListener
(
_
=>
finish
())
toolbar
.
inflateMenu
(
R
.
menu
.
tasker_menu
)
toolbar
.
setOnMenuItemClickListener
(
_
.
getItemId
match
{
case
R
.
id
.
save
=>
saveResult
()
true
case
_
=>
false
})
loadSettings
()
loadFragment
()
}
private
def
loadSettings
()
{
val
intent
:
Intent
=
getIntent
if
(
intent
.
getAction
!=
ApiIntent
.
ACTION_EDIT_SETTING
)
{
Log
.
w
(
Shadowsocks
.
TAG
,
"unknown tasker action"
)
finish
()
return
}
}
private
var
item
:
Profile
=
_
taskerOption
=
TaskerSettings
.
fromIntent
(
intent
)
private
val
text
=
itemView
.
findViewById
(
android
.
R
.
id
.
text1
).
asInstanceOf
[
CheckedTextView
]
}
itemView
.
setOnClickListener
(
this
)
private
def
loadFragment
()
{
def
bindDefault
{
actionSelected
=
!
taskerOption
.
isEmpty
item
=
null
val
fragment
:
Fragment
=
taskerOption
.
action
match
{
text
.
setText
(
R
.
string
.
profile_default
)
case
TaskerSettings
.
ACTION_TOGGLE_SERVICE
=>
text
.
setChecked
(
taskerOption
.
profileId
<
0
)
new
ToggleServiceFragment
case
TaskerSettings
.
ACTION_SWITCH_PROFILE
=>
new
ProfileChoiceFragment
case
_
=>
val
fragment
:
ActionChoiceFragment
=
new
ActionChoiceFragment
fragment
.
onItemClickedListener
=
(
_
,
_
,
_
,
id
)
=>
{
taskerOption
.
action
=
getResources
.
getStringArray
(
R
.
array
.
tasker_action_value
)(
id
.
toInt
)
loadFragment
()
actionSelected
=
true
}
fragment
}
}
def
bind
(
item
:
Profile
)
{
getSupportFragmentManager
.
beginTransaction
()
this
.
item
=
item
.
replace
(
R
.
id
.
fragment
,
fragment
)
text
.
setText
(
item
.
name
)
.
commit
()
text
.
setChecked
(
taskerOption
.
profileId
==
item
.
id
)
}
private
def
saveResult
()
{
if
(
actionSelected
)
{
val
fragment
:
OptionFragment
=
getSupportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment
).
asInstanceOf
[
OptionFragment
]
if
(
fragment
.
saveResult
())
{
setResult
(
Activity
.
RESULT_OK
,
taskerOption
.
toIntent
(
this
))
finish
()
}
}
else
{
Toast
.
makeText
(
this
,
R
.
string
.
no_action_selected
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
}
private
class
ActionChoiceFragment
extends
ListFragment
{
var
onItemClickedListener
:
OnItemClickListener
=
_
override
def
onActivityCreated
(
savedInstanceState
:
Bundle
)
{
super
.
onActivityCreated
(
savedInstanceState
)
val
adapter
=
ArrayAdapter
.
createFromResource
(
getActivity
,
R
.
array
.
tasker_action_name
,
android
.
R
.
layout
.
simple_selectable_list_item
)
def
onClick
(
v
:
View
)
{
taskerOption
.
switchOn
=
switch
.
isChecked
setListAdapter
(
adapter
)
taskerOption
.
profileId
=
if
(
item
==
null
)
-
1
else
item
.
id
}
setResult
(
Activity
.
RESULT_OK
,
taskerOption
.
toIntent
(
TaskerActivity
.
this
))
finish
override
def
onListItemClick
(
l
:
ListView
,
v
:
View
,
position
:
Int
,
id
:
Long
)
{
if
(
onItemClickedListener
!=
null
)
{
onItemClickedListener
.
onItemClick
(
l
,
v
,
position
,
id
)
}
}
}
}
}
private
class
ToggleServiceFragment
extends
Fragment
with
OptionFragment
{
private
class
ProfilesAdapter
extends
RecyclerView
.
Adapter
[
ProfileViewHolder
]
{
var
switch
:
Switch
=
_
private
val
profiles
=
ShadowsocksApplication
.
profileManager
.
getAllProfiles
.
getOrElse
(
List
.
empty
[
Profile
])
def
getItemCount
=
1
+
profiles
.
length
override
def
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
,
savedInstanceState
:
Bundle
)
:
View
=
{
def
onBindViewHolder
(
vh
:
ProfileViewHolder
,
i
:
Int
)
=
i
match
{
val
view
:
View
=
inflater
.
inflate
(
R
.
layout
.
layout_tasker_toggle_service
,
container
,
false
)
case
0
=>
vh
.
bindDefault
case
_
=>
vh
.
bind
(
profiles
(
i
-
1
))
switch
=
view
.
findViewById
(
R
.
id
.
service_switch
).
asInstanceOf
[
Switch
]
view
}
override
def
onActivityCreated
(
savedInstanceState
:
Bundle
)
{
super
.
onActivityCreated
(
savedInstanceState
)
if
(!
taskerOption
.
isEmpty
)
{
switch
.
setChecked
(
taskerOption
.
isStart
)
}
}
override
def
saveResult
()
=
{
taskerOption
.
action
=
TaskerSettings
.
ACTION_TOGGLE_SERVICE
taskerOption
.
isStart
=
switch
.
isChecked
true
}
}
private
val
name
=
"select_dialog_singlechoice_"
+
(
if
(
Build
.
VERSION
.
SDK_INT
>=
21
)
"material"
else
"holo"
)
def
onCreateViewHolder
(
vg
:
ViewGroup
,
i
:
Int
)
=
new
ProfileViewHolder
(
LayoutInflater
.
from
(
vg
.
getContext
)
.
inflate
(
Resources
.
getSystem
.
getIdentifier
(
name
,
"layout"
,
"android"
),
vg
,
false
))
}
}
private
class
ProfileChoiceFragment
extends
ListFragment
with
OptionFragment
{
private
var
taskerOption
:
TaskerSettings
=
_
override
def
onActivityCreated
(
savedInstanceState
:
Bundle
)
{
private
var
switch
:
Switch
=
_
super
.
onActivityCreated
(
savedInstanceState
)
private
val
profilesAdapter
=
new
ProfilesAdapter
import
scala.collection.JavaConverters._
val
profiles
=
ShadowsocksApplication
.
profileManager
.
getAllProfiles
.
getOrElse
(
List
.
empty
)
val
adapter
=
new
ArrayAdapter
[
Profile
](
getActivity
,
0
,
android
.
R
.
id
.
text1
,
profiles
.
asJava
)
{
override
def
getView
(
position
:
Int
,
convertView
:
View
,
parent
:
ViewGroup
)
:
View
=
{
val
view
:
TextView
=
if
(
convertView
==
null
)
{
val
inflater
=
LayoutInflater
.
from
(
parent
.
getContext
)
inflater
.
inflate
(
android
.
R
.
layout
.
simple_list_item_single_choice
,
parent
,
false
).
asInstanceOf
[
TextView
]
}
else
{
convertView
.
asInstanceOf
[
TextView
]
}
view
.
setText
(
getItem
(
position
).
name
)
view
}
}
setListAdapter
(
adapter
)
val
listView
:
ListView
=
getListView
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
listView
.
setChoiceMode
(
AbsListView
.
CHOICE_MODE_SINGLE
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
layout_tasker
)
if
(!
taskerOption
.
isEmpty
)
{
val
index
=
profiles
.
indexWhere
(
_
.
id
==
taskerOption
.
profileId
)
if
(
index
>
-
1
)
{
listView
.
setItemChecked
(
index
,
true
)
}
}
}
override
def
saveResult
()
=
{
val
toolbar
=
findViewById
(
R
.
id
.
toolbar
).
asInstanceOf
[
Toolbar
]
taskerOption
.
action
=
TaskerSettings
.
ACTION_SWITCH_PROFILE
toolbar
.
setTitle
(
R
.
string
.
app_name
)
val
listView
=
getListView
toolbar
.
setNavigationIcon
(
R
.
drawable
.
ic_close
)
val
item
=
listView
.
getItemAtPosition
(
listView
.
getCheckedItemPosition
)
toolbar
.
setNavigationOnClickListener
(
_
=>
finish
())
if
(
item
==
null
)
{
Toast
.
makeText
(
getActivity
,
R
.
string
.
no_profile_selected
,
Toast
.
LENGTH_SHORT
).
show
()
false
}
else
{
taskerOption
.
profileId
=
item
.
asInstanceOf
[
Profile
].
id
true
}
}
}
trait
OptionFragment
extends
Fragment
{
taskerOption
=
TaskerSettings
.
fromIntent
(
getIntent
)
def
saveResult
()
:
Boolean
switch
=
findViewById
(
R
.
id
.
serviceSwitch
).
asInstanceOf
[
Switch
]
switch
.
setChecked
(
taskerOption
.
switchOn
)
val
profilesList
=
findViewById
(
R
.
id
.
profilesList
).
asInstanceOf
[
RecyclerView
]
profilesList
.
setLayoutManager
(
new
LinearLayoutManager
(
this
))
profilesList
.
setItemAnimator
(
new
DefaultItemAnimator
)
profilesList
.
setAdapter
(
profilesAdapter
)
}
}
}
}
src/main/scala/com/github/shadowsocks/TaskerReceiver.scala
View file @
e5ce8fd0
...
@@ -39,7 +39,6 @@
...
@@ -39,7 +39,6 @@
package
com.github.shadowsocks
package
com.github.shadowsocks
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
}
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
}
import
android.util.Log
import
com.github.shadowsocks.helper.TaskerSettings
import
com.github.shadowsocks.helper.TaskerSettings
import
com.github.shadowsocks.utils.Utils
import
com.github.shadowsocks.utils.Utils
...
@@ -47,20 +46,15 @@ import com.github.shadowsocks.utils.Utils
...
@@ -47,20 +46,15 @@ import com.github.shadowsocks.utils.Utils
* @author CzBiX
* @author CzBiX
*/
*/
class
TaskerReceiver
extends
BroadcastReceiver
{
class
TaskerReceiver
extends
BroadcastReceiver
{
override
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
:
Unit
=
{
override
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
val
settings
:
TaskerSettings
=
TaskerSettings
.
fromIntent
(
intent
)
val
settings
=
TaskerSettings
.
fromIntent
(
intent
)
val
switched
=
ShadowsocksApplication
.
profileManager
.
getProfile
(
settings
.
profileId
)
match
{
settings
.
action
match
{
case
Some
(
p
)
=>
case
TaskerSettings
.
ACTION_TOGGLE_SERVICE
=>
Utils
.
stopSsService
(
context
)
if
(
settings
.
isStart
)
{
Utils
.
startSsService
(
context
)
}
else
{
Utils
.
stopSsService
(
context
)
}
case
TaskerSettings
.
ACTION_SWITCH_PROFILE
=>
ShadowsocksApplication
.
switchProfile
(
settings
.
profileId
)
ShadowsocksApplication
.
switchProfile
(
settings
.
profileId
)
case
_
=>
true
Log
.
e
(
Shadowsocks
.
TAG
,
s
"unknown tasker action: ${settings.action}"
)
case
_
=>
false
}
}
if
(
settings
.
switchOn
)
Utils
.
startSsService
(
context
)
else
if
(!
switched
)
Utils
.
stopSsService
(
context
)
}
}
}
}
src/main/scala/com/github/shadowsocks/helper/TaskerSettings.scala
View file @
e5ce8fd0
...
@@ -40,78 +40,35 @@ package com.github.shadowsocks.helper
...
@@ -40,78 +40,35 @@ package com.github.shadowsocks.helper
import
android.content.
{
Context
,
Intent
}
import
android.content.
{
Context
,
Intent
}
import
android.os.Bundle
import
android.os.Bundle
import
android.util.Log
import
com.github.shadowsocks.
{
R
,
ShadowsocksApplication
}
import
com.github.shadowsocks.
{
R
,
Shadowsocks
,
ShadowsocksApplication
}
import
com.twofortyfouram.locale.api.
{
Intent
=>
ApiIntent
}
import
com.twofortyfouram.locale.api.
{
Intent
=>
ApiIntent
}
object
TaskerSettings
{
object
TaskerSettings
{
val
ACTION_UNKNOWN
=
"unknown"
private
val
KEY_ACTION
=
"action"
val
ACTION_TOGGLE_SERVICE
=
"toggle_service"
private
val
KEY_SWITCH_ON
=
"switch_on"
val
ACTION_SWITCH_PROFILE
=
"switch_profile"
private
val
KEY_PROFILE_ID
=
"profile_id"
def
fromIntent
(
intent
:
Intent
)
:
TaskerSettings
=
{
val
bundle
:
Bundle
=
if
(
intent
.
hasExtra
(
ApiIntent
.
EXTRA_BUNDLE
))
intent
.
getBundleExtra
(
ApiIntent
.
EXTRA_BUNDLE
)
else
Bundle
.
EMPTY
new
TaskerSettings
(
bundle
)
def
fromIntent
(
intent
:
Intent
)
=
new
TaskerSettings
(
if
(
intent
.
hasExtra
(
ApiIntent
.
EXTRA_BUNDLE
)
)
}
intent
.
getBundleExtra
(
ApiIntent
.
EXTRA_BUNDLE
)
else
Bundle
.
EMPTY
)
def
fromBundle
(
bundle
:
Bundle
)
:
TaskerSettings
=
{
def
fromBundle
(
bundle
:
Bundle
)
=
new
TaskerSettings
(
bundle
)
new
TaskerSettings
(
bundle
)
}
}
}
class
TaskerSettings
(
bundle
:
Bundle
)
{
class
TaskerSettings
(
bundle
:
Bundle
)
{
import
TaskerSettings._
import
TaskerSettings._
private
val
KEY_ACTION
=
"action"
var
switchOn
=
bundle
.
getBoolean
(
KEY_SWITCH_ON
,
true
)
private
val
KEY_IS_START
=
"is_start"
var
profileId
=
bundle
.
getInt
(
KEY_PROFILE_ID
,
-
1
)
private
val
KEY_PROFILE_ID
=
"profile_id"
var
action
:
String
=
bundle
.
getString
(
KEY_ACTION
,
ACTION_UNKNOWN
)
var
isStart
:
Boolean
=
_
def
toIntent
(
context
:
Context
)
=
{
var
profileId
:
Int
=
_
action
match
{
case
ACTION_TOGGLE_SERVICE
=>
isStart
=
bundle
.
getBoolean
(
KEY_IS_START
,
true
)
case
ACTION_SWITCH_PROFILE
=>
profileId
=
bundle
.
getInt
(
KEY_PROFILE_ID
,
-
1
)
assert
(
profileId
!=
-
1
,
"profile id was wrong"
)
case
_
=>
Log
.
w
(
Shadowsocks
.
TAG
,
s
"unknown tasker action settings: $action"
)
}
def
isEmpty
=
action
==
ACTION_UNKNOWN
def
toIntent
(
context
:
Context
)
:
Intent
=
{
val
bundle
=
new
Bundle
()
val
bundle
=
new
Bundle
()
if
(!
switchOn
)
bundle
.
putBoolean
(
KEY_SWITCH_ON
,
false
)
action
match
{
if
(
profileId
>=
0
)
bundle
.
putInt
(
KEY_PROFILE_ID
,
profileId
)
case
ACTION_TOGGLE_SERVICE
=>
new
Intent
().
putExtra
(
ApiIntent
.
EXTRA_BUNDLE
,
bundle
).
putExtra
(
ApiIntent
.
EXTRA_STRING_BLURB
,
bundle
.
putString
(
KEY_ACTION
,
action
)
ShadowsocksApplication
.
profileManager
.
getProfile
(
profileId
)
match
{
bundle
.
putBoolean
(
KEY_IS_START
,
isStart
)
case
Some
(
p
)
=>
context
.
getString
(
if
(
switchOn
)
R
.
string
.
start_service
else
R
.
string
.
stop_service
,
p
.
name
)
case
ACTION_SWITCH_PROFILE
=>
case
None
=>
context
.
getString
(
if
(
switchOn
)
R
.
string
.
start_service_default
else
R
.
string
.
stop
)
bundle
.
putString
(
KEY_ACTION
,
action
)
})
bundle
.
putInt
(
KEY_PROFILE_ID
,
profileId
)
}
val
desc
:
String
=
action
match
{
case
ACTION_TOGGLE_SERVICE
=>
context
.
getString
(
R
.
string
.
turn_service_state
,
context
.
getString
(
if
(
isStart
)
R
.
string
.
state_on
else
R
.
string
.
state_off
))
case
ACTION_SWITCH_PROFILE
=>
val
profileName
=
ShadowsocksApplication
.
profileManager
.
getProfile
(
profileId
)
match
{
case
Some
(
p
)
=>
p
.
name
case
None
=>
context
.
getString
(
R
.
string
.
removed
)
}
context
.
getString
(
R
.
string
.
switch_profile_to
,
profileName
)
}
val
intent
:
Intent
=
new
Intent
()
intent
.
putExtra
(
ApiIntent
.
EXTRA_STRING_BLURB
,
desc
)
.
putExtra
(
ApiIntent
.
EXTRA_BUNDLE
,
bundle
)
}
}
}
}
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