Skip to content

Commit 720e9ef

Browse files
authored
Merge pull request #19 from ChaosLeong/develop
[Release] 1.3.2
2 parents ef6f2b0 + 490d0c1 commit 720e9ef

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repositories {
1515
}
1616
1717
dependencies {
18-
compile 'com.chaos.view:pinview:1.3.1'
18+
compile 'com.chaos.view:pinview:1.3.2'
1919
}
2020
```
2121

pinview/publish.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def issueUrl = 'https://github.com/ChaosLeong/PinView/issues'
66
def gitUrl = '[email protected]:ChaosLeong/PinView.git'
77

88
group = "com.chaos.view"
9-
version = "1.3.1"
9+
version = "1.3.2"
1010

1111
install {
1212
repositories.mavenInstaller {

pinview/src/main/java/com/chaos/view/PinView.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* Provides a widget for enter PIN/OTP/password etc.
4747
*
4848
* @author Chaos Leong
49-
* 01/04/2017
49+
* 01/04/2017
5050
*/
5151
public class PinView extends AppCompatEditText {
5252

@@ -67,8 +67,8 @@ public class PinView extends AppCompatEditText {
6767

6868
private int mPinItemCount;
6969

70-
private float mPinItemWidth;
71-
private float mPinItemHeight;
70+
private int mPinItemWidth;
71+
private int mPinItemHeight;
7272
private int mPinItemRadius;
7373
private int mPinItemSpacing;
7474

@@ -125,14 +125,14 @@ public PinView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)
125125

126126
mViewType = a.getInt(R.styleable.PinView_viewType, VIEW_TYPE_RECTANGLE);
127127
mPinItemCount = a.getInt(R.styleable.PinView_itemCount, DEFAULT_COUNT);
128-
mPinItemHeight = a.getDimensionPixelSize(R.styleable.PinView_itemHeight,
128+
mPinItemHeight = (int) a.getDimension(R.styleable.PinView_itemHeight,
129129
res.getDimensionPixelSize(R.dimen.pv_pin_view_item_size));
130-
mPinItemWidth = a.getDimensionPixelSize(R.styleable.PinView_itemWidth,
130+
mPinItemWidth = (int) a.getDimension(R.styleable.PinView_itemWidth,
131131
res.getDimensionPixelSize(R.dimen.pv_pin_view_item_size));
132132
mPinItemSpacing = a.getDimensionPixelSize(R.styleable.PinView_itemSpacing,
133133
res.getDimensionPixelSize(R.dimen.pv_pin_view_item_spacing));
134-
mPinItemRadius = a.getDimensionPixelSize(R.styleable.PinView_itemRadius, 0);
135-
mLineWidth = a.getDimensionPixelSize(R.styleable.PinView_lineWidth,
134+
mPinItemRadius = (int) a.getDimension(R.styleable.PinView_itemRadius, 0);
135+
mLineWidth = (int) a.getDimension(R.styleable.PinView_lineWidth,
136136
res.getDimensionPixelSize(R.dimen.pv_pin_view_item_line_width));
137137
mLineColor = a.getColorStateList(R.styleable.PinView_lineColor);
138138
isCursorVisible = a.getBoolean(R.styleable.PinView_android_cursorVisible, true);
@@ -183,14 +183,14 @@ public void onAnimationUpdate(ValueAnimator animation) {
183183

184184
private void checkItemRadius() {
185185
if (mViewType == VIEW_TYPE_LINE) {
186-
int halfOfLineWidth = mLineWidth / 2;
186+
float halfOfLineWidth = ((float) mLineWidth) / 2;
187187
if (mPinItemRadius > halfOfLineWidth) {
188-
throw new RuntimeException("The itemRadius can not be greater than lineWidth when viewType is line");
188+
throw new IllegalArgumentException("The itemRadius can not be greater than lineWidth when viewType is line");
189189
}
190190
}
191-
int halfOfItemWidth = (int) (mPinItemWidth / 2);
191+
float halfOfItemWidth = ((float) mPinItemWidth) / 2;
192192
if (mPinItemRadius > halfOfItemWidth) {
193-
throw new RuntimeException("The itemRadius can not be greater than itemWidth");
193+
throw new IllegalArgumentException("The itemRadius can not be greater than itemWidth");
194194
}
195195
}
196196

@@ -204,14 +204,14 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
204204
int width;
205205
int height;
206206

207-
float boxHeight = mPinItemHeight;
207+
int boxHeight = mPinItemHeight;
208208

209209
if (widthMode == MeasureSpec.EXACTLY) {
210210
// Parent has told us how big to be. So be it.
211211
width = widthSize;
212212
} else {
213-
float boxesWidth = (mPinItemCount - 1) * mPinItemSpacing + mPinItemCount * mPinItemWidth;
214-
width = Math.round(boxesWidth + ViewCompat.getPaddingEnd(this) + ViewCompat.getPaddingStart(this));
213+
int boxesWidth = (mPinItemCount - 1) * mPinItemSpacing + mPinItemCount * mPinItemWidth;
214+
width = boxesWidth + ViewCompat.getPaddingEnd(this) + ViewCompat.getPaddingStart(this);
215215
if (mPinItemSpacing == 0) {
216216
width -= (mPinItemCount - 1) * mLineWidth;
217217
}
@@ -221,7 +221,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
221221
// Parent has told us how big to be. So be it.
222222
height = heightSize;
223223
} else {
224-
height = Math.round(boxHeight + getPaddingTop() + getPaddingBottom());
224+
height = boxHeight + getPaddingTop() + getPaddingBottom();
225225
}
226226

227227
setMeasuredDimension(width, height);
@@ -377,7 +377,7 @@ private void drawPinLine(Canvas canvas, int i) {
377377
}
378378
mPaint.setStyle(Paint.Style.FILL);
379379
mPaint.setStrokeWidth(((float) mLineWidth) / 10);
380-
float halfLineWidth = (float) mLineWidth / 2;
380+
float halfLineWidth = ((float) mLineWidth) / 2;
381381
mItemLineRect.set(mItemBorderRect.left, mItemBorderRect.bottom - halfLineWidth, mItemBorderRect.right, mItemBorderRect.bottom + halfLineWidth);
382382

383383
updateRoundRectPath(mItemLineRect, mPinItemRadius, mPinItemRadius, l, r);
@@ -464,7 +464,7 @@ private void updateRoundRectPath(RectF rectF, float rx, float ry,
464464
}
465465

466466
private void updateItemRectF(int i) {
467-
float halfLineWidth = (float) mLineWidth / 2;
467+
float halfLineWidth = ((float) mLineWidth) / 2;
468468
float left = getScrollX() + ViewCompat.getPaddingStart(this) + i * (mPinItemSpacing + mPinItemWidth) + halfLineWidth;
469469
if (mPinItemSpacing == 0 && i > 0) {
470470
left = left - (mLineWidth) * i;
@@ -497,8 +497,8 @@ private void drawTextAtBox(Canvas canvas, Paint paint, CharSequence text, int ch
497497
paint.getTextBounds(text.toString(), charAt, charAt + 1, mTextRect);
498498
float cx = mItemCenterPoint.x;
499499
float cy = mItemCenterPoint.y;
500-
float x = cx - Math.abs(mTextRect.width()) / 2 - mTextRect.left;
501-
float y = cy + Math.abs(mTextRect.height()) / 2 - mTextRect.bottom;// always center vertical
500+
float x = cx - Math.abs((float) mTextRect.width()) / 2 - mTextRect.left;
501+
float y = cy + Math.abs((float) mTextRect.height()) / 2 - mTextRect.bottom;// always center vertical
502502
canvas.drawText(text, charAt, charAt + 1, x, y, paint);
503503
}
504504

@@ -654,7 +654,6 @@ public void setLineWidth(@Px int borderWidth) {
654654
* @return Returns the width of the item's line.
655655
* @see #setLineWidth(int)
656656
*/
657-
@Px
658657
public int getLineWidth() {
659658
return mLineWidth;
660659
}
@@ -695,7 +694,6 @@ public void setItemRadius(@Px int itemRadius) {
695694
* @return Returns the radius of square.
696695
* @see #setItemRadius(int)
697696
*/
698-
@Px
699697
public int getItemRadius() {
700698
return mPinItemRadius;
701699
}
@@ -726,17 +724,17 @@ public int getItemSpacing() {
726724
* @attr ref R.styleable#PinView_itemHeight
727725
* @see #getItemHeight()
728726
*/
729-
public void setItemHeight(float itemHeight) {
727+
public void setItemHeight(@Px int itemHeight) {
730728
mPinItemHeight = itemHeight;
731729
updateCursorHeight();
732730
requestLayout();
733731
}
734732

735733
/**
736734
* @return Returns the height of item.
737-
* @see #setItemHeight(float)
735+
* @see #setItemHeight(int)
738736
*/
739-
public float getItemHeight() {
737+
public int getItemHeight() {
740738
return mPinItemHeight;
741739
}
742740

@@ -746,17 +744,17 @@ public float getItemHeight() {
746744
* @attr ref R.styleable#PinView_itemWidth
747745
* @see #getItemWidth()
748746
*/
749-
public void setItemWidth(float itemWidth) {
747+
public void setItemWidth(@Px int itemWidth) {
750748
mPinItemWidth = itemWidth;
751749
checkItemRadius();
752750
requestLayout();
753751
}
754752

755753
/**
756754
* @return Returns the width of item.
757-
* @see #setItemWidth(float)
755+
* @see #setItemWidth(int)
758756
*/
759-
public float getItemWidth() {
757+
public int getItemWidth() {
760758
return mPinItemWidth;
761759
}
762760

0 commit comments

Comments
 (0)