Compute better default scroll and zoom

This patch gives 2row keys a width of 31.25dp at default zoom (twice
for the 3row layout), and scrolls to the center of the keyboard.
master
Raph Levien 11 years ago
parent 6f5fa7b91c
commit 4de0fd0884
  1. 2
      android/src/com/levien/synthesizer/android/widgets/keyboard/KeyboardView.java
  2. 15
      android/src/com/levien/synthesizer/android/widgets/keyboard/ScrollStripView.java

@ -48,9 +48,9 @@ public class KeyboardView extends View {
paint_.setTextAlign(Paint.Align.CENTER); paint_.setTextAlign(Paint.Align.CENTER);
strokeWidth_ = 1.0f * density; strokeWidth_ = 1.0f * density;
paint_.setStrokeWidth(strokeWidth_); paint_.setStrokeWidth(strokeWidth_);
keyboardSpec_ = KeyboardSpec.make2Row();
offset_ = 0.0f; offset_ = 0.0f;
zoom_ = 1.0f; zoom_ = 1.0f;
setKeyboardSpec(KeyboardSpec.make2Row());
} }
public void setKeyboardSpec(KeyboardSpec keyboardSpec) { public void setKeyboardSpec(KeyboardSpec keyboardSpec) {

@ -35,13 +35,22 @@ public class ScrollStripView extends View {
paint_.setColor(Color.GRAY); paint_.setColor(Color.GRAY);
touchDown_ = new boolean[2]; touchDown_ = new boolean[2];
touchx_ = new float[2]; touchx_ = new float[2];
offset_ = -2000.0f; // TODO: make more systematic zoom_ = -1f; // placeholder value to be replaced in onLayout
zoom_ = 2.5f;
} }
public void bindKeyboard(KeyboardView kv) { public void bindKeyboard(KeyboardView kv) {
keyboardView_ = kv; keyboardView_ = kv;
kv.setScrollZoom(offset_, zoom_); }
@Override
public void onLayout(boolean changed, int left, int top, int right, int bottom) {
if (zoom_ < 0) {
float density = getResources().getDisplayMetrics().density;
int width = right - left;
zoom_ = 3000f * density / width;
offset_ = -width * 0.5f * (zoom_ - 1);
keyboardView_.setScrollZoom(offset_, zoom_);
}
} }
@Override @Override

Loading…
Cancel
Save