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).
master
Raph Levien 11 years ago
parent 4de0fd0884
commit 385a3509a8
  1. 93
      android/res/layout-sw600dp/piano2.xml
  2. 27
      android/res/layout/piano2.xml
  3. 44
      android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java
  4. 4
      android/src/com/levien/synthesizer/android/widgets/keyboard/ScrollStripView.java

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.levien.synthesizer"
android:id="@+id/TableLayout01"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.levien.synthesizer.android.widgets.knob.KnobView
android:id="@+id/cutoffKnob"
app:value="1.0"
app:min="0"
app:max="1"
android:layout_width="@dimen/knobsize"
android:layout_height="@dimen/knobsize"
android:layout_margin="2dp"
android:paddingTop="8dp"
app:label="@string/cutoff" />
<com.levien.synthesizer.android.widgets.knob.KnobView
android:id="@+id/resonanceKnob"
app:value="0.0"
app:min="0"
app:max="1"
android:layout_width="@dimen/knobsize"
android:layout_height="@dimen/knobsize"
android:paddingTop="8dp"
android:layout_margin="2dp"
app:label="@string/resonance"/>
<com.levien.synthesizer.android.widgets.knob.KnobView
android:id="@+id/overdriveKnob"
app:value="0.0"
app:min="0"
app:max="1"
android:layout_width="@dimen/knobsize"
android:layout_height="@dimen/knobsize"
android:paddingTop="8dp"
android:layout_margin="2dp"
app:label="@string/overdrive"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Spinner
android:id="@+id/presetSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!--
<TextView
android:id="@+id/status"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/capture"
android:text="@string/capture"
/>
<TextView
android:id="@+id/stats"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:textIsSelectable="true"
/>
-->
</LinearLayout>
</LinearLayout>
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<com.levien.synthesizer.android.widgets.keyboard.ScrollStripView
android:id="@+id/scrollstrip"
android:layout_width="match_parent"
android:layout_height="@dimen/scrollstripheight"
/>
<com.levien.synthesizer.android.widgets.keyboard.KeyboardView
android:id="@+id/piano"
android:layout_width="fill_parent"
android:layout_height="300dp"
app:octaves="2"
app:first_octave="4" />
</LinearLayout>

@ -1,14 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.levien.synthesizer"
android:id="@+id/TableLayout01"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:shrinkColumns="*">
<TableRow>
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.levien.synthesizer.android.widgets.knob.KnobView
android:id="@+id/cutoffKnob"
app:value="1.0"
@ -41,7 +43,8 @@
app:label="@string/overdrive"/>
<LinearLayout
android:orientation="vertical"
android:layout_span="3" >
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Spinner
android:id="@+id/presetSpinner"
android:layout_width="wrap_content"
@ -69,25 +72,17 @@
/>
-->
</LinearLayout>
</TableRow>
<TableRow
>
</LinearLayout>
<com.levien.synthesizer.android.widgets.keyboard.ScrollStripView
android:id="@+id/scrollstrip"
android:layout_width="match_parent"
android:layout_height="@dimen/scrollstripheight"
android:layout_weight="1"
android:layout_span="6"
/>
</TableRow>
<TableRow>
<com.levien.synthesizer.android.widgets.keyboard.KeyboardView
android:id="@+id/piano"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_span="6"
app:octaves="2"
app:first_octave="4" />
</TableRow>
</TableLayout>
</LinearLayout>

@ -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();

@ -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_);
}
}
}

Loading…
Cancel
Save