Skip to content

Commit

Permalink
1.3.4
Browse files Browse the repository at this point in the history
- fix issue #25.

- add `giveFocus` param in `setError()` for setting whether the field will gain focus when set error on.
  • Loading branch information
HITGIF committed Oct 13, 2017
1 parent 9f10036 commit 21b267f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ A new Material Design text field that comes in a box, based on Google Material D
## ***UPDATE NOTICE***

#### 1.3.3 Release
- add `app:isResponsiveIconColor` attribute for setting, in xml, whether the icon signifier will change its color when gaining or losing focus in.
#### 1.3.4 Release
- fix issue #25.

- set icon signifier and end icon with drawable (PR #23).
- add `giveFocus` param in `setError()` for setting whether the field will gain focus when set error on.

#### 1.3.0 Release
- the "EditText" part is now **seperated** from the TextFieldBoxes. TextFieldBoxes is now a **container** (just like a `TextInputLayout`) that should and should only contain **one** `ExtendedEditText` that inherents the `TextInputEditText`.
Expand Down Expand Up @@ -53,7 +53,7 @@ allprojects {
```
```groovy
dependencies {
   compile 'com.github.HITGIF:TextFieldBoxes:1.3.3'
   compile 'com.github.HITGIF:TextFieldBoxes:1.3.4'
}
```

Expand All @@ -70,7 +70,7 @@ dependencies {
<dependency>
<groupId>com.github.HITGIF</groupId>
<artifactId>TextFieldBoxes</artifactId>
   <version>1.3.3</version>
   <version>1.3.4</version>
</dependency>
```

Expand All @@ -79,7 +79,7 @@ dependencies {
resolvers += "jitpack" at "https://jitpack.io"
```
```scala
libraryDependencies += "com.github.HITGIF" % "TextFieldBoxes" % "1.3.3"
libraryDependencies += "com.github.HITGIF" % "TextFieldBoxes" % "1.3.4"
```


Expand All @@ -88,7 +88,7 @@ libraryDependencies += "com.github.HITGIF" % "TextFieldBoxes" % "1.3.3"
:repositories [["jitpack" "https://jitpack.io"]]
```
```scala
:dependencies [[com.github.hitgif/textfieldboxes "1.3.3"]]
:dependencies [[com.github.hitgif/textfieldboxes "1.3.4"]]
```

Expand Down Expand Up @@ -144,7 +144,9 @@ helper text: `app:helperText` in xml or `setHelperText(String helperText)` in Ja

![](https://raw.githubusercontent.com/HITGIF/TextFieldBoxes/master/images/helper.png)

error text: `setError(String errorText)` in Java.
error text: `setError(String errorText, boolean giveFocus)` in Java.

Param `giveFocus` determines whether the field will gain focus when set error on. If `true`, the field gains focus immediately.

*NOTE: Error will be removed when the text changes (input or delete).*

Expand Down
18 changes: 10 additions & 8 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
## ***更新注意***

#### 1.3.3 Release
- 增加 `app:isResponsiveIconColor` 属性以在 xml 中设置首图标是否会在获得或失去焦点时改变颜色
#### 1.3.4 Release
- 修复 issue #25

- 可使用 Drawable 设置首/末图标 (PR #23)
- `setError()` 中新增参数 `giveFocus` 以设置是否在被设置错误时令文本域获得焦点

#### 1.3.0 Release
- "EditText" 部分现已与 TextFieldBoxes **分开**。 TextFieldBoxes 将作为一个**容器**(就像 `TextInputLayout`),应且只应包含**一个** `ExtendedEditText`(继承于 `TextInputEditText`)。
Expand Down Expand Up @@ -53,7 +53,7 @@ allprojects {
```
```groovy
dependencies {
   compile 'com.github.HITGIF:TextFieldBoxes:1.3.3'
   compile 'com.github.HITGIF:TextFieldBoxes:1.3.4'
}
```

Expand All @@ -70,7 +70,7 @@ dependencies {
<dependency>
<groupId>com.github.HITGIF</groupId>
<artifactId>TextFieldBoxes</artifactId>
   <version>1.3.3</version>
   <version>1.3.4</version>
</dependency>
```

Expand All @@ -79,7 +79,7 @@ dependencies {
resolvers += "jitpack" at "https://jitpack.io"
```
```scala
libraryDependencies += "com.github.HITGIF" % "TextFieldBoxes" % "1.3.3"
libraryDependencies += "com.github.HITGIF" % "TextFieldBoxes" % "1.3.4"
```


Expand All @@ -88,7 +88,7 @@ libraryDependencies += "com.github.HITGIF" % "TextFieldBoxes" % "1.3.3"
:repositories [["jitpack" "https://jitpack.io"]]
```
```scala
:dependencies [[com.github.hitgif/textfieldboxes "1.3.3"]]
:dependencies [[com.github.hitgif/textfieldboxes "1.3.4"]]
```

Expand Down Expand Up @@ -145,7 +145,9 @@ _**注意:** 将帮助或错误信息设置为任何**不为空**的字符将会
![](https://raw.githubusercontent.com/HITGIF/TextFieldBoxes/master/images/helper.png)

##### 错误信息:
在 Java 代码中使用 `setError(String errorText)`
在 Java 代码中使用 `setError(String errorText, boolean giveFocus)`

`giveFocus` 参数决定被设置错误的文本域是否获得焦点。如果为 `true`,则该文本域立即获得焦点。

*注意: 文本改动 (输入或删除) 时会自动清除错误信息。*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public class TextFieldBoxes extends FrameLayout {
protected int ANIMATION_DURATION = 100;
protected boolean onError = false;
protected boolean activated = false;
protected boolean doNotRemoveError = false;

public TextFieldBoxes(Context context) {

Expand Down Expand Up @@ -272,8 +273,10 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

@Override
public void afterTextChanged(Editable editable) {
removeError();
updateCounterText();
if (!doNotRemoveError) {
removeError();
updateCounterText();
}
}
});

Expand Down Expand Up @@ -533,8 +536,12 @@ protected void makeCursorBlink() {
int cursorPos = this.editText.getSelectionStart();
if (cursorPos == 0)
if (this.editText.getText().toString().isEmpty()) {
this.editText.setText(" ");
this.editText.setText("");
if (this.onError) {
this.doNotRemoveError = true;
this.editText.setText(" ");
this.editText.setText("");
this.doNotRemoveError = false;
}
} else {
this.editText.setSelection(1);
this.editText.setSelection(0);
Expand Down Expand Up @@ -652,14 +659,17 @@ protected void removeCounterError() {
* set helperLabel Label text to error message
*
* @param errorText error message
* @param giveFocus whether the field will gain focus when set error on
*/
public void setError(String errorText) {
public void setError(String errorText, boolean giveFocus) {

if (this.enabled) {
this.onError = true;
activate(true);
setHighlightColor(this.errorColor);
this.helperLabel.setTextColor(this.errorColor);
this.helperLabel.setText(errorText);
if (giveFocus) setHasFocus(true);
makeCursorBlink();
}
}
Expand Down

0 comments on commit 21b267f

Please sign in to comment.