I can't set text for password field via uiautomator:
UiObject eaPassword = uiDevice.findObject(new UiSelector().textContains("Password"));
assertTrue(eaPassword.waitForExists(35_000));
eaPassword.click(); // optional
eaPassword.setText("1234"); // return true
It is able to find the object itself.
If I execute eaPassword.getText(); it returns "Password".
If you run eaPassword.click() , screen would be change(keyboard pop up),
so you cannot find eaPassword(Uiobject) again
setText() this function has two behavior
1. Long press EditView
2. Input text
UiObject eaPassword = uiDevice.findObject(new UiSelector().textContains("Password"));
assertTrue(eaPassword.waitForExists(35_000));
eaPassword.setText("1234");
or try other method
UiObject eaPassword = uiDevice.findObject(new UiSelector().textContains("Password"));
assertTrue(eaPassword.waitForExists(35_000));
eaPassword.click();
setStrings("test");
public void setStrings(String text) {
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c >= 48 && c <= 57) // 0~9
uiDevice.pressKeyCode(c - 41);
else if (c >= 65 && c <= 90) // A~Z
uiDevice.pressKeyCode(c - 36, 1);
else if (c >= 97 && c < 122) // a~z
uiDevice.pressKeyCode(c - 68);
else if (c == 42) // *
uiDevice.pressKeyCode(KEYCODE_STAR);
else if (c == 35) // #
uiDevice.pressKeyCode(KEYCODE_POUND);
else if (c == 46) // .
uiDevice.pressKeyCode(KEYCODE_PERIOD);
else if (c == 47) // /
uiDevice.pressKeyCode(KEYCODE_SLASH);
else if (c == 58) // :
uiDevice.pressKeyCode(KEYCODE_SEMICOLON);
}
}
It would be one by one to input word (not use setText())
Related
I have a button which is let users when open the application then can use the function.
This is the function:
if(eyeDected)
{
if(detectedFrame > 25)
{
eyeDected = false;
detectedFrame = 0;
finish();
} else {
detectedFrame++;
Log.d("UNLOCK:", String.valueOf(detectedFrame));
}
} else {
eyeDected = true;
detectedFrame++;
Log.d("UNLOCK:", String.valueOf(detectedFrame));
}
I want do a while loop function: (the number of click is a,b,c) (For example b=1 is mean that user click once time only)
a=0
b=1
c=2
when 'a' = 0,3,6,9,12,15..... (mean 'a'+3) then run the function
when 'b' = 1,4,7,10 ,13....(mean b+3) then run the function
when 'c' = 2,5,8,11,16... (mean b+3) then run the function
How can i perform a while loop for these? Thanks
You can add following condition :
a=0
b=1
c=2
when 'a' = 0,3,6,9,12 (mean 'a'+3) then run a function
if(a%3 == 0){
// run a function
}
when 'b' = 1,4,7,10 (mean b+3) then run a function
if((b+1)%3 == 0){
// run B function
}
when 'c' = 2,5,8,11 (mean b+3) then run a function
if((c+2)%3 == 0){
// run B function
}
Ex. in loop :
for (int i=0;i<100;i++){
if( i % 3 == 0){
// run a function
}
else if( (i+1) % 3 == 0){
// run b function
}
else if( (i+2) % 3 == 0){
// run c function
}
}
What I am trying to do is this: User enters text in an edittext. Example: "ab" then when he enters a character like '<' let's say, that would cause the last char typed before that to be increased by one. In this example, it'd do "ac" ('<' should be deleted too). On onTextChanged method, I use:
if (s.length() > 0 && s.toString().charAt(s.length() - 1) == '<') { //ab<
character = s.toString().charAt(s.length() - 2); //keep b
current_string = s.toString().substring(0, (s.length() - 2)); //a
et.setText(current_string); //set a
next_character_to_integer = (int) character + 1; //b is 98 ascii, need 99
integer_to_character = (char) next_character_to_integer; // 99 = char c
et.setText(s + String.valueOf(integer_to_character)); //set a+c
length = s.length();
et.setSelection(length); //move cursor after c
}
But this gives "abqc"!!! I might be close enough but still can't find the solution. Any ideas? Thanks a lot
Try this:
if (s.length() > 0 && s.toString().charAt(s.length() - 1) == '<') {
character = s.toString().charAt(s.length() - 2);
current_string = s.toString().substring(0, (s.length() - 2));
character += 1;
et.setText(current_string + character);
length = et.getText().toString().length();
et.setSelection(length);
}
This should work.
When you call:
et.setText(s + String.valueOf(integer_to_character)); //set a+c
you are using the original value of s which you have not updated. Change the line to:
et.setText(current_string + String.valueOf(integer_to_character)); //set a+c
and see what you get.
I want to check whether the entered strings length is between 3 to 8 characters. Previously I used if condition and it worked. However when I introduced some substring from the string , one of the if statements doesnt work. Can some one help me to understand why. Thanks.
My codes is
Working Code:
text = et.getText().toString();
l = text.length();
a = text.substring(0, 1);
if (l >=9) tv.setText("Invalid length!!! Please check your code");
if (l <= 2) tv.setText("Invalid length! Please check your code");
And here, the second if statement doesnt work.
text = et.getText().toString();
l = text.length();
a = text.substring(0, 1);
c = text.substring(1, 2);
d = text.substring(3, 4);
e = text.substring(4);
if (l >=9) tv.setText("Invalid length!!! Please check your code");
if (l <= 2) tv.setText("Invalid length! Please check your code");
You will want to ensure that you handle a null string as well as ensuring your string is within the limits you want. consider:
text = et.getText().toString();
if (text == null || text.length() < 3 || text.length > 8) {
tv.setText("Invalid length, should be from 3 to 8 characters. Please check your code");
} else {
a = text.substring(0,1);
b = text.substring(1,2);
c = text.substring(3,4);
if (text.length() > 3) {
d = text.substring(4);
} else {
d = null;
}
}
You need to check the length before trying to create substrings, since if the length is too short the substring indexes are invalid. Try this:
text = et.getText().toString();
l = text.length();
if (l >= 9 || l <= 2) {
tv.setText("Invalid length!!! Please check your code");
} else {
a = text.substring(0, 1);
c = text.substring(1, 2);
d = text.substring(3, 4);
e = text.substring(4);
}
You can use like this:
editText.getText().toString().length() < 3
EditText etmobile_no;
if (etmobile_no.getText().toString("") ||
etmobile_no.getText().toString().length() <3 ||
etmobile_no.getText().toString().length() >8)
{
tv.setText("Invalid length, should be from 3 to 8 characters. Please check your code");
}
Hi I have some code which encrypts a text and display it in a textView and send it as an SMS.
The algorithm is (letterInt * constant)%29 = new letterInt
so basically it is the leftovers of division of 29 on the letter value times the constant
The alphabet is like this
private List<Character> alfabet = new ArrayList<Character>();
alfabet.add('a');
alfabet.add('b');
alfabet.add('c');
alfabet.add('d');
alfabet.add('e');
alfabet.add('f');
alfabet.add('g');
alfabet.add('h');
alfabet.add('i');
alfabet.add('j');
alfabet.add('k');
alfabet.add('l');
alfabet.add('m');
alfabet.add('n');
alfabet.add('o');
alfabet.add('p');
alfabet.add('q');
alfabet.add('r');
alfabet.add('s');
alfabet.add('t');
alfabet.add('u');
alfabet.add('v');
alfabet.add('w');
alfabet.add('x');
alfabet.add('y');
alfabet.add('z');
alfabet.add('æ');
alfabet.add('ø');
alfabet.add('å');
The problem is, that whenever C becomes larger than 1 the text isnt encrypted corretly.
e.g. d = 4, but if i choose C = 4 then the output becomes h (8), not p (16).
The code part is like this:
char[] bogstaver = tekstString.toCharArray();
for (int i = 1; i <= bogstaver.length; i++) {
if (bogstaver[i-1] == ' ' || bogstaver[i-1] == '.' || bogstaver[i-1] == '?' || bogstaver[i-1] == '!' ||
bogstaver[i-1] == ',' || bogstaver[i-1] == ';' || bogstaver[i-1] == '+' || bogstaver[i-1] == '(' ||
bogstaver[i-1] == ')' || bogstaver[i-1] == '{' || bogstaver[i-1] == '}' || bogstaver[i-1] == ':'){
continue;
}
if( CType == 1){
C = Integer.valueOf(faktorA);
CType = 2;
}
else if (CType == 2){
C = Integer.valueOf(faktorB);
CType = 3;
}
else if (CType == 3){
C = Integer.valueOf(faktorE);
CType = 1;
}
bogstaver[i-1] = alfabet.get((alfabet.indexOf(bogstaver[i-1]) * C)%29);
}
String endeligeTekst = new String(bogstaver);
if (k == 1){
krypteredeTekst.setText(endeligeTekst);
}
else{
sendString(endeligeTekst, Nr);
}
This is why you're not getting the result you're expecting;
e is the 4th value in your List (it's 0 indexed, a=0, b=1 etc.
With C=3, the result is 4*3=12, and the 13'th character (at index 12) is m which is the output (I can't get n as your question states).
I am trying to mask the phone number as the user types. I have used the javascript code below with jquery and the setTimeout workaround successfully on android 2.x devices, but I have not found a workaround for that works for android 4.0.3.
if (navigator.userAgent.toLowerCase().indexOf("android") >= 0) {
$.fn.usphone = function() {
this.keyup(function(e) {
// do not process del, backspace, escape, arrow left and arrow right characters
var k = e.which;
if (k == 8 || k == 46 || k == 27 || k == 37 || k == 39)
return;
// remove invalid characters
var value = "";
for (var i = 0; i < this.value.length; i++) {
var ch = this.value[i];
if (ch >= "0" && ch <= "9")
value += ch;
}
// remove extra characters
if (value.length > 10)
value = value.substring(0, 10);
// insert formatting characters
if (value.length >= 3)
value = "(" + value.substring(0, 3) + ")" + value.substring(3);
if (value.length > 5)
value = value.substring(0, 5) + " " + value.substring(5);
if (value.length > 9)
value = value.substring(0, 9) + "-" + value.substring(9);
// set new value
var $this = this;
var length = value.length;
setTimeout(function() {
$this.value = value;
$this.setSelectionRange(length, length);
}, 0);
});
};
$('#contact_edit_page, #contact_new_page, #callback_create, #callback_edit, #new_phonecall_contact_page, #new_phonecall').live('pagecreate', function() {
$('[type^="tel"]').usphone();
});
}
I just met the same problem. My solution is as follows,
.input {
-webkit-user-modify: read-write;
}
It works in android 4.0.3 in my HTC.