New Trigger and Constraint: Device Hinge Angle

Quidn

Passionate Member
I own many devices but for verification purposes. (Many of them used).

For example, many people use Xiaomi devices, but you can't tell them to buy a Google Pixel, can you?
I go out of my way to buy a Xiaomi device and post a solution, even though the Google Pixel has a lower incidence of problems.

If development resources were focused on folding devices and new features for folding devices were released one after another, would you all pay $1000 for a folding device?

Wouldn't it be better to devote resources to features that will be useful to everyone rather than features that you have to pay $1000 to use?

I have included a screenshot of the donation to prove that it is not just a menu selection. Please don't make accusations.

I still don't understand your perspective, but I'd say I'll trying to respect.

However even if suppose that your opinion is all correct, I think saying like that is inappropriate at all in any perspective.

What if OP already donated thousands of dollars and the device was a very first model of Z Flip from used market? Then that must costed cheaper than a new Xiaomi phone's.

I wonder that you think there's no possibility to being happens like that because you don't remember any similar case which confirmed by your eyes.

You said "$1000" for several times, and now say to having numerous of devices is just fine because purpose is very good and many of those are used ones?

If you think what you said are okay because those were just your opinion, please think about what if someone else says like this to you:
"Sir, in my humble opinion your donation amount is too petty to be bragged or make any meaning. If you don't mind then I'd ask very carefully to you to stop collecting toys which were just for fun, and please think about if you couldn't to do donate realistic amount rather than small pennies. I truly appreciate for your understanding that this is of course for public goodness and just my straight opinion only."
 

Dimlos

Well-known member
I don't understand why posting a screenshot of a donation is taken as bragging.
I just did what I said I would do.
Surely $1000 is the reference price for a new Galaxy Z Flip5.

I'm sure there are other things that both sides don't agree on, but I think we should stop here.
If the discussion heats up away from MD, it's going to get the thread thing erased.

If the thread remains, maybe @MacroDroidDev will see it and adopt it.
 

Dimlos

Well-known member
@apollo316
I knew that you often check the thread, so I decided to read your post again. I was surprised to see that Automate had already implemented Device Hinge Angle? from a reddit post two years ago.

I prepared a device and did some trial and error, but to reproduce it on MacroDroid, the logcat trigger seems to be good, although it is currently limited to Android 12.
I have attached the macro for reference, so please take a look if you like.

I am not very familiar with Samsung devices so I am not sure how to set up Android 12 or 13 to not get taskkilled.
I would like to know if you have time to help me.
 

Attachments

  • macro.jpg
    macro.jpg
    560.3 KB · Views: 8
  • flip_angle_sound.macro
    2.3 KB · Views: 2
Last edited:

apollo316

New member
Thank you all for playing out some theories and trying to come up with a solution. I was able to test the macro posted above and it works, with some caveats. I'm still hoping for a Constraint and Trigger to be added along with some configuration options for a Flip Angle Sensor.

Using the logcat works but I run into the following issues:
- The 1s delay (Pause), which is needed so it has enough time to check that the screen is off makes it delayed to firing the actions.
- Removing the pause breaks it from working
- Requires advanced knowledge/setup to use ADB to enable logcat.

For a novice user this would be a difficult setup where sharing a saved .macro file is not the only step, and couldn't be shared easily on the community Templates page. Having an Action and Condition of Flip Angle Sensor would provide an advantage in ease of setup for others. As an Action it could be defined as FlipAngle=xx and then fire the actions. As a Constraint it would also prove useful by limiting other Triggers based on the flip open/closed state.

----------------------------
Example:
Trigger:
Screen=Off
Screen=On

Actions:
Play Sound close.mp3
--Constraint: FlipAngle=0 (degrees)
Play Sound open.mp3
--Constraint: Flip Angle not equal to 0 (degrees) ---this would be even better if it can tell what the previous state was. The native Bixby Routines app seems to do this so that it knows the device was actually opened/closed.
----------------------------

----------------------------
Another example:
Trigger:
Shake Device

Actions:
Toggle Flashlight
--Constraint: FlipAngle=180
----------------------------

This would prevent notifications that wake the external screen (or other use of the external screen) from from firing the actions since the FlipAngle constraint is not met. And there's no pause so it would be very responsive.

My full build in Macrodroid for custom flip sounds would be as follows:
Trigger:
FlipAngle=0 (Option: when-changed)
--Constraint Screen=Off
FlipAngle=180 (Option: when-changed)
--Constraint Screen=On
Device Unlocked=True

