From eb07c9410a95f0d97e4bd9d7b60915345537958a Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Wed, 21 Nov 2012 17:51:06 +0400 Subject: [PATCH] Calculator Overlay --- .../overlay/CalculatorOverlayService.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/overlay/CalculatorOverlayService.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/overlay/CalculatorOverlayService.java index bf12d73d..410e86b8 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/overlay/CalculatorOverlayService.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/overlay/CalculatorOverlayService.java @@ -93,20 +93,35 @@ public class CalculatorOverlayService extends Service implements ExternalCalcula switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: + if (move) { + float xOffset = event.getX() - x0; + float yOffset = event.getY() - y0; + final WindowManager.LayoutParams params = (WindowManager.LayoutParams) onscreenView.getLayoutParams(); - params.x = (int) (params.x - x0 + event.getX()); - params.y = (int) (params.y - y0 + event.getY()); + + int newX = (int) (params.x + xOffset); + int newY = (int) (params.y + yOffset); + + params.x = newX; + params.y = newY; wm.updateViewLayout(onscreenView, params); + + if (newX != params.x) { + x0 = event.getX(); + } + + if (newY != params.y) { + y0 = event.getY(); + } } else { move = true; } + return true; } move = false; - x0 = event.getX(); - y0 = event.getY(); return false; }