Skip to content

Commit 4b33e6d

Browse files
committed
[Sample] Update smaple and README
1 parent 63d5fa8 commit 4b33e6d

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

README.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PinView
22

3-
Provides a widget for enter PIN/OTP/password etc.
3+
Provides a widget for enter PIN/OTP/password etc on Android 4.1+ (API 16).
44

55
<p><img src="screenshots/styles.png" width="35%" />
66
<img src="screenshots/input.gif" width="35%" /></p>
@@ -15,7 +15,7 @@ repositories {
1515
}
1616
1717
dependencies {
18-
compile 'com.chaos.view:pinview:1.2.0'
18+
compile 'com.chaos.view:pinview:1.3.0'
1919
}
2020
```
2121

@@ -38,6 +38,9 @@ Add PinView in your layout.
3838
android:padding="@dimen/common_padding"
3939
android:textColor="@color/text_colors"
4040
android:textSize="18sp"
41+
android:cursorVisible="true"
42+
app:cursorColor="@color/line_selected"
43+
app:cursorWidth="2dp"
4144
app:itemCount="5"
4245
app:itemHeight="48dp"
4346
app:itemRadius="4dp"
@@ -55,18 +58,22 @@ PinView pinView = (PinView) findViewById(R.id.secondPinView);
5558
pinView.setTextColor(
5659
ResourcesCompat.getColor(getResources(), R.color.colorAccent, getTheme()));
5760
pinView.setTextColor(
58-
ResourcesCompat.getColorStateList(getResources(), R.color.line_colors, getTheme()));
61+
ResourcesCompat.getColorStateList(getResources(), R.color.text_colors, getTheme()));
5962
pinView.setLineColor(
6063
ResourcesCompat.getColor(getResources(), R.color.colorPrimary, getTheme()));
6164
pinView.setLineColor(
62-
ResourcesCompat.getColorStateList(getResources(), R.color.text_colors, getTheme()));
65+
ResourcesCompat.getColorStateList(getResources(), R.color.line_colors, getTheme()));
6366
pinView.setItemCount(4);
6467
pinView.setItemHeight(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_size));
6568
pinView.setItemWidth(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_size));
6669
pinView.setItemRadius(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_radius));
6770
pinView.setItemSpacing(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_spacing));
6871
pinView.setLineWidth(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_line_width));
6972
pinView.setAnimationEnable(true);// start animation when adding text
73+
pinView.setCursorVisible(false);
74+
pinView.setCursorColor(
75+
ResourcesCompat.getColor(getResources(), R.color.line_selected, getTheme()));
76+
pinView.setCursorWidth(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_cursor_width));
7077
```
7178

7279
### Step 2:
@@ -90,18 +97,34 @@ or use the `PinWidget.PinView` style.
9097
style="@style/PinWidget.PinView" />
9198
```
9299

100+
### Step 3 (Optional):
101+
102+
To highlight current item,
103+
104+
add `android:state_selected="true"` to `app:lineColor`
105+
106+
``` xml
107+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
108+
<!-- Use for the item to be input, set the value as the default to disable it -->
109+
<item android:color="@color/line_selected" android:state_selected="true" />
110+
<item android:color="@color/line_focused" android:state_focused="true" />
111+
<item android:color="@color/line_default" />
112+
</selector>
113+
```
114+
115+
or add `android:cursorVisible="true"`.
116+
93117
## Attributes
94118

95-
* **itemSize**, @deprecated use itemWidth or itemHeight instead.
96-
* **borderWidth**, @deprecated use lineWidth instead.
97-
* **borderColor**, @deprecated use lineColor instead.
98119
* **itemCount**, the length of your pin code.
99120
* **itemWidth**, the width of each item.
100121
* **itemHeight**, the height of each item.
101122
* **itemSpacing**, the spacing between two items.
102-
* **lineWidth**, the line(border) width.
103-
* **lineColor**, the line(border) colors.
123+
* **lineWidth**, the line (border) width.
124+
* **lineColor**, the line (border) colors.
104125
* **viewType**, the view type of PinView, currently this will be one of `rectangle` or `line`.
126+
* **cursorColor**, the cursor color.
127+
* **cursorWidth**, the width of cursor.
105128

106129
## Thanks
107130

simple/src/main/java/com/chaos/view/example/MainActivity.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,26 @@ protected void onCreate(Bundle savedInstanceState) {
3232
super.onCreate(savedInstanceState);
3333
setContentView(R.layout.activity_main);
3434

35-
PinView pinView = (PinView) findViewById(R.id.secondPinView);
35+
final PinView pinView = findViewById(R.id.secondPinView);
3636
pinView.setTextColor(
3737
ResourcesCompat.getColor(getResources(), R.color.colorAccent, getTheme()));
3838
pinView.setTextColor(
39-
ResourcesCompat.getColorStateList(getResources(), R.color.line_colors, getTheme()));
39+
ResourcesCompat.getColorStateList(getResources(), R.color.text_colors, getTheme()));
4040
pinView.setLineColor(
4141
ResourcesCompat.getColor(getResources(), R.color.colorPrimary, getTheme()));
4242
pinView.setLineColor(
43-
ResourcesCompat.getColorStateList(getResources(), R.color.text_colors, getTheme()));
43+
ResourcesCompat.getColorStateList(getResources(), R.color.line_colors, getTheme()));
4444
pinView.setItemCount(4);
4545
pinView.setItemHeight(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_size));
4646
pinView.setItemWidth(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_size));
4747
pinView.setItemRadius(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_radius));
4848
pinView.setItemSpacing(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_spacing));
4949
pinView.setLineWidth(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_item_line_width));
5050
pinView.setAnimationEnable(true);// start animation when adding text
51+
pinView.setCursorVisible(false);
52+
pinView.setCursorColor(
53+
ResourcesCompat.getColor(getResources(), R.color.line_selected, getTheme()));
54+
pinView.setCursorWidth(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_cursor_width));
5155
}
5256

5357
@Override

simple/src/main/res/color/line_colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
-->
1717

1818
<selector xmlns:android="http://schemas.android.com/apk/res/android">
19+
<item android:color="@color/line_selected" android:state_selected="true" />
1920
<item android:color="@color/line_focused" android:state_focused="true" />
2021
<item android:color="@color/line_default" />
2122
</selector>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@
3535
android:padding="@dimen/common_padding"
3636
android:textColor="@color/text_colors"
3737
android:textSize="18sp"
38+
android:cursorVisible="true"
39+
app:cursorColor="@color/line_selected"
40+
app:cursorWidth="2dp"
3841
app:itemCount="5"
3942
app:itemHeight="48dp"
4043
app:itemRadius="4dp"
4144
app:itemSpacing="0dp"
4245
app:itemWidth="36dp"
43-
app:lineColor="@color/line_colors"
46+
app:lineColor="@color/line_selected"
4447
app:lineWidth="2dp"
4548
app:viewType="rectangle" />
4649

simple/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<color name="text_focused">#E91E63</color>
2424
<color name="text_default">#F8BBD0</color>
2525
<color name="text_hint_default">#BDBDBD</color>
26+
<color name="line_selected">#E91E63</color>
2627
<color name="line_focused">#3F51B5</color>
2728
<color name="line_default">#C5CAE9</color>
2829
</resources>

0 commit comments

Comments
 (0)