From 64b01cb22a0e21d2ca10d97d269b820ba0e750cb Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Wed, 21 Nov 2012 18:34:58 +0400 Subject: [PATCH] Calculator Overlay --- calculatorpp/res/layout/overlay_layout.xml | 52 +++++++++++-------- .../overlay/CalculatorOverlayService.java | 46 +++++++++++++--- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/calculatorpp/res/layout/overlay_layout.xml b/calculatorpp/res/layout/overlay_layout.xml index d13759a6..079600ef 100644 --- a/calculatorpp/res/layout/overlay_layout.xml +++ b/calculatorpp/res/layout/overlay_layout.xml @@ -1,37 +1,43 @@ + a:orientation="vertical" + style="@style/cpp_widget_main_layout_style"> - + - + - + - + - + - + + + + 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 410e86b8..2504ae57 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 @@ -64,6 +64,44 @@ public class CalculatorOverlayService extends Service implements ExternalCalcula } } + + final int initialWindowWidth = Math.max(wm.getDefaultDisplay().getWidth() / 2, 300); + final int initialWindowHeight = Math.max(wm.getDefaultDisplay().getHeight() / 2, 450); + + final WindowManager.LayoutParams params = new WindowManager.LayoutParams( + initialWindowWidth, + initialWindowHeight, + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, + PixelFormat.TRANSLUCENT); + + final View overlayContent = onscreenView.findViewById(R.id.overlay_content); + final View overlayHideButton = onscreenView.findViewById(R.id.overlay_hide_button); + overlayHideButton.setOnClickListener(new View.OnClickListener() { + + private boolean hidden = false; + + private int windowHeight = initialWindowHeight; + + @Override + public void onClick(View v) { + final WindowManager.LayoutParams params = (WindowManager.LayoutParams) onscreenView.getLayoutParams(); + if (hidden) { + overlayContent.setVisibility(View.VISIBLE); + params.height = windowHeight; + } else { + windowHeight = params.height; + overlayContent.setVisibility(View.GONE); + params.height = overlayHideButton.getHeight(); + } + + wm.updateViewLayout(onscreenView, params); + + hidden = !hidden; + } + }); + + onscreenView.findViewById(R.id.overlay_close_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -71,14 +109,6 @@ public class CalculatorOverlayService extends Service implements ExternalCalcula } }); - - final WindowManager.LayoutParams params = new WindowManager.LayoutParams( - Math.max(wm.getDefaultDisplay().getWidth() / 2, 300), - Math.max(wm.getDefaultDisplay().getHeight() / 2, 450), - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, - PixelFormat.TRANSLUCENT); - final TextView overlayTitleTextView = (TextView) onscreenView.findViewById(R.id.overlay_title); overlayTitleTextView.setOnTouchListener(new View.OnTouchListener() {