Iterate over items in list (longer than screen)?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Iterate over items in list (longer than screen)?

Post by Bluscre » 17 Sep 2018 15:16

https://gyazo.com/7e2ee29bff89b19a5cce888d6494a62e.png

Image

how would i iterate over all of them? I mean i get that i would have to use the

Code: Select all

*ByIdAndIndex...
stuff but how do i even get how many indexes are on there? Or do i need to iterate to 999999 and just end the loop when the first one does not exist anymore?
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Iterate over items in list (longer than screen)?

Post by Bluscre » 18 Sep 2018 07:39

I tried my loop idea but with limited success:

Code: Select all

{
  "[1] Rotation Control": "Yes",
  "[2] SCR Pro": "Yes",
  "[3] Skype": "Yes",
  "[4] SuperSU": "Yes",
  "[5] SWF Player Free": "No",
  "[6] TalkBack": "Yes",
  "[7] TeamSpeak": "Yes",
  "[8] TeamSpeak": "No",
  "[9] Telegram X": "No",
  "[10] Twitch": "Yes",
  "[11] Twitter": "Yes",
  "[12] VLC": "No",
  "[13] Xbox beta": "No",
  "[14] XNotifications": "Yes",
  "[15] YouTube Vanced": "No"
}

Code: Select all

//value = existsElementById("android:id/list");
exists = existsElementByIdAndIndex("android:id/title", step);
if (!exists) {
scrollForwardByIdAndIndex("android:id/title", step-1);
sleep(1000);
exists = existsElementByIdAndIndex("android:id/title", step);
if (!exists) return;
}
title = getTextByIdAndIndex("android:id/title", step);
enabled = getTextByIdAndIndex("com.android.settings:id/widget_text1", step);
items = addMapEntry(items, "[{step}] "+title, enabled);
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

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

Re: Iterate over items in list (longer than screen)?

Post by Desmanto » 19 Sep 2018 15:59

We must loop using while(), and set a condition for it to stop. I have tried this CUI script and it works at mine. But you've got to modify it to suit your need (as every CUI script is device-dependant)

EDIT : I have fixed the script, just download the flow in the following post

Code: Select all

sleep(500);
list = newList(); 
scroll = 0;
id = "android:id/title";

while(scroll < 100)  //set a max scroll so no infinite loop
{
  index = 0; temp = newList();

  //loop over the whole index on screen, usually it is 8-15 item per screen
  while(getTextByIdAndIndex(id, index) != null)
  {
    addElement(temp, getTextByIdAndIndex(id, index));
    index = index + 1;
  }
 
  //if no element found, id must be wrong, stop immediately
  if(isEmpty(temp))
    break;

  //find the next element in previous element index, in reverse
  dup = indexOfElement(reverse(copyList(list)), temp[0]);
  end = length(temp) - 1; //save the length first, before removing elements
  removeElements(temp, 0, dup+1);
  if(dup >= 2)
    scroll = 100; //stop until this iteration if it reach end of scroll
  
  addAllElements(list, temp);

  //add the action to iterate here

  for(i in [dup+1 to end])
  {
    clickByIdAndIndex(id, i);
    sleep(100);
    clickById("android:id/switch_widget");
    sleep(100);
    back();
    sleep(100);
  }

  scrollForwardById(id);
  scroll = scroll + 1;
  sleep(200);  //don't set this too low, otherwise the script don't have enough time to capture the text
}
The action to iterate can be put at the /* */ part. I just use clickByIdAndIndex() there, assuming you want to click on each of them.
You probably should understand the flow of the script first, before adding your own action

temp contain the next scroll list to iterated. dup is to find whether the next temp has the same element in the previous saved list. If there is, remove that, as we have iterated over it in previous scroll.
Hence, in each iteration, we only use the dup+1 (the index which haven't be iterated yet) until the length of temp - 1.

PS : This only work in Automagic 1.36 above (currently dev version)
Last edited by Desmanto on 19 Sep 2018 17:40, edited 1 time in total.
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.

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Iterate over items in list (longer than screen)?

Post by Bluscre » 19 Sep 2018 16:20

Can you send the flow instead of the code? That way i can understand it better
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

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

Re: Iterate over items in list (longer than screen)?

Post by Desmanto » 19 Sep 2018 17:38

That is actually the whole flow. The flow only contains single control UI (and I attach debug dialog after it). My secondary phone don't have the permission manager to manage the draw over other apps, so I test it in development settings. Using other flow to execute this flow in the development settings. After testing finish, I simply change the id to match yours.

But I just tested it again in Bliss, turns out I missed something. The length of the temp should be saved first before removing the duplicate elements. And the list should be same actually as mine before, android:id/title. I have prooftest the flow and it is working in bliss oreo 8.1.
Draw Over other app iteration (require Automagic 1.36 above)
This flow will launch shortcut directly to overlay permission manager (should be the same in yours). Then iterate toggling over each of them until finish. So if you execute twice, the state will back to original (except automagic, you have to turn it on manually again after first execution).
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.

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Iterate over items in list (longer than screen)?

Post by Bluscre » 20 Sep 2018 12:24

Your code only puts a fraction of the list into the list variable

Code: Select all

[
  "AdGuard",
  "Adobe AIR",
  "AndChat",
  "Android System WebView",
  "App Settings",
  "ARP Guard (WiFi Security)",
  "Authenticator",
  "Automagic Premium",
  "Better Open With",
  "BoxToGo Pro",
  "burning series",
  "Caffeine",
  "Calculator",
  "Calendar",
  "Camera"
]
This is my flow btw: http://automagic4android.com/flow.php?i ... b9eae81c6e
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

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

Re: Iterate over items in list (longer than screen)?

Post by Desmanto » 20 Sep 2018 17:12

Try to increase the sleep in every step of my previous script. If the sleep is too short, some elements can be not finished scrolling yet. This depends on the animation speed at your device too, that's you have to try directly.

And if the CUI always stop prematurely, try to increase the dup check in this part, example to 5. The maximum value is the length of temp - 1.

Code: Select all

  if(dup >= temp - 1)
    scroll = 100; //stop until this iteration if it reach end of scroll
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.

Post Reply