From 89df2bc715dddf83873de7c116063cece8a55d28 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 17 Jun 2016 14:36:13 +0800 Subject: [PATCH] Hide stop action in notification if the quick settings tile is present --- .../shadowsocks/ShadowsocksNotification.scala | 4 ++-- .../shadowsocks/ShadowsocksTileService.scala | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala index 2dfe1ff5..73b61938 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala @@ -40,8 +40,8 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str .setContentIntent(PendingIntent.getActivity(service, 0, new Intent(service, classOf[Shadowsocks]) .setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), 0)) .setSmallIcon(R.drawable.ic_stat_shadowsocks) - .addAction(R.drawable.ic_navigation_close, service.getString(R.string.stop), - PendingIntent.getBroadcast(service, 0, new Intent(Action.CLOSE), 0)) + if (!ShadowsocksTileService.running) builder.addAction(R.drawable.ic_navigation_close, + service.getString(R.string.stop), PendingIntent.getBroadcast(service, 0, new Intent(Action.CLOSE), 0)) app.profileManager.getAllProfiles match { case Some(profiles) => if (profiles.length > 1) builder.addAction(R.drawable.ic_action_settings, service.getString(R.string.quick_switch), diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala index 3d1c4392..52ca468a 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksTileService.scala @@ -10,8 +10,14 @@ import com.github.shadowsocks.ShadowsocksApplication.app /** * @author Mygod */ +object ShadowsocksTileService { + var running: Boolean = _ +} + @TargetApi(24) final class ShadowsocksTileService extends TileService with ServiceBoundContext { + import ShadowsocksTileService._ + private lazy val iconIdle = Icon.createWithResource(this, R.drawable.ic_start_idle).setTint(0x80ffffff) private lazy val iconBusy = Icon.createWithResource(this, R.drawable.ic_start_busy) private lazy val iconConnected = Icon.createWithResource(this, R.drawable.ic_start_connected) @@ -42,11 +48,19 @@ final class ShadowsocksTileService extends TileService with ServiceBoundContext override def onServiceConnected = callback.stateChanged(bgService.getState, null) + override def onCreate { + super.onCreate + running = true + } + override def onDestroy { + super.onDestroy + running = false + } + override def onStartListening { super.onStartListening attachService(callback) } - override def onStopListening { super.onStopListening detachService // just in case the user switches to NAT mode, also saves battery