Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created March 20, 2018 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/527983621c86bc86939b223624a8ba98 to your computer and use it in GitHub Desktop.
Save ssaurel/527983621c86bc86939b223624a8ba98 to your computer and use it in GitHub Desktop.
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