Share My Creation New B4A 1.3 Android Icons

I was playing with the new 1.3 release and the ability to load phone icon resources, so decided to put together a simple listview/imageview combo to browse all the icon resources that can be loaded and display them.

Hope this is useful to someone.

./tim
 

Attachments

  • IconListView.zip
    325.6 KB · Views: 2,133
D

Deleted member 103

Guest
Hi timisusually,

the idea is good, better would be if you were to see the icons already in Listview.;)


Ciao,
Filippo
 

alfcen

Well-Known Member
Licensed User
Longtime User
Icons in ListView

Hi Filippo

here you are...

Some icons may not be shown in the Listview, since not all are bitmap drawables. However, if you tap on the listview the relevant icon will be shown at the top in an imageview, if it resides in the resource of your o/s.

Thanks a lot to timisusually for pioneering this time-saver :sign0098:
 

Attachments

  • AndroidIcons.zip
    318.5 KB · Views: 1,370

alfcen

Well-Known Member
Licensed User
Longtime User
Exotic Drawables

The icons are of various types of drawables, such as NinePatchDrawable, LayerDrawable, AnimationDrawable, LevelListDrawable, all of which appear to be unknown to B4A. Does anyone know more or how to deal with those?
 
D

Deleted member 103

Guest
Hi Robert,
Yes, I'm here ... :)

You can use Canvas.DrawDrawable to draw any Drawable object.
As Erel writes that it is already possible to show all icons.
I have also tried it last night.


Grüße aus Schwäbisch Gmünd
Filippo
 

alfcen

Well-Known Member
Licensed User
Longtime User
Ciao, Filippo,

Good to see you in best shape.

Yep, with a Canvas you can do that, but this won't work for the ImageViews in the ListView, if I'm not totaly mistaken. Fortunately, all common, useful icons are bitmap drawables.

Anyway, I hope the snippet is of some help.

Viele Gruesse aus Okinawa,

Roberto
 
D

Deleted member 103

Guest
Hi Roberto,

ich habe an dein Code was geändert, jetzt funktioniert alles.

I changed your code to something, now everything works.

PHP:
Sub Globals
    Dim ListView1 As ListView
   Dim ImageView1 As ImageView
   Dim Phone1 As Phone
   Dim IconList As List
   Dim i As Long
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.Title = "Andoid System Icons - Requio, Okinawa"
   ImageView1.Initialize("ImageView1")
   ImageView1.Gravity = Gravity.FILL
   IconList.Initialize
   IconList = File.ReadList(File.DirAssets,"codenames.txt")
   ListView1.Initialize("ListView1")
   Activity.AddView(ImageView1, 0, 0, 48dip, 48dip)
   Activity.AddView(ListView1, 0, 60dip, 100%x, 80%y)
   ListView1.FastScrollEnabled = True
   ListView1.TwoLinesAndBitmap.ItemHeight = 55dip
   ListView1.TwoLinesAndBitmap.Label.TextSize = 16
   ListView1.TwoLinesAndBitmap.SecondLabel.TextSize = 16
   ListView1.TwoLinesAndBitmap.SecondLabel.TextColor = Colors.RGB(255,60,0)
   ListView1.TwoLinesAndBitmap.Label.Gravity = Gravity.CENTER_VERTICAL
   ListView1.TwoLinesAndBitmap.SecondLabel.Gravity = Gravity.TOP
   ListView1.TwoLinesAndBitmap.ImageView.Width = 48dip
   ListView1.TwoLinesAndBitmap.ImageView.Height = 48dip
   ListView1.TwoLinesAndBitmap.ImageView.Gravity = Gravity.FILL
   For i = 17301504 To 17301683
      If i <> 17301679 Then 'constant value 17301679 throws an error on Sharp IS03
         'ImageView1.Background = Phone1.GetResourceDrawable(i)
         'ListView1.AddTwoLinesAndBitmap2(IconList.Get(i - 17301504),i,ImageView1.Bitmap,i)
         ListView1.AddTwoLinesAndBitmap2(IconList.Get(i - 17301504),i,getSystemIcon(i),i)
      End If
   Next
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
   ImageView1.Background = Phone1.GetResourceDrawable(Value)
