how to access older ui events and their data in a flow triggered by another ui event

Post your questions and help other users.

Moderator: Martin

Post Reply
kenvega
Posts: 12
Joined: 19 Nov 2019 17:57

how to access older ui events and their data in a flow triggered by another ui event

Post by kenvega » 30 Jul 2020 02:55

use case: In the Pocket app, I want to have automatic access to my selected text every time I click the highlight button

My current trigger for my flow is the click of the button with text `highlight`. This gives me precise control to trigger my flow.

The issue is that in that UI event I don't have access to the selected text I highlighted. That text is actually in an old UI event, but I haven't found a way to access old UI events and their data.

I simulated the process of a highlight in the app and attached a screenshot so is gets easier to see what I mean (Sorry the massive image. I would really like to know how to make them smaller but I can't find a way to do it)

Also the UI event that holds the selected text has event type of `Text selection changed` and the text could be anything so it's not really a good way to set it as a trigger for my flow. It would be great that once my highlight button UI event trigger runs, it would search for the last UI event with type of `Text selection changed` and get the related text.

Thanks in advance!
Screenshot.jpg
Screenshot.jpg (672.12 KiB) Viewed 28084 times

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

Re: how to access older ui events and their data in a flow triggered by another ui event

Post by Desmanto » 30 Jul 2020 05:52

The screenshot is fine, it explains the idea clearly. To reduce the screenshot size, I have my own flow to take the screenshot in half sized, so it save some file size, while still maintain the whole information.

It is painful to use text selection changed, many unwanted event triggered. Better use the Highlight, then try to use Control UI getTextInActiveWindow(). Usually this will return everything that is visible in current windows scroll. Sometimes it extend to the scrollable field too, where the text is not visible, but still in the same window.

Unfortunately, this will return everything, so it can be mixed with some unwanted text too. If you have pattern on some text that always appear before and after the text you want, you can use regex to extract that out.
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
Hit
Posts: 91
Joined: 20 Jan 2020 11:31

Re: how to access older ui events and their data in a flow triggered by another ui event

Post by Hit » 30 Jul 2020 07:01

kenvega wrote:
30 Jul 2020 02:55
use case: In the Pocket app, I want to have automatic access to my selected text every time I click the highlight button

My current trigger for my flow is the click of the button with text `highlight`. This gives me precise control to trigger my flow.

The issue is that in that UI event I don't have access to the selected text I highlighted. That text is actually in an old UI event, but I haven't found a way to access old UI events and their data.

I simulated the process of a highlight in the app and attached a screenshot so is gets easier to see what I mean (Sorry the massive image. I would really like to know how to make them smaller but I can't find a way to do it)

Also the UI event that holds the selected text has event type of `Text selection changed` and the text could be anything so it's not really a good way to set it as a trigger for my flow. It would be great that once my highlight button UI event trigger runs, it would search for the last UI event with type of `Text selection changed` and get the related text.

Thanks in advance!

Screenshot.jpg
I like your idea.

User avatar
Hit
Posts: 91
Joined: 20 Jan 2020 11:31

Re: how to access older ui events and their data in a flow triggered by another ui event

Post by Hit » 30 Jul 2020 07:08

kenvega wrote:Also the UI event that holds the selected text has event type of `Text selection changed` and the text could be anything so it's not really a good way to set it as a trigger for my flow. It would be great that once my highlight button UI event trigger runs, it would search for the last UI event with type of `Text selection changed` and get the related text.

Trigger UI Event Event Type Text selection changed
+ provided a variable named 'text' which stores the text you selected.

You have to use Action Script to assign the value of variable 'text' to a global variable like this:

global_textselection = text;
// then you never lost the text :)
// Every time you select a text, it is stored in variable global_textselection
// Global Variables start with global_ and are available in all flows and are stored when the flow has ended.

Important! You have to change [contains text] to [matches global] of option Text in your Trigger with text:

*

// copy the asterisk above
Then it will trigger whenever you select a text.

kenvega
Posts: 12
Joined: 19 Nov 2019 17:57

Re: how to access older ui events and their data in a flow triggered by another ui event

Post by kenvega » 30 Jul 2020 23:00

I tried both approaches but the one that worked better was the one from Hit. So in the end I have two flows: one that frequently saves the selected text and another that triggers when the highlight button is clicked. My final idea is to save the highlighted texts on other app through an API :D

The issue I noticed with the Pocket app is that the UI event not always get exactly the text I selected. It gets the whole paragraph instead of the exact lines I selected. Judging by the UI events I would say is Pocket's app fault. But is good enough still I guess.

Thanks for the info and ideas!

User avatar
Hit
Posts: 91
Joined: 20 Jan 2020 11:31

Re: how to access older ui events and their data in a flow triggered by another ui event

Post by Hit » 31 Jul 2020 00:19

kengeva wrote:I have two flows: one that frequently saves the selected text and another that triggers when the highlight button is clicked

You can create one flow with more than two Trigger and use Condition Expression to test which Trigger triggered the flow:

trigger == "Trigger name";
//Every flow provides the variable 'trigger', is the name of the Trigger that triggered the flow

kengeva wrote:The issue I noticed with the Pocket app is that the UI event not always get exactly the text I selected. It gets the whole paragraph instead of the exact lines I selected. Judging by the UI events I would say is Pocket's app fault. But is good enough still I guess.

It is not really. I forgot that Trigger UI Event Event Type Text selection changed
+ provided variables from_index and to_index

So you should rewrite the Action Script :

global_textselection = substring(text, from_index, to_index);

// It get only text you selected
// Function substring(String s, Number start, Number end)
// Returns the substring of the specified string

It's not work with every text sources, but many, like editable text.
// If it false, from_index and to_index equal 0, you get blank text


kenvega
Posts: 12
Joined: 19 Nov 2019 17:57

Re: how to access older ui events and their data in a flow triggered by another ui event

Post by kenvega » 31 Jul 2020 16:03

Wow! didn't know that! Amazing what you can do with UI event

Now I can select exactly the thing. There is only minor issues when trying to select lines that contain bold text and normal text. Not sure why but it gets confused.

But anyway this is more than what I expected when I started haha. Thanks!

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

Re: how to access older ui events and their data in a flow triggered by another ui event

Post by Desmanto » 31 Jul 2020 19:02

@kenvenga : If you have limit the package name, then it won't mis-trigger outside of the app already. So it is ok to use that trigger now.

@Hit : I forgot that we can limit the app, so text selection changed only happen in that particular app. I have another flow which auto translate text from pdf; but I I use copy instead. Using text selection will save me 1 step then. Thanks for the idea too.
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
Hit
Posts: 91
Joined: 20 Jan 2020 11:31

Re: how to access older ui events and their data in a flow triggered by another ui event

Post by Hit » 31 Jul 2020 22:25


Hello, I'm happy that you guys like my flow.

I add some Notes to the post that I haven't mentioned before.
Please check it.

Post Reply