how to make status bar event?

i have one issue
i try to add EventListener to status bar
i make one “display.newRect”
size just same as status bar
and add “tap” event on it.
i just try to do same thing as Facebook.
click status bar make tableview roll to index 1

local function listUp()  
 local barrect = display.newRect(group, 0, 0, display.contentWidth,display.statusBarHeight)  
 barrect:setFillColor(102, 102, 102, 255)  
 local function listUp(event)  
 if (list) then  
 list:scrollToIndex( 1, 200 )  
 end  
end  
  
 barrect:addEventListener("touch",listUp) -- tried "tap", same situation  

it works on simulator.
but doesn’t work on device.
anybody knows how to do it ?
it’s very helpful! [import]uid: 25057 topic_id: 34798 reply_id: 334798[/import]

Hello @OwenYang,
First question is, did you mean to use a “tap” listener instead of a “touch” listener? In your code, you’ll actually get 2 touch responses because you haven’t filtered out the “began” and “ended” phases of the touch. This will result in two “scrollToIndex” calls.

Brent [import]uid: 200026 topic_id: 34798 reply_id: 138318[/import]

?Brent Sorrentino
I have tried both tap and touch.

but i wanna say is they are not working BOTH!!
i know that will result two events with touch.

fact is “scrollToIndex” never been called. [import]uid: 25057 topic_id: 34798 reply_id: 138400[/import]

Hi @OwenYang,
Can you please post more of your code? Including where you create the “list” widget, and also if you’re using Storyboard (where you declare each thing in each phase), etc.

Thanks!
Brent [import]uid: 200026 topic_id: 34798 reply_id: 138423[/import]

?Brent Sorrentino
I am using Sample
Interface->ListView1

and just add some code below(just copied)
if set “display.HiddenStatusBar”, it worked on device(iPhone)
if set “display.TranslucentStatusBar”, not worked on device(iPhone)

[code]
– main.lua
– Abstract: List View sample app

– Version: 2.0

– Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
– Copyright © 2010 Corona Labs Inc. All Rights Reserved.

– Demonstrates how to create a list view using the widget’s Table View Library.
– A list view is a collection of content organized in rows that the user
– can scroll up or down on touch. Tapping on each row can execute a
– custom function.

display.setStatusBar( display.HiddenStatusBar )

local sbheight = display.statusBarHeight

–import the widget library
local widget = require(“widget”)
widget.setTheme( “theme_ios” )

–Set the background to white
display.setDefault( “background”, 255, 255, 255 )

–Create a group to hold our widgets & images
local widgetGroup = display.newGroup()

– create a gradient for the top-half of the toolbar
local toolbarGradient = graphics.newGradient( {168, 181, 198, 255 }, {139, 157, 180, 255}, “down” )

– create toolbar to go at the top of the screen
local titleBar = widget.newTabBar{
gradient = toolbarGradient,
bottomFill = { 117, 139, 168, 255 },
height = 44,
}
titleBar.y = display.screenOriginY + titleBar.contentHeight * 0.5+sbheight

– create embossed text to go on toolbar
local titleText = display.newEmbossedText( “My List”, 0, 0, native.systemFontBold, 20 )
titleText:setReferencePoint( display.CenterReferencePoint )
titleText:setTextColor( 255 )
titleText.x = 160
titleText.y = titleBar.y

– create a shadow underneath the titlebar (for a nice touch)
local shadow = display.newImage( “shadow.png” )
shadow:setReferencePoint( display.TopLeftReferencePoint )
shadow.x, shadow.y = 0, titleBar.y + titleBar.contentHeight * 0.5
shadow.xScale = 320 / shadow.contentWidth
shadow.alpha = 0.45

–Text to show which item we selected
local itemSelected = display.newText( "You selected item ", 0, 0, native.systemFontBold, 28 )
itemSelected:setTextColor( 0 )
itemSelected.x = display.contentWidth + itemSelected.contentWidth * 0.5
itemSelected.y = display.contentCenterY
widgetGroup:insert( itemSelected )

–Forward reference for our back button
local backButton

–Create Table view
local list = widget.newTableView{
width = 320,
height = 448,
bottomPadding = 8,
maskFile = “mask-320x448.png”
}
list.y = titleBar.y + titleBar.contentHeight * 0.5

