Android Question how to avoid using the doevents

LordZenzo

Well-Known Member
Licensed User
Longtime User
if I have to use more commands like that
mMano.SetLayoutAnimated (MDURATION, x, y, mMano.Width, mMano.Height)
to create a complex animation you only see the last command
if I insert a sleep (0) the animations are reduced to some flashes in the beginning positions, except the last one
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Upvote 0

LordZenzo

Well-Known Member
Licensed User
Longtime User
i don't think it belongs doevents
sleep(0) = doevents

i think your need is a animation list which not exists as feature.
sleep (0) and DoEvents are very different
sleep (0) generates a Return, DoEvents no

How about showing all the code. From the code that calls test. From the code that calls the code that calls test. etc. Test and the animations.

I'm building a library that processes a string to execute a series of commands
 
Upvote 0

LordZenzo

Well-Known Member
Licensed User
Longtime User
That is what sleep is designed to do. You need to use it in conjunction with the Wait for. If you tested @Erel's original example there was an error, you need the sleep command after the animation. Try the example in @OliverA's post (https://www.b4x.com/android/forum/threads/how-to-avoid-using-the-doevents.96649/#post-609780) and change the "Sleep(200)" to "Sleep(duration)" and see if does what you expect.

exact, the DoEvents instead was designated only to refresh the graphics, at the moment nothing does the same thing, (maybe)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
this is an example of how DoEvents' deprecation makes things much more complicated
I'm sorry to contradict you, but on the contrary this is one of the few cases in which Sleep is necessary.

Do Event with the graphics or views conflicted. So putting a DoEvent with an asynchronous animation would have created unexplained crashes.

As you know I love the DoEvent, but unfortunately in this case I would not have used it.

Also I would have chosen the Timer because more precise than the Asynchronous events, I already tried in other libraries mine. Sometimes I preferred to create animations with Timer for better movements. Often SetAnimation tend to overlap effects and cancel each other out.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Star-Dust
I always take what you say for gold
in fact now I'm trying to merge the timer with the ResumableSub
Do not overestimate me, I'm not so good. ;)

Only that I had the same problem in some of my libraries.
In this, the leftward movement was not equal to the right shift. Although it is the same animation but I was only changing to the direction. Moving to the right I used SetLayoutAnimated while left a Timer and then the animations look the same

I dealt with a problem created by System animations even with IPhone just yesterday in my XUIView library.

Use SetAnimatedLayout only if simple animations. Otherwise I use Timer, system resources with JavaObejct with Android or OBJC with IPhone.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
example
main:
B4X:
#Region  Project Attributes
    #ApplicationLabel: UI Anim Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Label1 As Label  'a label in Layout1
   
    Private Anim As Animation
    Private Timer1 As Timer
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")

    Anim.Initialize
    Anim.Clear
   
    Dim x As Int
    Dim y As Int
    Dim w As Double
    For w = 0.0 To 3600.0 Step 60.0/90.0
        x = SinD(w)*50dip
        y = CosD(w)*50dip
        Dim A As AnimObj
        A.Initialize
        A.Obj = Label1
        A.Left = 50%x + x
        A.Top = 50%y + y
        A.Width = Label1.Width
        A.Height = Label1.Height
        Anim.Add(A)
    Next

    Timer1.Initialize("Timer1",20)
    Timer1.Enabled = True

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Timer1_Tick
   
    Anim.Tick
   
End Sub

class Animation:
B4X:
Sub Class_Globals

    Type AnimObj (Obj As View,Left As Int,Top As Int,Width As Int,Height As Int)
    Dim List1 As List  
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
   
    List1.Initialize
   
End Sub

Public Sub Clear
    List1.Clear
End Sub

public Sub Add(Obj As AnimObj)
   
    List1.Add(Obj)
   
End Sub

Public Sub Tick
   
    If List1.Size = 0 Then Return
   
    Dim Obj As AnimObj
    Obj = List1.Get(0)
   
    Dim ObjUI As View
    ObjUI = Obj.Obj
    ObjUI.Left = Obj.Left
    ObjUI.Top = Obj.Top
    ObjUI.Width = Obj.Width
    ObjUI.Height = Obj.Height
    ObjUI.Invalidate
   
    List1.RemoveAt(0)
   
End Sub
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Have you watched Erels video on 'Resumable Subs'?

 
Upvote 0
Top