End Sub

Sub getSystemIcon(intResurce As Int) As Bitmap
   Dim Icon2 As Bitmap
   Dim ph As Phone
   Dim can As Canvas 
   Dim rc As Rect 
   
   icon2.InitializeMutable(48,48)
   can.Initialize2(icon2)
   rc.Initialize (0,0,47,47)
   
   icon2.InitializeMutable(48,48)'just guessed the size for now
   can.DrawDrawable(ph.GetResourceDrawable(intResurce), rc)
   Return can.Bitmap
End Sub

Viele Grüße aus Schwäbisch Gmünd,
Filippo
 

alfcen

Well-Known Member
Licensed User
Longtime User
Ciao Filippo

Bist ganz schoen ausgefuchst! Genial!
So, it was a matter of proper conversion of the various types of drawables.

Sorry, I am pedantic when it comes to shorter source codes and speed.
I have shortened your getSystemIcon sub since it is called 175 times,
though it does not make human-noticeable difference with my phone.

Also removed a few lines from my original code, since these were default settings in the listview.

Nice team work, gang, let's keep it up!

B4X:
Sub Globals
    Dim ListView1 As ListView
    Dim ImageView1 As ImageView
    Dim Phone1 As Phone
    Dim IconList As List
    Dim i As Long
[COLOR="Red"]    Dim Icon2 As Bitmap
    Dim can As Canvas 
    Dim rc As Rect [/COLOR]   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.Title = "Android Icons - timisusually, Filippo, alfcen"
    ImageView1.Initialize("ImageView1")
    IconList.Initialize
    IconList = File.ReadList(File.DirAssets,"codenames.txt")
    ListView1.Initialize("ListView1")
    Activity.AddView(ImageView1, 0, 0, 48dip, 48dip)
    Activity.AddView(ListView1, 0, 60dip, 100%x, 80%y)
    ListView1.FastScrollEnabled = True
    ListView1.TwoLinesAndBitmap.ItemHeight = 55dip
    ListView1.TwoLinesAndBitmap.Label.TextSize = 16
    ListView1.TwoLinesAndBitmap.SecondLabel.TextSize = 16
    ListView1.TwoLinesAndBitmap.SecondLabel.TextColor = Colors.RGB(255,60,0)
    ListView1.TwoLinesAndBitmap.Label.Gravity = Gravity.CENTER_VERTICAL
    ListView1.TwoLinesAndBitmap.SecondLabel.Gravity = Gravity.TOP
    rc.Initialize (0,0,47dip,47dip)
    For i = 17301504 To 17301683[COLOR="SeaGreen"] 'constant value 17301679 throws an error on Sharp IS03[/COLOR]
        If i <> 17301679 Then ListView1.AddTwoLinesAndBitmap2(IconList.Get(i - 17301504),i,getSystemIcon(i),i)
    Next
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
    [COLOR="Red"]ImageView1.Bitmap = getSystemIcon(Value)[/COLOR]
End Sub

Sub getSystemIcon(intResource As [COLOR="Red"]Long[/COLOR]) As Bitmap
    Icon2.InitializeMutable(48[COLOR="Red"]dip[/COLOR],48[COLOR="Red"]dip[/COLOR]) [COLOR="YellowGreen"]'an educated guess[/COLOR]
    can.Initialize2(Icon2)
    can.DrawDrawable(Phone1.GetResourceDrawable(intResource), rc)
    Return can.Bitmap
End Sub
 
D

Deleted member 103

Guest
Ciao Roberto,

Bist ganz schoen ausgefuchst! Genial!
Nein, der Geniale ist Erel, ich habe nur sein Tip gefolgt.

Sorry, I am pedantic when it comes to shorter source codes and speed.
I also think so.

Ich habe diese Procedur(getSystemIcon) in meine Anwendung als Globale-Sub definiert damit man von überall ausführen kann.

I have defined the procedure(getSystemIcon) in an application as a Sub-Global so that you can run from anywhere.

Ciao,
Filippo
 
Last edited by a moderator:
Top