Example #1
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    // react on touch events
    // get pointer index from the event object
    int pointerIndex = event.getActionIndex();

    // get pointer ID
    int pointerId = event.getPointerId(pointerIndex);

    // get masked (not specific to a pointer) action
    int maskedAction = event.getActionMasked();

    MainActivity.debug("WidgetView: maskedAction = " + maskedAction);

    switch (maskedAction) {
      case MotionEvent.ACTION_DOWN:
      case MotionEvent.ACTION_POINTER_DOWN:
        {
          motionDown = true;
          downX = event.getX();
          downY = event.getY();
          break;
        }
      case MotionEvent.ACTION_MOVE:
        {
          if (Math.abs(downX - event.getX()) + Math.abs(downY - event.getY()) > 20) {
            motionMove = true;
          }

          break;
        }

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
        {
          if (!motionMove && clickable && MainActivity.isSafe()) {
            Intent intent = new Intent(this.getContext(), WidgetActivity.class);
            selectedDrawable = this.getDrawable();
            this.getContext().startActivity(intent);
          }

          motionDown = false;
          motionMove = false;
          break;
        }
      case MotionEvent.ACTION_CANCEL:
        {
          break;
        }
    }

    invalidate();

    return true;
  }
Example #2
0
  // @Override
  public boolean onTouchEvent__disabled(MotionEvent event) {
    // react on touch events
    // get pointer index from the event object
    int pointerIndex = event.getActionIndex();

    // get pointer ID
    int pointerId = event.getPointerId(pointerIndex);

    // get masked (not specific to a pointer) action
    int maskedAction = event.getActionMasked();

    switch (maskedAction) {
      case MotionEvent.ACTION_DOWN:
      case MotionEvent.ACTION_POINTER_DOWN:
        {
          if (clickable && MainActivity.isSafe()) {
            Intent intent = new Intent(this.getContext(), WidgetActivity.class);
            selectedDrawable = this.getDrawable();
            this.getContext().startActivity(intent);
          }
          break;
        }
      case MotionEvent.ACTION_MOVE:
        {
          break;
        }
        /*case MotionEvent.ACTION_MOVE: { // a pointer was moved

         break;
        }*/
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
      case MotionEvent.ACTION_CANCEL:
        {
          break;
        }
    }

    invalidate();

    return true;
  }