Android Question Changing Alpha on a large number of StatelistDrawable buttons.

Gary Miyakawa

Active Member
Licensed User
Longtime User
I've got a program (physical remote control replacement) that uses a lot of buttons (50+). I setup the buttons as Alpha of 0 (Transparent) when I distribute the app but during development, I change the buttons to Alpha of 100 to allow me to see their positioning on the background.

What I'm trying to find is a way to change all the buttons at one time. Currently, they are separate button objects but I can certainly recode it as a button array. What I can't figure out, is how to then change the Alpha programitically.

Any help would be greatly appreciated.

Gary M
 

Gary Miyakawa

Active Member
Licensed User
Longtime User
For those of you that might be in the same situation I was in, here is what I ended up doing..

I changed from "button" object to small Panel objects... I built an array of panel objects and pointed them to a common "click" processing routing. In the panel object, I defined the panel number in the tag field and then interprete it in the "click" routine so I only have one click routine.

Now, to blink the button (which is clear (alpha 0) to start with), I've defined a couple of colordrawable values... One pressed, one unpressed. Then, in the click routine, I change the panel from Alpha 0 to Alpha 255, then wait for 25ms and change it back to Alpha 0. I know it's a bit more work, but it made my routine totally soft.

Hopefully, this will help someone else down the road....

Cheers,

Gary M

B4X:
Sub Globals
    Dim a(500) As Panel
    Dim swork As String
    Dim myclick As esClickSound
    Dim vibrate As PhoneVibrate
    Dim cd_unpressed As ColorDrawable
    Dim cd_pressed As ColorDrawable
 
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("p")
    cd_pressed.Initialize( Colors.ARGB(255, 50, 50, 250), 50dip)
    cd_unpressed.Initialize( Colors.ARGB(30, 50, 50, 250), 25dip)
    myclick.Initialize    'just a clicker routine I found
    Dim i As Int = 0
  
    For k = 0 To 25
      
        For j = 0 To 18
            swork = i                        'button identifier (array number)
      
            a(i).Initialize("buttons")        ' Where to go when clicked
            Activity.AddView(a(i),j * 41dip, k * 41dip, 40dip, 40dip) ' create view at left, top, width, height
            a(i).Tag = swork & "    ;"      ' add a delimier to make finding the cell number easier in the tag
            a(i).Background = cd_unpressed    ' set unpressed color/alpha
            i = i + 1
        Next
      
    Next
    DoEvents                      
End Sub
Sub buttons_click
    Dim p As Panel
    Dim t As String
    Dim nwork As Int
    p = Sender
    t = p.Tag
    nwork = t.SubString2(0,3)
    a(nwork).Background = cd_pressed        ' show pressed
    DoEvents                                ' make sure it shows up
    vibrate.vibrate(25)                        ' make buzz
    myclick.standardfx(1)                    ' make noise
    Sleep(20)                                ' give a little time for things to settle on the screen
    a(nwork).Background = cd_unpressed        ' now, put it back to unpressed state
    Log("hit " & nwork)
End Sub
 
Upvote 0

Gary Miyakawa

Active Member
Licensed User
Longtime User
btw, in a bit more testing... I found that using panel click is an UP trigger... if you need a down trigger, change panel to button and use the down event...
 
Upvote 0

Gary Miyakawa

Active Member
Licensed User
Longtime User
Klaus,

Thank you! I did test panel touch event, for some reason, the "Tag" value was not getting set... So I moved it to Button Down event (and adjusted everything else)..

I did find out, if you put 6000 buttons on a single panel, on the Samsung Tab 2 10.1 tablet, the response is a bit slow (maybe 750 to 1000 ms to process the button blink)...

Cheers,

Gary M
 
Upvote 0
Top