diff --git a/project/plugins.sbt b/project/plugins.sbt index 5388c040..eb8c16ec 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,5 @@ resolvers += Resolver.url("scalasbt releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-snapshots"))(Resolver.ivyStylePatterns) -addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.5.10") +addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.5.11") resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.7.0-SNAPSHOT") diff --git a/src/main/scala/com/github/shadowsocks/AppManager.scala b/src/main/scala/com/github/shadowsocks/AppManager.scala index 2e977e00..2a3b5a55 100644 --- a/src/main/scala/com/github/shadowsocks/AppManager.scala +++ b/src/main/scala/com/github/shadowsocks/AppManager.scala @@ -150,6 +150,10 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC handler.removeCallbacksAndMessages(null) handler = null } + if (overlay != null) { + getWindowManager.removeViewImmediate(overlay) + overlay = null + } } def onMenuItemClick(item: MenuItem): Boolean = { @@ -210,7 +214,7 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC toolbar.inflateMenu(R.menu.app_manager_menu) toolbar.setOnMenuItemClickListener(this) - this.overlay = View.inflate(this, R.layout.overlay, null).asInstanceOf[TextView] + overlay = View.inflate(this, R.layout.overlay, null).asInstanceOf[TextView] getWindowManager.addView(overlay, new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_APPLICATION, @@ -219,7 +223,7 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC findViewById(R.id.onSwitch).asInstanceOf[Switch] .setOnCheckedChangeListener((button: CompoundButton, checked: Boolean) => { - ShadowsocksApplication.settings.edit().putBoolean(Key.isProxyApps, checked).apply() + ShadowsocksApplication.settings.edit().putBoolean(Key.isProxyApps, checked).commit() finish() }) diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala index 7f5de8c4..6dd51b30 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala @@ -24,10 +24,6 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan getPreferenceManager.getSharedPreferences.registerOnSharedPreferenceChangeListener(this) isProxyApps = findPreference(Key.isProxyApps).asInstanceOf[SwitchPreference] - isProxyApps.setOnPreferenceChangeListener((preference: Preference, newValue: Any) => { - startActivity(new Intent(activity, classOf[AppManager])) - newValue.asInstanceOf[Boolean] // keep it ON - }) findPreference("recovery").setOnPreferenceClickListener((preference: Preference) => { ShadowsocksApplication.track(Shadowsocks.TAG, "reset") @@ -67,8 +63,19 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan } override def onResume { - super.onResume + super.onResume() isProxyApps.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isProxyApps, false)) // update + isProxyApps.setOnPreferenceChangeListener((preference: Preference, newValue: Any) => { + if (newValue.asInstanceOf[Boolean] == true) { + startActivity(new Intent(activity, classOf[AppManager])) + } + true + }) + } + + override def onPause { + super.onPause() + isProxyApps.setOnPreferenceChangeListener(null) } def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) = key match {