|
1 | 1 | # PatternLockView |
2 | 2 | A Simple Pattern Lock View for Android |
3 | 3 |
|
| 4 | +# Features: |
| 5 | +* support n * n Pattern |
| 6 | +* two layout mode supported: Identical-Area mode & SpacingPadding mode. |
| 7 | +* support viborate |
| 8 | +* Support `API LEVEL >= 8` |
4 | 9 |
|
5 | | -## ScreenShot ## |
| 10 | +# ScreenShot |
6 | 11 |  |
7 | 12 |  |
| 13 | + |
| 14 | +# How to use |
| 15 | +```xml |
| 16 | +<com.reginald.patternlockview.PatternLockView |
| 17 | + android:id="@+id/lock_view" |
| 18 | + android:layout_width="match_parent" |
| 19 | + android:layout_height="wrap_content" |
| 20 | + android:layout_gravity="center" |
| 21 | + app:lock_size="3" |
| 22 | + app:lock_enableVibrate="true" |
| 23 | + app:lock_vibrateTime="100" |
| 24 | + app:lock_lineColor="#b2ffffff" |
| 25 | + app:lock_lineWidth="8dp" |
| 26 | + app:lock_nodeSize="10dp" |
| 27 | + app:lock_spacing="90dp" |
| 28 | + app:lock_padding="20dp" |
| 29 | + app:lock_nodeTouchExpand="15dp" |
| 30 | + app:lock_nodeSrc="@drawable/pattern_lock_dot_node_normal" |
| 31 | + app:lock_nodeHighlightSrc="@drawable/pattern_lock_dot_node_highlighted" |
| 32 | + app:lock_nodeOnAnim="@anim/pattern_lock_node_anim_larger" |
| 33 | + app:lock_autoLink="false" |
| 34 | + /> |
| 35 | +``` |
| 36 | +properties: |
| 37 | +* lock_size: the size of the n * n lock view. (Optional, default is 3) |
| 38 | +* lock_enableVibrate: enable vibration when one node is linked (Optional, default is false) |
| 39 | +* lock_vibrateTime: time the vibration lasting (Optional, default is 20ms) |
| 40 | +* lock_lineWidth: the width of the link line between nodes (Required) |
| 41 | +* lock_lineColor: the color of the link line between nodes (Required) |
| 42 | +* lock_nodeSize: the size of the node (Required) |
| 43 | +* lock_spacing: the spacing between adjacent nodes (Optional, if given, SpacingPadding Mode is applied, otherwise, Identical-Area Mode is applied) |
| 44 | +* lock_padding: the padding of the lockview (Optional, default is 0) |
| 45 | +* lock_nodeTouchExpand: the expanded area of the node which receive touch action. (Optional, default is 0) |
| 46 | +* lock_nodeSrc: the resource id the node when it's in normal state, e.g. node is unlinked. (Required) |
| 47 | +* lock_nodeHighlightSrc: the resource id the node when it's in highlighted state, e.g. node is linked. (Optional) |
| 48 | +* lock_nodeCorrectSrc: the resource id the node when it's in correct state, e.g. password correct. (Optional) |
| 49 | +* lock_nodeErrorSrc: the resource id the node when it's in error state, e.g. password error. (Optional) |
| 50 | +* lock_autolink: whether to automatic link the nodes in the path of two selected nodes. (Optional, default is false) |
| 51 | +# |
| 52 | + |
| 53 | +# Layout Mode: |
| 54 | +* **SpacingPadding Mode:** |
| 55 | +If lock_spacing is given, PatternLockView use lock_nodeSize, lock_spacing and lock_padding to layout the view as the figure below shows. |
| 56 | +<div><img src='https://github.com/xyxyLiu/PatternLockView/blob/master/demo/SpacingPaddingMode.png' width="400px" style='border: #f1f1f1 solid 1px'/></div> |
| 57 | + |
| 58 | +* **Identical-Area Mode:** |
| 59 | +If lock_spacing is NOT given, PatternLockView only use nodeSize to layout the view(lock_spacing and lock_padding are ignored). It will devided the whole area into n * n identical area, and layout the node in center as the figure below shows. |
| 60 | +<div><img src='https://github.com/xyxyLiu/PatternLockView/blob/master/demo/Identical-AreaMode.png' width="400px" style='border: #f1f1f1 solid 1px'/></div> |
| 61 | + |
| 62 | +# Handle Callbacks |
| 63 | +* **Handle password result:** |
| 64 | +handle password result when user complete password input |
| 65 | +```java |
| 66 | +mLockView.setCallBack(new PatternLockView.CallBack() { |
| 67 | + @Override |
| 68 | + public int onFinish(PatternLockView.Password password) { |
| 69 | + Log.d(TAG, "password is " + password.string); |
| 70 | + if (password.string.equals(myPassWord)) { |
| 71 | + // password is correct |
| 72 | + return PatternLockView.CODE_PASSWORD_CORRECT; |
| 73 | + } else { |
| 74 | + // password is error |
| 75 | + return PatternLockView.CODE_PASSWORD_ERROR; |
| 76 | + } |
| 77 | + } |
| 78 | + }); |
| 79 | +``` |
| 80 | + |
| 81 | +* **Handle Node Touched Event:** |
| 82 | +handle the callback when one node is selected by the user |
| 83 | +```java |
| 84 | +mLockView.setOnNodeTouchListener(new PatternLockView.OnNodeTouchListener() { |
| 85 | + @Override |
| 86 | + public void onNodeTouched(int NodeId) { |
| 87 | + Log.d(TAG, "node " + NodeId + " is touched!"); |
| 88 | + } |
| 89 | + }); |
| 90 | +``` |
0 commit comments