Is there a basic library reference for standard Android Icons?

BarrySumpter

Active Member
Licensed User
Longtime User
Hi all,
Super noob. Still hacking away.
I've been using a lot of msgbox to debug and have just noticed there are no icons on my msgbox.

I'm used to being able to define which icon to use in my msgbox.
http://msdn.microsoft.com/en-us/library/sfw6660x%28v=vs.85%29.aspx


Are there no built in icons in Android like vbInformation or vbQuestion ?

B4X:
Dim result As Int 
result = Msgbox2("This is the message", "This is the title", "Good", "", "Bad", LoadBitmap (File.DirAssets, "smiley.gif")) 
If result = DialogResponse.Positive Then ...
So for each and every one of my different Andoid apps I have to install my msgbox gifs in my File.DirAssets?
 
Last edited:

JonPM

Well-Known Member
Licensed User
Longtime User
See Here

and use like this:
B4X:
Dim bd As BitmapDrawable
bd = p.GetResourceDrawable(17301555)
Msgbox2("Message", "OK", "","",bd.Bitmap)

Though I think I heard somewhere that the icon that is displayed may vary, depending on the device's version of Android.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
B4X:
Dim o as Object
o = ph.GetResourceDrawable(17301746) '<- This line fails
sld.AddState(sld.State_Disabled, o)
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Continually too quick for me. LOL:sign0188:

I posted that before I read the previous post.
As I was conducting research.


So the resource is a number.

I'm hoping b4a has a lib of the numbers.

Say

Icons.lib
Dim b4aSmily as BitmapDrawable.bitmap = GetResourceDrawable(123456789)

bgs.b4a

msgbox ("see me smile", "Smily", b4aSmily)

if its not there I'd be happy to do the work.
I just need someone to point me int he right direction.
The numbers need to be cross referenced by understanble words cross referenced by the actual icon.

Something like this enumeration where we can actually see the name, the icon, and the number.
Androidâ„¢ 2.1 android.R.drawable Icon Resources


Android Drawables

Android Drawables - Status

Android Drawables - Dialogs
 
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Cool. Thanks guys.
The last two links above really suit me.
But they don't contain the numbers. grrrr

Any chance you can setup a .lib with the first kinda entry

ic_dialog_info
ic_dialog_alert

At the moment I don't fid the ic_dialog_alert as a reserved word.
So the all caps tells me that android wants ME to dim it as a static variable.

you know how a professional b4a developer would set it up
and not like a noob stubling around for weeks
and a Q&D sample app and
I'll duplicate the defintions in the .lib and fill in the rest?

Should we worry about the versions:
1.6, 2.1, 2.2, 2.3.x, 3.x, and 4.x

To be clear I will post my results here for all to share.

Unless you guys think its not practical.
Or I'm asking too much.

tia
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
My AndroidResources library allows you to get the built in Android Drawables by String name - you don't need to look up the id and use a number.

If the requested Drawable does not exist then the library method returns Null.

Martin.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Thanks martin.

I got a not found on button2

You still have to look something up.
in this case the DrawableName/StringName to type it into EditText1.


----

Can we build enumerated objects in b4a?

where:
Msgbox2("Message", "OK", "", "", b4aIcons.smily)
Msgbox2("Message", "OK", "", "", b4aIcons.info)
Msgbox2("Message", "OK", "", "", b4aIcons.alert)
Msgbox2("Message", "OK", "", "", b4aIcons.mail)
Msgbox2("Message", "OK", "", "", b4aIcons.CheckOn)

where
when I type the . in b4aIcons. (in the IDE script editor) I get a auto complete list of icon names.

psudo code

Class
b4aIcons:
enumerate b4aIcons
smily = 1234
info = 5678
or
CheckOn = "btn_check_on"
etc
end enumerate

get b4aIcons(iconRef)
...
return AndroidResources.GetAndroidIcon(iconRef)
...

end get

I'm sure in this (my) case a little knowledge is worse that a lot of knowledge.

 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
You could acheive that with code such as:

B4X:
Type b4aIconsType (smily As String, info As String, alert As String, mail As String)

Dim b4aIcons As b4aIconsType

b4aIcons.smily="whatever"

' define the other properties

I'm pretty sure there's no real enumerated objects in b4a.

Martin.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Thaks warwound

Type b4aIconsType (smily AsString, info AsString, alert AsString, mail AsString)
Dim b4aIcons As b4aIconsType
b4aIcons.smily="ic_dialog_smily"
b4aIcons.info=
"ic_dialog_info"
b4aIcons.alert=
"ic_dialog_alert"
b4aIcons.mail=
"ic_dialog_mail" '

----

then how would I use it in code?
testing now ...
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
See Here

and use like this:
B4X:
Dim bd As BitmapDrawable
bd = p.GetResourceDrawable(17301555)
Msgbox2("Message", "OK", "","",bd.Bitmap)
Though I think I heard somewhere that the icon that is displayed may vary, depending on the device's version of Android.

Yeah I thought of that.
I'm pretty sure they will keep the icons and add new ones but NOT replace them.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Thanks guys!

Ok I'm stunned.
thats the first time something I did worked without a laborious dramma.
:sign0060:

Checkout Button2 and Msgbox4


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

