Android Code Snippet [B4X] [XUI] Simple Halo Animation

Discussion in 'Code Snippets' started by Erel, Jun 4, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Code to create a nice halo animation:

    halo.gif

    Code is compatible with B4A, B4J and B4i.
    Code:
    Sub CreateHaloEffect (Parent As B4XView, x As Int, y As Int, clr As Int)
       
    Dim cvs As B4XCanvas
       
    Dim p As B4XView = xui.CreatePanel("")
       
    Dim radius As Int = 150dip
       p.SetLayoutAnimated(
    000, radius * 2, radius * 2)
       cvs.Initialize(p)
       cvs.DrawCircle(cvs.TargetRect.CenterX, cvs.TargetRect.CenterY, cvs.TargetRect.Width / 
    2, clr, True0)
       
    Dim bmp As B4XBitmap = cvs.CreateBitmap
       
    For i = 1 To 5
         CreateHaloEffectHelper(Parent,bmp, x, y, clr, radius)
         Sleep(
    800)
       
    Next
    End Sub

    Sub CreateHaloEffectHelper (Parent As B4XView,bmp As B4XBitmap, x As Int, y As Int, clr As Int, radius As Int)
       
    Dim iv As ImageView
       iv.Initialize(
    "")
       
    Dim p As B4XView = iv
       p.SetBitmap(bmp)
       Parent.AddView(p, x, y, 
    00)
       
    Dim duration As Int = 3000
       p.SetLayoutAnimated(duration, x - radius, y - radius, 
    2 * radius, 2 * radius)
       p.SetVisibleAnimated(duration, 
    False)
       Sleep(duration)
       p.RemoveViewFromParent
    End Sub
    Usage example:
    Code:
    Sub Activity_Touch (Action As Int, X As Float, Y As Float)
       
    If Action = Activity.ACTION_DOWN Then
         CreateHaloEffect(
    Activity, X, Y, xui.Color_Red)
       
    End If
    End Sub
    Requires XUI library v1.25+
     
    Last edited: Oct 17, 2017
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code was updated and it is now based on XUI library. It works in B4A, B4i and B4J.
     
    Peter Simpson likes this.
  3. Mashiane

    Mashiane Expert Licensed User

  4. Almora

    Almora Active Member Licensed User

    hi..

    I created a project but did not react at all. no error code.
    XUI library v1.25+ ---->ok

    Code:
    Sub Process_Globals
       
        
    Dim xui As XUI
    End Sub

    Sub Globals
     
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
     
         
    Activity.LoadLayout("d")

    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub



    Sub CreateHaloEffect (Parent As B4XView, x As Int, y As Int, clr As Int)
        
    Dim cvs As B4XCanvas
        
    Dim p As B4XView = xui.CreatePanel("")
        
    Dim radius As Int = 150dip
        p.SetLayoutAnimated(
    000, radius * 2, radius * 2)
        cvs.Initialize(p)
        cvs.DrawCircle(cvs.TargetRect.CenterX, cvs.TargetRect.CenterY, cvs.TargetRect.Width / 
    2, clr, True0)
        
    Dim bmp As B4XBitmap = cvs.CreateBitmap
        
    For i = 1 To 5
            CreateHaloEffectHelper(Parent,bmp, x, y,  radius)
            Sleep(
    800)
        
    Next
    End Sub

    Sub CreateHaloEffectHelper (Parent As B4XView,bmp As B4XBitmap, x As Int, y As Int, radius As Int)
        
    Dim iv As ImageView
        iv.Initialize(
    "")
        
    Dim p As B4XView = iv
        p.SetBitmap(bmp)
        Parent.AddView(p, x, y, 
    00)
        
    Dim duration As Int = 3000
        p.SetLayoutAnimated(duration, x - radius, y - radius, 
    2 * radius, 2 * radius)
        p.SetVisibleAnimated(duration, 
    False)
        Sleep(duration)
        p.RemoveViewFromParent
    End Sub



    Sub Activity_Touch (Action As Int, X As Float, Y As Float)
        
    If Action = Activity.ACTION_DOWN Then
            CreateHaloEffect(
    Activity, X, Y, xui.Color_Red)
        
    End If
    End Sub
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Please upload the project.
     
  6. Almora

    Almora Active Member Licensed User

    added..
     

    Attached Files:

    • d.zip
      File size:
      10 KB
      Views:
      37
  7. Erel

    Erel Administrator Staff Member Licensed User

    Works fine here. I see red halos when I click on the activity.
     
  8. Almora

    Almora Active Member Licensed User

    I have no events. may be related to the phone I use.
    thanks..
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice