ScrollView trouble

madru

Active Member
Licensed User
Longtime User
Hi,

me again ;)


I use a ScrollView where I can move a cursor in x,y direction and select the position to receive UDP video. Moving the cursor works always before the VideoView was called, after that the UP & DOWN Keyboard events are not consumed anymore (Activity_KeyPress) LEFT & RIGHT are still OK.

any ideas ?

THX

B4X:
 Sub Process_Globals
 
 End Sub
 
Sub Globals
    Dim vv As VideoView
   Dim sv As ScrollView
   Dim panels(9, 50) As Panel
   Dim Buttons(9,50) As Button
   Dim back As Bitmap
   Dim CurrentX As Int
   Dim CurrentY As Int
   Dim normalTransparent As ColorDrawable
   Dim button_bg As BitmapDrawable
   Dim Ph As Phone
   Dim size As Int:size = 100
   Dim ScreenFour As String:   ScreenFour       = "echo  2 >> /sys/class/video/screen_mode"
   Dim ScreenSixt As String:   ScreenSixt       = "echo  3 >> /sys/class/video/screen_mode"
   Dim ScreenAuto As String:   ScreenAuto       = "echo  0 >> /sys/class/video/screen_mode"
   Dim play As Boolean ' dummy will go away
End Sub


Sub Activity_Create(FirstTime As Boolean)
play=False

back.Initialize(File.DirAssets,"Ara_bg.jpg")
Activity.SetBackgroundImage(back)

sv.Initialize(2000dip)
Activity.AddView(sv, 165,190, 900, 440)

normalTransparent.Initialize(Colors.ARGB(0,255,246,241), 0)

Dim bmp As Bitmap
   
   For x = 0 To 8
      For y = 0 To 14
      bmp = LoadBitmap(File.DirAssets,Rnd(0,47)&".jpg")
         Dim iv As Button
         Dim p As Panel
         iv.Initialize("Button")
         iv.SetBackgroundImage(bmp)
         iv.Gravity = Gravity.FILL
         iv.Tag=((y*8)+ x + 1)
         'iv.Text= ran
         p.Initialize("PanelEvent")
         sv.Panel.AddView(p, x * 100, y * 100, 100-10dip, 100-10dip)
         'p.Color = Colors.aRGB(0,248,246,241)
         p.AddView(iv, 5dip, 5dip, 100 - 20dip, 100 -20dip)
         panels(x, y) = p
         Buttons(x,y)=iv
      Next
   Next
   

ChangeSelection(0,0)
SetScreensize(ScreenSixt)
End Sub

Sub SetScreensize(ScreenSize As String)
   Dim Command, Runner As String
   Dim StdOut, StdErr As StringBuilder
   Dim Result As Int
   Dim Ph As Phone
   StdOut.Initialize
   StdErr.Initialize
   Runner = File.Combine(File.DirInternalCache, "runner")
   Command = File.Combine(File.DirInternalCache, "command")
   File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
   File.WriteString(File.DirInternalCache, "command", ScreenSize & CRLF & "exit") 
   Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
End Sub


Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
      Dim x, y,x1 As Int

   x = CurrentX
   y = CurrentY
   Select KeyCode
      Case KeyCodes.KEYCODE_DPAD_LEFT
         x = x - 1
      Case KeyCodes.KEYCODE_DPAD_RIGHT
         x = x + 1
      Case KeyCodes.KEYCODE_DPAD_DOWN
         'x = x + 1
         y = Min(y + 1, 50)
      Case KeyCodes.KEYCODE_DPAD_UP
         'x = x - 1
         y = Max(y - 1, 0)
      Case KeyCodes.KEYCODE_DPAD_CENTER
            SelectChannel(x,y)
      Case KeyCodes.KEYCODE_BACK
         'If vv.IsInitialized Then
         '   vv.Stop
          '   vv.RemoveView
         '   play=False
            'ChangeSelection(0,0)
            Return True
         'End If
      
      Case  111 ' Test only
      vv.Stop
      vv.RemoveView
      sv.ScrollPosition =0
   End Select
   
   
   Log ("my keycode " &KeyCode)
   
   If x < 0 Then
      x = 8
      y = y - 1
      If y < 0 Then
         y=0
      End If
   Else If x > 8  Then
      x = 0
      If y < 14 Then
      y = y + 1
      End If
   Else If y > 14 Then
       y=14
   End If
   
   'If play=False Then
      If x >= 0 AND x <= 8 Then ChangeSelection(x, y)
   'End If
End Sub

Sub ChangeSelection(x As Int, y As Int)
   panels(CurrentX, CurrentY).Color = Colors.aRGB(0,248,246,241)
   CurrentX = x
   CurrentY = y
   panels(CurrentX, CurrentY).Color = Colors.RGB(255,0,0)'Colors.red