local barrect = display.newRect(widgetGroup, 0, 0, display.contentWidth,sbheight)
barrect:setFillColor(102, 102, 102, 255)
local function listUp(event)
if (list) then
list:scrollToIndex( 1, 200 )
end
end

barrect:addEventListener(“tap”,listUp)
–Insert widgets/images into a group
widgetGroup:insert( list )
widgetGroup:insert( titleBar )
widgetGroup:insert( titleText )
widgetGroup:insert( shadow )
–Handle row rendering
local function onRowRender( event )
local row = event.row
local rowGroup = event.view
local label = "List item "
local color = 0

–Create the row’s text
row.textObj = display.newRetinaText( rowGroup, label … row.index, 0, 0, native.systemFontBold, 16 )
row.textObj:setTextColor( color )
row.textObj:setReferencePoint( display.CenterLeftReferencePoint )
row.textObj.x, row.textObj.y = 20, rowGroup.contentHeight * 0.5
rowGroup:insert( row.textObj )

–Create the row’s arrow
row.arrow = display.newImage( “rowArrow.png”, false )
row.arrow.x = rowGroup.contentWidth - row.arrow.contentWidth * 2
row.arrow.y = rowGroup.contentHeight * 0.5
rowGroup:insert( row.arrow )
end

–Handle the back button release event
local function onBackRelease()
–Transition in the list, transition out the item selected text and the back button
transition.to( list, { x = 0, time = 400, transition = easing.outExpo } )
transition.to( itemSelected, { x = display.contentWidth + itemSelected.contentWidth * 0.5, time = 400, transition = easing.outExpo } )
transition.to( backButton, { x = 60, alpha = 0, time = 400, transition = easing.outQuad } )
end

–Create the back button
backButton = widget.newButton{
style = “backSmall”,
label = “Back”,
yOffset = - 3,
onRelease = onBackRelease
}
backButton.alpha = 0
backButton.x = 60
backButton.y = titleBar.y
widgetGroup:insert( backButton )
–Hande row touch events
local function onRowTouch( event )
local row = event.row
local background = event.background

if event.phase == “press” then
print( "Pressed row: " … row.index )
background:setFillColor( 0, 110, 233, 255 )

elseif event.phase == “release” or event.phase == “tap” then
–Update the item selected text
itemSelected.text = "You selected item " … row.index

–Transition out the list, transition in the item selected text and the back button
transition.to( list, { x = - list.contentWidth, time = 400, transition = easing.outExpo } )
transition.to( itemSelected, { x = display.contentCenterX, time = 400, transition = easing.outExpo } )
transition.to( backButton, { x = 40, alpha = 1, time = 400, transition = easing.outQuad } )

print( "Tapped and/or Released row: " … row.index )
background:setFillColor( 0, 110, 233, 255 )
row.reRender = true
end
end
– insert rows into list (tableView widget)
for i = 1, 20 do
list:insertRow{
height = 72,
onRender = onRowRender,
listener = onRowTouch
}
end
[/code] [import]uid: 25057 topic_id: 34798 reply_id: 138432[/import]

Hi @OwenYang,
I realize the issue, and it’s a small bug in the Corona Simulator.

On a device/phone, when you display the status bar (any setting except “Hidden”), it prevents any touch reaction in the bar’s region.

However, in the Corona Simulator, we are not copying that behavior… it still shows touch behavior occurring in the bar’s region. So, we need to fix this in the Simulator.

I have submitted a bug report for this, along with a test app showing the behavior. When I have an official bug number related to this, I’ll post it to this thread so you can track it.

In the meantime, you should probably make your “sensing bar” bigger than the status bar (or hide the status bar) if you want to receive touch events on it.

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 34798 reply_id: 138525[/import]

Hello @OwenYang,
First question is, did you mean to use a “tap” listener instead of a “touch” listener? In your code, you’ll actually get 2 touch responses because you haven’t filtered out the “began” and “ended” phases of the touch. This will result in two “scrollToIndex” calls.

Brent [import]uid: 200026 topic_id: 34798 reply_id: 138318[/import]

?Brent Sorrentino
I have tried both tap and touch.

