From 385a3509a8e2f860938e7ae55b0077b06ffe1e2c Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 31 Dec 2013 14:07:22 -0800 Subject: [PATCH] Rework vertical space Align keyboard at bottom of screen if there's plenty of space (tablets). Use simpler logic (do as little as possible programatically, use XML to do heavy lifting). --- android/res/layout-sw600dp/piano2.xml | 93 +++++++++++++++++++ android/res/layout/piano2.xml | 27 +++--- .../widgets/keyboard/KeyboardView.java | 44 --------- .../widgets/keyboard/ScrollStripView.java | 4 +- 4 files changed, 107 insertions(+), 61 deletions(-) create mode 100644 android/res/layout-sw600dp/piano2.xml diff --git a/android/res/layout-sw600dp/piano2.xml b/android/res/layout-sw600dp/piano2.xml new file mode 100644 index 0000000..e296c0e --- /dev/null +++ b/android/res/layout-sw600dp/piano2.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + diff --git a/android/res/layout/piano2.xml b/android/res/layout/piano2.xml index 6968ea4..4a70cff 100644 --- a/android/res/layout/piano2.xml +++ b/android/res/layout/piano2.xml @@ -1,14 +1,16 @@ - - + android:orientation="vertical"> + + android:layout_width="wrap_content" + android:layout_height="wrap_content" > --> - - + - - - - + diff --git a/android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java b/android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java index b7950a1..e64877b 100644 --- a/android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java +++ b/android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java @@ -136,50 +136,6 @@ public class KeyboardView extends View { } } - /** - * Layout measurement for this widget. - * This method just sets a basic minimum size and makes the widget maximized otherwise. - */ - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int widthMode = MeasureSpec.getMode(widthMeasureSpec); - int widthSize = MeasureSpec.getSize(widthMeasureSpec); - int heightMode = MeasureSpec.getMode(heightMeasureSpec); - int heightSize = MeasureSpec.getSize(heightMeasureSpec); - - int width = 0; - int height = 0; - - float density = getResources().getDisplayMetrics().density; - int maxHeight = (int) (300.0f * density + 0.5f); - - switch (widthMode) { - case MeasureSpec.EXACTLY: - width = widthSize; - break; - case MeasureSpec.AT_MOST: - width = widthSize; - break; - case MeasureSpec.UNSPECIFIED: - width = 10; - break; - } - - switch (heightMode) { - case MeasureSpec.EXACTLY: - height = heightSize; - break; - case MeasureSpec.AT_MOST: - height = Math.min(maxHeight, heightSize); - break; - case MeasureSpec.UNSPECIFIED: - height = 10; - break; - } - - setMeasuredDimension(width, height); - } - @Override public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); diff --git a/android/src/com/levien/synthesizer/android/widgets/keyboard/ScrollStripView.java b/android/src/com/levien/synthesizer/android/widgets/keyboard/ScrollStripView.java index 3f78c3b..4e6510c 100644 --- a/android/src/com/levien/synthesizer/android/widgets/keyboard/ScrollStripView.java +++ b/android/src/com/levien/synthesizer/android/widgets/keyboard/ScrollStripView.java @@ -49,7 +49,9 @@ public class ScrollStripView extends View { int width = right - left; zoom_ = 3000f * density / width; offset_ = -width * 0.5f * (zoom_ - 1); - keyboardView_.setScrollZoom(offset_, zoom_); + if (keyboardView_ != null) { + keyboardView_.setScrollZoom(offset_, zoom_); + } } }