Commit 8e3af716 authored by Mygod's avatar Mygod

Change tile to a quick switch

parent 048219a7
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
</intent-filter> </intent-filter>
</service> </service>
<service android:name=".ShadowsocksTileService" android:label="@string/app_name" <service android:name=".ShadowsocksTileService" android:label="@string/quick_toggle"
android:icon="@drawable/ic_start_connected" android:icon="@drawable/ic_start_connected"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"> android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter> <intent-filter>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="quick_toggle">Переключение</string>
<!-- global/misc category --> <!-- global/misc category -->
<string name="misc_cat">Разное</string> <string name="misc_cat">Разное</string>
<string name="profile">Профиль</string> <string name="profile">Профиль</string>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">影梭</string> <string name="app_name">影梭</string>
<string name="quick_toggle">开关</string>
<string name="misc_cat">其他</string> <string name="misc_cat">其他</string>
<string name="proxy_cat">服务器设置</string> <string name="proxy_cat">服务器设置</string>
<string name="profile_name">配置名称</string> <string name="profile_name">配置名称</string>
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
<resources> <resources>
<string name="app_name">Shadowsocks</string> <string name="app_name">Shadowsocks</string>
<string name="quick_toggle">開關</string>
<string name="misc_cat">其他</string> <string name="misc_cat">其他</string>
<string name="proxy_cat">伺服器設定</string> <string name="proxy_cat">伺服器設定</string>
<string name="profile_name">設定檔名稱</string> <string name="profile_name">設定檔名稱</string>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<resources> <resources>
<string name="app_name">Shadowsocks</string> <string name="app_name">Shadowsocks</string>
<string name="quick_toggle">Toggle</string>
<!-- global/misc category --> <!-- global/misc category -->
<string name="misc_cat">Misc</string> <string name="misc_cat">Misc</string>
......
package com.github.shadowsocks package com.github.shadowsocks
import android.content.Intent
import android.graphics.drawable.Icon import android.graphics.drawable.Icon
import android.service.quicksettings.{Tile, TileService} import android.service.quicksettings.{Tile, TileService}
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import com.github.shadowsocks.utils.State import com.github.shadowsocks.utils.{State, Utils}
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
/** /**
...@@ -48,10 +47,14 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext ...@@ -48,10 +47,14 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext
override def onStopListening { override def onStopListening {
super.onStopListening super.onStopListening
detachService // just in case the user switches to NAT mode detachService // just in case the user switches to NAT mode, also saves battery
} }
override def onClick = if (isLocked) unlockAndRun(configure) else configure() override def onClick = if (isLocked) unlockAndRun(toggle) else toggle()
private def configure() = startActivityAndCollapse(new Intent(this, classOf[Shadowsocks])) private def toggle() = bgService.getState match {
case State.STOPPED => Utils.startSsService(this)
case State.CONNECTED => Utils.stopSsService(this)
case _ => // ignore
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment