Browse files

some refactoring after Review

  • Loading branch information...
1 parent 7c2cf28 commit 6148b0d1e4eb0d43f8f02c50b6c27fc274787345 azkobain committed May 12, 2012
View
9 src/com/flexymind/alpha/customviews/PianoKey.java
@@ -31,21 +31,24 @@ public PianoKey(Context context) {
*/
public PianoKey(Context context, int keyH, int keyW, Picture picture) {
+
super(context);
this.keyHeight = keyH;
this.keyWidth = keyW;
this.picture = picture;
}
@Override
- protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec){
+ protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
+
setMeasuredDimension(keyWidth, keyHeight);
}
@Override
protected void onDraw (Canvas canvas) {
- canvas.drawPicture(picture,
- new RectF(0, 0, keyWidth, keyHeight) );
+
+ canvas.drawPicture( picture
+ , new RectF(0, 0, keyWidth, keyHeight));
super.onDraw(canvas);
}
View
77 src/com/flexymind/alpha/customviews/PianoKeyboard.java
@@ -3,7 +3,6 @@
import android.content.Context;
import android.graphics.Picture;
import android.util.AttributeSet;
-import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.flexymind.alpha.R;
import com.larvalabs.svgandroid.SVG;
@@ -12,7 +11,6 @@
public class PianoKeyboard extends RelativeLayout {
private final int COUNT_OF_WHITE_KEYS = 8;
- //[review] mandrigin: remove unused constants
private final int COUNT_OF_BLACK_KEYS = 5;
private final int START_ID_FOR_KEY_VIEWS = 100;
private final int[] BLACK_KEY_POSITIONS = {1, 2, 4, 5, 6};
@@ -21,16 +19,13 @@
private int keyboardH = 0;
public PianoKeyboard(Context context, AttributeSet attrs) {
+
super(context, attrs);
}
- //[review] mandrigin: ',' should be on the new line:
- // Make:
- //protected void onMeasure( int widthMeasureSpec
- // , int heightMeasureSpec) {
@Override
- protected void onMeasure (int widthMeasureSpec,
- int heightMeasureSpec) {
+ protected void onMeasure( int widthMeasureSpec
+ , int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -50,31 +45,32 @@ public void onLayout(boolean changed, int l,
private void addWhiteKeys() {
int id = START_ID_FOR_KEY_VIEWS;
- SVG svg = SVGParser.getSVGFromResource(getResources(),
- R.raw.whitekey);
+ SVG svg = SVGParser.getSVGFromResource( getResources()
+ , R.raw.whitekey);
LayoutParams params = new RelativeLayout.LayoutParams(
- RelativeLayout.LayoutParams.WRAP_CONTENT,
- RelativeLayout.LayoutParams.WRAP_CONTENT);
+ RelativeLayout.LayoutParams.WRAP_CONTENT
+ , RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(ALIGN_LEFT);
- addKey(svg.getPicture(),
- getWhiteKeyHeight(),
- getWhiteKeyWidth(),
- params,
- id++);
+ addKey( svg.getPicture()
+ , getWhiteKeyHeight()
+ , getWhiteKeyWidth()
+ , params
+ , id++);
for (int i = 0; i < COUNT_OF_WHITE_KEYS - 1; i++) {
- addKey(svg.getPicture(),
- getWhiteKeyHeight(),
- getWhiteKeyWidth(),
- paramsWithRightOf(id - 1),
- id++);
+ addKey( svg.getPicture()
+ , getWhiteKeyHeight()
+ , getWhiteKeyWidth()
+ , paramsWithRightOf(id - 1)
+ , id++);
}
}
private RelativeLayout.LayoutParams paramsWithRightOf(int id) {
+
LayoutParams params = new LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RIGHT_OF, id);
@@ -83,53 +79,60 @@ private void addWhiteKeys() {
}
private void addBlackKeys() {
- SVG svg = SVGParser.getSVGFromResource(getResources(),
- R.raw.blackkey);
+
+ SVG svg = SVGParser.getSVGFromResource( getResources()
+ , R.raw.blackkey);
int id = START_ID_FOR_KEY_VIEWS + COUNT_OF_WHITE_KEYS;
for (int whiteKeyNumber: BLACK_KEY_POSITIONS) {
- addKey(svg.getPicture(),
- getBlackKeyHeight(),
- getBlackKeyWidth(),
- paramsWithMargin(whiteKeyNumber * getWhiteKeyWidth()
- - getBlackKeyWidth() / 2),
- ++id);
+ addKey( svg.getPicture()
+ , getBlackKeyHeight()
+ , getBlackKeyHeight()
+ , paramsWithMargin(whiteKeyNumber * getWhiteKeyWidth()
+ - getBlackKeyWidth() / 2)
+ , ++id);
}
}
private LayoutParams paramsWithMargin(int margin) {
+
LayoutParams params = new LayoutParams
- (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ ( LayoutParams.WRAP_CONTENT
+ , LayoutParams.WRAP_CONTENT);
params.leftMargin = margin;
return params;
}
- private void addKey(Picture picture, int keyH, int keyW,
- LayoutParams params, int id) {
+ private void addKey( Picture picture, int keyH, int keyW
+ , LayoutParams params, int id) {
- PianoKey key = new PianoKey(getContext(),
- keyH,
- keyW,
- picture);
+ PianoKey key = new PianoKey( getContext()
+ , keyH
+ , keyW
+ , picture);
key.setId(id);
addView(key, params);
}
private int getWhiteKeyWidth() {
+
return keyboardW / COUNT_OF_WHITE_KEYS;
}
private int getWhiteKeyHeight() {
+
return keyboardH;
}
private int getBlackKeyWidth() {
+
return getWhiteKeyWidth() / 2;
}
private int getBlackKeyHeight() {
+
return getWhiteKeyHeight() / 2;
}
}

0 comments on commit 6148b0d

Please sign in to comment.