Commit d70480a8 authored by Mygod's avatar Mygod

Remove ProgressDialog in AppManager

parent e6cf38e6
......@@ -32,8 +32,17 @@
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"/>
</LinearLayout>
<FrameLayout android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ProgressBar android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/applistview"/>
android:layout_height="fill_parent"
android:id="@+id/applistview"
android:visibility="gone"/>
</FrameLayout>
</LinearLayout>
\ No newline at end of file
......@@ -41,7 +41,6 @@ package com.github.shadowsocks
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream}
import android.app.ProgressDialog
import android.content.pm.PackageManager
import android.content.{ClipData, ClipboardManager, Context, SharedPreferences}
import android.graphics.{Bitmap, PixelFormat}
......@@ -112,7 +111,6 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
var apps: Array[ProxiedApp] = null
var appListView: ListView = null
var overlay: TextView = null
var progressDialog: ProgressDialog = null
var adapter: ListAdapter = null
var appsLoaded: Boolean = false
......@@ -295,41 +293,8 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
bypassSwitch.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isBypassApps, false))
appListView = findViewById(R.id.applistview).asInstanceOf[ListView]
}
protected override def onResume() {
super.onResume()
Future {
handler.post(loadStartRunnable)
if (!appsLoaded) loadApps()
handler.post(loadFinishRunnable)
}
}
def saveAppSettings(context: Context) {
if (apps == null) return
val proxiedApps = new StringBuilder
apps.foreach(app =>
if (app.proxied) {
proxiedApps ++= app.uid.toString
proxiedApps += '|'
})
val edit: SharedPreferences.Editor = ShadowsocksApplication.settings.edit
edit.putString(Key.proxied, proxiedApps.toString())
edit.apply
}
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 {
var visible = false
def onScroll(view: AbsListView, firstVisibleItem: Int, visibleItemCount: Int,
totalItemCount: Int) {
if (visible) {
......@@ -348,13 +313,31 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
overlay.setVisibility(View.INVISIBLE)
}
}
var visible = false
})
if (progressDialog != null) {
progressDialog.dismiss()
progressDialog = null
}
protected override def onResume() {
super.onResume()
Future {
if (!appsLoaded) loadApps()
handler.post(() => {
appListView.setAdapter(adapter)
Utils.crossFade(AppManager.this, findViewById(R.id.loading), appListView)
})
}
}
def saveAppSettings(context: Context) {
if (apps == null) return
val proxiedApps = new StringBuilder
apps.foreach(app =>
if (app.proxied) {
proxiedApps ++= app.uid.toString
proxiedApps += '|'
})
val edit: SharedPreferences.Editor = ShadowsocksApplication.settings.edit
edit.putString(Key.proxied, proxiedApps.toString())
edit.apply
}
var handler: Handler = null
......
......@@ -42,6 +42,7 @@ import java.io._
import java.net._
import java.security.MessageDigest
import android.animation.{AnimatorListenerAdapter, Animator}
import android.app.ActivityManager
import android.content.pm.{ApplicationInfo, PackageManager}
import android.content.{Context, Intent}
......@@ -142,6 +143,16 @@ object Utils {
toast
}
def crossFade(context: Context, from: View, to: View) {
def shortAnimTime = context.getResources.getInteger(android.R.integer.config_shortAnimTime)
to.setAlpha(0)
to.setVisibility(View.VISIBLE)
to.animate().alpha(1).setDuration(shortAnimTime)
from.animate().alpha(0).setDuration(shortAnimTime).setListener(new AnimatorListenerAdapter {
override def onAnimationEnd(animation: Animator) = from.setVisibility(View.GONE)
})
}
// Blocked > 3 seconds
def toggleAirplaneMode(context: Context) {
if (Build.VERSION.SDK_INT >= 17) {
......
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