I want to create the player in group on mobile.
I use this command "mobileControlCreate" for create player.
Here my code:
mobileControlCreate "player", "videoControl"
mobileControlSet "videoControl", "filename", specialFolderPath("engine") & "/vdo.mp4"
mobileControlSet "videoControl", "preserveAspect", true
mobileControlSet "videoControl", "showController", true
mobileControlSet "videoControl", "visible", true
mobileControlSet "videoControl", "rect", the rect of grp "o_c2"
How do I do?
Native controls float above the stack and are not part of the card, so - unfortunately - you can't place them in a group.
Use mobileControlCreate to create a player, as you currently do. Now use mobileControlCreate to create a scroller.
local lMovieScrollerID // declare outside handler
on createScroller
mobileControlCreate "scroller","Movie Scroller"
put the result into lMovieScrollerID
mobileControlSet lMovieScrollerID,"rect",the rect of this cd
put the rect of this cd into myRect
put item 3 of myRect * 2 into item 3 of myRect
put item 4 of myRect * 2 into item 4 of myRect
mobileControlSet lMovieScrollerID,"contentRect",myRect
end createScroller
The createScroller handler creates a scroller that can scroll over an area that is 4 times as large as your card. Therefore, you can scroll your movie exactly off screen. You will need to experiment to find out what kinf of rect (the value of myRect) you actually need.
In the next handler, let's assume that the rect of your group is 100,100,200,200.
on scrollerDidScroll theScrollH,theScrollV
put "100,100,200,200" into myInitialRect
add theScrollH to item 1 of myInitialRect
add theScrollH to item 3of myInitialRect
add theScrollV to item 2 of myInitialRect
add theScrollV to item 4 of myInitialRect
// obviously myInitialRect is no longer "initial" here
set the rect of grp "o_c2" to myInitialRect
mobileControlSet lMovieScrollerID,"rect",myInitialRect
end scrollerDidScroll
It should be clear that these handlers are untested and need some experimentation, but I am pretty sure that this is the path you'll have to follow.
Related
I am using the following code in a scrolling field. It works fine in both windows and android. The only problem is that the selected item changes as the mouse mouses up and down the list. I would like the original highlighted line to remain highlighted during the scroll and only change if the mouse have not moves move than 11 units(row height is 22) from initial vertical position. How do I modify this code to achieve that?
local lmousev,lvscroll,lscrolling
on mousedown
--If we don't use lscrolling the list will scroll when the mouse hovers over it
put true into lscrolling
--Set the initial vertical position of the cursor
put the mousev into lmousev
--Set the inital position of the vertical scroll
put the dgvscroll of me into lvscroll
end mousedown
on mousemove x,y
if lscrolling=true then --lscrolling is only true after mousedown so no scroll when mouse hovers over
--adjust the scroll position based on the vertical distance that the mouse has moved since mousedown
set the dgvscroll of me to lvscroll -(y - lmousev)
end if
end mousemove
on mouseUp
--stop scrolling when mouse hovers
put false into lscrolling
If abs( the mousev-lmousev)<11 then --If vertival position of mouse has not moved far from vertical position at mousedown
--selectlist command is in the group. It insert list selection into the textbox
selectlist
end if
end mouseUp
on mouserelease
--stop scrolling when mouse is release outside the listbox and there is no mouseup
put false into lscrolling
end mouserelease
The button,textbox and listbox that forms the combobox are grouped.The code to show/hide listbox and add selected to textbox is in the group script as follows:
Additional Info
local ldrop=false
on buttonclick --show/hide the listbox
--Get the name of the group,textbox & listbox.
--Naming convention required:- textboxname=txt & groupName,listboxname=lst & groupname
--Using quote as deliminater allows us to get the groupname from group "groupname"
set the itemdel to quote
put item 2 of the name of me into groupname
put "lst" & groupname into lstName
put "txt" & groupname into txtName
--status of ldrop let us know if the listbox is visible
if ldrop=false then
--show listbox
set the visible of field lstName to true
put true into ldrop
else
--hide listbox
set the visible of field lstName to false
put false into ldrop
end if
end buttonclick
on selectlist
--Get the name of the group,textbox & listbox.
--Naming convention required:- textboxname=txt & groupName,listboxname=lst & groupname
--Using quote as deliminater allows us to get the groupname from group "groupname"
set the itemdel to quote
put item 2 of the name of me into groupname
put "lst" & groupname into lstName
put "txt" & groupname into txtName
put the hilitedLine of field lstName into lhilitedLine
put line lhilitedLine of field lstName into field txtName
set the visible of field lstName to false
put false into ldrop
end selectlist
I think you have to make your own control that acts like a list so that you can control all the messages it sends and receives. You are otherwise stuck with some of those basic functions of LC's built-in controls. seems like you'd need an engine-level tweak to the control.
I'm using the Data Grid with native Android scroller with the code below.
When using it for just one view in the Data Grid it works OK. But when switching between different views the scrolling of the DG does not work anymore - it gets stuck or does not show the whole list - see the complete description in the document with screenshots here
See also the stack.
What do I have to change in the code and where to make it work properly?
local sScrollerID,isScrolling
on openCard
## Create scroller now:
create_scroller
pass openCard -- added just to see if it helps; it does not
end openCard
on closecard
delete_scroller
pass closeCard -- added just to see if it helps; it does not
end closecard
command create_scroller
put "DataGrid 1" into tScrollerGroup
if the environment <> "mobile" then
exit create_scroller
end if
## Create native scroller object and save its ID in a local variable
MobileControlCreate "scroller"
put the result into sScrollerID
## RECT is the area on the card where the SCOLLER should do its work
MobileControlSet sScrollerID, "rect", (the rect of grp tScrollerGroup)
put the width of grp tScrollerGroup into tWidth
put the dgFormattedheight of grp tScrollerGroup into tHeight
set the dgvScroll of grp tScrollerGroup to 0
## WHAT part fo the datagrid shall be scrolled-> the complete datagrid
MobileControlSet sScrollerID, "contentRect", (0,0,tWidth,tHeight)
## Display SCROLLER
MobileControlSet sScrollerID, "visible", "true"
## the typical BUMP effect when you ge to the edge of the object
MobileControlSet sScrollerID, "canBounce", "true"
MobileControlSet sScrollerID, "pagingEnabled", "false"
MobileControlSet sScrollerID, "vIndicator", "false"
MobileControlSet sScrollerID, "borderStyle", "none"
MobileControlSet sScrollerID, "canScrollToTop", "false"
end create_scroller
## Will be sent when the user actually SCROLLs with his finger
on scrollerDidScroll OffsetX, OffsetY
lock screen
put true into isScrolling
set the dgvScroll of grp "DataGrid 1" to OffsetY
unlock screen
end scrollerDidScroll
## REMOVE natove object when card closes!!!!!
command delete_scroller
if the environment <> "mobile" then
exit delete_scroller
end if
MobileControlDelete sScrollerID
end delete_scroller
I tried to solve it by changing the local variables to global ones. Then I put empty into global ones in every button that has script for opening different view in the data grid but it does not work.
OK, I figured it out.
I added this line: send "delete_scroller" to cd "main" in 0 sec in each handler (at the beginning of it) that creates new view in the data grid
and this one: send "create_scroller" to cd "main" in 0 sec in the same handler at the end of it.
In other words, I had to delete and create the scroller each time the data grid was updated with new data.
I'd like to use Android native scroller for a Data Grid displaying about 700 records. The scroller code below is in the card that has the Data Grid on it. The card script is:
on openCard
dispatch "ResetList" to group "DataGrid 1"
if text of fld "view" of cd "main" is "Favourites" then
send "mouseUp" to btn "favourites" of cd "home"
end if
RefreshAllLines
local sScrollerID,isScrolling
## Create scroller now:
create_scroller
end openCard
on closecard
delete_scroller
end closecard
command create_scroller
put "DataGrid 1" into tScrollerGroup
if the environment <> "mobile" then
exit create_scroller
end if
## Create native scroller object and save its ID in a local variable
MobileControlCreate "scroller"
put the result into sScrollerId
## RECT is the area on the card where the SCOLLER should do its work
MobileControlSet sScrollerId, "rect", (the rect of grp tScrollerGroup)
put the width of grp tScrollerGroup into tWidth
put the dgFormattedheight of grp tScrollerGroup into tHeight
set the dgvScroll of grp tScrollerGroup to 0
## WHAT part fo the datagrid shall be scrolled-> the complete datagrid
MobileControlSet sScrollerId, "contentRect", (0,0,tWidth,tHeight)
## Display SCROLLER
MobileControlSet sScrollerId, "visible", "true"
## the typical BUMP effect when you ge to the edge of the object
MobileControlSet sScrollerId, "canBounce", "true"
MobileControlSet sScrollerId, "pagingEnabled", "false"
MobileControlSet sScrollerId, "vIndicator", "false"
MobileControlSet sScrollerId, "borderStyle", "none"
MobileControlSet sScrollerId, "canScrollToTop", "false"
end create_scroller
## Will be sent when the user actually SCROLLs with his finger
on scrollerDidScroll OffsetX, OffsetY
lock screen
put true into isScrolling
set the dgvScroll of grp "DataGrid 1" to OffsetY
unlock screen
end scrollerDidScroll
## REMOVE native object when card closes!
command delete_scroller
if the environment <> "mobile" then
exit delete_scroller
end if
MobileControlDelete sScrollerId
end delete_scroller
--local isScrolling
on mouseUp
if not isScrolling then
send mouseUp to field "Label" of group "Row Template 0003" \
of group "dgList" of group "dgListMask" of group "DataGrid 1" of card "main"
end if
end mouseUp
on mouseDown
put false into isScrolling
end mouseDown
The code works very well when used for a text field but when used for the Data Grid the scrolling is slow and sluggish.
Is it due to a code or the innate functioning of the data Grid?
How to improve the responsiveness and the speed of the scrolling?
The link for my stack is: DG-only-1.16.zip
To test the Data Grid srolling in the standalone click on "Select All", then "Lines" and then "Entire Selection"
I added 2 buttons on the card with the data grid for testing purposes. The upper one is switching the layerMode of the DG to scrolling/static and the lower one is switching the acceleratedRendering of the stack On/Off.
Surprisingly, I've noticed that the scrolling is slightly better with acceleratedRendering turned Off and the layerMode of the DG set to scrolling and slightly more sluggish with acceleratedRendering turned ON!
The link for the new stack with added buttons is: DG-only-1.16+accelRend.zip
buttons codes:
on mouseUp
## Switch layerMode
if the label of me is "Off" then
set the label of me to "On"
set the layerMode of group "DataGrid 1" to "scrolling"
else
set the label of me to "Off"
set the layerMode of group "DataGrid 1" to "static"
end if
end mouseUp
and
on mouseUp
## Switch acceleratedRendering on and off
if the label of me is "Off" then
set the label of me to "On"
set the acceleratedRendering of this stack to true
else
set the label of me to "Off"
set the acceleratedRendering of this stack to false
end if
end mouseUp
I don't do any Android development so I can't test. One thing that sticks out is the lock screen in scrollerDidScroll. I've seen lock screen calls called very frequently slow things down before. Can you try removing the lock screen call in scrollerDidScroll and letting me know if that improves performance at all?
You might also try changing the data grid group layerMode to "scrolling".
Let me know if either of those improves performance.
I'm working with the data grid with SQLite database using a feature called callbacks as described in this lesson: displaying-large-amounts-of-data
I'd like to make some changes to the sample stack included in that lesson (you can download the stack from the link on the top of that page).
I'd like to display the 'plot' text in the DG instead of the 'Title' of the movie and the plot text should have variable line heights as described in this lesson: how-do-i-create-a-form-with-variable-line-heights
In the sample stack I made these changes:
in the Row Template:
renamed field "Title" to "plot", set the dontWrap to false and changed fixedLineHeight to false
renamed field "ReleaseDate" to "nr"
added:
set the text of field "nr" of me to pDataArray["id"]
in the Row Behavior:
## changed the layoutControl to make space for wrapping of field "plot"
on LayoutControl pControlRect
local theFieldRect
put the rect of me into theFieldRect
set the right of button "Genre" of me to item 3 of theFieldRect
set the right of field "LblGenre" of me to the left of button "Genre" of me
set the right of field "nr" of me to item 3 of theFieldRect
## Expand field "plot"
put the rect of field "plot" of me into theFieldRect
put item 3 of pControlRect - 180 into item 3 of theFieldRect
set the rect of field "plot" of me to theFieldRect
##Now resize field to fit content
put item 2 of theFieldRect \
+ the formattedheight of field "plot" of me - \
the bottommargin of field "plot" of me \
into item 4 of theFieldRect
set the rect of field "plot" of me to theFieldRect
## Now update the bounding rect to match total height you
## want this row to have
put item 4 of theFieldRect into item 4 of pControlRect
set the rect of graphic "Background" of me to pControlRect
end LayoutControl
In the lesson on setting variable line heights it says to turn off the "fixed control height" of the data grid. However when I do that nothing gets displayed and I'm getting a scrip error.
The stack with my changes is here: Databases-callbacks-variable-line-height.zip
(just replace the original stack from the lesson with it; the SQLite database is the same and should be placed in the same folder as the stack).
How to fix this so that the variable line height will work?
I located the problem with fixed control height turned off. The data grid behavior isn't setting the GetDataForLine pLine parameter properly when caching the height for each row. I'll provide a modification you can make to the data grid behavior until a fix is included in LiveCode, but you should probably reconsider your approach. When fixed line height is turned off the data grid has to compute the height of every line prior to displaying the data grid. This takes a loooooong time for the 50,000 record example you are working with.
First, edit the script of the data grid behavior:
edit script of btn "data grid" of stack "revdatagridlibrary"
Next, go to line 3097. Below 3097 add the following line of code:
add 1 to theSequence
The code should now look like this:
repeat for each key theIndex in sDataArray
add 1 to theSequence
## Get height
if sDataArray[theIndex] is NULL then
Save the script. This will save the change in your current version of LiveCode. Be aware that the next time you update LiveCode the change will be lost. I submitted the fix to RunRev, however, so it should be fixed in the next release.
Also, your code that sets the rect of graphic "Background" needs a small change. Right now it won't work if the bottom of the field is higher than the bottom of the "Genre" button. The code should probably be something like this:
put max(item 4 of theFieldRect, the bottom of button "Genre" of me + 4) into item 4 of pControlRect
I made a stack that displays lines of text that change their width when the stack is resized.
The Category columns is changing its position on resizing but the check box does not.
What am I missing in the code? What changes have to be made?
See the code in the stack that can be downloaded here:
https://dl.dropboxusercontent.com/u/99863601/Data%20grid%20Form-variable%20line%20height%2Bcheckbox.zip
Thanks in advance.
keram
If I understand what you are trying to achieve here then in your LayoutControl handler make the following change:
-- put the rect of btn "btnCheck" of me into theFieldRect
-- put item 3 of pControlRect - 5 into item 3 of theFieldRect
-- set the rect of btn "btnCheck" of me to theFieldRect
set the left of btn "btnCheck" of me to the right of fld "cat" of me
However I think the resizing of the Cat field is wrong too. Try something like:
on LayoutControl pControlRect
set the right of btn "btnCheck" of me to item 3 of pControlRect-4
set the right of fld "Cat" of me to the left of btn "btnCheck" of me
get the rect of fld "Line" of me
put the left of fld "Cat" of me into item 3 of it
set the rect of fld "Line" of me to it
put the formattedHeight of fld "Line" of me + item 2 of it into item 4 of it
set the rect of fld "Line" of me to it
put item 4 of it into item 4 of pControlRect
set the rect of graphic "Background" of me to pControlRect
end LayoutControl
To edit the LayoutControl script you need to open the datagrid property inspector and click on the Row Behavior... button. This will present the script editor for the behavior of the row template.
Because the DataGrid doesn't have this feature. If you would use the Geometry manager, the GM propeties are not copied from the checkbox in the template to the checkboxes in the actual DG. So, the GM won't work. Perhaps you could write a script of your own that sets the right of all checkboxes to a position relative to the width of the card:
on resizeStack
lock screen
repeat with x = 1 to number of buttons
if the style of btn x is "checkbox" then
set the right of btn x to the width of this cd - 100
end if
end repeat
unlock screen
end resizeStack
Unfortunately, this doesn't work with the datagrid either, because the DG also does some (or a lot) resizing of its own.
It would be much easier to create your own.