mobilecontrolcreate browser

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

mobilecontrolcreate browser

Post by cusingerBUSCw5N » Sun Dec 30, 2012 3:35 pm

I am trying to modify the sample code to have a browser open within Livecode - and am currently getting "webpage not available" in the testing mode. Here is the code:

Code: Select all

-- We use this variable to store the id of the UIWebView native
-- control.
local sBrowserId

on preOpenCard
   if the environment is not "mobile" then
      exit preOpenCard
   end if
   
   -- Create our browser control and store the id
   if the platform is "android" then
      mobileControlCreate "browser"
mobileControlCreate "browser", "web view"
put the result into sBrowserID
mobileControlSet sBrowserID, "visible", "true"
mobileControlSet sBrowserID, "url", "http://www.irs.gov"
else
   iphoneControlCreate "browser"
   put the result into sBrowserId
   -- Native controls start off invisible
   iphoneControlSet sBrowserId, "visible", "true"
   -- Set up a suitable initial url
   iphoneControlSet sBrowserId, "url", "http://www.google.com"
   
   end if
   -- Make sure everything is the right size
   resizeStack
end preOpenCard

on closeCard
   if the environment is not "mobile" then
      exit closeCard
   end if
   
   -- Destroy the control, if we fail to do this native UIViews
   -- will just accumulate
   if the platform is "android" then
      mobileControlDelete sBrowserId
      else
         iphoneControlDelete sBrowserId
         end if
end closeCard

on resizeStack
   if the environment is not "mobile" then
      exit resizeStack
   end if
   
   -- Adjust the size of the URL entry field
   set the rect of field "URL" to the left of field "URL", the top of field "URL", the width of this card - 4, the bottom of field "URL"
   
   -- Adjust the size of the browser view
   set the rect of group "Browser" to the left of group "Browser", the top of group "Browser", the width of this card - 4, the height of this card - 40
   
   -- Adjust the status field
   set the rect of field "Status" to 4, the bottom of group "Browser" + 4, the width of this card - 4, the height of this card - 4
   
   -- Now adjust the control itself
   if the platform is "android" then
       mobileControlSet sBrowserId, "rect", the rect of group "Browser"
      else
         iphoneControlSet sBrowserId, "rect", the rect of group "Browser"
         end if
end resizeStack

--------

-- This message is received after a request has been allowed and
-- loading is starting
on browserStartedLoading pUrl
   put "Started loading:" && pUrl into field "Status"
end browserStartedLoading

-- This message is received when a page has been completely
-- loaded and is displayed to the user
on browserFinishedLoading pUrl
   put "Finished loading:" && pUrl into field "Status"
   put pUrl into field "Url"
end browserFinishedLoading

-- This message is received when a new url is requested. Passing it
-- causes the load to go ahead, otherwise it does not.
on browserLoadRequest pUrl, pReason
   answer "Do you want to load:" && pUrl with "Yes" and "No"
   if it is "Yes" then
      pass browserLoadRequest
   else
      put "Refused:" && pUrl into field "Status"
   end if
end browserLoadRequest

--------

-- This handler is invoked by our Back/Forward/Stop/Refresh buttons
-- we just pass the request onto the control.
command doAction pAction
   if the environment is not "mobile" then
      exit doAction
   end if
   if the platform is "android" then
  mobileControlDo sBrowserId, pAction
      else
         iphoneControlDo sBrowserId, pAction
         end if
end doAction

-- This handler is invoked when the url field is closed after editing.
-- It causes a new url to be requested
command goUrl pUrl
   if the environment is not "mobile" then
      exit goUrl
   end if
   if the platform is "android" then
       mobileControlSet sBrowserId, "url", pUrl
      else
         iphoneControlSet sBrowserId, "url", pUrl
         end if
end goUrl
Seems like it should work....

Thanks

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: mobilecontrolcreate browser

Post by cusingerBUSCw5N » Sun Dec 30, 2012 3:41 pm

OK. I was stupid. The example I was following didn't click Internet on the Standalone settings - so once that was clicked, it works fine.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: mobilecontrolcreate browser

Post by Simon » Sun Dec 30, 2012 9:37 pm

Ok cusinger,
Can you tell me if iphoneControlCreate is still needed? Doesn't mobileControlCreate work for both iOS and Android? (along with all the other iphoneControls...)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: mobilecontrolcreate browser

Post by cusingerBUSCw5N » Mon Dec 31, 2012 6:46 am

I will check. I just got it working on the android...

Post Reply