当前位置: 首页>>代码示例>>Scala>>正文


Scala Handler类代码示例

本文整理汇总了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
        }
      })
    }
  }
} 
开发者ID:aafa,项目名称:rest-android-scala.g8,代码行数:39,代码来源:UiThreading.scala

示例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)
  }

} 
开发者ID:perrier1034,项目名称:Post-it-Note,代码行数:48,代码来源:HackyEditText.scala

示例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
        }
      })
    }
  }
} 
开发者ID:aafa,项目名称:bitrader,代码行数:40,代码来源:UiThreading.scala


注:本文中的android.os.Handler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。