B4A Library dgActionBar - yet another ActionBar

Hi all,

I'm proud to publish dgActionBar, a very flexible action bar.

Do we really need another AB? Well, considering what's already available maybe not. But I needed a way to integrate my dgPickers lib with an action bar, so I folded my sleeves and went to work.

I liked vey much NJDude's Compact ActionBar, so that was my starting point (I even borrowed some graphics stuff from it with its author permission).

Anyway, here we are. Let's highlight a few dgActionBar's characteristics:
  • horizontal or vertical orientation
  • place it anywhere on its owner panel (not necessarily on the edges)
  • static or auto-hide (relative to end user item selection)
  • owner panel partially or entirely filled (edge to edge) by action bar
  • gradient or image background
  • logo panel, icons panel and menu button on action bar. Each one is optional.
  • Enable/Disable each icon showing optional alternating bimaps
And now for the files attached to this post:
  • dgActionBar_110 - version 1.10 of the lib (see post #22 for details)
  • dgActionBar_104 - version 1.04 of the lib
  • dgActionBar_100 - version 1.00 of the lib
  • dgActionBar_Ex1 - a simple bar on an Activity
  • dgActionBar_Ex2 - two indipendent bars on two adjacent panels
  • dgActionBar_Ex3 - dgActionBar and dgPickers working together
Well, it started as a very simple and focused project..but adding flexibility here and there it grew more complex and, I hope, useful to most. Enjoy it!

Umberto
 

Attachments

  • dgActionBar_100.zip
    10.7 KB · Views: 477
  • dgActionBar_Ex1.zip
    48.8 KB · Views: 582
  • dgActionBar_Ex2.zip
    44 KB · Views: 511
  • dgActionBar_Ex3.zip
    48.9 KB · Views: 627
  • dgActionBar_104.zip
    10.9 KB · Views: 512
  • dgActionBar_110.zip
    11 KB · Views: 289
Last edited:

udg

Expert
Licensed User
Longtime User
Thanks to Martin Pearmans' great work I can easily publish here, in a highly readable form, the lib structure:

dgActionBar
Author:
UDG
Version: 1.00
  • cl_dgactbar
    Fields:
    • bar_autohide As Byte
    • bar_fill As Byte
    • bar_horizontal As Byte
    • bar_menubottom As Byte
    • bar_menuleft As Byte
    • bar_menuright As Byte
    • bar_menutop As Byte
    • bar_nofill As Byte
    • bar_static As Byte
    • bar_vertical As Byte
    Methods:
    • IsInitialized As Boolean
      Tests whether the object has been initialized.
    • addmenuitem (aItemBitmap As BitmapWrapper, aItemText As String, aItemVal As Int) As String
      Adds an Item to the Menu panel
      aItemBitMap - bitmap for the item. Optional
      aItemText - item text to show
      aItemVal - value to return (in its negative form) when Item is clicked
    • bariconenable (aIndex As Int, Status As Boolean, aIcon As BitmapWrapper) As String
      Change an icon bar's state, alternating between enabled and disabled
      aIndex - icon index as passed in the array used for setBitmapArray()
      Status - TRUE = enable; False = disable
      aIcon - optional parameter used to change icon image depending on its status
    • class_globals As String
      Version: 1.00
      Aurthor: UDG
      Last Modified: 27.04.2014
      Location: Di Gioia Consulting - Lugano (CH)
    • destroy As String
      Remove all views from the ActionBar and sets the latter to Null
    • getanchorview As ConcreteViewWrapper
      Return the View (panel) containing the selected item.
      Used as AnchorView for dgPickers library objects
    • getitemvalue As Int
      Returns the selected item value
      0 = Logo panel selected
      1..x = positive value refers to corresponding icon item
      -1..-x = negative vale refers to corresponding menu item (in absolute terms, so -5 refers to fifth menu item)
    • hidestaticbar As String
      Hides an ActionBar previously showed in bar_Static mode
    • initialize (OwnerPanel As PanelWrapper, CallbackModule As Object, EventName As String) As String
      Initializes the object.
      OwnerPanel - Panel (or Activity) object whose layout will be superimposed by ActionBar
      CallbackModule - the module containing the callback function
      EventName - name prefix to callback function
    • isvalueready As Boolean
      Returns True if user selected an ActionBar item OR a Menu item
    • setappearance (aBarType As Byte, aBarFillMode As Byte, StartColor As Int, StopColor As Int, aBkgImage As BitmapWrapper) As String
      Sets appearance properties of an already initialized ActionBar
      aBarType - ActionBar's spatial orientation (bar_Horizontal, bar_Vertical)
      aBarFillMode - ActionBar fully extends to OwnerPanel's edge (bar_Fill) or depends on items number (bar_NoFill)
      StartColor - ActionBar's background color (start color for gradient)
      StopColor - ActionBar's background color (stop color for gradient)
      aBkgImage - ActionBar's background image
    • setbitmaparray (aBMArray() As BitmapWrapper, aSpan As Int) As String
      Init internal array to manage an array of Bitmaps
      aBMArray - an array containing Bitmaps
      aSpan - span between icons measured in dip
    • setlogo (aLogo As BitmapWrapper) As String
      Sets logo for the optional logo panel on ActionBar
    • setmenu (MenuPos As Byte, MenuWidth As Int, MenuHeight As Int, aMenuBackground As BitmapWrapper, aMenuColor As Int, aItemsTextColor As Int) As String
      Initialize a Menu panel
      MenuPos - menu position relative to ActionBar (see constants bar_MenuTop..)
      MenuWidth,MenuHeight - menu horizontal and vertical dimensions, respectively
      aMenuBackground - bitmap for menu background. Optional
      aMenuColor - color for Menu background
      aItemsTextColor - color for menu items text
    • setmenulogo (aLogo As BitmapWrapper) As String
      Sets logo for optional menu panel on ActionBar
    • setverbose (VerboseMode As Boolean) As String
      Sets verbosity of library logs
    • showactionbar (aBarLeft As Int, aBarTop As Int, aBarMode As Byte, ShowLogo As Boolean, aShowIcons As Boolean, aShowMenu As Boolean) As String
      Superimposes an ActionBar on its OwnerPanel.
      aBarLeft - ActionBar's left position (in dip units) relative to its OwnerPanel
      aBarTop - ActionBar's top position (in dip units) relative to its OwnerPanel
      aBarMode - bar_Static, the ActionBar stays visible after any user choice; bar_AutoHide, the AB is automatically hidden
      aShowLogo - True shows logo panel on ActionBar; False hides it
      aShowIcons - True shows icons panel on ActionBar; False hides it
      aShowMenu - True shows menu panel on ActionBar; False hides it
    Properties:
    • anchorview As ConcreteViewWrapper [read only]
      Return the View (panel) containing the selected item.
      Used as AnchorView for dgPickers library objects
    • itemvalue As Int [read only]
      Returns the selected item value
      0 = Logo panel selected
      1..x = positive value refers to corresponding icon item
      -1..-x = negative vale refers to corresponding menu item (in absolute terms, so -5 refers to fifth menu item)
    • logo As Void
      Sets logo for the optional logo panel on ActionBar
    • menulogo As Void
      Sets logo for optional menu panel on ActionBar
    • verbose As Void
      Sets verbosity of library logs
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi all,

today I thoroughly read the Android Developers' section about the element called Action Bar and found it is a very different beast then my dgActionBar!
"The action bar is the most important structural element of an Android app. It provides consistent navigation across the platform and allows your app to surface actions."

As of today, dgActionBar is more of a command bar then a fully functional AB.
My lib expands the concept of a highly customizable bar made up of clickable elements (in the form of an undertemined number of action icons, a logo and a menu), where the programmer links the desidered action/command to each element.

Will dgActionBar evolve to a complete and standard AB? Honestly, I don't know. But that sounds like re-inventing the wheel..

Umberto
 

udg

Expert
Licensed User
Longtime User
Hi all,

please find dgActionBar version 1.04 attached to post#1 above.

This version is needed to solve two flaws that surfaced recently.

Flaw #1: faulty AnchorView
As you may know, this element is used in conjunction with my lib dgPickers to show a specialized picker panel along the selected icon on the Action Bar.
A bug caused an error on the last icon and, anyway, the placement of the AnchorView wasn't correctly calculated.

Flaw #2: Touch event returned coordinates
Only recently I found that the value returned by the Touch event is a whole on some devices and a decimal on others. More, on some devices it returns as a whole if the device is linked by an USB cable and decimal otherwise.
That, along with my initial decision to consider an icon clicked only when down and up values exactly matched led to cases where the Action Bar looked like not responding to gestures on those devices returning decimal values.
Now the "click" is triggered when the difference between DOWN coordinates and UP ones stays in the dimension boundaries of the icon tile.

Sorry for any inconvenience the above may have caused to your projects so far.

Umberto
 

MhdBoy

Member
Licensed User
Longtime User
is any image from sample?
my emulator doesn't work
i need an image from sample
tnx
 

udg

Expert
Licensed User
Longtime User
Hi Mhdboy,
unfortunately for a couple of days more I'll be away from my PC , but as soon as I'll be back home I'll post a demo image.
In the mean time you may want to check NJdude Compact ActionBar since my work was strongly inspired by that.

Edit: please find attached a sample image taken as a screenshot on my tablet
 

Attachments

  • Screenshot_2014-12-27-10-59-32.png
    Screenshot_2014-12-27-10-59-32.png
    103 KB · Views: 845
Last edited:

udg

Expert
Licensed User
Longtime User
Hi stanks,

since I didn't receive any feedback on it, I guessed that those using it were happy enough with current version.
Did you find any valuable feature missing? Any suggestion is welcomed.

Umberto
 

stanks

Active Member
Licensed User
Longtime User
so here is the feedback :)
what i don't like with all actuion bars here is that when you tap on item you don't know which item you tapped (yes you can note user in activity title, but what if i don't have activity title and i put your bar in place of activity title?). read -> tapped action bar item's background should be changed and for example in your example to yellow (?!), so users knows which option they choose! next change of item's background is when user choose another action bar item, and previous one's background is set to default (disabled/unchoosen/whatever)

thanks
 

udg

Expert
Licensed User
Longtime User
Hi stanks,

I see your point. I don't know about others' AB, so speaking just for dgActionBar I presumably missed the "selection indication" point because I thought of AB commands as immediate action commands more than selection among options. Let me have a look at the code to understand how easy could be to introduce the visual aid you signaled.
Thank you for your feedback.
 

stanks

Active Member
Licensed User
Longtime User
"...as immediate action commands..." but which action user choose in that "forest" of (5 or more...your example have a lot icons/actions as some other app can have) action items?
 

udg

Expert
Licensed User
Longtime User
Hi stanks,
maybe this time I better understood your request.

Let's use my Example 1 code as a quick reference. In it I define 15 items besides a Logo and a menu (sporting 10 items).
The AB is initialized naming its events "Manager", so we have the following code activated when the user clicks on any of the mentioned elements (logo, icon items, menu items):

B4X:
Sub Manager_Done
  If ActionBar.IsValueReady Then
    'Returned values:
     ' 0 = logo menu was clicked
     ' positive number, 1 to number of icons = corresponding icon was clicked
     ' negative number, -1 to -1*number of menu items = corresponding menu item was clicked (in absolute form)
     Select True
      Case ActionBar.ItemValue = 0
        ToastMessageShow("Value = 0; Logo selected", False)
       Case ActionBar.ItemValue > 0
      ToastMessageShow("Value = " & ActionBar.ItemValue&"; Icon item selected", False)
       Case ActionBar.ItemValue < 0
      ToastMessageShow("Value = " & ActionBar.ItemValue&"; Menu item selected", False)
     End Select  
    Log("Manager done ok")
  End If
End Sub
So just look for a positive integer to know which of the 15 icon items was tapped on. In my example code there's a ToastMessage, but in actual code you will use a more elaborate Select-Case statement to call appropriate subs each relating to a clickable item on the AB.

Anyway, a visual indication (alternating between pressed/not pressed icon for example) for the tapped icon could be an useful addition.

udg
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi WTD,

I'm not sure I understood your needs.
To have the dgActionBar taller (or wider, depending if it's horizontal or vertical) you can load a larger image for the menu "three-dots" as with
ActionBar.MenuLogo = LoadBitmap(File.DirAssets,"actionbarmenubutton.png") <-- use a larger png image, any image not necessarily the traditiona 3-dots
In general, the dgActionBar will auto-size based on its elements (accomodating for the largest among logo, icons and menu image).

As I understand it, you don't need:
ActionBar.setBitmapArray(mIcons,60)
since you only want a menu "symbol" to be hosted on the bar.

ActionBar.SetMenu(ActionBar.bar_MenuBottom, 90%x, 90%y, LoadBitmap(File.DirAssets,"bkggreen.png"), Colors.DarkGray, Colors.White)
I'm not sure about those 90% xy measures because they are used as relative to the containing Activity/Panel not the screen

Finally, this is wrong due to your expectations:
ActionBar.ShowActionBar(92%X, 2%y, ActionBar.bar_Static, True, True, True)
'Superimposes an ActionBar on its OwnerPanel.
'aBarLeft - ActionBar's left position (in dip units) relative to its OwnerPanel
'aBarTop - ActionBar's top position (in dip units) relative to its OwnerPanel
It should be something like:
ActionBar.ShowActionBar(Activity.width*0.92dip, Activity.height*0.02dip, ActionBar.bar_Static, False, False, True)
placing a very small dgAB at 92% of the width of the containing Activity, so for its height (2% of Activity global height). Having activated only the "menu" portion of the dgAB, the bar dimensions will depend entirely on it (i.e. the image you loaded initially with ActionBar.MenuLogo property).

Let me know if the above works for you or feel free to post any error / problem you encounter since it's a long time I wrote this lib and, honestly, I've to check the code to be able to reply to most questions..

udg
 

techknight

Well-Known Member
Licensed User
Longtime User
its not working.

Just tried 1.0.4 with the sample, using the later B4A 7.01 and I get this error:

java.lang.NoSuchMethodError: anywheresoftware.b4a.objects.ListViewWrapper.AddTwoLinesAndBitmap2

java.lang.NoSuchMethodError: anywheresoftware.b4a.objects.ListViewWrapper.AddTwoLinesAndBitmap2
 

udg

Expert
Licensed User
Longtime User
I am waiting for the final release of the newer B4A to upgrade my current installation, so can't check it at the moment.
The error seems to indicate that method AddTwoLinesAndBitMap2 doesn't exist anymore for a ListView object; it sounds really strange.

Please find attached version 1.05. It is the same 1.04 but compiled today with B4A 6.50.

Note: I removed version 1.05 because it didn't solve the problem signaled on posts #16 and #18.
Note2: I now published version 1.10 on post #1; that version solves the above mentioned problem.

udg
 
Last edited:

clarionero

Active Member
Licensed User
Longtime User
I am waiting for the final release of the newer B4A to upgrade my current installation, so can't check it at the moment.
The error seems to indicate that method AddTwoLinesAndBitMap2 doesn't exist anymore for a ListView object; it sounds really strange.

Please find attached version 1.05. It is the same 1.04 but compiled today with B4A 6.50.

udg

Hi. Same error here with 105 and 7.30 beta

java.lang.NoSuchMethodError: anywheresoftware.b4a.objects.ListViewWrapper.AddTwoLinesAndBitmap2

Thank you


Rubén
 

udg

Expert
Licensed User
Longtime User
Same error here with 105 and 7.30 beta

So, just recompiling with B4A6.50 didn't help.
AFAIK in a few days we will have 7.30 final and I will be able to publish 1.06 compiled against it.

udg
 

techknight

Well-Known Member
Licensed User
Longtime User
That function must not exist anymore. Might have to code around it in native java?
 

udg

Expert
Licensed User
Longtime User
Once I'll have the latest B4A installed I will surely have a look at it. Presumably on next weekend.
 
Top