<commit_before>package info.spielproject.spiel

import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
import android.media.AudioManager

object StateObserver {

  def apply(service:SpielService) {

    def registerReceiver(r:(Context, Intent) => Unit, i:String) {
      service.registerReceiver(new BroadcastReceiver {
        override def onReceive(c:Context, i:Intent) = r(c, i)
      }, new IntentFilter(i))
    }

    registerReceiver((c, i) => ringerModeChanged, AudioManager.RINGER_MODE_CHANGED_ACTION)

    registerReceiver((c, i) => screenOff , Intent.ACTION_SCREEN_OFF)

    registerReceiver((c, i) => screenOn, Intent.ACTION_SCREEN_ON)

  }

  private var callAnsweredHandlers = List[() => Unit]()
  def onCallAnswered(h:() => Unit) = callAnsweredHandlers ::= h
  def callAnswered = callAnsweredHandlers.foreach { f => f() }

  private var callIdleHandlers = List[() => Unit]()
  def onCallIdle(h:() => Unit) = callIdleHandlers ::= h
  def callIdle = callIdleHandlers.foreach { f => f() }

  private var callRingingHandlers = List[(String) => Unit]()
  def onCallRinging(h:(String) => Unit) = callRingingHandlers ::= h
  def callRinging(number:String) = callRingingHandlers.foreach { f => f(number) }

  private var ringerModeChangedHandlers = List[() => Unit]()
  def onRingerModeChanged(h:() => Unit) = ringerModeChangedHandlers ::= h
  def ringerModeChanged = ringerModeChangedHandlers.foreach { f => f() }

  private[spiel] var _ringerOn = true
  def isRingerOn = _ringerOn
  def isRingerOff = !isRingerOn

  private var screenOffHandlers = List[() => Unit]()
  def onScreenOff(h:() => Unit) = screenOffHandlers ::= h
  def screenOff = screenOffHandlers.foreach { f => f() }

  private var screenOnHandlers = List[() => Unit]()<commit_msg>Add handler functions for application changes.<commit_after>package info.spielproject.spiel

import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
import android.media.AudioManager

object StateObserver {

  def apply(service:SpielService) {

    def registerReceiver(r:(Context, Intent) => Unit, intents:List[String]) {
      val f = new IntentFilter
      intents.foreach(f.addAction(_))
      service.registerReceiver(new BroadcastReceiver {
        override def onReceive(c:Context, i:Intent) = r(c, i)
      }, f)
    }

    registerReceiver((c, i) => ringerModeChanged, AudioManager.RINGER_MODE_CHANGED_ACTION :: Nil)

    registerReceiver((c, i) => screenOff , Intent.ACTION_SCREEN_OFF :: Nil)

    registerReceiver((c, i) => screenOn, Intent.ACTION_SCREEN_ON :: Nil)

    registerReceiver((c, i) => applicationsChanged(i), Intent.ACTION_PACKAGE_ADDED :: Intent.ACTION_PACKAGE_REMOVED :: Nil)
  }

  private var applicationsChangedHandlers = List[(Intent) => Unit]()
  def onApplicationsChanged(h:(Intent) => Unit) = applicationsChangedHandlers ::= h
  def applicationsChanged(i:Intent) = applicationsChangedHandlers.foreach { f => f(i) }

  private var callAnsweredHandlers = List[() => Unit]()
  def onCallAnswered(h:() => Unit) = callAnsweredHandlers ::= h
  def callAnswered = callAnsweredHandlers.foreach { f => f() }

  private var callIdleHandlers = List[() => Unit]()
  def onCallIdle(h:() => Unit) = callIdleHandlers ::= h
  def callIdle = callIdleHandlers.foreach { f => f() }

  private var callRingingHandlers = List[(String) => Unit]()
  def onCallRinging(h:(String) => Unit) = callRingingHandlers ::= h
  def callRinging(number:String) = callRingingHandlers.foreach { f => f(number) }

  private var ringerModeChangedHandlers = List[() => Unit]()
  def onRingerModeChanged(h:() => Unit) = ringerModeChangedHandlers ::= h
  def ringerModeChanged = ringerModeChangedHandlers.foreach { f => f() }

  private[spiel] var _ringerOn = true
  def isRingerOn = _ringerOn
  def isRingerOff = !isRingerOn

  private var screenOffHandlers = List[() => Unit]()
  def onScreenOff(h:() => Unit) = screenOffHandlers ::= h
  def screenOff = screenOffHandlers.foreach { f => f() }

  private var screenOnHandlers = List[() => Unit]()
{'fraction_non_alphanumeric': 0.13129808885579547, 'fraction_numerical': 0.0, 'mean_word_length': 4.86608442503639, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2273480', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1280, 'n_words': 292}