Marquee text within widget

Post your questions and help other users.

Moderator: Martin

Post Reply
Quando
Posts: 2
Joined: 19 Nov 2017 13:45

Marquee text within widget

Post by Quando » 19 Nov 2017 20:36

Hello everyone,

I am wondering if it is actually possible to create auto-scrolling text within a widget in case its string is too long to be displayed in a single line/the amount of letters is above a defined range?
For layout purposes, multiline is not an option for me and I have an inkling that it might be possible by using script actions, though I cannot wrap my head around how it could work.

Thanks in advance for any information I am lacking!

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

Re: Marquee text within widget

Post by Desmanto » 20 Nov 2017 07:12

Possible but maybe not practical. Widget are mainly used for static home screen widget, but can be used as overlay too. Currently there is no animation support yet, maybe it will be added in the future. The maximum refresh speed is twice per second (500 ms). For your case, refresh speed should not be a problem, since the scrolling text will wait maybe for 1 or 2 seconds before showing another.

For scrolling direction, while it is possible to scroll horizontally, it won't be smooth when used (because only 2 update per second). So it is better to scroll vertically, just like notification ticker in status bar.

Need to know your example whole text first. Is it a long text or multiple lines of short text? For long text, I still don't know how to check the result is how many lines. Probably need to split based on the space and count of character (quite complicated). But for multiple lines, we can split the lines first and directly can check the length of the list.

It can be done thru the same text element with multiline enabled. Make the text bigger than the widget shown. Example widget only show 1 line of text, but the actual text element is 5 line height. Then use script to shift the Y part of the text, example -30 (depends on the widget/text size). Loop the shifting endlessly using while(). After it hit the end of the line, reset the shift back to -30. This can work with long text. But the number of lines must be fixed. If it is used in multiple lines text, we can add check for the length.

The other way is to use widget and text with same size, showing only 1 line. Use loop to change the text to each elements from the splitted lines before. After reaching end of list, go back to index 0. But this only work for multiple lines. For long text, need to find the way to split it first to multiple lines.

Both method will drain you battery and make your phone can't sleep to conserve battery. The script must be stopped using stop flow or you can put some condition for the while(). So use only when needed and stop refreshing the widget after certain condition are not met anymore.
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.

Quando
Posts: 2
Joined: 19 Nov 2017 13:45

Re: Marquee text within widget

Post by Quando » 20 Nov 2017 15:16

Oh I see, that makes a lot of sense. I haven't even thought about scrolling vertically.
The string I use within the widget displays music information such as the currently playing track, album and artist, so it is basically a singleline string with an undefined length.

The part about checking the final string length is probably the crux of the matter.
As long as there is a way to grab that information and use it as a trigger or condition, I could work around the text being cut in a variety of ways.
Otherwise, I guess the solution/s is/are too complex and impractical when looking at the usefulness of the final outcome.

EDIT: Thank you very much for your input, I figured out an alternative approach by replacing any returned string longer than X characters by a substring with a "..." suffix. Therefore centered text won't be cut off on either side, but will instead be abbreviated. This is sufficient for my purposes.

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

Re: Marquee text within widget

Post by Desmanto » 21 Nov 2017 06:34

Oh, glad you have the alternative. I am also using almost similiar concept for multi QR transferring. I take only 20 char from front and back, replacing the middle with ... That way, I don't have to read the whole text to confirm the scanned QC is correct, just check the beginning and the end.

I was just about to suggest you another alternative. You can add another flow to check if you are on the home screen page where the widget located. And if text is too long, activate this flow, it will monitor. The if you are at page, it will show up another popup widget to show the full text.

Another way maybe to trigger the popup by tapping the widget manually. Or probably just decrease the font size when it is too long.
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