When IDLE do something, when touch screen, other

Post your questions and help other users.

Moderator: Martin

pickone
Posts: 22
Joined: 08 Sep 2017 14:52

When IDLE do something, when touch screen, other

Post by pickone » 09 Sep 2017 21:41

Hi guys!

I have a tablet which I use it AC plugged all the time (without battery) and with a program which keeps my screen on always (alive, it never goes locked or screen off) and... I need to know how can I make automagic to do something when the device is getting in IDLE mode (like not used, no touch) after a specified time and how can I make automagic to respond to a touch of the screen or button?

Like:

- When the device is IDLE (no screen/button touched) for 10 seconds, run an appliction
- When the screen is touched or a button, kill that application

Thank you in advance!

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

Re: When IDLE do something, when touch screen, other

Post by Desmanto » 10 Sep 2017 05:59

First, you don't need additional program to make your screen alive. Why use one trick pony app when Automagic can do it already? :) Just create action Set Screen Timeout, change to Never and execute it manually, not need to make it becomes a flow. Then your screen will never sleep anymore. If at your phone, never sleep didn't work, let's say only max to 24 hours. Then you can use trigger Display State off, add single action Turn Screen On. I believe you should have disabled the keyguard already since you want the screen always on.

I make some assumption to make it easier to explain. You want the tablet screen always on (done already). When it is idle 10 seconds at home screen, launch IPcam app to monitor CCTV. If someone touch the screen, close the IPcam app and jumps back to home screen. To do something like this, you need to create 1 custom widget and 3 flows to accomodate the event. The widget will act somewhat just like a screen saver which will be dimissed when touch. You have to make sure automagic is granted Draw over other apps permission. Or if you ROM has something like permission monitor, check it and make sure automagic is granted the windows popup permission.

Widget : Screen Saver
Create a custom widget as big as your tablet resolution. Pay attention to the default orientation you use. If you use the tablet in landscape mode, you should make the resolution in landscape mode as well. For example, 1080x1920. This widget can be make completely transparant or you can give some white transparant color or add some small object like a stars or something to indicate the widget is showing in front. Later you wanna add action to this widget to execute the complementary flow.

Flow 1 : Tablet Idle
This will detect when the tablet is idle, under one condition, you have to back at the default home launcher first.
Trigger : App Task Started : Choose your home launcher.
Action 1 : Sleep 10s, or as long as you want for the Idle timer.
Action 2 : Launch App, select the app you want launch (IPcam app or anything) and use Control UI (need accessibility) as needed to navigate to the menu until the intended view.
Action 3 : Show Custom Widget Overlay, Overlay Name : Screen Saver, choose the widget Screen Saver, put the resolution of your tablet and check Clickable.
This flow detect when you are in home launcher and idle for as long as the sleep timer, it will launch the app and block the screen using the pseudo screen saver. Don't enable this flow yet! Make sure you finished until flow 3 before trying this.

Flow 2 : Reset Idle
This will reset stop Tablet Idle flow and make sure it doesn't launch the app and show the widget while we are still using it.
Trigger : App Task Ended : Choose your home launcher
Action 1 : Stop Flows, Choose Tablet Idle flow.
This doesn't mean when your home launcher is ended/killed. It simply means when the launcher is not the foreground app. However this has limitation though. When you back to homescreen, Flow 1 has been triggered, and start counting down. If you still navigating to your app drawer, it won't trigger this Reset Idle flow. So you might get the widget shown even if you are still using it. So it requires the condition where you have setup your tablet properly so you won't be navigating the home screen anymore unless for the several seconds switching the app. You can increase the sleep timeout to make sure you have enough time for navigating.

There is a better way to replace this 2 flows, using single flow Trigger UI Event at the home launcher. However it requires accessibility and I don't know if your tablet implemented it properly (need JB 4.3+). It is also more complicated, need to use Info overlay to select the element. But won't suffer from this navigating app drawer locked out issue. If your tablet supports it, and you really need to make sure it works precisely, then I can show you the way.

Flow 3 : Screen Saver Unlock
Create a flow without any trigger. This flow 3 only need to be executed from Widget Screen Saver, so no trigger needed.
Action 1 : Hide Custom Widget Overlay, choose the Screen Saver
Action 2 : Show Home Screen. We don't need to kill the current running app, since we are going to open it again later. But if it is needed, you can add Kill App after this action 2.
Then go back to Custom Widget Screen Saver > Clickable Actions > Add Click > Execute Flows, choose Screen Saver Unlock (this flow 3).