'   label_Channel.Text=Buttons(CurrentX, CurrentY).Tag & " - "& ChName(Buttons(CurrentX, CurrentY).Tag-1)' .text & " - "&ran ' Fake Update Channel name 
   'check If need To scroll
   If (y + 1) * size > sv.ScrollPosition + sv.Height Then
      sv.ScrollPosition = sv.ScrollPosition + size
   Else If (y * size) < sv.ScrollPosition Then
      sv.ScrollPosition = sv.ScrollPosition - size
   End If
End Sub
Sub SelectChannel(x As Int ,y As Int)
   Dim b As Int
   x=x+1
   If vv.IsInitialized AND vv.IsPlaying Then
      vv.RemoveView
   End If
      vv.Initialize("vv")
      Activity.AddView(vv,0,0,100%x,100%y)
      vv.MediaControllerEnabled=False
      vv.LoadVideo("http","udp://239.0.0." & x &":1234")
      vv.play
      play =True
End Sub
 

madru

Active Member
Licensed User
Longtime User
Erel,

looks like it has nothing to do with the Videoview, also here in this example after starting the 2nd activity and returning to the main activity the up/down arrow key events are not longer consumed.

where is the Activity_KeyPress for those keys are gone?
has it something to do with the mix of ScrollView, Panel & Button?
or do I have a general mistake in that code?

THX

:)

B4X:
 Sub Process_Globals
    Dim channel_x As Int ' get the index for 2nd activity
 End Sub
 
Sub Globals
   Dim sv As ScrollView
   Dim CurrentX As Int
   Dim CurrentY As Int
   Dim button_bg As BitmapDrawable
   Dim size As Int:size = 100
   Dim LastRow As Int:LastRow=14
   Dim LastColomn As Int:LastColomn=8
   Dim panels(LastColomn+1, LastRow+1) As Panel
   Dim Buttons(LastColomn+1,LastRow+1) As Button
End Sub

Sub Activity_Resume
ChangeSelection(video.newchannel,0)
End Sub

Sub Activity_Create(FirstTime As Boolean)

sv.Initialize(2000dip)
Activity.AddView(sv, 165,190, 900, 440)


Dim bmp As Bitmap
   
   For x = 0 To 8
      For y = 0 To 14
      bmp = LoadBitmap(File.DirAssets,Rnd(0,47)&".jpg")
         Dim iv As Button
         Dim p As Panel
         iv.Initialize("Button")
         iv.SetBackgroundImage(bmp)
         iv.Gravity = Gravity.FILL
         iv.Tag=((y*8)+ x + 1)
         'iv.Text= ran
         p.Initialize("PanelEvent")
         sv.Panel.AddView(p, x * 100, y * 100, 100-10dip, 100-10dip)
         'p.Color = Colors.aRGB(0,248,246,241)
         p.AddView(iv, 5dip, 5dip, 100 - 20dip, 100 -20dip)
         panels(x, y) = p
         Buttons(x,y)=iv
      Next
   Next
ChangeSelection(0,0)
End Sub


Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
      Dim x, y,x1 As Int

   x = CurrentX
   y = CurrentY
   Select KeyCode
      Case KeyCodes.KEYCODE_DPAD_LEFT
         x = x - 1
      Case KeyCodes.KEYCODE_DPAD_RIGHT
         x = x + 1
      Case KeyCodes.KEYCODE_DPAD_DOWN
         y = Min(y + 1, 50)
      Case KeyCodes.KEYCODE_DPAD_UP
         y = Max(y - 1, 0)
      Case KeyCodes.KEYCODE_ENTER ' .KEYCODE_DPAD_CENTER
      channel_x=x
      StartActivity(video)
   End Select
   
   ' find the position and set cursor accordantly 
   If x < 0 Then
      If y>0 Then
         x = LastColomn
         y = y - 1
         If y < 0 Then
            y=0
         End If
      End If
   Else If x > LastColomn  Then
      If y=LastRow Then
            x=LastColomn
         Else
            x = 0
         End If
   
         If y < LastRow Then
            y = y + 1
         End If
      Else If y > LastRow Then
         y = LastRow
      End If
   
      If x >= 0 AND x <= 8 Then ChangeSelection(x, y)
End Sub

Sub ChangeSelection(x As Int, y As Int)
   panels(CurrentX, CurrentY).Color = Colors.aRGB(0,248,246,241)
   CurrentX = x
   CurrentY = y
   panels(CurrentX, CurrentY).Color = Colors.RGB(255,0,0)'Colors.red
   'check If need To scroll
   If (y + 1) * size > sv.ScrollPosition + sv.Height Then
      sv.ScrollPosition = sv.ScrollPosition + size
   Else If (y * size) < sv.ScrollPosition Then
      sv.ScrollPosition = sv.ScrollPosition - size
   End If
End Sub
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
yes, looks like the scrollview 'eats' the event.

Is there a way that the scrollview/system ignores the key press so that I can handle those two keys ?
 
Upvote 0
Top