but i wanna say is they are not working BOTH!!
i know that will result two events with touch.

fact is “scrollToIndex” never been called. [import]uid: 25057 topic_id: 34798 reply_id: 138400[/import]

Hi @OwenYang,
Can you please post more of your code? Including where you create the “list” widget, and also if you’re using Storyboard (where you declare each thing in each phase), etc.

Thanks!
Brent [import]uid: 200026 topic_id: 34798 reply_id: 138423[/import]

?Brent Sorrentino
I am using Sample
Interface->ListView1

and just add some code below(just copied)
if set “display.HiddenStatusBar”, it worked on device(iPhone)
if set “display.TranslucentStatusBar”, not worked on device(iPhone)

[code]
– main.lua
– Abstract: List View sample app

– Version: 2.0

– Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
– Copyright © 2010 Corona Labs Inc. All Rights Reserved.

– Demonstrates how to create a list view using the widget’s Table View Library.
– A list view is a collection of content organized in rows that the user
– can scroll up or down on touch. Tapping on each row can execute a
– custom function.

display.setStatusBar( display.HiddenStatusBar )

local sbheight = display.statusBarHeight

–import the widget library
local widget = require(“widget”)
widget.setTheme( “theme_ios” )

–Set the background to white
display.setDefault( “background”, 255, 255, 255 )

–Create a group to hold our widgets & images
local widgetGroup = display.newGroup()

– create a gradient for the top-half of the toolbar
local toolbarGradient = graphics.newGradient( {168, 181, 198, 255 }, {139, 157, 180, 255}, “down” )

– create toolbar to go at the top of the screen
local titleBar = widget.newTabBar{
gradient = toolbarGradient,
bottomFill = { 117, 139, 168, 255 },
height = 44,
}
titleBar.y = display.screenOriginY + titleBar.contentHeight * 0.5+sbheight

– create embossed text to go on toolbar
local titleText = display.newEmbossedText( “My List”, 0, 0, native.systemFontBold, 20 )
titleText:setReferencePoint( display.CenterReferencePoint )
titleText:setTextColor( 255 )
titleText.x = 160
titleText.y = titleBar.y

– create a shadow underneath the titlebar (for a nice touch)
local shadow = display.newImage( “shadow.png” )
shadow:setReferencePoint( display.TopLeftReferencePoint )
shadow.x, shadow.y = 0, titleBar.y + titleBar.contentHeight * 0.5
shadow.xScale = 320 / shadow.contentWidth
shadow.alpha = 0.45

–Text to show which item we selected
local itemSelected = display.newText( "You selected item ", 0, 0, native.systemFontBold, 28 )
itemSelected:setTextColor( 0 )
itemSelected.x = display.contentWidth + itemSelected.contentWidth * 0.5
itemSelected.y = display.contentCenterY
widgetGroup:insert( itemSelected )

–Forward reference for our back button
local backButton

–Create Table view
local list = widget.newTableView{
width = 320,
height = 448,
bottomPadding = 8,
maskFile = “mask-320x448.png”
}
list.y = titleBar.y + titleBar.contentHeight * 0.5

local barrect = display.newRect(widgetGroup, 0, 0, display.contentWidth,sbheight)
barrect:setFillColor(102, 102, 102, 255)
local function listUp(event)
if (list) then
list:scrollToIndex( 1, 200 )
end
end

barrect:addEventListener(“tap”,listUp)
–Insert widgets/images into a group
widgetGroup:insert( list )
widgetGroup:insert( titleBar )
widgetGroup:insert( titleText )
widgetGroup:insert( shadow )
–Handle row rendering
local function onRowRender( event )
local row = event.row
local rowGroup = event.view
local label = "List item "
local color = 0

–Create the row’s text
row.textObj = display.newRetinaText( rowGroup, label … row.index, 0, 0, native.systemFontBold, 16 )
row.textObj:setTextColor( color )
row.textObj:setReferencePoint( display.CenterLeftReferencePoint )
row.textObj.x, row.textObj.y = 20, rowGroup.contentHeight * 0.5
rowGroup:insert( row.textObj )

–Create the row’s arrow
row.arrow = display.newImage( “rowArrow.png”, false )
row.arrow.x = rowGroup.contentWidth - row.arrow.contentWidth * 2
row.arrow.y = rowGroup.contentHeight * 0.5
rowGroup:insert( row.arrow )
end

–Handle the back button release event
local function onBackRelease()
–Transition in the list, transition out the item selected text and the back button
transition.to( list, { x = 0, time = 400, transition = easing.outExpo } )
transition.to( itemSelected, { x = display.contentWidth + itemSelected.contentWidth * 0.5, time = 400, transition = easing.outExpo } )
transition.to( backButton, { x = 60, alpha = 0, time = 400, transition = easing.outQuad } )
end

–Create the back button
backButton = widget.newButton{
style = “backSmall”,
label = “Back”,
yOffset = - 3,
onRelease = onBackRelease
}
backButton.alpha = 0
backButton.x = 60
backButton.y = titleBar.y
widgetGroup:insert( backButton )
–Hande row touch events
local function onRowTouch( event )
local row = event.row
local background = event.background

if event.phase == “press” then
print( "Pressed row: " … row.index )
background:setFillColor( 0, 110, 233, 255 )

elseif event.phase == “release” or event.phase == “tap” then
–Update the item selected text
itemSelected.text = "You selected item " … row.index

–Transition out the list, transition in the item selected text and the back button
transition.to( list, { x = - list.contentWidth, time = 400, transition = easing.outExpo } )
transition.to( itemSelected, { x = display.contentCenterX, time = 400, transition = easing.outExpo } )
transition.to( backButton, { x = 40, alpha = 1, time = 400, transition = easing.outQuad } )

print( "Tapped and/or Released row: " … row.index )
background:setFillColor( 0, 110, 233, 255 )
row.reRender = true
end
end
– insert rows into list (tableView widget)
for i = 1, 20 do
list:insertRow{
height = 72,
onRender = onRowRender,
listener = onRowTouch
}
end
[/code] [import]uid: 25057 topic_id: 34798 reply_id: 138432[/import]

Hi @OwenYang,
I realize the issue, and it’s a small bug in the Corona Simulator.

On a device/phone, when you display the status bar (any setting except “Hidden”), it prevents any touch reaction in the bar’s region.

However, in the Corona Simulator, we are not copying that behavior… it still shows touch behavior occurring in the bar’s region. So, we need to fix this in the Simulator.

I have submitted a bug report for this, along with a test app showing the behavior. When I have an official bug number related to this, I’ll post it to this thread so you can track it.

In the meantime, you should probably make your “sensing bar” bigger than the status bar (or hide the status bar) if you want to receive touch events on it.

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 34798 reply_id: 138525[/import]

Brent, why are you calling this a bug in the simulator? It looks to me like a bug on the phone. Other apps like Facebook and web browsers let you tap the status bar to scroll to the top, which is the same behavior Owen and I are trying to emulate. Obviously, something in iOS let’s you still receive tap/touch events on the status bar, so I think Corona is just missing something to allow it to do the same.

Corona display objects are part of the OpenGL layer of the app which sits behind anything native.  The status bar is native and sits on top of everything.  Facebook and other apps are native built apps and are not using OpenGL.  They have access to do things like sit invisible touch areas on top of the status bar.  Corona SDK can’t do this.  If you were using Corona Enterprise, you could do this.

Why is a bug in the simulator?  Well the simulator’s status bar is letting touch events through, which is not the device behavior.

Rob

Brent, why are you calling this a bug in the simulator? It looks to me like a bug on the phone. Other apps like Facebook and web browsers let you tap the status bar to scroll to the top, which is the same behavior Owen and I are trying to emulate. Obviously, something in iOS let’s you still receive tap/touch events on the status bar, so I think Corona is just missing something to allow it to do the same.

Corona display objects are part of the OpenGL layer of the app which sits behind anything native.  The status bar is native and sits on top of everything.  Facebook and other apps are native built apps and are not using OpenGL.  They have access to do things like sit invisible touch areas on top of the status bar.  Corona SDK can’t do this.  If you were using Corona Enterprise, you could do this.

Why is a bug in the simulator?  Well the simulator’s status bar is letting touch events through, which is not the device behavior.

Rob