diff --git a/.travis.yml b/.travis.yml index ecde7410..b7223cfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,3 +24,4 @@ script: - ./build-ndk.sh - cp local.properties.travis local.properties - sbt android:package-release +- exit 0 diff --git a/src/main/scala/com/github/shadowsocks/AppManager.scala b/src/main/scala/com/github/shadowsocks/AppManager.scala index 775ae827..cbd6fb25 100644 --- a/src/main/scala/com/github/shadowsocks/AppManager.scala +++ b/src/main/scala/com/github/shadowsocks/AppManager.scala @@ -206,8 +206,19 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe saveAppSettings(this) } + override def onDestroy() { + super.onDestroy() + if (handler != null) { + handler.removeCallbacksAndMessages(null) + handler = null + } + } + protected override def onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) + + handler = new Handler() + getActionBar.setTitle(R.string.proxied_help) this.setContentView(R.layout.layout_apps) this.overlay = View.inflate(this, R.layout.overlay, null).asInstanceOf[TextView] @@ -237,10 +248,10 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe super.onResume() new Thread { override def run() { - handler.sendEmptyMessage(MSG_LOAD_START) + handler.post(loadStartRunnable) appListView = findViewById(R.id.applistview).asInstanceOf[ListView] if (!appsLoaded) loadApps() - handler.sendEmptyMessage(MSG_LOAD_FINISH) + handler.post(loadFinishRunnable) } }.start() } @@ -259,46 +270,46 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe edit.commit } - val handler: Handler = new Handler { - override def handleMessage(msg: Message) { - msg.what match { - case MSG_LOAD_START => - progressDialog = ProgressDialog - .show(AppManager.this, "", getString(R.string.loading), true, true) - case MSG_LOAD_FINISH => - appListView.setAdapter(adapter) - appListView.setOnScrollListener(new AbsListView.OnScrollListener { - def onScroll(view: AbsListView, firstVisibleItem: Int, visibleItemCount: Int, - totalItemCount: Int) { - if (visible) { - val name: String = apps(firstVisibleItem).name - if (name != null && name.length > 1) { - overlay.setText(apps(firstVisibleItem).name.substring(0, 1)) - } else { - overlay.setText("*") - } - overlay.setVisibility(View.VISIBLE) - } - } - - def onScrollStateChanged(view: AbsListView, scrollState: Int) { - visible = true - if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) { - overlay.setVisibility(View.INVISIBLE) - } - } - - var visible = false - }) - if (progressDialog != null) { - progressDialog.dismiss() - progressDialog = null - } - } - super.handleMessage(msg) + val loadStartRunnable = new Runnable { + override def run() { + progressDialog = ProgressDialog + .show(AppManager.this, "", getString(R.string.loading), true, true) } } + val loadFinishRunnable = new Runnable { + override def run() = { + appListView.setAdapter(adapter) + appListView.setOnScrollListener(new AbsListView.OnScrollListener { + def onScroll(view: AbsListView, firstVisibleItem: Int, visibleItemCount: Int, + totalItemCount: Int) { + if (visible) { + val name: String = apps(firstVisibleItem).name + if (name != null && name.length > 1) { + overlay.setText(apps(firstVisibleItem).name.substring(0, 1)) + } else { + overlay.setText("*") + } + overlay.setVisibility(View.VISIBLE) + } + } + def onScrollStateChanged(view: AbsListView, scrollState: Int) { + visible = true + if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) { + overlay.setVisibility(View.INVISIBLE) + } + } + var visible = false + }) + if (progressDialog != null) { + progressDialog.dismiss() + progressDialog = null + } + } + } + + var handler: Handler = null + class AppIconDownloader(context: Context, connectTimeout: Int, readTimeout: Int) extends BaseImageDownloader(context, connectTimeout, readTimeout) { diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index c268cecd..6bbff452 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -67,6 +67,7 @@ import net.simonvt.menudrawer.MenuDrawer import scala.collection.mutable.{ArrayBuffer, ListBuffer} import scala.concurrent.ops._ +import scala.ref.WeakReference class ProfileIconDownloader(context: Context, connectTimeout: Int, readTimeout: Int) extends BaseImageDownloader(context, connectTimeout, readTimeout) { @@ -236,7 +237,7 @@ class Shadowsocks private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication] - val handler = new Handler() + var handler: Handler = null def isSinglePane: Boolean = { if (singlePane == -1) { @@ -442,6 +443,8 @@ class Shadowsocks super.onCreate(savedInstanceState) + handler = new Handler() + addPreferencesFromResource(R.xml.pref_all) // Initialize the profile @@ -797,6 +800,10 @@ class Shadowsocks Crouton.cancelAllCroutons() unregisterReceiver(preferenceReceiver) new BackupManager(this).dataChanged() + if (handler != null) { + handler.removeCallbacksAndMessages(null) + handler = null + } } def copyToSystem() {