how to access older ui events and their data in a flow triggered by another ui event
Moderator: Martin
how to access older ui events and their data in a flow triggered by another ui event
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!
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!
Re: how to access older ui events and their data in a flow triggered by another ui event
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.
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.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: how to access older ui events and their data in a flow triggered by another ui event
I like your idea.kenvega wrote: ↑30 Jul 2020 02:55use 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
Re: how to access older ui events and their data in a flow triggered by another ui event
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.
Re: how to access older ui events and their data in a flow triggered by another ui event
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
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!
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!
Re: how to access older ui events and their data in a flow triggered by another ui event
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
Re: how to access older ui events and their data in a flow triggered by another ui event
I shared my flow, you can try it by clicking the link below
Re: how to access older ui events and their data in a flow triggered by another ui event
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!
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!
Re: how to access older ui events and their data in a flow triggered by another ui event
@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.
@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.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: how to access older ui events and their data in a flow triggered by another ui event
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.