<commit_before>package info.spielproject.spiel
package keys

import android.accessibilityservice.AccessibilityService._
import android.content._
import android.util.Log
import android.view._
import KeyEvent._
import accessibility._

import routing._

case class KeyPayload(event:KeyEvent, source:Option[AccessibilityNodeInfo])

class Listener(directive:Option[Directive] = None) extends Handler[KeyPayload](KeyDispatcher, directive) {

  private type Callback = (KeyPayload) => Boolean

  private var down:Option[Callback] = None
  def onDown(c:Callback) = down = Some(c)

  private var up:Option[Callback] = None
  def onUp(c:Callback) = up = Some(c)

  KeyDispatcher.register(this)

  def apply(payload:KeyPayload) = payload.event.getAction match {
    case ACTION_DOWN => down.exists(_(payload))
    case ACTION_UP => up.exists(_(payload))
  }

}

object KeyDispatcher extends Router[KeyPayload] {

  def apply() {
    utils.instantiateAllMembers(classOf[Keys])
  }

}

class Keys {

  class Default extends Listener(Some(Directive(Value(""), Value("")))) with Commands {

    private var spielKeyDown = false

    onDown { payload =>
      payload.event.getKeyCode match {
        case KEYCODE_CAPS_LOCK =>
          spielKeyDown = true
          true
        case KEYCODE_DPAD_RIGHT if spielKeyDown =>
          if(payload.event.isCtrlPressed)
            payload.source.map(_.perform(Action.ScrollBackward)).getOrElse(true)
          else
            navigate(NavigationDirection.Next)
        case KEYCODE_DPAD_LEFT if spielKeyDown => 
          if(payload.event.isCtrlPressed)
            payload.source.map(_.perform(Action.ScrollForward)).getOrElse(true)
          else
            navigate(NavigationDirection.Prev)
        case KEYCODE_DPAD_UP if spielKeyDown => changeGranularity(GranularityDirection.Decrease)
        case KEYCODE_DPAD_DOWN if spielKeyDown =>
          if(payload.event.isCtrlPressed)
            continuousRead()
          else
            changeGranularity(GranularityDirection.Increase)
        case KEYCODE_ESCAPE if spielKeyDown => SpielService.performGlobalAction(GLOBAL_ACTION_HOME)
        case KEYCODE_N if spielKeyDown => SpielService.performGlobalAction(GLOBAL_ACTION_NOTIFICATIONS)
        case KEYCODE_T if spielKeyDown => speakTime()
        case _ =>
          TTS.stop()
          false
      }
    }

    onUp { payload =>
      payload.event.getKeyCode match {
        case KEYCODE_CAPS_LOCK =>
          spielKeyDown = false
          true
        case _ => false
      }
    }

  }

}
<commit_msg>Make calling convention of KeyHandler match that of others more closely.<commit_after>package info.spielproject.spiel
package keys

import android.accessibilityservice.AccessibilityService._
import android.content._
import android.util.Log
import android.view._
import KeyEvent._
import accessibility._

import routing._

case class KeyPayload(event:KeyEvent, source:Option[AccessibilityNodeInfo])

class Listener(directive:Option[Directive] = None) extends Handler[KeyPayload](KeyDispatcher, directive) {

  private type Callback = (KeyEvent, Option[AccessibilityNodeInfo]) => Boolean

  private var down:Option[Callback] = None
  def onDown(c:Callback) = down = Some(c)

  private var up:Option[Callback] = None
  def onUp(c:Callback) = up = Some(c)

  KeyDispatcher.register(this)

  def apply(payload:KeyPayload) = payload.event.getAction match {
    case ACTION_DOWN => down.exists(_(payload.event, payload.source))
    case ACTION_UP => up.exists(_(payload.event, payload.source))
  }

}

object KeyDispatcher extends Router[KeyPayload] {

  def apply() {
    utils.instantiateAllMembers(classOf[Keys])
  }

}

class Keys {

  class Default extends Listener(Some(Directive(Value(""), Value("")))) with Commands {

    private var spielKeyDown = false

    onDown { (event, source) =>
      event.getKeyCode match {
        case KEYCODE_CAPS_LOCK =>
          spielKeyDown = true
          true
        case KEYCODE_DPAD_RIGHT if spielKeyDown =>
          if(event.isCtrlPressed)
            source.map(_.perform(Action.ScrollBackward)).getOrElse(true)
          else
            navigate(NavigationDirection.Next)
        case KEYCODE_DPAD_LEFT if spielKeyDown => 
          if(event.isCtrlPressed)
            source.map(_.perform(Action.ScrollForward)).getOrElse(true)
          else
            navigate(NavigationDirection.Prev)
        case KEYCODE_DPAD_UP if spielKeyDown => changeGranularity(GranularityDirection.Decrease)
        case KEYCODE_DPAD_DOWN if spielKeyDown =>
          if(event.isCtrlPressed)
            continuousRead()
          else
            changeGranularity(GranularityDirection.Increase)
        case KEYCODE_ESCAPE if spielKeyDown => SpielService.performGlobalAction(GLOBAL_ACTION_HOME)
        case KEYCODE_N if spielKeyDown => SpielService.performGlobalAction(GLOBAL_ACTION_NOTIFICATIONS)
        case KEYCODE_T if spielKeyDown => speakTime()
        case _ =>
          TTS.stop()
          false
      }
    }

    onUp { (event, source) =>
      event.getKeyCode match {
        case KEYCODE_CAPS_LOCK =>
          spielKeyDown = false
          true
        case _ => false
      }
    }

  }

}

{'fraction_non_alphanumeric': 0.08693138010794141, 'fraction_numerical': 0.0, 'mean_word_length': 3.1052215189873418, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '7557118', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1498, 'n_words': 309}