Skip to content

Commit 1ef9044

Browse files
committed
add readme and modify style
1 parent f09377d commit 1ef9044

File tree

7 files changed

+129
-10
lines changed

7 files changed

+129
-10
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# PianoKeyBoard
2+
3+
# 效果图
4+
<img src="/screenshots/screenshot.gif"/>
5+
6+
# 属性
7+
8+
```
9+
<!--设置白键被按下去时的BitmapDrawable-->
10+
<attr name="whiteKeyPressedDrawable" format="reference" />
11+
12+
<!--白键默认的Drawable-->
13+
<attr name="whiteKeyDrawable" format="reference" />
14+
15+
<!--设置黑键被按下去时的BitmapDrawable-->
16+
<attr name="blackKeyPressedDrawable" format="reference" />
17+
18+
<!--黑键默认的BitmapDrawable-->
19+
<attr name="blackKeyDrawable" format="reference" />
20+
21+
<!--设置一屏/一页 展示的白键的个数-->
22+
<attr name="keyCount" format="integer" />
23+
24+
<!--黑键占整个键盘高度的比-->
25+
<attr name="blackKeyHeightRatio" format="float" />
26+
27+
<!--黑键的宽度 黑键宽度和白键宽度的比-->
28+
<attr name="blackKeyWidthRatioToWhiteKeyWidth" format="float" />
29+
30+
<!--设置白键上字体的高度占白键高度的比-->
31+
<attr name="pronuncTextYRatio" format="float" />
32+
33+
<!--设置白键上字体的大小-->
34+
<attr name="pronuncTextSize" format="dimension" />
35+
36+
<!--设置白键上字体的颜色-->
37+
<attr name="pronuncTextColor" format="color" />
38+
```
39+
# 声明-布局中
40+
```java
41+
<tech.oom.library.keyBoard.PianoKeyBoard
42+
android:id="@+id/keyboard"
43+
android:layout_width="match_parent"
44+
android:layout_height="match_parent"
45+
android:background="#ccc"
46+
app:blackKeyDrawable="@drawable/black_up"
47+
app:blackKeyPressedDrawable="@drawable/black_down"
48+
app:keyCount="12"
49+
app:pronuncTextColor="#000000"
50+
app:pronuncTextSize="12sp"
51+
app:pronuncTextYRatio="0.9"
52+
app:whiteKeyDrawable="@drawable/white_up"
53+
app:whiteKeyPressedDrawable="@drawable/white_down" />
54+
```
55+
56+
57+
# Gradle
58+
[![](https://jitpack.io/v/ideastudios/LuckView.svg)](https://jitpack.io/#ideastudios/LuckView)
59+
60+
1. Add it in your root build.gradle at the end of repositories:
61+
```
62+
allprojects {
63+
repositories {
64+
...
65+
maven { url 'https://jitpack.io' }
66+
}
67+
}
68+
```
69+
2. Add the dependency
70+
```
71+
dependencies {
72+
compile 'com.github.ideastudios:LuckView:0.0.1'
73+
}
74+
75+
```
76+
77+
# 注意
78+
* LuckView属性中,只有奖品图片的偏移量 和 文字的偏移量 是相对于圆盘半径的,其他的相关属性都是相对于圆盘的直径
79+
* LuckView中奖项的数量大小应该设置为可以能被360整除的数,如果不能被360整除,则会出现相应bug
80+
* LuckView draw不同奖项图片 draw不同奖项名称是通过canvas.rotate(sectorAnger)的方式实现的
81+
82+
83+
84+
# 感谢
85+
该工程参考了[Nipuream/LuckPan](https://github.com/Nipuream/LuckPan) 的相关代码和UI,感谢这位小伙伴

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
app:keyCount="12"
5151
app:pronuncTextColor="#000000"
5252
app:pronuncTextSize="12sp"
53+
app:pronuncTextYRatio="0.9"
5354
app:whiteKeyDrawable="@drawable/white_up"
5455
app:whiteKeyPressedDrawable="@drawable/white_down" />
5556

library/src/main/java/tech/oom/library/keyBoard/PianoKeyBoard.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class PianoKeyBoard extends View {
4545
private BitmapDrawable blackKeyPressedDrawable;
4646
private TextPaint pronuncTextPaint;
4747
private float blackKeyHeightRatio = 0.5f;
48+
private float pronuncTextYRatio = 0.9f;
4849
private int min_size = 700;
4950
private float blackKeyWidthRatioToWhiteKeyWidth = 0.8f;
5051
private KeyListener keyListener;
@@ -66,11 +67,6 @@ public PianoKeyBoard(Context context, AttributeSet attrs, int defStyle) {
6667
init(attrs, defStyle);
6768
}
6869

69-
public void setKeyCount(int keyCount) {
70-
this.keyCount = keyCount;
71-
initKeys();
72-
}
73-
7470

7571
private void init(AttributeSet attrs, int defStyle) {
7672
final TypedArray a = getContext().obtainStyledAttributes(
@@ -87,6 +83,7 @@ private void init(AttributeSet attrs, int defStyle) {
8783
keyCount = a.getInt(R.styleable.PianoKeyBoard_keyCount, keyCount);
8884

8985
blackKeyHeightRatio = a.getFloat(R.styleable.PianoKeyBoard_blackKeyHeightRatio, blackKeyHeightRatio);
86+
pronuncTextYRatio = a.getFloat(R.styleable.PianoKeyBoard_pronuncTextYRatio, pronuncTextYRatio);
9087

9188
blackKeyWidthRatioToWhiteKeyWidth = a.getFloat(R.styleable.PianoKeyBoard_blackKeyWidthRatioToWhiteKeyWidth, blackKeyWidthRatioToWhiteKeyWidth);
9289

@@ -254,7 +251,7 @@ private void initKeys() {
254251
keyBoardContentWidth = whiteKeyWidth * Const.PRONUNCIATION.length;
255252
// xOffset = -(keyBoardContentWidth - keyBoardWidth) / 2;
256253
// xOffset = -(keyBoardContentWidth - keyBoardWidth) / 2;
257-
list.addAll(WhiteKey.generatorWhiteKey(whiteKeyWidth, keyBoardHeight, whiteKeyDrawable.getBitmap(), whiteKeyPressedDrawable.getBitmap(), pronuncTextPaint));
254+
list.addAll(WhiteKey.generatorWhiteKey(whiteKeyWidth, keyBoardHeight, whiteKeyDrawable.getBitmap(), whiteKeyPressedDrawable.getBitmap(), pronuncTextPaint, whiteKeyHeight * pronuncTextYRatio));
258255
list.addAll(BlackKey.generatorBlackKey(whiteKeyWidth, blackKeyWidth, blackKeyHeight, blackKeyDrawable.getBitmap(), blackKeyPressedDrawable.getBitmap()));
259256
// pointerInWhichKey(xOffset,0);
260257
reverseList.clear();
@@ -290,6 +287,17 @@ public void setKeyListener(KeyListener listener) {
290287
this.keyListener = listener;
291288
}
292289

290+
/**
291+
* 设置一屏/一页 展示的白键的个数
292+
*
293+
* @param keyCount 白键个数
294+
*/
295+
public void setKeyCount(int keyCount) {
296+
this.keyCount = keyCount;
297+
initKeys();
298+
}
299+
300+
293301
/**
294302
* 设置是否播放音效
295303
*

library/src/main/java/tech/oom/library/keyBoard/WhiteKey.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.text.TextPaint;
77

88

9-
109
import java.util.ArrayList;
1110
import java.util.List;
1211

@@ -28,7 +27,7 @@ public WhiteKey(float left, float top, float right, float bottom) {
2827
super(left, top, right, bottom);
2928
}
3029

31-
public static List<WhiteKey> generatorWhiteKey(float whiteKeyWidth, float whiteKeyHeight, Bitmap unPressedBitmap, Bitmap pressedBitmap, TextPaint whiteTextPaint) {
30+
public static List<WhiteKey> generatorWhiteKey(float whiteKeyWidth, float whiteKeyHeight, Bitmap unPressedBitmap, Bitmap pressedBitmap, TextPaint whiteTextPaint, float textYCoordinate) {
3231
ArrayList<WhiteKey> list = new ArrayList<>();
3332
Paint whitePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
3433
whitePaint.setFilterBitmap(true);
@@ -39,7 +38,7 @@ public static List<WhiteKey> generatorWhiteKey(float whiteKeyWidth, float whiteK
3938
whiteKey.setUnPressedBitmap(unPressedBitmap);
4039
whiteKey.setPressedBitmap(pressedBitmap);
4140
whiteKey.setTextPaint(whiteTextPaint);
42-
whiteKey.setDrawTextCoordinate(i * whiteKeyWidth + whiteKeyWidth / 2, whiteKeyHeight - 80);
41+
whiteKey.setDrawTextCoordinate(i * whiteKeyWidth + whiteKeyWidth / 2, textYCoordinate);
4342
whiteKey.setTextToDraw(Const.RANGE[i]);
4443
whiteKey.setKeyCode(Const.WHITEKEY_CODE[i]);
4544
list.add(whiteKey);
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
<resources>
22
<declare-styleable name="PianoKeyBoard">
3+
<!--设置白键被按下去时的BitmapDrawable-->
34
<attr name="whiteKeyPressedDrawable" format="reference" />
5+
6+
<!--白键默认的Drawable-->
47
<attr name="whiteKeyDrawable" format="reference" />
8+
9+
<!--设置黑键被按下去时的BitmapDrawable-->
510
<attr name="blackKeyPressedDrawable" format="reference" />
11+
12+
<!--黑键默认的BitmapDrawable-->
613
<attr name="blackKeyDrawable" format="reference" />
14+
15+
<!--设置一屏/一页 展示的白键的个数-->
716
<attr name="keyCount" format="integer" />
17+
18+
<!--黑键占整个键盘高度的比-->
819
<attr name="blackKeyHeightRatio" format="float" />
20+
21+
<!--黑键的宽度 黑键宽度和白键宽度的比-->
922
<attr name="blackKeyWidthRatioToWhiteKeyWidth" format="float" />
10-
<attr name="pronuncTextRation" format="float" />
23+
24+
<!--设置白键上字体的高度占白键高度的比-->
25+
<attr name="pronuncTextYRatio" format="float" />
26+
27+
<!--设置白键上字体的大小-->
1128
<attr name="pronuncTextSize" format="dimension" />
29+
30+
<!--设置白键上字体的颜色-->
1231
<attr name="pronuncTextColor" format="color" />
32+
1333
</declare-styleable>
1434
</resources>

screenshots/screenshot.gif

986 KB
Loading

0 commit comments

Comments
 (0)