Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mobile
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Agendador
Mobile
Merge requests
!15
Password retrieval layout
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Password retrieval layout
recuperar_senha
into
develop
Overview
0
Commits
2
Pipelines
0
Changes
40
Merged
Lucas Braz Cunha
requested to merge
recuperar_senha
into
develop
7 years ago
Overview
0
Commits
2
Pipelines
0
Changes
40
Expand
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
ee6baa5c
2 commits,
7 years ago
40 files
+
574
−
166
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
40
Search (e.g. *.vue) (Ctrl+P)
app/src/main/java/br/ufpr/c3sl/agendador/agendador/helpers/Mask.java
+
67
−
15
Options
@@ -9,38 +9,80 @@ import android.text.TextWatcher;
import
android.widget.EditText
;
public
abstract
class
Mask
{
/**
* Remove all symbols from masked string
*/
public
static
String
unmask
(
String
s
)
{
/**
* Remove all symbols
*/
return
s
.
replaceAll
(
"[.]"
,
""
).
replaceAll
(
"[-]"
,
""
)
.
replaceAll
(
"[/]"
,
""
).
replaceAll
(
"[(]"
,
""
)
.
replaceAll
(
"[)]"
,
""
);
}
private
static
boolean
isMaskSymbol
(
char
c
){
return
c
==
'.'
||
c
==
'-'
||
c
==
'/'
||
c
==
'('
||
c
==
')'
;
}
/**
* Create the mask
* REF: https://nuvemandroid.wordpress.com/2013/12/13/aplicacao-de-mascaras-em-formularios/
*/
public
static
TextWatcher
insert
(
final
String
mask
,
final
EditText
ediTxt
)
{
return
new
TextWatcher
()
{
boolean
isUpdating
;
boolean
isUpdating
=
false
;
boolean
isDeleting
=
false
;
boolean
reMask
=
false
;
int
pos
=
0
;
String
old
=
""
;
public
void
onTextChanged
(
CharSequence
s
,
int
start
,
int
before
,
int
count
)
{
String
str
=
Mask
.
unmask
(
s
.
toString
());
String
mask2
=
""
;
if
(!
isUpdating
&&
(
count
<
before
)
||
(
start
+
count
)
<
s
.
length
()){
isDeleting
=
true
;
pos
=
start
+
count
;
}
}
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{
if
(
count
==
1
&&
after
==
0
&&
isMaskSymbol
(
s
.
charAt
(
start
))){
reMask
=
true
;
}
}
public
void
afterTextChanged
(
Editable
s
)
{
StringBuilder
str
=
new
StringBuilder
(
Mask
.
unmask
(
s
.
toString
()));
StringBuilder
checkMaskLastPos
;
if
(
isUpdating
)
{
old
=
str
;
old
=
str
.
toString
()
;
isUpdating
=
false
;
return
;
}
StringBuilder
mask2
=
new
StringBuilder
(
""
);
//if last position is a character mask related, remove it.
if
(
reMask
&&
s
.
toString
().
length
()
>
0
)
{
checkMaskLastPos
=
new
StringBuilder
(
s
.
toString
());
if
(
isMaskSymbol
(
checkMaskLastPos
.
charAt
(
checkMaskLastPos
.
length
()
-
1
)))
{
checkMaskLastPos
.
deleteCharAt
(
checkMaskLastPos
.
length
()
-
1
);
str
=
new
StringBuilder
(
unmask
(
checkMaskLastPos
.
toString
()));
}
}
int
i
=
0
;
if
(
str
.
length
()
>
old
.
length
()){
if
(
reMask
||
str
.
length
()
>
old
.
length
()){
for
(
char
m
:
mask
.
toCharArray
())
{
if
(
m
!=
'#'
)
{
mask2
+=
m
;
mask2
.
append
(
m
)
;
}
else
{
mask2
.
append
(
str
.
charAt
(
i
));
try
{
mask2
+=
str
.
charAt
(
i
);
//stop putting the mask when user string ends
str
.
charAt
(
i
+
1
);
}
catch
(
Exception
e
)
{
break
;
}
@@ -48,14 +90,24 @@ public abstract class Mask {
}
}
}
else
{
mask2
=
s
.
toString
();
mask2
.
append
(
s
.
toString
());
}
//has to be set before setting text to prevent infinite recursion.
isUpdating
=
true
;
ediTxt
.
setText
(
mask2
);
ediTxt
.
setSelection
(
mask2
.
length
());
ediTxt
.
setText
(
mask2
.
toString
());
if
(!
isDeleting
)
{
ediTxt
.
setSelection
(
mask2
.
length
());
}
else
{
ediTxt
.
setSelection
(
pos
);
}
reMask
=
false
;
isDeleting
=
false
;
}
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{}
public
void
afterTextChanged
(
Editable
s
)
{}
};
}
}
\ No newline at end of file
Loading