Add long press toast for FAB
This commit is contained in:
@@ -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