本文整理汇总了Scala中android.os.Handler类的典型用法代码示例。如果您正苦于以下问题:Scala Handler类的具体用法?Scala Handler怎么用?Scala Handler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Handler类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: UiFuture
//设置package包名称以及导入依赖的类
package $package$.helpers
import android.os.{Looper, Handler}
import macroid.UiThreadExecutionContext
import scala.concurrent.{Future, ExecutionContext}
trait UiThreading {
implicit val ec: ExecutionContext = ExecutionContext.global
implicit class UiFuture[T](future: Future[T]) {
def mapUi[S](f: Function[T, S]) = future.map(f)(UiThreadExecutionContext)
}
lazy val handler = new Handler(Looper.getMainLooper)
lazy val uiThread = Looper.getMainLooper.getThread
def assertBackground() {
assert(uiThread != Thread.currentThread)
}
def assertUIThread() {
assert(uiThread == Thread.currentThread)
}
def runOnUiThread(f: => Unit): Unit = {
if (uiThread == Thread.currentThread) {
f
} else {
handler.post(new Runnable() {
def run() {
f
}
})
}
}
}
示例2: HackyEditText
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.ui.views
import android.graphics.Canvas
import android.os.{Looper, Handler}
import android.support.v7.widget.AppCompatEditText
import android.util.AttributeSet
import android.content.Context
import android.view.inputmethod.InputMethodManager
import com.android.perrier1034.post_it_note.App
class HackyEditText(ctx: Context, attrs: AttributeSet) extends AppCompatEditText(ctx, attrs) {
def this(ctx: Context) = this(ctx, null)
var isTarget = false
setWillNotDraw(false)
override def onDraw(canvas: Canvas ) {
super.onDraw(canvas)
if (isTarget) {
isTarget = false
requestFocus()
// setShowSoftInputOnFocus(true)
if (isInputMethodTarget) {
showKeyBoard()
} else{
// ugly hack but I have no choice.
// this occur when CheckListAdapter.appendNewRow() called on creating new check-list-note
new Thread(new Runnable() {
override def run() = {
new Handler(Looper.getMainLooper).postDelayed(new Runnable() {
def run() = showKeyBoard()
}, 50)
}
}).start()
}
}
}
def showKeyBoard() {
val imm = getContext.getSystemService(Context.INPUT_METHOD_SERVICE).asInstanceOf[InputMethodManager]
imm.showSoftInput(this, InputMethodManager.SHOW_FORCED)
}
}
示例3: UiFuture
//设置package包名称以及导入依赖的类
package app.bitrader.helpers
import android.os.{Handler, Looper}
import macroid.UiThreadExecutionContext
import scala.concurrent.{ExecutionContext, Future}
trait UiThreading {
implicit val ec: ExecutionContext = ExecutionContext.global
implicit class UiFuture[T](future: Future[T]) {
def mapUi[S](f: Function[T, S]) = future.map(f)(UiThreadExecutionContext)
}
lazy val handler = new Handler(Looper.getMainLooper)
lazy val uiThread = Looper.getMainLooper.getThread
def assertBackground() {
assert(uiThread != Thread.currentThread)
}
def assertUIThread() {
assert(uiThread == Thread.currentThread)
}
def runOnUiThread(f: => Unit): Unit = {
if (uiThread == Thread.currentThread) {
f
} else {
handler.post(new Runnable() {
def run() {
f
}
})
}
}
}