Mobile Rotation Redux

Brian Milby brian at milby7.com
Thu Aug 30 21:46:43 EDT 2018


I finally installed Android Studio.  I have API 28, 26, and 15 installed.
Everything else was pretty much the defaults.  (Hint: you don't need to
move the sdk directory out of your Library, just create an alias and put it
on your desktop.  When you select the alias, LC will resolve it and store
the actual path.)

I couldn't get the (slow) emulators to launch.  Finding AVD in Studio is
somewhat of a pain (had to create a project to get the menu option).  Log
had some complaint about a file not being in the right place.

I decided to try to build a simple app and put it on my 5th Gen Fire (Fire
OS 5.6.1.0).  Ended up putting the apk on Dropbox, then copying it to the
SD card on the Fire, then installing the app (for some reason trying to
install directly from Dropbox didn't want to work).

Stack has 3 objects on the only card:  field "label", field "log", and
widget "Browser"
Objects all resize and move based on the rect (log and browser positions
change when rotated to landscape).  In LC, the stack is saved as 320x480 to
be sure that it has to resize.

I'll post the stack file if anyone wants to see it.  On the one Android
device I have available it works correctly.  Resizestack handlers fire
correctly.  So I guess I need to find something with a later OS to test
against to see the problems others are seeing on the Android side.

I linked the label field to open the r9 demo stack from the other thread
and it worked fine as well.

Here is the stack script:
---------------------------------------------------
on preOpenStack
   logRects "stack preOpenStack"
   pass preOpenStack
end preOpenStack

command logRects pText
   put pText & lf & \
         "   stack rect" && the rect of this stack & lf & \
         "   screenrect" && the screenrect & lf \
         after field "log" of card id 1002 of me
end logRects


Here is the card script:
---------------------------------------------------
on preOpenStack
   if the environment is "mobile" then
      local tOrientations
      put "portrait,portrait upside down,landscape left,landscape right"
into tOrientations
      mobileSetAllowedOrientations tOrientations
   end if
   --
   logRects "card preOpenStack"
   pass preOpenStack
end preOpenStack

on preOpenCard
   logRects "card preOpenCard"
end preOpenCard

on openCard
   logRects "card openCard"
end openCard

on resizeStack pNewWidth, pNewHeight, pOldWidth, pOldHeight
   logRects "resizeStack" && pNewWidth & slash & pNewHeight & \
         slash & pOldWidth & slash & pOldHeight

   local tMid
   if pNewWidth > pNewHeight then
      -- landscape
      put round(pNewWidth/2) into tMid
      set the rect of field "log" of me to 24,48,tMid-12,pNewHeight-24
      set the rect of widget "Browser" of me to
tMid+12,48,pNewWidth-24,pNewHeight-24
   else
      -- portrait
      put round(pNewHeight/2) into tMid
      set the rect of field "log" of me to 24,48,pNewWidth-24,tMid-12
      set the rect of widget "Browser" of me to
24,tMid+12,pNewWidth-24,pNewHeight-24
   end if
   set the rect of field "label" of me to 24,12,pNewWidth-24,48
end resizeStack


This is probably a good basic stack that could be used to gather
information on when events are firing and when values are getting updated.
For example, a send in time could be used to check the rects a certain
amount of time after the openCard finished.



More information about the use-livecode mailing list