From 1c6027bc3ba6758f5c935e20850458cd9db54303 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 27 Dec 2013 21:19:32 -0800 Subject: [PATCH] Tweaking height of keyboard view With these changes, there's a max height of 300dp, and a bit more room in a phone layout (some of the hidden status message widgets were taking vertical space). --- android/res/layout/piano2.xml | 2 ++ .../android/widgets/keyboard/KeyboardView.java | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/android/res/layout/piano2.xml b/android/res/layout/piano2.xml index 513f9d4..97e7ed4 100644 --- a/android/res/layout/piano2.xml +++ b/android/res/layout/piano2.xml @@ -61,6 +61,7 @@ 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 062525c..0d0bda0 100644 --- a/android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java +++ b/android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java @@ -32,8 +32,8 @@ import com.levien.synthesizer.core.midi.MidiListener; public class KeyboardView extends View { public KeyboardView(Context context, AttributeSet attrs) { super(context, attrs); - nKeys_ = 36; // TODO: make configurable - firstKey_ = 36; + nKeys_ = 25; // TODO: make configurable + firstKey_ = 48; noteStatus_ = new byte[128]; noteForFinger_ = new int[FINGERS]; for (int i = 0; i < FINGERS; i++) { @@ -136,6 +136,9 @@ public class KeyboardView extends View { 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; @@ -153,7 +156,7 @@ public class KeyboardView extends View { height = heightSize; break; case MeasureSpec.AT_MOST: - height = heightSize; + height = Math.min(maxHeight, heightSize); break; case MeasureSpec.UNSPECIFIED: height = 10;