/*
 * Copyright (c) 2009-2011. Created by serso aka se.solovyev.
 * For more information, please, contact se.solovyev@gmail.com
 * or visit http://se.solovyev.org
 */

package org.solovyev.android.calculator;

import android.view.MotionEvent;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.view.widgets.DirectionDragButton;
import org.solovyev.android.view.widgets.DragButton;
import org.solovyev.android.view.widgets.DragDirection;
import org.solovyev.android.view.widgets.SimpleOnDragListener;
import org.solovyev.common.utils.Point2d;

/**
 * User: serso
 * Date: 10/24/11
 * Time: 9:52 PM
 */
public class EvalDragProcessor implements SimpleOnDragListener.DragProcessor {
	@NotNull
	private final CalculatorEngineControl calculatorControl;

	public EvalDragProcessor(@NotNull CalculatorEngineControl calculatorControl) {
		this.calculatorControl = calculatorControl;
	}

	@Override
	public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
		boolean result = false;

		if (dragButton instanceof DirectionDragButton) {
			String text = ((DirectionDragButton) dragButton).getText(dragDirection);
			if ("≡".equals(text)) {
				calculatorControl.simplify();
				result = true;
			}
		}

		return result;
	}
}
