コード例 #1
0
ファイル: TouchView.java プロジェクト: evernote/kgb
  @Override
  protected void onDraw(Canvas canvas) {
    if (paint == null) {
      paint = new Paint();
      textPaint = new Paint();
      textPaint.setTextSize(11);
      textPaint.setTextAlign(Paint.Align.CENTER);
    }

    paint.setColor(Color.RED);
    paint.setAlpha(80);
    for (int row = 0; row < kgb.numRows; row++) {
      canvas.drawLine(
          0,
          kgb.spaceBarBottom - row * (kgb.keyHeight + kgb.rowPadding),
          getWidth(),
          kgb.spaceBarBottom - row * (kgb.keyHeight + kgb.rowPadding),
          paint);
      canvas.drawLine(
          0,
          kgb.spaceBarBottom - row * (kgb.keyHeight + kgb.rowPadding) - kgb.keyHeight,
          getWidth(),
          kgb.spaceBarBottom - row * (kgb.keyHeight + kgb.rowPadding) - kgb.keyHeight,
          paint);
    }

    for (KeyInfo keyInfo : kgb.foundKeys.values()) {
      canvas.drawCircle(
          keyInfo.getLocation().getAbsoluteX(),
          keyInfo.getLocation().getAbsoluteY(),
          TOUCH_RADIUS,
          paint);
      canvas.drawText(
          keyInfo.getKey().getCharacter(),
          keyInfo.getLocation().getAbsoluteX(),
          keyInfo.getLocation().getAbsoluteY(),
          textPaint);
    }

    paint.setColor(Color.BLUE);
    long curTime = System.currentTimeMillis();
    for (Iterator<Touch> iterator = touches.iterator(); iterator.hasNext(); ) {
      Touch touch = iterator.next();
      long age = curTime - touch.t;
      if (age > TOUCH_DECAY_MS) {
        iterator.remove();
      } else {
        paint.setAlpha((int) (255 * (1 - ((float) age / TOUCH_DECAY_MS))));
        canvas.drawCircle(touch.x, touch.y, TOUCH_RADIUS, paint);
      }
    }
    // canvas.drawRect(5, 5, getWidth() - 5, getHeight() - 5, paint);
  }
コード例 #2
0
ファイル: TypeCommand.java プロジェクト: evernote/kgb
  @Override
  public String getShellCommand() {
    KeyInfo existingKey =
        kgb.foundKeys.get(Key.getCharacter(Character.toString(text.charAt(index++))));

    if (existingKey != null) {
      return "input tap "
          + existingKey.getLocation().getAbsoluteX()
          + " "
          + existingKey.getLocation().getAbsoluteY();
    } else {
      return null;
    }
  }