How to manipulate buttons when using control UI

Post your questions and help other users.

Moderator: Martin

Econdoc
Posts: 153
Joined: 28 May 2016 20:06

How to manipulate buttons when using control UI

Post by Econdoc » 07 Apr 2018 13:42

I am having a terrible time figuring out what commands like click, check, uncheck, etc work. Let me provide a specific example and relate my confusion. Any suggestions would greatly appreciated.

My specific example is this: (I am using LineageOS Oreo, if it matters)
Launch App, com.android.settings.settings$networkdashboardactivity. This action allows access to the Airplane Mode toggle button. It is this button that I wish to manipulate, i.e. toggle on or toggle off. [I wrote the draft of this post in Word which likes to capitalize things that should not be capitalized. Big pain to change it, so some commands are not capitalized properly. Hope you understand.]

Let’s suppose that the button is OFF and I wish to toggle it ON. If I enable “Show Overlay Control”, I find the following actions:
Check(“OFF”),click( “OFF”),uncheck( “OFF”), if(isChecked( “OFF”)), click(974,1411),check(974,1411),uncheck(974,1411), if(isChecked(974,1411)).

Alternately, suppose that the button is toggled ON and I wish to toggle it OFF.
I find the following actions:
Check(“ON”),click( “ON”),uncheck( “ON”), if(isChecked( “ON”)), click(974,1359),check(974,1359),uncheck(974,1359), if(isChecked(974,1359)).

[Interesting that the button position is slightly different!]

Suppose that the button is OFF and I want to toggle it ON. Does it make any difference if I use any of the SIX (6!) different click, check, uncheck options? Same question applies to toggling the button OFF if was ON.

Next question:
Suppose that the button is ON and I want to toggle it off. Will it make any difference if I use the following possible(?) snippets? [I will use check() in all the examples below, although the answer to the question above may make this a poor choice. The issue below is about finding the current state of the button.

IfisChecked(“ON”))
Check(“ON”) //This should turn if off or click() or uncheck() ?

If (NOT isChecked(“OFF”))
Check(“ON”)

Ifischecked(“OFF”))
{
// I need some action here, so the next line is just a placeholder
Junk=1;
}
Else
Check(“ON”);


Ifischecked(“OFF”))
{
// I need some action here, so the next line is just a placeholder
Junk=1;
}
Else
Check(974,1359);



As you can see, I have too many choices and little direction on what the “right” way to proceed might be. Can someone straighten me out, please?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: How to manipulate buttons when using control UI

Post by Desmanto » 07 Apr 2018 18:02

Do you have any other button that has the same name as ON and OFF at the same window? Because check("ON") will only check the first element with the label ON, from top left. That's the problem with android element list, and automagic doesn't have the function to access that yet. I have explain it in : viewtopic.php?f=6&t=7234

It will be different when using click vs check/uncheck. Using click, you will always toggle the ON/OFF. But when using check, you will turn it ON when the button is OFF. IF the button is ON already, it will remain ON. vice versa with uncheck. For realibility, just use check/uncheck if you really need that button in ON or OFF position for certain case. Using click(x,y) usually doesn't work well, at least at most of my test.

That isChecked() usually doesn't work in so many places at mine. So I never bother it. At your case, ON supposed to be checked right? and OFF should be unchecked. So you need to use

Code: Select all

