Commit d70480a8 authored by Mygod's avatar Mygod

Remove ProgressDialog in AppManager

parent e6cf38e6
...@@ -32,8 +32,17 @@ ...@@ -32,8 +32,17 @@
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"/> android:layout_marginRight="6dp"/>
</LinearLayout> </LinearLayout>
<ListView <FrameLayout android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="0dp"
android:layout_height="wrap_content" android:layout_weight="1">
android:id="@+id/applistview"/> <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="fill_parent"
android:id="@+id/applistview"
android:visibility="gone"/>
</FrameLayout>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -41,7 +41,6 @@ package com.github.shadowsocks ...@@ -41,7 +41,6 @@ package com.github.shadowsocks
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream} import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream}
import android.app.ProgressDialog
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.{ClipData, ClipboardManager, Context, SharedPreferences} import android.content.{ClipData, ClipboardManager, Context, SharedPreferences}
import android.graphics.{Bitmap, PixelFormat} import android.graphics.{Bitmap, PixelFormat}
...@@ -112,7 +111,6 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -112,7 +111,6 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
var apps: Array[ProxiedApp] = null var apps: Array[ProxiedApp] = null
var appListView: ListView = null var appListView: ListView = null
var overlay: TextView = null var overlay: TextView = null
var progressDialog: ProgressDialog = null
var adapter: ListAdapter = null var adapter: ListAdapter = null
var appsLoaded: Boolean = false var appsLoaded: Boolean = false
...@@ -295,14 +293,37 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -295,14 +293,37 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
bypassSwitch.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isBypassApps, false)) bypassSwitch.setChecked(ShadowsocksApplication.settings.getBoolean(Key.isBypassApps, false))
appListView = findViewById(R.id.applistview).asInstanceOf[ListView] appListView = findViewById(R.id.applistview).asInstanceOf[ListView]
appListView.setOnScrollListener(new AbsListView.OnScrollListener {
var visible = false
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)
}
}
})
} }
protected override def onResume() { protected override def onResume() {
super.onResume() super.onResume()
Future { Future {
handler.post(loadStartRunnable)
if (!appsLoaded) loadApps() if (!appsLoaded) loadApps()
handler.post(loadFinishRunnable) handler.post(() => {
appListView.setAdapter(adapter)
Utils.crossFade(AppManager.this, findViewById(R.id.loading), appListView)
})
} }
} }
...@@ -319,44 +340,6 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC ...@@ -319,44 +340,6 @@ class AppManager extends AppCompatActivity with OnCheckedChangeListener with OnC
edit.apply 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 {
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 var handler: Handler = null
class AppIconDownloader(context: Context, connectTimeout: Int, readTimeout: Int) class AppIconDownloader(context: Context, connectTimeout: Int, readTimeout: Int)
......
...@@ -42,6 +42,7 @@ import java.io._ ...@@ -42,6 +42,7 @@ import java.io._
import java.net._ import java.net._
import java.security.MessageDigest import java.security.MessageDigest
import android.animation.{AnimatorListenerAdapter, Animator}
import android.app.ActivityManager import android.app.ActivityManager
import android.content.pm.{ApplicationInfo, PackageManager} import android.content.pm.{ApplicationInfo, PackageManager}
import android.content.{Context, Intent} import android.content.{Context, Intent}
...@@ -142,6 +143,16 @@ object Utils { ...@@ -142,6 +143,16 @@ object Utils {
toast 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 // Blocked > 3 seconds
def toggleAirplaneMode(context: Context) { def toggleAirplaneMode(context: Context) {
if (Build.VERSION.SDK_INT >= 17) { 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