Add long press toast for FAB
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
<string name="port_empty">端口号不能为空</string>
|
||||
<string name="proxy_empty">代理服务器地址不能为空</string>
|
||||
<string name="crash_alert">检测到意外退出,状态已被重置。</string>
|
||||
<string name="connecting">正在连接...</string>
|
||||
<string name="connect">连接</string>
|
||||
<string name="initializing">正在初始化...</string>
|
||||
<string name="recovering">重置中...</string>
|
||||
<string name="loading">正在加载...</string>
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
<string name="proxy_empty">Proxy should not be empty</string>
|
||||
<string name="crash_alert">An unexpected exit detected, the context has been reset.
|
||||
</string>
|
||||
<string name="connecting">Connecting…</string>
|
||||
<string name="connect">Connect</string>
|
||||
<string name="initializing">Initializing…</string>
|
||||
<string name="recovering">Resetting…</string>
|
||||
<string name="loading">Loading…</string>
|
||||
|
||||
@@ -505,6 +505,11 @@ class Shadowsocks
|
||||
}
|
||||
}
|
||||
})
|
||||
fab.setOnLongClickListener((v: View) => {
|
||||
Utils.positionToast(Toast.makeText(this, if (serviceStarted) R.string.stop else R.string.connect,
|
||||
Toast.LENGTH_SHORT), fab, getWindow, 0, Utils.dpToPx(this, 8).toInt).show
|
||||
true
|
||||
})
|
||||
toolbar.setNavigationIcon(R.drawable.ic_drawer)
|
||||
toolbar.setNavigationOnClickListener((v: View) => drawer.toggleMenu())
|
||||
title.setOnLongClickListener((v: View) => {
|
||||
|
||||
@@ -50,7 +50,10 @@ import android.graphics.drawable.{BitmapDrawable, Drawable}
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.util.{Base64, Log}
|
||||
import android.util.{DisplayMetrics, Base64, Log}
|
||||
import android.view.View.MeasureSpec
|
||||
import android.view.{Gravity, View, Window}
|
||||
import android.widget.Toast
|
||||
import com.github.shadowsocks.BuildConfig
|
||||
import org.xbill.DNS._
|
||||
|
||||
@@ -126,6 +129,23 @@ object Utils {
|
||||
bitmap
|
||||
}
|
||||
|
||||
// Based on: http://stackoverflow.com/a/21026866/2245107
|
||||
def positionToast(toast: Toast, view: View, window: Window, offsetX: Int = 0, offsetY: Int = 0) = {
|
||||
val rect = new Rect
|
||||
window.getDecorView.getWindowVisibleDisplayFrame(rect)
|
||||
val viewLocation = new Array[Int](2)
|
||||
view.getLocationInWindow(viewLocation)
|
||||
val metrics = new DisplayMetrics
|
||||
window.getWindowManager.getDefaultDisplay.getMetrics(metrics)
|
||||
val toastView = toast.getView
|
||||
toastView.measure(MeasureSpec.makeMeasureSpec(metrics.widthPixels, MeasureSpec.UNSPECIFIED),
|
||||
MeasureSpec.makeMeasureSpec(metrics.heightPixels, MeasureSpec.UNSPECIFIED))
|
||||
toast.setGravity(Gravity.LEFT | Gravity.TOP,
|
||||
viewLocation(0) - rect.left + (view.getWidth - toast.getView.getMeasuredWidth) / 2 + offsetX,
|
||||
viewLocation(1) - rect.top + view.getHeight + offsetY)
|
||||
toast
|
||||
}
|
||||
|
||||
// Blocked > 3 seconds
|
||||
def toggleAirplaneMode(context: Context) {
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
|
||||
Reference in New Issue
Block a user