Skip to content

Commit e915bbf

Browse files
committed
Draw concurrentNotesWidget at correct y position
1 parent 94ddb0e commit e915bbf

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

mobile/src/main/java/com/ataulm/notes/ConcurrentNotesWidget.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ConcurrentNotesWidget extends View {
1414

1515
public ConcurrentNotesWidget(Context context) {
1616
super(context);
17-
setBackgroundColor(Color.RED);
17+
setBackgroundColor(Color.BLACK);
1818

1919
positionCalculator = new PositionsApartFromMiddleCCalculator();
2020
symbolSizes = MusicalSymbolSizes.create();

mobile/src/main/java/com/ataulm/notes/SongFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static Sequence pachelbelsCanon() {
2121
);
2222
}
2323

24-
Sequence maryHadALittleLamb() {
24+
static Sequence maryHadALittleLamb() {
2525
return Sequence.create(
2626
ConcurrentNotes.create(Fixtures.E4), ConcurrentNotes.create(Fixtures.E4), ConcurrentNotes.create(Fixtures.D4), ConcurrentNotes.create(Fixtures.C4), ConcurrentNotes.create(Fixtures.D4), ConcurrentNotes.create(Fixtures.E4), ConcurrentNotes.create(Fixtures.E4), ConcurrentNotes.create(Fixtures.E4),
2727
ConcurrentNotes.create(Fixtures.D4), ConcurrentNotes.create(Fixtures.D4), ConcurrentNotes.create(Fixtures.D4), ConcurrentNotes.create(Fixtures.E4), ConcurrentNotes.create(Fixtures.E4), ConcurrentNotes.create(Fixtures.E4),

mobile/src/main/java/com/ataulm/notes/TrebleStaffSizer.java

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ int[] linesY() {
6868
};
6969
}
7070

71+
int middleCY() {
72+
int noteHeight = musicalSymbolSizes.note.height();
73+
return 10 * noteHeight;
74+
}
75+
7176
@Px
7277
int height() {
7378
return 14 * musicalSymbolSizes.note.height();

mobile/src/main/java/com/ataulm/notes/TrebleStaffWidget.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@ private List<ConcurrentNotes> buildCurrentWindowFrom(Sequence sequence) {
7373

7474
@Override
7575
protected void onLayout(boolean changed, int l, int t, int r, int b) {
76+
int middleCY = trebleStaffSizer.middleCY();
77+
7678
for (int i = 0; i < getChildCount(); i++) {
7779
ConcurrentNotesWidget child = (ConcurrentNotesWidget) getChildAt(i);
78-
int childLeft = i * 20;
79-
child.layout(childLeft, child.topToMiddleC(), childLeft + child.getMeasuredWidth(), child.getMeasuredHeight());
80+
int childLeft = 60 + i * 20;
81+
int childTop = middleCY + child.topToMiddleC();
82+
child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight());
8083
}
8184
}
8285

mobile/src/main/java/com/ataulm/notes/VirtualPianoActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
1414
setContentView(R.layout.activity_virtual_piano);
1515

1616
TrebleStaffWidget trebleStaffWidget = (TrebleStaffWidget) findViewById(R.id.treble_staff_widget);
17-
trebleStaffWidget.bind(pachelbelsCanon());
17+
trebleStaffWidget.bind(SongFactory.maryHadALittleLamb());
1818
}
1919

2020
}

0 commit comments

Comments
 (0)