'Dialog Icons
Type b4aIconsType ( _
    alert As String, alertDark As String, alertLight As String, closeNormal As String, _
    closePressed As String, dialer As String, email As String, focused As String, _
    info As String, Map As String, menu As String, time As String, usb As String )
    
Dim b4aIcons As b4aIconsType

b4aIcons.alert="ic_dialog_alert"
b4aIcons.alertDark="ic_dialog_alert_holo_dark"
b4aIcons.alertLight="ic_dialog_alert_holo_light"
b4aIcons.closeNormal="ic_dialog_close_normal_holo"
b4aIcons.closePressed="ic_dialog_close_pressed_holo"
b4aIcons.dialer="ic_dialog_dialer"
b4aIcons.email="ic_dialog_email"
b4aIcons.focused="ic_dialog_focused_holo"
b4aIcons.info="ic_dialog_info"
b4aIcons.map = "ic_dialog_map"
b4aIcons.menu="ic_dialog_menu_generic"
b4aIcons.time="ic_dialog_time"
b4aIcons.usb="ic_dialog_usb"

Dim andResource As AndroidResources

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.

    Dim EditText1 As EditText
    Dim ImageView1 As ImageView
    Dim Label1 As Label

End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("Main")
    
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button2_Click
    
    msgbox4("Dialer Icon", "Title", "OK","Cancel","Retry", b4aIcons.dialer)
    
End Sub

Sub msgbox4(mbMsg As String, mbTitle As String, mbPositive As String, mbCacnel As String, mbNegative As String, Icon As String) As Int


    Dim BitmapDrawable1 As BitmapDrawable
    Dim DrawableName As String
    Dim Object1 As Object
    Dim result As Int
        
    Object1=andResource.GetAndroidDrawable(Icon)
    
    '    Object1 will now be Null or the requested Drawable
    
    If Object1=Null Then
        Log("Drawable NOT FOUND: "& Icon)
        BitmapDrawable1=Null
        ImageView1.Bitmap=Null
        
        result = Msgbox2(mbMsg, mbTitle, mbPositive, mbCacnel, mbNegative, BitmapDrawable1.Bitmap) 
        Return result
        
    Else
        BitmapDrawable1=Object1
        ImageView1.Bitmap=BitmapDrawable1.Bitmap

        result = Msgbox2(mbMsg, mbTitle, mbPositive, mbCacnel, mbNegative, BitmapDrawable1.Bitmap) 
        Return result
End If
    
    
    
End Sub


Sub Button1_Click
    
    Dim BitmapDrawable1 As BitmapDrawable
    Dim DrawableName As String
    Dim Object1 As Object
    
    Object1=andResource.GetAndroidDrawable(b4aIcons.info)
    
    '    Object1 will now be Null or the requested Drawable
    
    If Object1=Null Then
        Log("Drawable NOT FOUND: "&DrawableName)
        ImageView1.Bitmap=Null
    Else
        BitmapDrawable1=Object1
        ImageView1.Bitmap=BitmapDrawable1.Bitmap
    End If
    
End Sub
 
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
The Type is going to get pretty long
is there an easier way?

B4X:
Type b4aIconsType ( _
    alert As String, alertDark As String, alertLight As String, closeNormal As String, _
    closePressed As String, etc)

And should I be worried about how much memory this is taking?
 
Last edited:
Upvote 0

Jost aus Soest

Active Member
Licensed User
Longtime User
I dont't think that in your case memory is a limit.

An easier way?

Hmmm...

Another way would be to build a Code Module called "b4aIcons", where you declare in Process_Globals your String variables.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Some interesting links in this thread.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Much larger than expected.

Attached.


Tried to move it out to a code Module but couldn't get it to compile.
Too nooby.

If I moved that code to a code module anyone know how to script to reference as Icons.alert?

tia
 

Attachments

  • IconTypes.zip
    24.2 KB · Views: 193
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Icons as a mobule
b4aIcons.Icons.xxxx

Pleas let me know if there is a way to reference by
b4aIcons.xxxx
or
Icons.xxx

tia
 

Attachments

  • IconTypesAsModule.zip
    24.3 KB · Views: 176
Upvote 0

warwound

Expert
Licensed User
Longtime User
Blimey however long did it take you to type all that out :icon_clap: LOL!

As you've found the only way to access the Icons object in the b4aIcons code module is:

B4X:
b4aIcons.Icons.???

There's no shorthand available to shorten that - only code in the b4aIcons code module itself can you omit the b4aIcons prefix and just use:

B4X:
Icons.???

Martin.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Yeah, its over 1000 references I think.
But its the kind of dead head stuff I like to do to relax.
That and write step-by-step procedures.

Conversion:
Copy the table into NotePad which left all kinds of tabs at the end of each line.
Removed tabs n spaces etc using replace in notepad.

Copied into Word.
Used replace to replace paragrah (return) with " as string,"
for the type definition.

Then copied the notepad results into Excel.
cell a =Icons.
cell b = notepad words
cell c = (space) = (space) "
cell d = matching cell a notepad words again
cell e = "
copied excel into notepad
removed tabs and double spaces
for the string assignments

----

Or perhaps,
Is there a way to
##Include b4aIcons.script
as in:
Code Main
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

##Include b4aIcons.script

end sub
?

Otherwise thats as short as the reference can get.
 
Last edited:
Upvote 0
Top