if(isChecked("ON")
  uncheck("ON");
if(NOT isChecked"OFF")
  check("OFF");
This is the problem when using label which have dynamic content (ON/OFF) depends on the state. You have to do the reverse label as above. (see from the point of view before the state changed). Try it out to see if it works.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Econdoc
Posts: 153
Joined: 28 May 2016 20:06

Re: How to manipulate buttons when using control UI

Post by Econdoc » 07 Apr 2018 21:33

Thanks as always. I will struggle with your explanation and see if I can work out how all this works. There are so many odd twists to doing this! Things are the opposite of what they seem.

P.S. As far as I know, there are no other controls on the page in question with ON or OFF. So if I can figure out how to click, check or uncheck, I probably can get this to work. :D

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: How to manipulate buttons when using control UI

Post by Desmanto » 08 Apr 2018 11:41

The problem is not all UI element present us with the clickable element id. That's why we have to use the label and accept its disadvantages as the label can change dynamically. Need a lot of try and error to make it work. But somehow the check method mostly doesn't work at mine. So I use alternative method instead.

Since it is airplane mode and it is one of the system setting, you can query the value using Action Init Variable System Setting, Category Global, Name : airplane_mode_on. If airplane mode is on, this value will be 1 (ON) and vice versa. So before doing the check/uncheck, just use store the query into a variable first, example {apm} and check this value to do the Control UI script.

Code: Select all

if(apm == 1) //airplane mode is ON
  uncheck("ON"); //turn it off
or

Code: Select all

if(apm == 0) //airplane mode is OFF
  check("OFF"); //turn it on
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Econdoc
Posts: 153
Joined: 28 May 2016 20:06

Re: How to manipulate buttons when using control UI

Post by Econdoc » 08 Apr 2018 12:13

Some follow-up questions, Desmanto…

I remain a little confused by some of your answers. Let’s start with your code snippet:

if(isChecked("ON")
uncheck("ON");
if(NOT isChecked"OFF")
check("OFF");

First, did you mean to imply that I should use BOTH of the above conditions to accomplish what I want?
Second, when [if(NOT isChecked"OFF")] is true, shouldn’t the following check be check(“ON”). I don’t think that check(“OFF”) exists. Or does it?

Next, more clarifying questions about click and check…
If I understand you correctly, the following will NOT toggle the button off:
if(isChecked("ON")
check("ON"); Am I correct that this will not work?
You said in your reply “IF the button is ON already, it will remain ON.”

However,
if(isChecked("ON")
click("ON");
will toggle it off. Is this correct?

Isn’t this stuff confusing and counter-intuitive? :?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: How to manipulate buttons when using control UI

Post by Desmanto » 08 Apr 2018 12:48

1. Yeah, I just put them into the same code block in the first reply, should be splitted and used as needed. That's why I split it in the next reply. Use only one of them or in the place where you need it.

2. When airplane mode is off, the radio button is unchecked and the label stated OFF. So when it is in this state, if(NOT isChecked("OFF") will produce true. After the test, the button still remain unchecked and label still OFF (nothing happened yet). We want to turn it on (turn airplane mode on), current label is OFF, so need to use this label OFF. Thus check("OFF"). If you use check("ON"), there is no label ON yet when the airplane mode is OFF, the Control UI will just passed and do nothing.

Code: Select all

if(isChecked("ON")
  check("ON");
this won't do anything and practically useless. Since the radio button is ON already and we keep checking it.

Code: Select all

if(isChecked("ON")
  click("ON");
Correct, this will "toggle" the radio button to be off and change the label to OFF (airplane mode off). If you always protect this using the if just like this, click("ON") will be the same usage case as uncheck("ON"). But as I stated, better safe rather than sorry. When you modify your script somewhere in the future, you might move the if() to somewhere else above. So it is better to ensure the script never fail by using check(). You will know it won't work when something wrong; rather than having the toggling (and you think it is still working).

Unfortunately, there is nothing we can do when the UI doesn't provide us any element Id. If we can use element Id, and you replace those with some certain Id name, maybe it is easier to understand. (android:id/toggleairplane is imaginary elemend Id)

Code: Select all

if(isCheckedById("android:id/toggleairplane")  //ON
  uncheckById("android:id/toggleairplane"); //ON
or

Code: Select all

if(NOT isCheckedById("android:id/toggleairplane") //OFF
  checkById("android:id/toggleairplane"); /OFF
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Econdoc
Posts: 153
Joined: 28 May 2016 20:06

Re: How to manipulate buttons when using control UI

Post by Econdoc » 09 Apr 2018 12:26

Desmanto, I am about to give up. I cannot determine the state of the button! I am using the Debug condition that we love so much to test this.

Control IU contains only these four statements and the screen locations are correct:
ischeckedon=isChecked(974,1359);
ischeckedoff=isChecked(974,1411);
ischeckedon2=isChecked("ON");
ischeckedoff2=isChecked("OFF");

ischeckedoff and ischeckedoff2 should both be true. All the statements above evaluate to false. I cannot control airplane mode if I don’t know its state! Any ideas? I am worried that this is not just an airplane mode issued but a much broader issue making Control UI completely unreliable for determining the state of conditions on my phone.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: How to manipulate buttons when using control UI

Post by Desmanto » 09 Apr 2018 15:16

It is correct already, all should be false. When your current radio button is OFF, the state should unchecked. So checking with
isChecked("OFF"), should give you false (unchecked). Same with isChecked(974,1411).

You should try to turn on the airplane and do the check again. ischeckedon and ischeckedon2 should be true. If the button is exclusively on in one of the state, you actuall only need to check the true part.

Code: Select all

ischeckedoff=isChecked(974,1411);
ischeckedoff2=isChecked("OFF");
these 2 will always evaluated to false in both OFF and ON condition. You can't use this one to check the condition.

Code: Select all

ischeckedon=isChecked(974,1359);
ischeckedon2=isChecked("ON");
But these two will result in true if the airplane mode is ON; and false if the airplane mode is OFF (CUI can't find the ON label, thus false). Just use one of this, I'd prefer to use the isChecked("ON")

It is confusing because both label and x,y changed during the state change.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Econdoc
Posts: 153
Joined: 28 May 2016 20:06

Re: How to manipulate buttons when using control UI

Post by Econdoc » 10 Apr 2018 13:26

I did as you suggested and checked the states when the button was on. You, of course, were correct. The “ON” condition was true.

I cannot begin to tell you how many hours I spent trying to figure out what was going on. The fact that isChecked(“OFF”) never correctly indicates the state of a button is not only confusing, but downright nasty. I believe that all users should be advised and warned not to use those conditions. Unless told otherwise, who could possible know that the isChecked() condition never returns a correct result unless the button is ON.

Thanks for your patient help. I am getting very, very discouraged with Automagic.

Econdoc
Posts: 153
Joined: 28 May 2016 20:06

Re: How to manipulate buttons when using control UI

Post by Econdoc » 14 Apr 2018 20:30

I have been doing more testing and finding more anomalies. I am playing with Oreo 8.1 (LineageOS) and that may explain some of the very strange results that I am getting. Here is the latest:
Airplane mode is OFF. The button is showing that airplane mode is disabled.

Checking the Airplane mode button with the following code returns incorrect results. Here is the code:
If (isChecked(“ON”))
Buttonon=true
Else
Buttonon=false;

Buttonon is always true! The slider button is clearly off.

It is impossible to correctly determine the state of airplane mode if isChecked(“ON”) does not correctly report it. Is this an Oreo issue?

Post Reply