Android Question DrawRect

madru

Active Member
Licensed User
Longtime User
Hi,

not sure if this was ever asked or maybe answered, could not find anything in the forum.....

is there a way get a continuous fading of the color in the DrawRect method ?

B4X:
    Dim pnl As Panel
    Dim cvs As Canvas
    pnl = GetPanel(SelectedPanel)
    cvs.Initialize(pnl)
    cvs.DrawRect(SelectedRect, tool.ParseColor("#"&SelectorColor), False, imgBorder)
'color should fade from red to green back to red continuous, no idea how :(
    Activity.Invalidate2(SelectedRect)

THX
 

derez

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
Dim timer1 As Timer
End Sub

Sub Globals
Dim count As Int = 5
Dim delta As Int = 5
Dim cnvs As Canvas
Dim rect1 As Rect
Dim pnl As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
pnl.Initialize("")
Activity.AddView(pnl,20%x,20%y,20%x,20%y)
cnvs.Initialize(pnl)
rect1.Initialize(0,0,20%x,20%y)
timer1.Initialize("timer1",30)   
timer1.Enabled = True
End Sub

Sub timer1_tick
If count = 255 OR count = 0 Then delta = -delta   
count = count + delta
cnvs.DrawRect(rect1,Colors.RGB(255-count,count,0),True,1)
pnl.Invalidate2(rect1)
End Sub
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi David,

thank you for the reply, unfortunately that is not exactly what I am looking for..... properly I asked the question very weak

I am using moving cursor animation on one of the Google STB's, the attached proc gets the actual cursor position and moves than to new position. The new cursor position will be surrounded by a rectangle. This rectangle should 'pulse' all the time.
I guess I need to use the animation class but I have no idea how I can 'animate' the canvas

B4X:
Sub SelectPanel(Index As Int)
    Dim pnl As Panel
    Dim cvs As Canvas

    CH_NameLabel.Text = titles.Get(Index)
   
    pnl = GetPanel(SelectedPanel)
    cvs.Initialize(pnl)
   
    cvs.DrawRect(SelectedRect, Colors.Transparent, False, imgBorder)

    Activity.Invalidate2(SelectedRect)

    SelectedPanel = Index
       

    pnl = GetPanel(SelectedPanel)
    cvs.Initialize(pnl)
    cvs.DrawRect(SelectedRect, tool.ParseColor("#"&SelectorColor), False, imgBorder)
    Activity.Invalidate2(SelectedRect)

   
   
    If scvTest.ScrollPosition <= (Row - NbVisibleRows + 1) * RowHeight Then
        scvTest.ScrollPosition = (Row - NbVisibleRows + 1) * RowHeight+RowHeight
    End If
   
    If scvTest.ScrollPosition >= Row * RowHeight Then
        scvTest.ScrollPosition = Row * RowHeight
    End If
    edtTest.RequestFocus

End Sub

THX :)
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Not knowing the exact details of your work, I think best way to handle it is to define a small panel or imageview which will hold the cursor and the frame around it. This view can be animated with any of the animations in the library, including fading, then changing color, un-fading etc.
 
Upvote 0
Top