How to handle Activity_Keypress with custom animation in b4xpage?
How is KeyPress related to custom animation?
You can always add whatever code you like to Activity_KeyPress in the main module.
Custom transitions between B4XPages
I use this code to create an animation transition (left/right or right/left) between activities: https://www.b4x.com/android/forum/threads/custom-transitions-between-activities.15065/#content Is possible to make this with B4XPages? If yes, how? Thanks in advance for any tip.www.b4x.com
Only now I understand why you wrote Activity_KeyPress. You should say "back key".
The back key is handled in B4XPage_CloseRequest: https://www.b4x.com/android/forum/t...or-managing-multiple-pages.118901/post-744867
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private LoginPage As B4XLoginPage
End Sub
Public Sub Initialize
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
LoginPage.Initialize
B4XPages.AddPage("LoginPage", LoginPage)
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Sub Button1_Click
B4XPages.ShowPageAndRemovePreviousPages("LoginPage")
LoginPage.AnimateFromRight
End Sub
Public Sub AnimateFromLeft
#if B4A
Root.Left = 100%x
Root.SetLayoutAnimated(300, 0, 0, Root.Width, Root.Height)
#End If
End Sub
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private ScrollView1 As B4XView
Private Panel1 As B4XView
Private MainPage As B4XMainPage
End Sub
'You can add more parameters here.
Public Sub Initialize As Object
Return Me
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
'load the layout to Root
Root.LoadLayout("LoginPage")
MainPage.Initialize
B4XPages.AddPage("MainPage", MainPage)
ScrollView1.ScrollViewInnerPanel.LoadLayout("LoginPage_Item")
ScrollView1.ScrollViewContentHeight = 100%y
End Sub
Sub B4XPage_CloseRequest As ResumableSub
B4XPages.ShowPageAndRemovePreviousPages("MainPage")
MainPage.AnimateFromLeft
Return True
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Public Sub AnimateFromRight
#if B4A
Root.Left = -100%x
Root.SetLayoutAnimated(300, 0, 0, Root.Width, Root.Height)
#End If
End Sub
** Activity (main) Resume **
Page with this id already exists: mainpage!
Error occurred on line: 35 (B4XMainPage)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:88)
at anywheresoftware.b4a.objects.B4XViewWrapper.setLeft(B4XViewWrapper.java:123)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.b4xloginpage._b4xpage_closerequest(b4xloginpage.java:80)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew(Debug.java:282)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug(Common.java:1050)
at b4a.example.b4xpagesmanager$ResumableSub_HandleCloseRequest.resume(b4xpagesmanager.java:811)
at b4a.example.b4xpagesmanager._handlecloserequest(b4xpagesmanager.java:781)
at b4a.example.b4xpagesmanager._activity_keypress(b4xpagesmanager.java:539)
at b4a.example.b4xpagesdelegator._activity_keypress(b4xpagesdelegator.java:63)
at b4a.example.main._activity_keypress(main.java:424)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.main$HandleKeyDelayed.runDirectly(main.java:231)
at b4a.example.main$HandleKeyDelayed.run(main.java:228)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
** Activity (main) Pause event (activity is not paused). **
Create a small project with the relevant code and upload it.
MainPage.Initialize
B4XPages.AddPage("MainPage", MainPage)
B4XPages.MainPage
'or other pages:
Dim SomeOtherPage1 As SomeOtherPage = B4XPages.GetPage("some other page id")
You should never create duplicate pages instances.
See the three pages example: [B4X] B4XPages - Cross platform and simple framework for managing multiple pages
Remove:
Correct way to access the main page:B4X:MainPage.Initialize B4XPages.AddPage("MainPage", MainPage)
B4X:B4XPages.MainPage 'or other pages: Dim SomeOtherPage1 As SomeOtherPage = B4XPages.GetPage("some other page id")