Add quick toggle shortcut (#950)

Mainly for Android 7.1, also backward compatible.
This commit is contained in:
Mygod
2016-10-23 14:16:56 +08:00
parent 54c696d00a
commit 244c2ecdfd
3 changed files with 65 additions and 0 deletions
@@ -0,0 +1,39 @@
package com.github.shadowsocks
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.github.shadowsocks.utils.{State, Utils}
/**
* @author Mygod
*/
class QuickToggleShortcut extends Activity with ServiceBoundContext {
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
getIntent.getAction match {
case Intent.ACTION_CREATE_SHORTCUT =>
setResult(Activity.RESULT_OK, new Intent()
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, classOf[QuickToggleShortcut]))
.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle))
.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)))
finish()
case _ => attachService()
}
}
override def onDestroy() {
detachService()
super.onDestroy()
}
override def onServiceConnected() {
bgService.getState match {
case State.STOPPED => Utils.startSsService(this)
case State.CONNECTED => Utils.stopSsService(this)
case _ => // ignore
}
finish()
}
}