Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created March 20, 2018 10:41
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/3323d38f84b44bc0a97ca8281b96fd66 to your computer and use it in GitHub Desktop.
Save ssaurel/3323d38f84b44bc0a97ca8281b96fd66 to your computer and use it in GitHub Desktop.
keyForCoords method for the PianoView on the SSaurel's Channel
private Key keyForCoords(float x, float y) {
for (Key k : blacks) {
if (k.rect.contains(x,y)) {
return k;
}
}
for (Key k : whites) {
if (k.rect.contains(x,y)) {
return k;
}
}
return null;
}
private void releaseKey(final Key k) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
k.down = false;
handler.sendEmptyMessage(0);
}
}, 100);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
invalidate();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment