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
7c5efdaa
Commit
7c5efdaa
authored
Mar 12, 2016
by
Lucas Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add quick switch from notification.
parent
9965a71c
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
140 additions
and
0 deletions
+140
-0
build.sbt
build.sbt
+1
-0
src/main/AndroidManifest.xml
src/main/AndroidManifest.xml
+11
-0
src/main/res/layout/layout_quick_switch.xml
src/main/res/layout/layout_quick_switch.xml
+34
-0
src/main/res/values-zh/strings.xml
src/main/res/values-zh/strings.xml
+1
-0
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+1
-0
src/main/res/values/styles.xml
src/main/res/values/styles.xml
+11
-0
src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala
...cala/com/github/shadowsocks/ShadowsocksNotification.scala
+2
-0
src/main/scala/com/github/shadowsocks/ShadowsocksQuickSwitchActivity.scala
...m/github/shadowsocks/ShadowsocksQuickSwitchActivity.scala
+78
-0
src/main/scala/com/github/shadowsocks/utils/Constants.scala
src/main/scala/com/github/shadowsocks/utils/Constants.scala
+1
-0
No files found.
build.sbt
View file @
7c5efdaa
...
...
@@ -38,6 +38,7 @@ libraryDependencies ++= Seq(
"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.android.support"
%
"cardview-v7"
%
"23.2.0"
,
"com.github.jorgecastilloprz"
%
"fabprogresscircle"
%
"1.01"
,
"com.j256.ormlite"
%
"ormlite-core"
%
"4.48"
,
"com.j256.ormlite"
%
"ormlite-android"
%
"4.48"
,
...
...
src/main/AndroidManifest.xml
View file @
7c5efdaa
...
...
@@ -86,6 +86,17 @@
</intent-filter>
</activity>
<activity
android:name=
".ShadowsocksQuickSwitchActivity"
android:launchMode=
"singleInstance"
android:excludeFromRecents=
"true"
android:taskAffinity=
""
android:theme=
"@style/PopupTheme.QuickSwitch"
>
<intent-filter>
<action
android:name=
"com.github.shadowsocks.QUICK_SWITCH"
/>
<category
android:name=
"android.intent.category.DEFAULT"
/>
</intent-filter>
</activity>
<service
android:name=
".ShadowsocksRunnerService"
android:exported=
"false"
>
...
...
src/main/res/layout/layout_quick_switch.xml
0 → 100644
View file @
7c5efdaa
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:orientation=
"vertical"
android:clickable=
"true"
android:foreground=
"@android:color/transparent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<android.support.v7.widget.CardView
android:layout_height=
"260dp"
android:layout_width=
"match_parent"
android:layout_margin=
"8dp"
android:layout_gravity=
"center_vertical"
android:clickable=
"true"
app:cardElevation=
"5dp"
app:cardBackgroundColor=
"#EEEEEE"
>
<LinearLayout
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<include
layout=
"@layout/toolbar_light_dark"
/>
<android.support.v7.widget.RecyclerView
android:id=
"@+id/profilesList"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
\ No newline at end of file
src/main/res/values-zh/strings.xml
View file @
7c5efdaa
...
...
@@ -38,6 +38,7 @@
<string
name=
"nat_no_root"
>
NAT 模式需要 ROOT 权限
</string>
<string
name=
"switch_to_vpn"
>
切换到 VPN 模式
</string>
<string
name=
"stop"
>
停止服务
</string>
<string
name=
"quick_switch"
>
快速切换
</string>
<string
name=
"stopping"
>
正在关闭……
</string>
<string
name=
"vpn_error"
>
后台服务启动失败:%s
</string>
<string
name=
"reboot_required"
>
VPN 服务启动失败。你可能需要重启设备。
</string>
...
...
src/main/res/values/strings.xml
View file @
7c5efdaa
...
...
@@ -73,6 +73,7 @@
<string
name=
"stopping"
>
Shutting down…
</string>
<string
name=
"vpn_error"
>
%s
</string>
<string
name=
"reboot_required"
>
Failed to start VPN service. You might need to reboot your device.
</string>
<string
name=
"quick_switch"
>
Quick Switch
</string>
<!-- alert category -->
<string
name=
"close"
>
Close
</string>
...
...
src/main/res/values/styles.xml
View file @
7c5efdaa
...
...
@@ -5,6 +5,7 @@
<style
name=
"Toolbar.Logo"
parent=
"TextAppearance.Widget.AppCompat.Toolbar.Title"
>
<item
name=
"android:textSize"
>
24sp
</item>
</style>
<style
name=
"Theme.Material"
parent=
"Theme.AppCompat.Light.NoActionBar"
>
<item
name=
"android:alertDialogTheme"
>
@style/Theme.Material.Dialog.Alert
</item>
<item
name=
"android:dialogTheme"
>
@style/Theme.Material.Dialog
</item>
...
...
@@ -14,19 +15,23 @@
<item
name=
"colorPrimary"
>
@color/material_accent_500
</item>
<item
name=
"colorPrimaryDark"
>
@color/material_accent_700
</item>
</style>
<style
name=
"Theme.Material.DialogBase"
parent=
"Theme.AppCompat.Light.Dialog"
>
<item
name=
"colorAccent"
>
@color/material_accent_500
</item>
<item
name=
"colorPrimary"
>
@color/material_accent_500
</item>
<item
name=
"colorPrimaryDark"
>
@color/material_accent_700
</item>
</style>
<style
name=
"Theme.Material.Dialog.AlertBase"
parent=
"Theme.AppCompat.Light.Dialog.Alert"
>
<item
name=
"colorAccent"
>
@color/material_accent_500
</item>
<item
name=
"colorPrimary"
>
@color/material_accent_500
</item>
<item
name=
"colorPrimaryDark"
>
@color/material_accent_700
</item>
</style>
<style
name=
"Theme.Material.Dialog"
parent=
"Theme.Material.DialogBase"
>
<item
name=
"android:windowBackground"
>
@android:color/transparent
</item>
</style>
<style
name=
"Theme.Material.Dialog.Alert"
parent=
"Theme.Material.Dialog.AlertBase"
>
<item
name=
"android:windowBackground"
>
@android:color/transparent
</item>
</style>
...
...
@@ -39,4 +44,10 @@
<item
name=
"android:windowBackground"
>
@android:color/transparent
</item>
</style>
<style
name=
"PopupTheme.QuickSwitch"
parent=
"PopupTheme"
>
<item
name=
"windowNoTitle"
>
true
</item>
<item
name=
"android:windowActionBar"
>
false
</item>
<item
name=
"android:windowAnimationStyle"
>
@android:style/Animation.Translucent
</item>
</style>
</resources>
src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala
View file @
7c5efdaa
...
...
@@ -41,6 +41,8 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
.
setSmallIcon
(
R
.
drawable
.
ic_stat_shadowsocks
)
.
addAction
(
android
.
R
.
drawable
.
ic_menu_close_clear_cancel
,
service
.
getString
(
R
.
string
.
stop
),
PendingIntent
.
getBroadcast
(
service
,
0
,
new
Intent
(
Action
.
CLOSE
),
0
))
.
addAction
(
android
.
R
.
drawable
.
ic_menu_manage
,
service
.
getString
(
R
.
string
.
quick_switch
),
PendingIntent
.
getActivity
(
service
,
0
,
new
Intent
(
Action
.
QUICK_SWITCH
),
0
))
private
lazy
val
style
=
new
BigTextStyle
(
builder
)
private
val
showOnUnlock
=
visible
&&
Utils
.
isLollipopOrAbove
private
var
isVisible
=
true
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksQuickSwitchActivity.scala
0 → 100644
View file @
7c5efdaa
package
com.github.shadowsocks
import
android.content.res.Resources
import
android.os.
{
Handler
,
Build
,
Bundle
}
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.widget.
{
Toolbar
,
DefaultItemAnimator
,
LinearLayoutManager
,
RecyclerView
}
import
android.view.
{
LayoutInflater
,
View
,
ViewGroup
}
import
android.widget.CheckedTextView
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.utils.Utils
/**
* Created by Lucas on 3/10/16.
*/
class
ShadowsocksQuickSwitchActivity
extends
AppCompatActivity
{
private
class
ProfileViewHolder
(
val
view
:
View
)
extends
RecyclerView
.
ViewHolder
(
view
)
with
View
.
OnClickListener
{
{
val
typedArray
=
obtainStyledAttributes
(
Array
(
android
.
R
.
attr
.
selectableItemBackground
))
view
.
setBackgroundResource
(
typedArray
.
getResourceId
(
0
,
0
))
typedArray
.
recycle
}
private
var
item
:
Profile
=
_
private
val
text
=
itemView
.
findViewById
(
android
.
R
.
id
.
text1
).
asInstanceOf
[
CheckedTextView
]
itemView
.
setOnClickListener
(
this
)
def
bind
(
item
:
Profile
)
{
this
.
item
=
item
text
.
setText
(
item
.
name
)
if
(
item
.
id
==
ShadowsocksApplication
.
profileId
)
{
text
.
setChecked
(
true
)
}
else
{
text
.
setChecked
(
false
)
}
}
def
onClick
(
v
:
View
)
{
Utils
.
stopSsService
(
ShadowsocksQuickSwitchActivity
.
this
)
ShadowsocksApplication
.
switchProfile
(
item
.
id
)
val
handler
=
new
Handler
(
ShadowsocksQuickSwitchActivity
.
this
.
getMainLooper
)
handler
.
postDelayed
(()
=>
{
Utils
.
startSsService
(
ShadowsocksQuickSwitchActivity
.
this
)
},
3000
)
finish
}
}
private
class
ProfilesAdapter
extends
RecyclerView
.
Adapter
[
ProfileViewHolder
]
{
val
profiles
=
ShadowsocksApplication
.
profileManager
.
getAllProfiles
.
getOrElse
(
List
.
empty
[
Profile
])
def
getItemCount
=
profiles
.
length
def
onBindViewHolder
(
vh
:
ProfileViewHolder
,
i
:
Int
)
=
i
match
{
case
_
=>
vh
.
bind
(
profiles
(
i
))
}
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
val
profilesAdapter
=
new
ProfilesAdapter
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
layout_quick_switch
)
val
toolbar
=
findViewById
(
R
.
id
.
toolbar
).
asInstanceOf
[
Toolbar
]
toolbar
.
setTitle
(
R
.
string
.
quick_switch
)
val
profilesList
=
findViewById
(
R
.
id
.
profilesList
).
asInstanceOf
[
RecyclerView
]
val
lm
=
new
LinearLayoutManager
(
this
)
profilesList
.
setLayoutManager
(
lm
)
profilesList
.
setItemAnimator
(
new
DefaultItemAnimator
)
profilesList
.
setAdapter
(
profilesAdapter
)
}
}
src/main/scala/com/github/shadowsocks/utils/Constants.scala
View file @
7c5efdaa
...
...
@@ -104,6 +104,7 @@ object State {
object
Action
{
val
SERVICE
=
"com.github.shadowsocks.SERVICE"
val
CLOSE
=
"com.github.shadowsocks.CLOSE"
val
QUICK_SWITCH
=
"com.github.shadowsocks.QUICK_SWITCH"
}
object
Route
{
...
...
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