Actions:
Play Sound close.mp3
--Constraint: FlipAngle=0 (degrees)
Play Sound open.mp3
--Constraint: FlipAngle not equal to 0 (degrees)
Play Sound coverscreen.mp3
--Constraint: FlipAngle=0, Device Unlocked

Constraints:
Not In Call
Not Ringing
Device Locked
Music Not Playing
Headphones Not Connected
Priority Mode / Do Not Disturb = Allow All
WiFi Not Connected (to set to a work/place where you don't want the sounds firing)
 

Snurre

Well-known member
Thank you all for playing out some theories and trying to come up with a solution. I was able to test the macro posted above and it works, with some caveats. I'm still hoping for a Constraint and Trigger to be added along with some configuration options for a Flip Angle Sensor.

Using the logcat works but I run into the following issues:
- The 1s delay (Pause), which is needed so it has enough time to check that the screen is off makes it delayed to firing the actions.
- Removing the pause breaks it from working
- Requires advanced knowledge/setup to use ADB to enable logcat.

For a novice user this would be a difficult setup where sharing a saved .macro file is not the only step, and couldn't be shared easily on the community Templates page. Having an Action and Condition of Flip Angle Sensor would provide an advantage in ease of setup for others. As an Action it could be defined as FlipAngle=xx and then fire the actions. As a Constraint it would also prove useful by limiting other Triggers based on the flip open/closed state.

----------------------------
Example:
Trigger:
Screen=Off
Screen=On

Actions:
Play Sound close.mp3
--Constraint: FlipAngle=0 (degrees)
Play Sound open.mp3
--Constraint: Flip Angle not equal to 0 (degrees) ---this would be even better if it can tell what the previous state was. The native Bixby Routines app seems to do this so that it knows the device was actually opened/closed.
----------------------------

----------------------------
Another example:
Trigger:
Shake Device

Actions:
Toggle Flashlight
--Constraint: FlipAngle=180
----------------------------

This would prevent notifications that wake the external screen (or other use of the external screen) from from firing the actions since the FlipAngle constraint is not met. And there's no pause so it would be very responsive.

My full build in Macrodroid for custom flip sounds would be as follows:
Trigger:
FlipAngle=0 (Option: when-changed)
--Constraint Screen=Off
FlipAngle=180 (Option: when-changed)
--Constraint Screen=On
Device Unlocked=True

Actions:
Play Sound close.mp3
--Constraint: FlipAngle=0 (degrees)
Play Sound open.mp3
--Constraint: FlipAngle not equal to 0 (degrees)
Play Sound coverscreen.mp3
--Constraint: FlipAngle=0, Device Unlocked

Constraints:
Not In Call
Not Ringing
Device Locked
Music Not Playing
Headphones Not Connected
Priority Mode / Do Not Disturb = Allow All
WiFi Not Connected (to set to a work/place where you don't want the sounds firing)
Instead of logcat, it's possible to do nearly all of this with a little workaround, it requires Bixby

Post in thread 'Open/close z flip trigger?' http://www.macrodroidforum.com/index.php?threads/open-close-z-flip-trigger.4007/post-22435
 

Dimlos

Well-known member
Since the use of Bixby is limited to Samsung devices, it may be more versatile to implement it on the MD side to support the increasing number of foldable devices in the future.
 

apollo316

New member
@Snurre Instead of logcat, it's possible to do nearly all of this with a little workaround, it requires Bixby

Great idea! I tried this option and yes it also works and is a better workaround than needing ADB commands for a novice user to set this up. Thank you for suggesting this! It does have about a 2-3 second delay before actions fire due to the delay in the notification appearing, but you got my interest in a workaround piqued so I also tried a few other methods, such as:

-Bixby Routines to create a "flip closed" and "flip open" notification.
-Macrodroid:
Triggers
Screen off
Screen on

Actions:
(if) notification present from Bixby contains "flip closed"
--Play sound closed.mp3
(end if)
(if) notification present from Bixby contains "flip open"
--Play sound open.mp3
(end if)
Clear Notifications

Everything I tried based on the notification from Bixby Routines worked well but still had the delay and would still be Samsung-specific, as @Dimlos also notes. I concur, it would be great if this was implemented on MD's side.

The good news is, for just about anything outside of a custom open/close sound, both the workarounds presented in this thread would work well with just a few second delay and some slightly advanced setup/configuration. It's just the open/closed sounds playing that don't match the speed of opening and closing, and they aren't as simple as sharing in the Macrodroid Templates page, or elsewhere with just a .macro file.

Hopefully @MacroDroidDev is interested in adding the Flip Angle Sensor as an Action/Constraint, as this would easily negate any workarounds being needed, but if you guys have any other ideas I'm happy to try them out. I'm amazed at the creative ways you guys have come up with to work around such a specific request, and it goes to show how versatile Macrodroid is. I love this app and this community. Thank you everyone!

P.S.
Who knows, maybe someday we'll have motors built-in that open the phone themselves and I'll be back to request this also be added as an Action 😂
 

Snurre

Well-known member
Great idea! I tried this option and yes it also works and is a better workaround than needing ADB commands for a novice user to set this up. Thank you for suggesting this! It does have about a 2-3 second delay before actions fire due to the delay in the notification appearing, but you got my interest in a workaround piqued so I also tried a few other methods, such as:

-Bixby Routines to create a "flip closed" and "flip open" notification.
-Macrodroid:
Triggers
Screen off
Screen on

Actions:
(if) notification present from Bixby contains "flip closed"
--Play sound closed.mp3
(end if)
(if) notification present from Bixby contains "flip open"
--Play sound open.mp3
(end if)
Clear Notifications

Everything I tried based on the notification from Bixby Routines worked well but still had the delay and would still be Samsung-specific, as @Dimlos also notes. I concur, it would be great if this was implemented on MD's side.

The good news is, for just about anything outside of a custom open/close sound, both the workarounds presented in this thread would work well with just a few second delay and some slightly advanced setup/configuration. It's just the open/closed sounds playing that don't match the speed of opening and closing, and they aren't as simple as sharing in the Macrodroid Templates page, or elsewhere with just a .macro file.

Hopefully @MacroDroidDev is interested in adding the Flip Angle Sensor as an Action/Constraint, as this would easily negate any workarounds being needed, but if you guys have any other ideas I'm happy to try them out. I'm amazed at the creative ways you guys have come up with to work around such a specific request, and it goes to show how versatile Macrodroid is. I love this app and this community. Thank you everyone!

P.S.
Who knows, maybe someday we'll have motors built-in that open the phone themselves and I'll be back to request this also be added as an Action 😂
I don't know if the open/close music plays faster (without delay) if you use it directly in Bixby (its possible) instead of MD
 

Snurre

Well-known member
Since the use of Bixby is limited to Samsung devices, it may be more versatile to implement it on the MD side to support the increasing number of foldable devices in the future.
This was just to help OP with a workaround on his Samsung, I don't know if other foldables have some similar app that could do something like this

But I totally agree with you 👍
 

apollo316

New member
I don't know if the open/close music plays faster (without delay) if you use it directly in Bixby (its possible) instead of MD - Snurre
Great idea! I poked around in Bixby Routines but unfortunately there's no play sound action I can find in there. It'll play music but I can't find any way to select a file to play individually.

Reviewed logcat to eliminate delays. - Dimlos
@Dimlos This is working perfectly! No delay/barely at all. Thank you! How do you capture what the item to watch for in the log was: "onFoldStateChanged" and "isFolded"
I'd like to capture if the external display (coverscreen) has an individual log/trigger so I can have actions only for when the coverscreen is used, versus when the phone is flipped open or closed. I've tried all sorts of constraints and triggers but it seems the screen on event is happening before the onFoldStateChanged is happening, causing my constraints to fail or actions to trigger multiple times.
Can you tell me how you're reading the logs and finding what commands to use?
 

apollo316

New member
I found the logcat macro that records everything, poured through the system log and, man, there's a lot to look through to figure out what tells the system the coverscreen is on. It appears to be 'subhomeactivity' but I'm trying to figure what is the on/true value that indicates it's on. I'll post back if I can figure that piece out.
 

Dimlos

Well-known member
If you want to get logs with the device closed, just connect it to a PC and use adb logcat>log.txt.
There are no shortcuts to decipher logcat, only steady trial and error.
 

apollo316

New member
@Dimlos I just saw the changelog. Thanks for bringing my attention to that. This is very exciting! Thank you, and @sampleuserhere @Snurre and @Quidn for your help, troubleshooting and support, as well as @MacroDroidDev for adding this feature! I just tossed the 5.38 on my Flip and I'm working on a flip sounds macro to release on Reddit once 5.38 hits the PlayStore for everyone. 🤞it brings in some new users who want to help support this amazing app! Thanks everyone!
 

BobW

New member
Similar solution for a different device, so no Bixby involved. It requires ADB, but no root and no delay:
 
Top