forked from rengwuxian/MaterialEditText
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added funcionality to pause and restart textwatchers
- Loading branch information
admin.ilegra
authored and
admin.ilegra
committed
Jun 21, 2017
1 parent
f6e9fa4
commit 815dd29
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
library/src/main/java/com/rengwuxian/materialedittext/MaterialBaseEditText.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.rengwuxian.materialedittext; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.AppCompatEditText; | ||
import android.text.TextWatcher; | ||
import android.util.AttributeSet; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by admin.ilegra on 21/06/17. | ||
*/ | ||
|
||
public class MaterialBaseEditText extends AppCompatEditText { | ||
|
||
ArrayList<TextWatcher> activeListeners = null; | ||
ArrayList<TextWatcher> pausedListeners = null; | ||
|
||
public MaterialBaseEditText(Context context) { | ||
super(context); | ||
} | ||
|
||
public MaterialBaseEditText(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public MaterialBaseEditText(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
@Override | ||
public void addTextChangedListener(TextWatcher watcher) { | ||
if (activeListeners == null) | ||
activeListeners = new ArrayList<>(); | ||
|
||
activeListeners.add(watcher); | ||
|
||
super.addTextChangedListener(watcher); | ||
|
||
} | ||
|
||
@Override | ||
public void removeTextChangedListener(TextWatcher watcher) { | ||
if (activeListeners != null) | ||
activeListeners.remove(watcher); | ||
|
||
super.removeTextChangedListener(watcher); | ||
} | ||
|
||
public void pauseTextChangedListeners() { | ||
pausedListeners = activeListeners; | ||
|
||
for (TextWatcher listener: activeListeners) { | ||
super.removeTextChangedListener(listener); | ||
} | ||
|
||
activeListeners = null; | ||
} | ||
|
||
public void restartPausedTextChangedListeners() { | ||
if (pausedListeners == null) | ||
return; | ||
for (TextWatcher watcher: pausedListeners) { | ||
super.addTextChangedListener(watcher); | ||
} | ||
pausedListeners = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters