예제 #1
0
  public void addMotionPoint(int index, int eventIndex, MotionEvent event) {
    try {
      PointF geckoPoint = new PointF(event.getX(eventIndex), event.getY(eventIndex));
      geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);

      mPoints[index] = new Point(Math.round(geckoPoint.x), Math.round(geckoPoint.y));
      mPointIndicies[index] = event.getPointerId(eventIndex);
      // getToolMajor, getToolMinor and getOrientation are API Level 9 features
      if (Build.VERSION.SDK_INT >= 9) {
        double radians = event.getOrientation(eventIndex);
        mOrientations[index] = (float) Math.toDegrees(radians);
        // w3c touchevents spec does not allow orientations == 90
        // this shifts it to -90, which will be shifted to zero below
        if (mOrientations[index] == 90) mOrientations[index] = -90;

        // w3c touchevent radius are given by an orientation between 0 and 90
        // the radius is found by removing the orientation and measuring the x and y
        // radius of the resulting ellipse
        // for android orientations >= 0 and < 90, the major axis should correspond to
        // just reporting the y radius as the major one, and x as minor
        // however, for a radius < 0, we have to shift the orientation by adding 90, and
        // reverse which radius is major and minor
        if (mOrientations[index] < 0) {
          mOrientations[index] += 90;
          mPointRadii[index] =
              new Point(
                  (int) event.getToolMajor(eventIndex) / 2,
                  (int) event.getToolMinor(eventIndex) / 2);
        } else {
          mPointRadii[index] =
              new Point(
                  (int) event.getToolMinor(eventIndex) / 2,
                  (int) event.getToolMajor(eventIndex) / 2);
        }
      } else {
        float size = event.getSize(eventIndex);
        Resources resources = GeckoApp.mAppContext.getResources();
        DisplayMetrics displaymetrics = resources.getDisplayMetrics();
        size = size * Math.min(displaymetrics.heightPixels, displaymetrics.widthPixels);
        mPointRadii[index] = new Point((int) size, (int) size);
        mOrientations[index] = 0;
      }
      mPressures[index] = event.getPressure(eventIndex);
    } catch (Exception ex) {
      Log.e(LOGTAG, "Error creating motion point " + index, ex);
      mPointRadii[index] = new Point(0, 0);
      mPoints[index] = new Point(0, 0);
    }
  }
  private void logMotionEvent(MotionEvent event, boolean gen) {
    String s = gen ? "GenericMotionEvent from " : "TouchEvent from ";
    s += printDevice(event.getDeviceId()) + " source " + printSource(event.getSource());

    int pointerCount = event.getPointerCount();
    String action;
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_CANCEL:
        action = "cancel";
        break;
      case MotionEvent.ACTION_DOWN:
        action = "down";
        break;
      case MotionEvent.ACTION_HOVER_ENTER:
        action = "hover_enter";
        break;
      case MotionEvent.ACTION_HOVER_EXIT:
        action = "hover_exit";
        break;
      case MotionEvent.ACTION_HOVER_MOVE:
        action = "hover_move";
        break;
      case MotionEvent.ACTION_MOVE:
        action = "move";
        break;
      case MotionEvent.ACTION_OUTSIDE:
        action = "outside";
        break;
      case MotionEvent.ACTION_POINTER_DOWN:
        action = "pointer_down";
        break;
      case MotionEvent.ACTION_POINTER_UP:
        action = "pointer_up";
        break;
      case MotionEvent.ACTION_UP:
        action = "up";
        break;
      case MotionEvent.ACTION_SCROLL:
        action = "scroll";
        break;
      default:
        action = "" + event.getAction();
        break;
    }
    s +=
        ", action "
            + action
            + " pointer count "
            + pointerCount
            + " buttons "
            + event.getButtonState()
            + " RawX "
            + event.getRawX()
            + " RawY "
            + event.getRawY()
            + " MetaState "
            + event.getMetaState()
            + " Flags "
            + event.getFlags()
            + "\n";
    for (int p = 0; p < pointerCount; p++) {
      int ptrId = event.getPointerId(p);
      s +=
          "Pointer id "
              + ptrId
              + " X "
              + event.getX(p)
              + " Y "
              + event.getY(p)
              + " pressure "
              + event.getPressure(p)
              + " size "
              + event.getSize(p)
              + " orientation "
              + event.getOrientation(p)
              + // (float)Math.toDegrees(event.getOrientation(p)) +
              " TouchMajor "
              + event.getTouchMajor(p)
              + " TouchMinor "
              + event.getTouchMinor(p)
              + " ToolMajor "
              + event.getToolMajor(p)
              + " ToolMinor "
              + event.getToolMinor(p)
              + "\n";
      for (int i = 0; i < 255; i++) {
        if (event.getAxisValue(i, p) != 0.0) {
          s += "Axis " + i + " " + event.axisToString(i) + ": " + event.getAxisValue(i, p);
          InputDevice device = InputDevice.getDevice(event.getDeviceId());
          if (device != null) {
            InputDevice.MotionRange range = device.getMotionRange(i);
            if (range != null) s += " range " + range.getMin() + " to " + range.getMax();
          }
          s += "\n";
        }
      }
    }

    pushText(s);
  }