B4A Library GSContextMenu v1.0

Hi guys I am happy to share with you all this new cute little library GSContextMenu v1.0


This library does not need much explanation.

I have uploaded two zip:

1 - library
2 - demos
4 - thumbnails


requires Min SDK 11



B4AContextMenu
Author:
Giuseppe Salvi
Version: 1
  • GSContextMenu
    Events:
    • ItemClick (Position As Int, Title As Object)
    • ItemLongClick (Position As Int, Title As Object)
    • MenuClick
    Methods:
    • Initialize (EventName As String)
      Initialize Object
      EventName:
    • Show
      Show Context Menu.
    • ShowActionBar
      Show custom ActionBar.
    • WithBgBitmap (index As Int, bitmap As Bitmap) As ContextMenuFragment
      Sets bitmap to the background at specified index.
      index:
      bitmap:
    • WithBgColor (index As Int, color As Object) As ContextMenuFragment
      Sets the color to the background at specified index.
      index:
      color:
    • WithBgDrawable (index As Int, drawable As Drawable) As ContextMenuFragment
      Sets drawable to the background at specified index.
      index:
      dravable:
    • WithBgResource (index As Int, res As String) As ContextMenuFragment
      Sets resource to the background at specified index.
      index:
      res:
    • WithBitmap (title As String, eventName As String, bitmap As Bitmap) As ContextMenuFragment
      Add Bitmap from assets.
      text:
      bitmap:
    • WithDividerColor (color As Object) As ContextMenuFragment
      Set color to the divider.
      Example:
      ContextMenu.WithDividerColor(Colors.Red)
      or
      ContextMenu.WithDividerColor("#FF0000")
      or
      ContextMenu.WithDividerColor(Colors.ARGB(100,255,255,255))
      color:
    • WithDrawable (title As String, eventName As String, drawable As Drawable) As ContextMenuFragment
      Add Bitmap from drawable.
      text:
      bitmap:
    • WithFontFromAssets (ttf As String) As ContextMenuFragment
      Loads a font and sets it to the whole menu.
      ttf:
    • WithFontFromAssets2 (index As Int, ttf As String) As ContextMenuFragment
      Loads a font and sets the specified index
      index:
      ttf:
    • WithMenuClosableOutside (closeable As Boolean) As ContextMenuFragment
      Set option menu can be closed on touch to non-button area.
      closeable:
    • WithResource (title As String, EventName As String, res As String) As ContextMenuFragment
      Add Bitmap from resources.
      text:
      bitmap:
    • WithText (index As Int, title As String) As ContextMenuFragment
      Changes the text at the specified index.
      index:
      text:
    • WithTextColor (color As Object) As ContextMenuFragment
      Sets color to the text.
      color:
    • WithTextColor2 (index As Int, color As Object) As ContextMenuFragment
      Change color to the text at the specified index.
      index:
      color:
    • WithTextSize (size As Int) As ContextMenuFragment
      Set the default text size to the given value, interpreted as
      "scaled pixel" units.
      size:
    • WithTextSize2 (index As Int, size As Int) As ContextMenuFragment
      Changes the text size at the specified index.
      index:
      size:
    • WithTextTypeFace (ttf As Typeface) As ContextMenuFragment
      Sets the typeface in which the text should be displayed.
      ttf:
    • WithTextTypeFace2 (index As Int, ttf As Typeface) As ContextMenuFragment
      Change the typeface in which the text should be displayed at the specified index.
      index:
      ttf:
    • WithTextTypeFaceStyle (style As Int) As ContextMenuFragment
      Sets the style in which the text should be displayed.
      style:
    • WithTextTypeFaceStyle2 (index As Int, style As Int) As ContextMenuFragment
      Change the style in which the text should be displayed at the specified index.
      index:
      style:
    Properties:
    • ActionBarBackground As Bitmap [write only]
      Set background to ActionBar.
    • ActionBarLogo As Bitmap [write only]
      Set ActionBarlogo.
    • ActionBarMenuIcon As Bitmap [write only]
      Set ActionBarIcon.
    • ActionBarSubtitle As CharSequence [write only]
      Set subtitle.
    • ActionBarSubtitleColor As Object [write only]
      Set subtitle color.
    • ActionBarSubtitleSize As Object [write only]
      Set subtitle size.
      Example:
      ActionBarSubtitleSize ="10px" - "10dp" - "10dip" - "10sp"
      or
      ActionBarSubtitleSize = 10 - 10dip
    • ActionBarTitle As CharSequence [write only]
      Set title.
    • ActionBarTitleColor As Object [write only]
      Set title color.
    • ActionBarTitleSize As Object [write only]
      Set title size.
      Example:
      ActionBarTitleSize ="10px" - "10dp" - "10dip" - "10sp"
      or
      ActionBarTitleSize = 10 - 10dip
    • MenuBackgroundColor As Object [write only]
      Set alpha + color to the menu
      Example:
      MenuBackgroundColor = Colors.ARGB(50,0,0,100)
      or
      MenuBackgroundColor = "#770000AA"
    • Version As String [read only]
 

Attachments

  • B4AContextMenu_Demo.zip
    451.8 KB · Views: 386
  • B4AContextMenu_Lib.zip
    166.4 KB · Views: 410
  • with_actoobar.jpg
    305.8 KB · Views: 501
  • with_actoobar_01.jpg
    237.2 KB · Views: 510
  • with_custom_bar.jpg
    315.3 KB · Views: 507
  • with_custom_bar_01.jpg
    267.1 KB · Views: 539

lonleystar

Well-Known Member
Licensed User
Longtime User
How these three events work:

_MenuClick - is used with ActionBarMenuIcon to show the ContextMenu

Example:

Sub GSContextMenu_MenuClick
GSContextMenu.Show
End Sub

_ItemClick and _ItemLongClick - is used When adding an item to the menu

Example:

B4X:
GSContextMenu.WithBitmap("Exit","exit",LoadBitmap(File.DirAssets,"exit.png")

These two commands below the icons go in the folder res/drawable, or a personal folder.

GSContextMenu.WithDrawable("Exit","exit","exit")

GSContextMenu.WithResource("Exit","exit","exit")

Sub exit_ItemClick(Position As Int, Title As Object)
   ToastMessageShow("Clicked on position = ( "& Position & " )" & CRLF & Title,False)
End Sub

This code below needs copy and paste in the Manifest or in the folder res/values or a personal res folder.

B4X:
SetApplicationAttribute(android:theme, "@style/AppTheme")

CreateResource(values, styles.xml,

<resources>

   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
   <!-- Color used for toolbar background -->
     <item name="colorPrimary">#9933ee</item>
     <item name="colorPrimaryDark">#9933cc</item>
     <item name="colorAccent">#FFFFFF</item>
   </style>

   <style name="MenuFragmentStyle" parent="AppTheme">
     <item name="android:background">@android:color/transparent</item>
     <item name="android:colorForeground">@android:color/transparent</item>
     <item name="android:colorForegroundInverse">@android:color/transparent</item>
     <item name="android:colorBackground">@android:color/transparent</item>
     <item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
     <item name="android:windowBackground">@android:color/transparent</item>
   </style>

</resources>

)

Anyway have a look to the demo to understand how it works, that's all.

any comment will be appreciated.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…