Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
onSizeChanged method for the PianoView on the SSaurel's Channel
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
keyWidth = w / NB;
height = h;
int count = 15;
for (int i = 0; i < NB; i++) {
int left = i * keyWidth;
int right = left + keyWidth;
if (i == NB - 1) {
right = w;
}
RectF rect = new RectF(left, 0, right, h);
whites.add(new Key(rect, i + 1));
if (i != 0 && i != 3 && i != 7 && i != 10) {
rect = new RectF((float) (i - 1) * keyWidth + 0.5f * keyWidth + 0.25f * keyWidth, 0,
(float) i * keyWidth + 0.25f * keyWidth, 0.67f * height);
blacks.add(new Key(rect, count));
count++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment