OriginalPaladin
Member
Hello,
I apologize for how n00b these two questions are, but any help with them would be greatly appreciated. I'm new to B4X (B4A), but am a long time (i.e. old) programmer and VB used to be my favorite programming language.
Regarding my second question, I am trying to make this app cross-platform as much as possible. I started out creating my first form/screen/page as a B4XPages module. I have code that seems to work fine to detect user swipes and taps, but I'm using a Panel for it, that I pop up, if the user swipes up. The user can then click on a drop down box, and select a different page/form/screen and I attempt to display it. I'd like to only have the code for this Table of Contents panel in one place, but I can't seem to find a way to do that either. The code for my main (testing right now) module is below, perhaps it'll enlighten someone as to my n00bness problems here and be able to help straighten me out. Again any help is greatly appreciated!
I apologize for the messiness of the code and lack of comments. I usually start with a minimal code framework that gets everything working, and then I write the real piece with properly named variables and comments throughout, but this is completely raw right now.
pnlTouch is the panel that reads the user's input for swiping left, right, up, etc. pnlToC is the panel to bring up the Table of Contents. Conversation1_1 is a second page/form/screen that I am testing all of these concepts with:
Sub Process_Globals
Public ActionBarHomeClicked As Boolean
Private xui As XUI
Dim MOVEMENT_THRESHOLD As Int
MOVEMENT_THRESHOLD = 50dip
Public DISPLAYPAGE As String = ""
'Public MsgTst As MessageTest
End Sub
Sub Globals
Dim pnlToC As Panel
Dim pnlTouch As Panel
Dim StartX As Int
Dim StartY As Int
Dim Spinner1 As Spinner
'Public vwConversation1_1 As Conversation1_1
'Public vwToC As ToC
End Sub
Public Sub test
'xui.MsgboxAsync("In test", "Testing")
End Sub
'Sub Popup_Click
'' Dim pnlInput As Panel
' pnlToC.Initialize ("Select")
' pnlToC.Color = Colors.ARGB (150,0,0,0)
' Activity.AddView (pnlToC, 0, 0, 100%x, 100%y)
'End Sub
Sub Select_Click As Boolean
Return True
End Sub
Private Sub pnlToC_Touch (Action As Int, X As Float, Y As Float) As Boolean
Return True
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim pm As B4XPagesManager
' vwToC.Initialize
' B4XPages.AddPage("Table of Contents", vwToC)
pm.Initialize(Activity)
pnlTouch.Initialize("pnlTouch")
Activity.AddView(pnlTouch, 0, 0, 100%x, 100%y)
pnlTouch.SendToBack
End Sub
Sub pnlTouch_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
Select Action
Case Activity.ACTION_DOWN
StartX = X
StartY = Y
Case Activity.ACTION_UP
If Abs(X - StartX) > MOVEMENT_THRESHOLD And Abs(Y - StartY) < MOVEMENT_THRESHOLD Then
If X > StartX Then
Swipe("Right")
Else
Swipe("Left")
End If
Else If Abs(X - StartX) < MOVEMENT_THRESHOLD And Abs(Y - StartY) > MOVEMENT_THRESHOLD Then
If Y > StartY Then
Swipe("Down")
Else
Swipe("Up")
End If
Else
Swipe ("Click/Tap")
'Log("User just clicked/tapped")
End If
End Select
Return True
End Sub
Sub Swipe(SwipeDir As String)
'xui.MsgboxAsync(SwipeDir, "Swipe")
Select SwipeDir
Case "Left"
Case "Right"
Case "Up"
pnlTouch.Enabled=False
pnlToC.Initialize ("Select")
'pnlToC.Color = Colors.ARGB (150,0,0,0)
'pnlToC.Color=255
Activity.AddView (pnlToC, 50dip, 50dip, 75%x, 75%y)
pnlToC.LoadLayout("vwToC")
pnlToC.BringToFront
Spinner1.Add("Main Page")
Spinner1.Add("Conversation1_1")
Spinner1.Color=222
'B4XPages.ShowPageAndRemovePreviousPages("Toc")
Case "Down"
Case "Click/Tap"
'B4XPages.ClosePage(Me)
'pnlToC.RemoveView
End Select
End Sub
'Template version: B4A-1.01
#Region Delegates
Sub Activity_ActionBarHomeClick
ActionBarHomeClicked = True
B4XPages.Delegate.Activity_ActionBarHomeClick
ActionBarHomeClicked = False
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
End Sub
Sub Activity_Resume
B4XPages.Delegate.Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
B4XPages.Delegate.Activity_Pause
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub
Sub Create_Menu (Menu As Object)
B4XPages.Delegate.Create_Menu(Menu)
End Sub
#if Java
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
processBA.raiseEvent(null, "create_menu", menu);
return true;
}
#End If
#End Region
'Program code should go into B4XMainPage and other pages.
Private Sub Button1_Click
pnlToC.RemoveView
pnlTouch.Enabled=True
'xui.MsgboxAsync("Hello world!", "B4X")
End Sub
Private Sub Spinner1_ItemClick (Position As Int, Value As Object)
'xui.MsgboxAsync(Value, "Chosen")
' Dim m As B4XPagesManager
' m.Initialize(Activity)
Select Value
Case "Conversation1_1"
DISPLAYPAGE="Conversation1_1"
pnlToC.RemoveView
pnlTouch.Enabled=True
StartActivity(Conversation1_1)
' m.ClosePage(Me)
' m.ShowPage("Conversation1_1")
'B4XPages.ShowPage("Conversation1_1")
Case "Main Page"
pnlToC.RemoveView
pnlTouch.Enabled=True
' m.ClosePage(Me)
' m.ShowPage("B4XMainPage")
'B4XPages.ShowPage("B4XMainPage")
End Select
End Sub
[/CODE]
I apologize for how n00b these two questions are, but any help with them would be greatly appreciated. I'm new to B4X (B4A), but am a long time (i.e. old) programmer and VB used to be my favorite programming language.
- How on earth do you declare a truly Global variable?
- How can I create a table of contents form/screen in a multi-form app, that displays each form in order based on user swiping right to get to the next form, but he/she can swipe up to see a table of contents and select any form in the sequence that they would like to jump to?
Regarding my second question, I am trying to make this app cross-platform as much as possible. I started out creating my first form/screen/page as a B4XPages module. I have code that seems to work fine to detect user swipes and taps, but I'm using a Panel for it, that I pop up, if the user swipes up. The user can then click on a drop down box, and select a different page/form/screen and I attempt to display it. I'd like to only have the code for this Table of Contents panel in one place, but I can't seem to find a way to do that either. The code for my main (testing right now) module is below, perhaps it'll enlighten someone as to my n00bness problems here and be able to help straighten me out. Again any help is greatly appreciated!
I apologize for the messiness of the code and lack of comments. I usually start with a minimal code framework that gets everything working, and then I write the real piece with properly named variables and comments throughout, but this is completely raw right now.
pnlTouch is the panel that reads the user's input for swiping left, right, up, etc. pnlToC is the panel to bring up the Table of Contents. Conversation1_1 is a second page/form/screen that I am testing all of these concepts with:
Main:
Sub Process_Globals
Public ActionBarHomeClicked As Boolean
Private xui As XUI
Dim MOVEMENT_THRESHOLD As Int
MOVEMENT_THRESHOLD = 50dip
Public DISPLAYPAGE As String = ""
'Public MsgTst As MessageTest
End Sub
Sub Globals
Dim pnlToC As Panel
Dim pnlTouch As Panel
Dim StartX As Int
Dim StartY As Int
Dim Spinner1 As Spinner
'Public vwConversation1_1 As Conversation1_1
'Public vwToC As ToC
End Sub
Public Sub test
'xui.MsgboxAsync("In test", "Testing")
End Sub
'Sub Popup_Click
'' Dim pnlInput As Panel
' pnlToC.Initialize ("Select")
' pnlToC.Color = Colors.ARGB (150,0,0,0)
' Activity.AddView (pnlToC, 0, 0, 100%x, 100%y)
'End Sub
Sub Select_Click As Boolean
Return True
End Sub
Private Sub pnlToC_Touch (Action As Int, X As Float, Y As Float) As Boolean
Return True
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim pm As B4XPagesManager
' vwToC.Initialize
' B4XPages.AddPage("Table of Contents", vwToC)
pm.Initialize(Activity)
pnlTouch.Initialize("pnlTouch")
Activity.AddView(pnlTouch, 0, 0, 100%x, 100%y)
pnlTouch.SendToBack
End Sub
Sub pnlTouch_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
Select Action
Case Activity.ACTION_DOWN
StartX = X
StartY = Y
Case Activity.ACTION_UP
If Abs(X - StartX) > MOVEMENT_THRESHOLD And Abs(Y - StartY) < MOVEMENT_THRESHOLD Then
If X > StartX Then
Swipe("Right")
Else
Swipe("Left")
End If
Else If Abs(X - StartX) < MOVEMENT_THRESHOLD And Abs(Y - StartY) > MOVEMENT_THRESHOLD Then
If Y > StartY Then
Swipe("Down")
Else
Swipe("Up")
End If
Else
Swipe ("Click/Tap")
'Log("User just clicked/tapped")
End If
End Select
Return True
End Sub
Sub Swipe(SwipeDir As String)
'xui.MsgboxAsync(SwipeDir, "Swipe")
Select SwipeDir
Case "Left"
Case "Right"
Case "Up"
pnlTouch.Enabled=False
pnlToC.Initialize ("Select")
'pnlToC.Color = Colors.ARGB (150,0,0,0)
'pnlToC.Color=255
Activity.AddView (pnlToC, 50dip, 50dip, 75%x, 75%y)
pnlToC.LoadLayout("vwToC")
pnlToC.BringToFront
Spinner1.Add("Main Page")
Spinner1.Add("Conversation1_1")
Spinner1.Color=222
'B4XPages.ShowPageAndRemovePreviousPages("Toc")
Case "Down"
Case "Click/Tap"
'B4XPages.ClosePage(Me)
'pnlToC.RemoveView
End Select
End Sub
'Template version: B4A-1.01
#Region Delegates
Sub Activity_ActionBarHomeClick
ActionBarHomeClicked = True
B4XPages.Delegate.Activity_ActionBarHomeClick
ActionBarHomeClicked = False
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
End Sub
Sub Activity_Resume
B4XPages.Delegate.Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
B4XPages.Delegate.Activity_Pause
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub
Sub Create_Menu (Menu As Object)
B4XPages.Delegate.Create_Menu(Menu)
End Sub
#if Java
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
processBA.raiseEvent(null, "create_menu", menu);
return true;
}
#End If
#End Region
'Program code should go into B4XMainPage and other pages.
Private Sub Button1_Click
pnlToC.RemoveView
pnlTouch.Enabled=True
'xui.MsgboxAsync("Hello world!", "B4X")
End Sub
Private Sub Spinner1_ItemClick (Position As Int, Value As Object)
'xui.MsgboxAsync(Value, "Chosen")
' Dim m As B4XPagesManager
' m.Initialize(Activity)
Select Value
Case "Conversation1_1"
DISPLAYPAGE="Conversation1_1"
pnlToC.RemoveView
pnlTouch.Enabled=True
StartActivity(Conversation1_1)
' m.ClosePage(Me)
' m.ShowPage("Conversation1_1")
'B4XPages.ShowPage("Conversation1_1")
Case "Main Page"
pnlToC.RemoveView
pnlTouch.Enabled=True
' m.ClosePage(Me)
' m.ShowPage("B4XMainPage")
'B4XPages.ShowPage("B4XMainPage")
End Select
End Sub
Public ActionBarHomeClicked As Boolean
Private xui As XUI
Dim MOVEMENT_THRESHOLD As Int
MOVEMENT_THRESHOLD = 50dip
Public DISPLAYPAGE As String = ""
'Public MsgTst As MessageTest
End Sub
Sub Globals
Dim pnlToC As Panel
Dim pnlTouch As Panel
Dim StartX As Int
Dim StartY As Int
Dim Spinner1 As Spinner
'Public vwConversation1_1 As Conversation1_1
'Public vwToC As ToC
End Sub
Public Sub test
'xui.MsgboxAsync("In test", "Testing")
End Sub
'Sub Popup_Click
'' Dim pnlInput As Panel
' pnlToC.Initialize ("Select")
' pnlToC.Color = Colors.ARGB (150,0,0,0)
' Activity.AddView (pnlToC, 0, 0, 100%x, 100%y)
'End Sub
Sub Select_Click As Boolean
Return True
End Sub
Private Sub pnlToC_Touch (Action As Int, X As Float, Y As Float) As Boolean
Return True
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim pm As B4XPagesManager
' vwToC.Initialize
' B4XPages.AddPage("Table of Contents", vwToC)
pm.Initialize(Activity)
pnlTouch.Initialize("pnlTouch")
Activity.AddView(pnlTouch, 0, 0, 100%x, 100%y)
pnlTouch.SendToBack
End Sub
Sub pnlTouch_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
Select Action
Case Activity.ACTION_DOWN
StartX = X
StartY = Y
Case Activity.ACTION_UP
If Abs(X - StartX) > MOVEMENT_THRESHOLD And Abs(Y - StartY) < MOVEMENT_THRESHOLD Then
If X > StartX Then
Swipe("Right")
Else
Swipe("Left")
End If
Else If Abs(X - StartX) < MOVEMENT_THRESHOLD And Abs(Y - StartY) > MOVEMENT_THRESHOLD Then
If Y > StartY Then
Swipe("Down")
Else
Swipe("Up")
End If
Else
Swipe ("Click/Tap")
'Log("User just clicked/tapped")
End If
End Select
Return True
End Sub
Sub Swipe(SwipeDir As String)
'xui.MsgboxAsync(SwipeDir, "Swipe")
Select SwipeDir
Case "Left"
Case "Right"
Case "Up"
pnlTouch.Enabled=False
pnlToC.Initialize ("Select")
'pnlToC.Color = Colors.ARGB (150,0,0,0)
'pnlToC.Color=255
Activity.AddView (pnlToC, 50dip, 50dip, 75%x, 75%y)
pnlToC.LoadLayout("vwToC")
pnlToC.BringToFront
Spinner1.Add("Main Page")
Spinner1.Add("Conversation1_1")
Spinner1.Color=222
'B4XPages.ShowPageAndRemovePreviousPages("Toc")
Case "Down"
Case "Click/Tap"
'B4XPages.ClosePage(Me)
'pnlToC.RemoveView
End Select
End Sub
'Template version: B4A-1.01
#Region Delegates
Sub Activity_ActionBarHomeClick
ActionBarHomeClicked = True
B4XPages.Delegate.Activity_ActionBarHomeClick
ActionBarHomeClicked = False
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
End Sub
Sub Activity_Resume
B4XPages.Delegate.Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
B4XPages.Delegate.Activity_Pause
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub
Sub Create_Menu (Menu As Object)
B4XPages.Delegate.Create_Menu(Menu)
End Sub
#if Java
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
processBA.raiseEvent(null, "create_menu", menu);
return true;
}
#End If
#End Region
'Program code should go into B4XMainPage and other pages.
Private Sub Button1_Click
pnlToC.RemoveView
pnlTouch.Enabled=True
'xui.MsgboxAsync("Hello world!", "B4X")
End Sub
Private Sub Spinner1_ItemClick (Position As Int, Value As Object)
'xui.MsgboxAsync(Value, "Chosen")
' Dim m As B4XPagesManager
' m.Initialize(Activity)
Select Value
Case "Conversation1_1"
DISPLAYPAGE="Conversation1_1"
pnlToC.RemoveView
pnlTouch.Enabled=True
StartActivity(Conversation1_1)
' m.ClosePage(Me)
' m.ShowPage("Conversation1_1")
'B4XPages.ShowPage("Conversation1_1")
Case "Main Page"
pnlToC.RemoveView
pnlTouch.Enabled=True
' m.ClosePage(Me)
' m.ShowPage("B4XMainPage")
'B4XPages.ShowPage("B4XMainPage")
End Select
End Sub
[/CODE]
Last edited: