ways to determine screen orientation

266 views
Skip to first unread message

nmyshkin

unread,
Sep 15, 2018, 1:12:27 PM9/15/18
to Tasker
First, I am using an older version of Tasker to produce apps for Android 2.1, so there is no Display > Test > Orientation option. Secondly, there is likely no accelerometer (device is e-reader), so there's nothing to query in that regard.

I currently change screen orientation using the Rotation Locker plugin. I guess I could establish in the task that sets orientation a global variable that I could use in a different task to detect the current orientation.

Is there a more general approach? Suppose someone is rotating their screen by some other means/app. Is there any way to detect/query that?

nmyshkin

unread,
Sep 15, 2018, 1:52:05 PM9/15/18
to Tasker
Mmm......

adb shell dumpsys window | grep DisplayWidth  (with root)

returns (in portrait mode): DisplayWidth=600 DisplayHeight=800

and

returns (in landscape mode): DisplayWidth=800 DisplayHeight=600

so the system clearly knows what's going on with the orientation change brought about by Rotation Locker, even on this ancient device :-)

Looks like a simple Variable Search or Variable Section on a piped txt file should tell me what I need to know!

Robert Ryan

unread,
Sep 15, 2018, 1:57:03 PM9/15/18
to tas...@googlegroups.com
Does that version have Display -> Test Display -> Available Resolution? On my device it returns 1440x2792 in portrait and 2792x1440 in landscape. 

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Robert Ryan

unread,
Sep 15, 2018, 3:13:01 PM9/15/18
to tas...@googlegroups.com
If your version has the Java Function action, you can use Java to get the rotation. %rotation will be even when you are in portrait and odd when you are in landscape. 

        Test
        
    A1: Java Function 
        Return: display 
        Class Or Object: CONTEXT 
        Function: getDisplay
        {Display} () 
        
    A2: Java Function 
        Return: %rotation 
        Class Or Object: display 
        Function: getRotation
        {int} () 
        
    A3: If %rotation % 2 = 0
            
        A4: Flash 
            Text: Portrait 
            Long: Off 
            
    A5: Else 
            
        A6: Flash 
            Text: Landscape 
            Long: Off 
            
    A7: End If 

nmyshkin

unread,
Sep 15, 2018, 3:45:38 PM9/15/18
to Tasker


On Saturday, September 15, 2018 at 10:57:03 AM UTC-7, Robert Ryan wrote:
Does that version have Display -> Test Display -> Available Resolution? On my device it returns 1440x2792 in portrait and 2792x1440 in landscape. 


Test actually appears only under Misc and there are no display-related options.

But this shell command thing turns out to be the ticket. It's easier than I thought and is fast (in Terminal execution was kind of slow so I was worried). I didn't even have to pipe the result to a txt file. I just used the "Store Result in" option for the Run Shell task and created a variable %Orientation. Then all I had to do was add one more line to rotate an image in the image buffer 90 degrees to the right If %Orientation did not match the conditions for Portrait. Simple--and a general solution for this device.

Thanks for your suggestions. No JAVA option either (although there is the JavaScript one), but the shell command is way easier and anyone who would want to install the app would have to be rooted so that's no issue.
Reply all
Reply to author
Forward
0 new messages