Skip to content

Commit ef6f2b0

Browse files
authored
Merge pull request #16 from ChaosLeong/develop
1.3.1
2 parents fc3a866 + 38941a2 commit ef6f2b0

File tree

8 files changed

+133
-19
lines changed

8 files changed

+133
-19
lines changed

README.md

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

2222
## Usage
2323

24+
PinView inherits from EditText, which means you can use all the APIs from EditText.
25+
2426
### Step 1:
2527

2628
Add PinView in your layout.
@@ -74,6 +76,7 @@ pinView.setCursorVisible(false);
7476
pinView.setCursorColor(
7577
ResourcesCompat.getColor(getResources(), R.color.line_selected, getTheme()));
7678
pinView.setCursorWidth(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_cursor_width));
79+
pinView.addTextChangedListener(new TextWatcher() {...});
7780
```
7881

7982
### Step 2:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.1'
9+
classpath 'com.android.tools.build:gradle:3.1.0'
1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1111
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
1212
// NOTE: Do not place your application dependencies here; they belong

pinview/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ android {
3838
}
3939

4040
dependencies {
41-
compile fileTree(dir: 'libs', include: ['*.jar'])
42-
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
41+
implementation fileTree(dir: 'libs', include: ['*.jar'])
42+
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
4343
exclude group: 'com.android.support', module: 'support-annotations'
4444
})
45-
compile 'com.android.support:appcompat-v7:27.0.2'
46-
testCompile 'junit:junit:4.12'
45+
implementation 'com.android.support:appcompat-v7:27.1.0'
46+
testImplementation 'junit:junit:4.12'
4747
}
4848

4949
apply from: 'publish.gradle'

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.0"
9+
version = "1.3.1"
1010

1111
install {
1212
repositories.mavenInstaller {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2018 Chaos
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.chaos.view;
18+
19+
import android.text.Selection;
20+
import android.text.Spannable;
21+
import android.text.method.MovementMethod;
22+
import android.view.KeyEvent;
23+
import android.view.MotionEvent;
24+
import android.widget.TextView;
25+
26+
/**
27+
* For disable arrow key
28+
*
29+
* @author Chaos
30+
* 31/03/2018
31+
*/
32+
class DefaultMovementMethod implements MovementMethod {
33+
34+
private static DefaultMovementMethod sInstance;
35+
36+
public static MovementMethod getInstance() {
37+
if (sInstance == null) {
38+
sInstance = new DefaultMovementMethod();
39+
}
40+
41+
return sInstance;
42+
}
43+
44+
private DefaultMovementMethod() {
45+
}
46+
47+
@Override
48+
public void initialize(TextView widget, Spannable text) {
49+
// It will mark the IMM as openable
50+
Selection.setSelection(text, 0);
51+
}
52+
53+
@Override
54+
public boolean onKeyDown(TextView widget, Spannable text, int keyCode, KeyEvent event) {
55+
return false;
56+
}
57+
58+
@Override
59+
public boolean onKeyUp(TextView widget, Spannable text, int keyCode, KeyEvent event) {
60+
return false;
61+
}
62+
63+
@Override
64+
public boolean onKeyOther(TextView view, Spannable text, KeyEvent event) {
65+
return false;
66+
}
67+
68+
@Override
69+
public void onTakeFocus(TextView widget, Spannable text, int direction) {
70+
71+
}
72+
73+
@Override
74+
public boolean onTrackballEvent(TextView widget, Spannable text, MotionEvent event) {
75+
return false;
76+
}
77+
78+
@Override
79+
public boolean onTouchEvent(TextView widget, Spannable text, MotionEvent event) {
80+
return false;
81+
}
82+
83+
@Override
84+
public boolean onGenericMotionEvent(TextView widget, Spannable text, MotionEvent event) {
85+
return false;
86+
}
87+
88+
@Override
89+
public boolean canSelectArbitrarily() {
90+
return false;
91+
}
92+
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,7 @@ private static boolean isPasswordInputType(int inputType) {
582582

583583
@Override
584584
protected MovementMethod getDefaultMovementMethod() {
585-
// we don't need arrow key, return null will also disable the copy/paste/cut pop-up menu.
586-
return null;
585+
return DefaultMovementMethod.getInstance();
587586
}
588587

589588
/**
@@ -646,8 +645,8 @@ public int getCurrentLineColor() {
646645
* @see #getLineWidth()
647646
*/
648647
public void setLineWidth(@Px int borderWidth) {
649-
checkItemRadius();
650648
mLineWidth = borderWidth;
649+
checkItemRadius();
651650
requestLayout();
652651
}
653652

@@ -687,8 +686,8 @@ public int getItemCount() {
687686
* @see #getItemRadius()
688687
*/
689688
public void setItemRadius(@Px int itemRadius) {
690-
checkItemRadius();
691689
mPinItemRadius = itemRadius;
690+
checkItemRadius();
692691
requestLayout();
693692
}
694693

@@ -748,8 +747,8 @@ public float getItemHeight() {
748747
* @see #getItemWidth()
749748
*/
750749
public void setItemWidth(float itemWidth) {
751-
checkItemRadius();
752750
mPinItemWidth = itemWidth;
751+
checkItemRadius();
753752
requestLayout();
754753
}
755754

@@ -792,7 +791,6 @@ public void setTextSize(int unit, float size) {
792791
* @see #getCursorWidth()
793792
*/
794793
public void setCursorWidth(@Px int width) {
795-
checkItemRadius();
796794
mCursorWidth = width;
797795
if (isCursorVisible()) {
798796
invalidateCursor(true);

simple/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ android {
2222
}
2323

2424
dependencies {
25-
compile fileTree(dir: 'libs', include: ['*.jar'])
26-
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
25+
implementation fileTree(dir: 'libs', include: ['*.jar'])
26+
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
2727
exclude group: 'com.android.support', module: 'support-annotations'
2828
})
29-
compile 'com.android.support:appcompat-v7:27.0.2'
30-
compile 'com.android.support.constraint:constraint-layout:1.0.2'
31-
testCompile 'junit:junit:4.12'
29+
implementation 'com.android.support:appcompat-v7:27.1.0'
30+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
31+
testImplementation 'junit:junit:4.12'
3232

33-
compile project(':pinview')
33+
implementation project(':pinview')
3434
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020
import android.os.Bundle;
2121
import android.support.v4.content.res.ResourcesCompat;
2222
import android.support.v7.app.AppCompatActivity;
23+
import android.text.Editable;
24+
import android.text.TextWatcher;
25+
import android.util.Log;
2326
import android.view.Menu;
2427
import android.view.MenuItem;
2528

2629
import com.chaos.view.PinView;
2730

2831
public class MainActivity extends AppCompatActivity {
2932

33+
private static final String TAG = "MainActivity";
34+
3035
@Override
3136
protected void onCreate(Bundle savedInstanceState) {
3237
super.onCreate(savedInstanceState);
@@ -52,6 +57,22 @@ protected void onCreate(Bundle savedInstanceState) {
5257
pinView.setCursorColor(
5358
ResourcesCompat.getColor(getResources(), R.color.line_selected, getTheme()));
5459
pinView.setCursorWidth(getResources().getDimensionPixelSize(R.dimen.pv_pin_view_cursor_width));
60+
pinView.addTextChangedListener(new TextWatcher() {
61+
@Override
62+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
63+
64+
}
65+
66+
@Override
67+
public void onTextChanged(CharSequence s, int start, int before, int count) {
68+
Log.d(TAG, "onTextChanged() called with: s = [" + s + "], start = [" + start + "], before = [" + before + "], count = [" + count + "]");
69+
}
70+
71+
@Override
72+
public void afterTextChanged(Editable s) {
73+
74+
}
75+
});
5576
}
5677

5778
@Override

0 commit comments

Comments
 (0)