Caution : Make sure you have add this clickable action to widget, and enable this flow before trying to show the widget. If you show the overlay widget and don't have any means to hide it again, you will ended up blocking yourself and can't do anything to the whole screen anymore. You have to force restart the tablet (hold power button 10 seconds) or unplug the charging cable.
You can try this widget out by using another separated action Show Custom Widget Overlay, but use lower resolution, example 360x640 (so it won't block the whole screen), executed it. And try to tap it to see if the widget disappeared (and you will jump back to homescreen). If it is working, then you can try to enable flow 1 and 2 now.

Further customization
You can still add more action click to the widget. For example you can split the clickable part to 4 parts. Click top left to directly launch music app, click top right to launch youtube and etc. You can also add another time trigger to change the color of the widget based on time, or to put some extra information, or maybe the motion detection from the IPcam.
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.

pickone
Posts: 22
Joined: 08 Sep 2017 14:52

Re: When IDLE do something, when touch screen, other

Post by pickone » 10 Sep 2017 09:18

In fact :))) I am trying to run a screen saver app for black screen if the device is IDLE and to close the screen saver app if I am touching the screen

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

Re: When IDLE do something, when touch screen, other

Post by Desmanto » 10 Sep 2017 10:11

:D Screensaver ception then? LOL

No problem, you just replace the IPCam app (that is what comes thru my mind first) with your screen saver. The concept is still the same.
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.

pickone
Posts: 22
Joined: 08 Sep 2017 14:52

Re: When IDLE do something, when touch screen, other

Post by pickone » 10 Sep 2017 10:30

There is a problem with this solution, I want that automagic detect idle or touches of the screen everywhere, maybe I let the tablet in an opened application, not directly in the home luncher :( ...

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

Re: When IDLE do something, when touch screen, other

Post by Desmanto » 10 Sep 2017 12:31

Yes, that's the ugly part. You have to back to the home screen. There is another way to detect using UI windows opened. But still facing the same 15 seconds problem. If you are watching video, then the screen saver will pop up after 15 seconds. So you have to check first what kind of usage do you have, so we can make a workaround avoiding the unnecessary screen saver. BTW, what is your tablet model, android version? Does the accessibility work?
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.

pickone
Posts: 22
Joined: 08 Sep 2017 14:52

Re: When IDLE do something, when touch screen, other

Post by pickone » 10 Sep 2017 12:56

android 6.0, a noname tablet from china :))
Does not matter what I do on the tablet, even if there is a movie or music playing... if i dont touch the screen or hardware buttons for 10 seconds, run the application, if I dont do any input, kill it

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

Re: When IDLE do something, when touch screen, other

Post by Desmanto » 10 Sep 2017 17:11

AFAIK there is no way for automagic to access directly to the touch screen input. Some app can do it with root though (GMD gesture). But we still can use accessibiliity.

You can enable the Accessibility for automagic. We will use UI event.
Trigger : UI Event : Component Clicked, package name * matches glob *
You probably need to add component scrolled too, to make sure it catches both.
The rest of action is same as flow 1.

After finish as flow 1, tap 3 dot menu > Options > Flow Execution Policy choose Stop the currently ....
Using this, you don't need flow 2 to stop flow 1 anymore. Anytime the flow get triggered, it will reset the sleep timer.
You still need the widget and the flow 3.

The logic will be anytime you click any component on any app, it triggers the flow and refresh the sleep timer (since it stops previous execution first). Basically as long as you keep clicking something, the sleep timer never reach 15 seconds. But if you stop clicking (no user activity, idle), then sleep can finish and will execute the show widget. Add the additional Event Type as needed. Component Clicked, Component Scrolled, and Text Changed are probably the suitable ones. Try it 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.

pickone
Posts: 22
Joined: 08 Sep 2017 14:52

Re: When IDLE do something, when touch screen, other

Post by pickone » 10 Sep 2017 21:55

Like I said in the first post, I think that I'm the problem not understanding exactly how the application is working... :(

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

Re: When IDLE do something, when touch screen, other

Post by Desmanto » 11 Sep 2017 06:40

I have made the flow, need some more testing to make sure it is working and not get locked out by the widget.
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