private void initSwipeAnimation()

in app/src/main/java/com/google/reviewit/SortChangesFragment.java [307:400]


  private void initSwipeAnimation(final View changeBox) {
    final Point screenSize = getScreenSize();
    final int screenCenter = screenSize.x / 2;

    // TODO swipe animation doesn't look good on wide screens,
    // e.g. when phone is turned horizontally
    final ViewGroup resultBox = vg(R.id.resultBox);
    changeBox.findViewById(R.id.changeBoxUpperPart).setOnTouchListener(
        new View.OnTouchListener() {
      private SortActionHandler.Action action = SortActionHandler.Action.NONE;
      private int x;
      private int y;

      @Override
      public boolean onTouch(View v, MotionEvent event) {
        int eventX = (int) event.getRawX();
        int eventY = (int) event.getRawY();
        switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
            x = (int) event.getRawX();
            y = (int) event.getRawY();
            break;
          case MotionEvent.ACTION_MOVE:
            changeBox.setX(widgetUtil.getDimension(R.dimen
                .activity_horizontal_margin) + eventX - x);
            changeBox.setY(widgetUtil.getDimension(R.dimen
                .activity_vertical_margin) + eventY - y);

            if (eventX >= screenCenter) {
              changeBox.setRotation(
                  (float) ((eventX - screenCenter) * (Math.PI / 32)));

              if (eventX > (screenCenter + (screenCenter / 2))) {
                ((GradientDrawable) changeBox.getBackground())
                    .setColor(widgetUtil.color(R.color.commitMessageStar));
                action = SortActionHandler.Action.STAR;
              } else {
                action = SortActionHandler.Action.NONE;
                ((GradientDrawable) changeBox.getBackground())
                    .setColor(widgetUtil.color(R.color.commitMessage));
              }
            } else {
              changeBox.setRotation(
                  (float) ((eventX - screenCenter) * (Math.PI / 32)));
              if (eventX < (screenCenter / 2)) {
                ((GradientDrawable) changeBox.getBackground())
                    .setColor(widgetUtil.color(R.color.commitMessageIgnore));
                action = SortActionHandler.Action.IGNORE;
              } else {
                action = SortActionHandler.Action.NONE;
                ((GradientDrawable) changeBox.getBackground())
                    .setColor(widgetUtil.color(R.color.commitMessage));
              }
            }
            break;
          case MotionEvent.ACTION_UP:
            ((GradientDrawable) changeBox.getBackground())
                .setColor(widgetUtil.color(R.color.commitMessage));
            switch (action) {
              case STAR:
                getSortActionHandler().star();
                widgetUtil.toast(R.string.change_starred);
                resultBox.removeView(changeBox);
                display();
                break;
              case IGNORE:
                getSortActionHandler().ignore();
                widgetUtil.toast(R.string.change_ignored);
                resultBox.removeView(changeBox);
                display();
                break;
              case SKIP:
                getSortActionHandler().skip();
                widgetUtil.toast(R.string.change_skipped);
                resultBox.removeView(changeBox);
                display();
                break;
              case NONE:
                WidgetUtil.setXY(changeBox,
                    widgetUtil.getDimension(R.dimen.activity_horizontal_margin),
                    widgetUtil.getDimension(R.dimen.activity_vertical_margin));
                changeBox.setRotation(0);
                break;
              default:
                throw new IllegalStateException("unknown action: " + action);
            }
            break;
          default:
            break;
        }
        return true;
      }
    });
  }