Copied from android sample Snake