﻿B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=9.8
@EndOfDesignText@
'ASTabMenu
'Author: Alexander Stolte
'Version: 1.16
' %%% above indicate code changes to allow halo effect on/off

#If Documentation
ToDos:
	-BitmapCreator Effects
	-Add Badgets (with numbers, just colors)
	-Add Stretch underline animation

Updates:
V1.0
	-Release
V1.01
	-Add RemoveAt - Removes a tab by a given index
	-Add Property PartingLineVisible - shows an parting line between the tabs
		-Add get and set PartingLineColor
		-Add get and set PartingLineWidth
		-Add get and set PartingLineVisible
	-Add get and set UnderLineColor
	-Add get and set UnderLineHeight
	-Add getTabIcon -gets the icon of a given tab
	-Add setTabIcon -sets a new icon to a tab
	-Add getTabText -gets the text ov a given tab
	-Add setTabText -sets a new text to a tab
V1.02
	-Add getTabTag
	-Add setTabTag
V1.03
	-Add Property Orientation - indicates the mode in which the view is, horizontal or vertical
	-The menu can now be used vertical
	-Add Property CurrentTabUnderlineGravity - sets the underline gravity, on vertical mode = Top and Bottom and on horizontal mode = Left and Right
V1.04
	-Add getCurrentIndex - gets the current tab index
	-Add getTabBackgroundColor and setTabBackgroundColor - gets or sets the tab background color
V1.05
	-Adds a short description about a property
	-Add get and set Badge_Visible - shows or hide a badge on a tab
	-Add get and set Badge_Height - set the size of the badge
	-Add set Badge_Text - sets the badge number, set it to -1 to have only the color
	-Add get Badge_getLabel - gets the badge label, to modify it to your own
	-Add get and set Badge_Color - gets or sets a badge color
	-Add set Badge_setVisibleEasy - shows the badge with all important parameters to save lines of code
V1.06
	-Badge Bug Fixing
	-Add get and set Badge_Gravity
	-Add enums. for the Badge_Gravity
		-Badge_MIDDLERIGHT
		-Badge_MIDDLELEFT
		-Badge_TOPRIGHT
		-Badge_TOPMIDDLE
		-Badge_TOPLEFT
V1.07
	-Icon Size is now smaller
	-Badge Bug Fixing
V1.08
	-Add Commit Mode Designer Property
	-Add CommitChanges Property
V1.09
	-Add Public Variable: text_font - change the font of the text
V1.10
	-TabClick Bug Fix if withHalo = false
V1.11
	-Add TextIcon_Padding public variable - if you need more space between text and icon
V1.12
	-B4I Underline Bug Fix
V1.13
	-Add VisibleAt -Shows or Hide a tab
	-Add Support for Icons or Text mixed
	-Add TabStripMode - if true, then the underline width/height is the full tab
V1.14
	-Add ViewEnable - enable or disable the view
V1.15
	-B4A only - BugFix if the text is too long
	-B4A only - new dependency "Reflection"
	-B4I only - ViewEnable BugFix
V1.16
	-Add RemoveAllTabs
#End If
#DesignerProperty: Key: CommitMode, DisplayName: Commit Mode, FieldType: String, DefaultValue: Automatic, List: Automatic|Manually, Description: set it to automatic, to commit changes automatically. If you set it to Manually then call .CommitChanges after you make changes
#DesignerProperty: Key: Orientation, DisplayName: Orientation, FieldType: String, DefaultValue: Automatic, List: Automatic|Horizontal|Vertical , Description: use the menu vertical or horizontal. Or detect it automatically based on the length and height of the view
'Tab
#DesignerProperty: Key: TabStyle, DisplayName: Tab Style, FieldType: String, DefaultValue: Text, List: Text|Icon|TextIcon , Description: do you want to show only text or only icons or both together
#DesignerProperty: Key: TabTextColor, DisplayName: Tab Text Color, FieldType: Color, DefaultValue: 0xFF121212, Description: The color of the text and/or icon
#DesignerProperty: Key: PartingLineVisible, DisplayName: Parting Line Visible, FieldType: Boolean, DefaultValue: False

'Underline
#DesignerProperty: Key: CurrentTabUnderline, DisplayName: Current Tab Underline, FieldType: Boolean, DefaultValue: True, Description: Click on a other tab, slides the underline to this tab
#DesignerProperty: Key: CurrentTabUnderlineAnimation, DisplayName: Current Tab Underline Animation, FieldType: String, DefaultValue: Normal, List: Normal , Description: Normal: Normal slide animation to the next tab Stretch: A stretch animation to the next tab 
#DesignerProperty: Key: CurrentTabUnderlineAnimationDuration, DisplayName: Current TabUnderline Animation Duration, FieldType: Int, DefaultValue: 250, MinRange: 0, Description: The duration of the slider animation
#DesignerProperty: Key: CurrentTabUnderlineGravity, DisplayName: Current Tab Underline Gravity, FieldType: String, DefaultValue: BottomRight, List: TopLeft|BottomRight, Description: sets the underline gravity on vertical mode = Top and Bottom and on orizontal mode = Left and Right
'Stretch
'Click Colors
#DesignerProperty: Key: EnableSelectedTabTextColor, DisplayName: Enable Selected Tab Text Color, FieldType: Boolean, DefaultValue: True, Description: If True then the icon and/or text will change the color on the current tab
#DesignerProperty: Key: SelectedTabTextColor, DisplayName: Selected Tab Text Color, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: The color of the icon and/or text of the current tab
' %%%
'Halo effect
#DesignerProperty: Key: HaloEffect, DisplayName: Halo Effect, FieldType: Boolean, DefaultValue: True,  Description: If True will show Halo effect on tab click
'Background
#DesignerProperty: Key: TabClickColor, DisplayName: Page Click Color, FieldType: Color, DefaultValue: 0xFF7F8C8D, Description: The color of halo effect during page click.

#Event: TabClick(index as int)

Sub Class_Globals
	Private mEventName As String 'ignore
	Private mCallBack As Object 'ignore
	Private mBase As B4XView 'ignore
	Private xui As XUI 'ignore
	
	Private underlinewidthbyonlyicon As Int = 20dip
	Private txt_height As Float = 22dip
	Private icon_height As Float = 25dip
	Private badge_height As Float = 15dip
	Public TextIcon_Padding As Float = 1.3
	Public text_font As B4XFont
	
    Type Tabs(TabText As String,Icon As B4XBitmap,Tag As Object,Index As Int,badge_visible As Boolean,Visible As Boolean)

	'Properties
	Private CurrenIndex As Int = 0
	
	'PartingLine
	Private pl_clr As Int = xui.Color_White
	Private pl_width As Float = 2dip
	
	'Underline
	Private ul_clr As Int = xui.Color_White
	Private ul_height As Float = 2dip
	
	Private g_badge_gravity As String = "Middle_Right"
	'Designer Props
	Private g_commitmode As String
	Private g_orientation As String
	
	Private g_TabStyle As String
	Private g_TabTextColor As Int
	Private g_PartingLineVisible As Boolean
	
	Private g_CurrentTabUnderline As Boolean
	Private g_CurrentTabUnderlineAnimation As String
	Private g_CurrentTabUnderlineAnimationDuration As Int
	Private g_CurrentTabUnderlineGravity As String
	
	Private g_EnableSelectedTabTextColor As Boolean
	Private g_SelectedTabTextColor As Int
	
	' %%%
	Private g_HaloEffect as Boolean
	
	Private g_TabClickColor As Int
	
	Private g_TabStripMode As Boolean = False
	
	'Views
	Private xpnl_tabbase As B4XView
	Private xpnl_underline As B4XView
End Sub

#Region Initialize

Public Sub Initialize (Callback As Object, EventName As String)
	mEventName = EventName
	mCallBack = Callback
	text_font = xui.CreateDefaultBoldFont(15)
End Sub

'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
	mBase = Base
	ini_props(Props)
	
	xpnl_tabbase = xui.CreatePanel("")
	xpnl_underline = xui.CreatePanel("")
	
	
	mBase.AddView(xpnl_tabbase,0,0,0,0)
	mBase.AddView(xpnl_underline,0,0,0,0)
	
	#If B4A
	Base_Resize(mBase.Width,mBase.Height)
	#End If
	
End Sub

Private Sub ini_props(Props As Map)
	g_commitmode = Props.Get("CommitMode")
	g_orientation = Props.Get("Orientation")
	
	g_TabStyle = Props.Get("TabStyle")
	g_TabTextColor = xui.PaintOrColorToColor(Props.Get("TabTextColor"))
	g_PartingLineVisible = Props.Get("PartingLineVisible")
	
	g_CurrentTabUnderline = Props.Get("CurrentTabUnderline")
	g_CurrentTabUnderlineAnimation = Props.Get("CurrentTabUnderlineAnimation")
	g_CurrentTabUnderlineAnimationDuration = Props.Get("CurrentTabUnderlineAnimationDuration")
	g_CurrentTabUnderlineGravity = Props.Get("CurrentTabUnderlineGravity")
	
	g_EnableSelectedTabTextColor = Props.Get("EnableSelectedTabTextColor")
	g_SelectedTabTextColor = xui.PaintOrColorToColor(Props.Get("SelectedTabTextColor"))
	
	' %%%
	g_HaloEffect = Props.Get("HaloEffect")
	
	g_TabClickColor = xui.PaintOrColorToColor(Props.Get("TabClickColor"))

End Sub

#End Region

Private Sub Base_Resize (Width As Double, Height As Double)

	xpnl_tabbase.SetLayoutAnimated(0,0,0,Width,Height)
	
	Dim isHorizontal As Boolean = False
	If GetOrientation(g_orientation) = getOrientation_HORIZONTAL Then
		isHorizontal = True
	End If
	
	xpnl_underline.Visible = g_CurrentTabUnderline

	'count all visible items
	Dim tmp_counter As Int = 0
	Dim tmp_TextIconCenter As Boolean = False
	For i = 0 To xpnl_tabbase.NumberOfViews -1
		Dim tmp_tab As Tabs = xpnl_tabbase.GetView(i).Tag
		If tmp_tab.Visible = True Then
			tmp_counter = tmp_counter +1
		End If
		If g_TabStyle = "TextIcon" And (tmp_tab.Icon.IsInitialized = False Or tmp_tab.TabText = "") Then
			tmp_TextIconCenter = True
		End If
	Next
	'Log(tmp_counter)
	'Log(xpnl_tabbase.NumberOfViews)
	Dim tmp_index As Int = -1
	For i = 0 To xpnl_tabbase.NumberOfViews -1
		Dim xpnl_base As B4XView = xpnl_tabbase.GetView(i)
		
		Dim tmp_tab As Tabs = xpnl_base.Tag
		Dim xlbl_text As B4XView = xpnl_base.GetView(0)
		Dim ximg_icon As B4XView = xpnl_base.GetView(1)
		
		If tmp_tab.Visible = True Then
			tmp_index = tmp_index +1
			If isHorizontal = True Then
'			xpnl_base.SetLayoutAnimated(0,(xpnl_tabbase.Width/xpnl_tabbase.NumberOfViews) * (tmp_tab.index),0,xpnl_tabbase.Width/xpnl_tabbase.NumberOfViews,xpnl_tabbase.Height)'quick maths :P
				xpnl_base.SetLayoutAnimated(0,(xpnl_tabbase.Width/tmp_counter) * tmp_index,0,xpnl_tabbase.Width/tmp_counter,xpnl_tabbase.Height)
			Else
				'xpnl_base.SetLayoutAnimated(0,0,(xpnl_tabbase.Height/xpnl_tabbase.NumberOfViews) * (tmp_tab.index),xpnl_tabbase.Width,xpnl_tabbase.Height/xpnl_tabbase.NumberOfViews)
				xpnl_base.SetLayoutAnimated(0,0,(xpnl_tabbase.Height/tmp_counter) * tmp_index,xpnl_tabbase.Width,xpnl_tabbase.Height/tmp_counter)
			End If
		Else
			xpnl_base.Width = 0
		End If
		
		mBase.GetView(tmp_tab.index + 2).Visible = g_PartingLineVisible
		If g_PartingLineVisible = True  Then
			Dim xpnl_partingline As B4XView = mBase.GetView(tmp_tab.index + 2)
			
			If isHorizontal = True Then
				xpnl_partingline.SetLayoutAnimated(0,xpnl_base.Left + xpnl_base.Width - pl_width/2,xpnl_base.Height/2 - xpnl_base.Height/4,pl_width,xpnl_base.Height/2)
			Else
				xpnl_partingline.SetLayoutAnimated(0,xpnl_base.Width/2 - xpnl_base.Width/4,xpnl_base.Top + xpnl_base.Height - pl_width/2,xpnl_base.Width/2,pl_width)
			End If
				
			xpnl_partingline.SetColorAndBorder(pl_clr,0,0,xpnl_partingline.Height/2)
			If tmp_tab.index = xpnl_tabbase.NumberOfViews -1 Then
				xpnl_partingline.Visible = False
			End If
		End If
		
		Dim xlbl_badge As B4XView = xpnl_base.GetView(2)
		xlbl_badge.Visible = tmp_tab.badge_visible
		
		If g_TabStyle = "Text" Then 'only Text
						
			xlbl_text.Visible = True
			ximg_icon.Visible = False
			
			xlbl_text.Text = tmp_tab.TabText
			xlbl_text.SetTextAlignment("CENTER","CENTER")
			If CurrenIndex = tmp_tab.index Then
				xlbl_text.TextColor = g_SelectedTabTextColor
			Else
				xlbl_text.TextColor = g_TabTextColor
			End If
			
			xlbl_text.Font = text_font
			
			xlbl_text.SetLayoutAnimated(0,0,xpnl_base.Height/2 - txt_height/2,xpnl_base.Width,txt_height)
			
			
			If tmp_tab.badge_visible = True Then
				If g_CurrentTabUnderlineGravity = getCurrentTabUnderlineGravity_TOPLEFT And GetOrientation(g_orientation) = getOrientation_HORIZONTAL Then
					xlbl_badge.SetLayoutAnimated(0,xlbl_text.Width/2 - badge_height/2,xlbl_text.Top + xlbl_text.Height,badge_height,badge_height)
				Else
					xlbl_badge.SetLayoutAnimated(0,xlbl_text.Width/2 - badge_height/2,xlbl_text.Top - badge_height,badge_height,badge_height)
				End If
			End If
			
		Else If g_TabStyle = "Icon" Then 'only Icon
				
			xlbl_text.Visible = False
			ximg_icon.Visible = True
			
			ximg_icon.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/2,xpnl_base.Height/2 - icon_height/2,icon_height,icon_height)
			'ximg_icon.SetBitmap(tmp_tab.Icon.Resize(ximg_icon.Width,ximg_icon.Height,True))
				
			If CurrenIndex = tmp_tab.index Then
				If tmp_tab.Icon.IsInitialized Then ximg_icon.SetBitmap(ChangeColorBasedOnAlphaLevel(tmp_tab.Icon,g_SelectedTabTextColor).Resize(ximg_icon.Width,ximg_icon.Height,True))
			Else
				If tmp_tab.Icon.IsInitialized Then ximg_icon.SetBitmap(ChangeColorBasedOnAlphaLevel(tmp_tab.Icon,g_TabTextColor).Resize(ximg_icon.Width,ximg_icon.Height,True))
			End If
			
			If tmp_tab.badge_visible = True Then
				If g_badge_gravity = getBadge_MIDDLELEFT Then
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/1.2,xpnl_base.Height/2,badge_height,badge_height)
				else If g_badge_gravity = getBadge_TOPLEFT Then
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/1.2,ximg_icon.top - badge_height/2,badge_height,badge_height)
				else If g_badge_gravity = getBadge_TOPMIDDLE Then
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - badge_height/2,ximg_icon.top - badge_height/2,badge_height,badge_height)
				else If g_badge_gravity = getBadge_TOPRIGHT Then
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 + icon_height/1.2 - badge_height,ximg_icon.top - badge_height/2,badge_height,badge_height)
				Else 'Middle_Right
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 + icon_height/1.2 - badge_height,xpnl_base.Height/2,badge_height,badge_height)
				End If
			
			End If
				
		Else If g_TabStyle = "TextIcon" Then 'text and icon
				
			xlbl_text.Visible = True
			ximg_icon.Visible = True
			
			xlbl_text.Text = tmp_tab.TabText
			xlbl_text.SetTextAlignment("TOP","CENTER")
			xlbl_text.Font = text_font
			
			If tmp_TextIconCenter = False Then
				If isHorizontal = True Then
					xlbl_text.SetLayoutAnimated(0,0,xpnl_base.Height/2,xpnl_base.Width,txt_height)
					ximg_icon.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/2 ,xpnl_base.Height/2 - icon_height/TextIcon_Padding,icon_height,icon_height)
				Else
					xlbl_text.SetLayoutAnimated(0,0,xpnl_base.Height/2,xpnl_base.Width,txt_height)
					ximg_icon.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/2 ,xpnl_base.Height/2 - icon_height/TextIcon_Padding,icon_height,icon_height)
				End If
			Else
				If isHorizontal = True Then
					xlbl_text.SetLayoutAnimated(0,0,xpnl_base.Height/2 - txt_height/2,xpnl_base.Width,txt_height)
					ximg_icon.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/2 ,xpnl_base.Height/2 - icon_height/2,icon_height,icon_height)
				Else
					xlbl_text.SetLayoutAnimated(0,0,xpnl_base.Height/2 - txt_height/2,xpnl_base.Width,txt_height)
					ximg_icon.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/2 ,xpnl_base.Height/2 - icon_height/2,icon_height,icon_height)
				End If
			End If
			
			If CurrenIndex = tmp_tab.index Then
				xlbl_text.TextColor = g_SelectedTabTextColor
				If tmp_tab.Icon.IsInitialized Then ximg_icon.SetBitmap(ChangeColorBasedOnAlphaLevel(tmp_tab.Icon,g_SelectedTabTextColor).Resize(ximg_icon.Width,ximg_icon.Height,True))
			Else
				xlbl_text.TextColor = g_TabTextColor
				If tmp_tab.Icon.IsInitialized Then ximg_icon.SetBitmap(ChangeColorBasedOnAlphaLevel(tmp_tab.Icon,g_TabTextColor).Resize(ximg_icon.Width,ximg_icon.Height,True))
			End If
				
			If tmp_TextIconCenter = False Then 'Icons or Text is centered
				If tmp_tab.badge_visible = True Then
					If g_badge_gravity = getBadge_MIDDLELEFT Then
						xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/1.2,xpnl_base.Height/2.7,badge_height,badge_height)
					else If g_badge_gravity = getBadge_TOPLEFT Then
						xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/1.2,xpnl_base.Height/2 - icon_height,badge_height,badge_height)
					else If g_badge_gravity = getBadge_TOPMIDDLE Then
						xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - badge_height/2,xpnl_base.Height/2 - icon_height,badge_height,badge_height)
					else If g_badge_gravity = getBadge_TOPRIGHT Then
						xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 + icon_height/1.2 - badge_height,xpnl_base.Height/2 - icon_height,badge_height,badge_height)
					Else 'Middle_Right
						xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 + icon_height/1.2 - badge_height,xpnl_base.Height/2.7,badge_height,badge_height)
					End If
				End If
			
			Else
				If tmp_tab.Icon.IsInitialized = True Then
				If g_badge_gravity = getBadge_MIDDLELEFT Then
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/1.2,xpnl_base.Height/2.7,badge_height,badge_height)
				else If g_badge_gravity = getBadge_TOPLEFT Then
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - icon_height/1.2,xpnl_base.Height/2 - icon_height,badge_height,badge_height)
				else If g_badge_gravity = getBadge_TOPMIDDLE Then
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 - badge_height/2,xpnl_base.Height/2 - icon_height,badge_height,badge_height)
				else If g_badge_gravity = getBadge_TOPRIGHT Then
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 + icon_height/1.2 - badge_height,xpnl_base.Height/2 - icon_height,badge_height,badge_height)
				Else 'Middle_Right
					xlbl_badge.SetLayoutAnimated(0,xpnl_base.Width/2 + icon_height/1.2 - badge_height,xpnl_base.Height/2.7,badge_height,badge_height)
				End If
				Else
					If g_CurrentTabUnderlineGravity = getCurrentTabUnderlineGravity_TOPLEFT And GetOrientation(g_orientation) = getOrientation_HORIZONTAL Then
						xlbl_badge.SetLayoutAnimated(0,xlbl_text.Width/2 - badge_height/2,xlbl_text.Top + xlbl_text.Height,badge_height,badge_height)
					Else
						xlbl_badge.SetLayoutAnimated(0,xlbl_text.Width/2 - badge_height/2,xlbl_text.Top - badge_height,badge_height,badge_height)
					End If
					End If
			End If

			
			'ximg_icon.SetLayoutAnimated(0,xpnl_base.Width/2 - (xpnl_base.Height/2)/2 ,xpnl_base.Height/2 - GetImage(ximg_icon).Height,xpnl_base.Height/2,GetImage(ximg_icon).Height)
		Else
			xlbl_text.Visible = False
			ximg_icon.Visible = False
		End If
		
	Next
  
End Sub

Private Sub GetOrientation(Orientation As String) As String
	If Orientation = getOrientation_AUTOMATIC Then		
		If mBase.Width >= mBase.Height Then
			Return getOrientation_HORIZONTAL
		Else
			Return getOrientation_VERTICAL
		End If		
	Else
		Return getOrientation_VERTICAL
	End If	
End Sub

'Refresh the view and commit changes to the view
Public Sub CommitChanges
	Base_Resize(mBase.Width,mBase.Height)
End Sub

Private Sub SetUnderline2NewPos
	If CurrenIndex >= xpnl_tabbase.NumberOfViews Then
		CurrenIndex = 0
		TabClick(xpnl_tabbase.GetView(0),True,g_EnableSelectedTabTextColor)
	End If
	Dim xpnl_targettab As B4XView = xpnl_tabbase.GetView(CurrenIndex)
	'Dim tmp_tab As Tabs = xpnl_targettab.Tag
	
	Dim xlbl_text As B4XView = xpnl_targettab.GetView(0)
	'Dim ximg_icon As B4XView = xpnl_targettab.GetView(1)
	
	If g_CurrentTabUnderlineAnimation = "Normal" Then
		
		If GetOrientation(g_orientation) = getOrientation_HORIZONTAL Then
		
			If g_TabStripMode = False Then
		
				Dim tmp_top As Float = xlbl_text.Top + xlbl_text.Height
				If g_TabStyle = "Text" Or g_TabStyle = "TextIcon" Then 'only Text or text and icons
					Dim textwidth As Int =  Max(1dip,MeasureTextWidth(xlbl_text.Text,xlbl_text.Font))
			
					If g_CurrentTabUnderlineGravity <> getCurrentTabUnderlineGravity_BOTTOMRIGHT Then
						If g_TabStyle = "TextIcon" Then
							tmp_top = xpnl_targettab.Height/2 - icon_height/2
						Else
							tmp_top = xpnl_targettab.Height/2 - xlbl_text.Height/2
						End If
					End If
			
					xpnl_underline.SetLayoutAnimated(g_CurrentTabUnderlineAnimationDuration,xpnl_targettab.Left + xpnl_targettab.Width/2 - textwidth/2,tmp_top,textwidth,ul_height)
				Else If g_TabStyle = "Icon" Then 'only Icon
					If g_CurrentTabUnderlineGravity = getCurrentTabUnderlineGravity_BOTTOMRIGHT Then
						tmp_top = xpnl_tabbase.Height/2 + 15dip
					Else
						tmp_top = xpnl_tabbase.Height/2 - icon_height/2.5
					End If
					xpnl_underline.SetLayoutAnimated(g_CurrentTabUnderlineAnimationDuration,xpnl_targettab.Left + xpnl_targettab.Width/2 - underlinewidthbyonlyicon/2,tmp_top,underlinewidthbyonlyicon,ul_height)
				End If
		
			Else
			
				Dim tmp_top As Float = 0
				If g_CurrentTabUnderlineGravity <> getCurrentTabUnderlineGravity_TOPLEFT Then
					tmp_top = xpnl_targettab.Height - ul_height
				End If
				xpnl_underline.SetLayoutAnimated(g_CurrentTabUnderlineAnimationDuration,xpnl_targettab.Left,tmp_top,xpnl_targettab.Width,ul_height)
			End If
		
		Else
			Dim tmp_left As Float = 0
			If g_CurrentTabUnderlineGravity = getCurrentTabUnderlineGravity_BOTTOMRIGHT Then
				tmp_left = xpnl_targettab.Width - ul_height
			End If
			If g_TabStripMode = False Then
			
				xpnl_underline.SetLayoutAnimated(g_CurrentTabUnderlineAnimationDuration,tmp_left,xpnl_targettab.Top + xpnl_targettab.Height/4,ul_height,xpnl_targettab.Height/2)
			Else
				xpnl_underline.SetLayoutAnimated(g_CurrentTabUnderlineAnimationDuration,tmp_left,xpnl_targettab.Top,ul_height,xpnl_targettab.Height)
				
			End If
						
		End If
		
'	Else
'		'Stretch				
'		If g_TabStyle = "Text" Or g_TabStyle = "TextIcon" Then 'only Text or text and icons
'			Dim textwidth As Int =  Max(1dip,MeasureTextWidth(xlbl_text.Text,xlbl_text.Font))
'		
'		
'			If xpnl_targettab.Left < xpnl_underline.Left Then 'to left
'	
'	
'	
'			Else 'to right
'			
'				xpnl_underline.SetLayoutAnimated(g_CurrentTabUnderlineAnimationDuration,xpnl_underline.Left,xlbl_text.Top + xlbl_text.Height,(xpnl_underline.Width  + textwidth/2) + (xpnl_targettab.Left - xpnl_underline.Left),2dip)
'				'Sleep(g_CurrentTabUnderlineAnimationDuration)
'				'xpnl_underline.SetLayoutAnimated(5000,xpnl_targettab.Left + xpnl_targettab.Width/2 - textwidth/2,xlbl_text.Top + xlbl_text.Height,textwidth,2dip)
'			End If
'		
'		
'		
'		
'		Else If g_TabStyle = "Icon" Then 'only Icon
'			xpnl_underline.SetLayoutAnimated(g_CurrentTabUnderlineAnimationDuration,xpnl_targettab.Left + xpnl_targettab.Width/2 - underlinewidthbyonlyicon/2,xpnl_tabbase.Height/2 + 15dip,underlinewidthbyonlyicon,2dip)
'		End If
			
	End If
	If GetOrientation(g_orientation) = getOrientation_HORIZONTAL Then
		xpnl_underline.SetColorAndBorder(ul_clr,0,0,xpnl_underline.Height/2)
	Else
		xpnl_underline.SetColorAndBorder(ul_clr,0,0,xpnl_underline.Width/2)
	End If

End Sub

#Region Enumerations

Public Sub getCommitMode_MANUALLY As String
	Return "Manually"
End Sub

Public Sub getCommitMode_AUTOMATIC As String
	Return "Automatic"
End Sub

Public Sub getBadge_MIDDLERIGHT As String
	Return "MiddleRight"
End Sub

Public Sub getBadge_MIDDLELEFT As String
	Return "MiddleLeft"
End Sub

Public Sub getBadge_TOPRIGHT As String
	Return "TopRight"
End Sub

Public Sub getBadge_TOPMIDDLE As String
	Return "TopMiddle"
End Sub

Public Sub getBadge_TOPLEFT As String
	Return "TopLeft"
End Sub

Public Sub getCurrentTabUnderlineGravity_TOPLEFT As String
	Return "TopLeft"
End Sub
Public Sub getCurrentTabUnderlineGravity_BOTTOMRIGHT As String
	Return "BottomRight"
End Sub
Public Sub getOrientation_AUTOMATIC As String
	Return "Automatic"
End Sub
Public Sub getOrientation_HORIZONTAL As String
	Return "Horizontal"
End Sub
Public Sub getOrientation_VERTICAL As String
	Return "Vertical"
End Sub

Public Sub getTabStyle_TEXT As String
	Return "Text"
End Sub
Public Sub getTabStyle_ICON As String
	Return "Icon"
End Sub
Public Sub getTabStyle_TEXTICON As String
	Return "TextIcon"
End Sub
Public Sub getCurrentTabUnderlineAnimation_NORMAL As String
	Return "Normal"
End Sub
'Public Sub getCurrentTabUnderlineAnimation_STRETCH As String
'	Return "Stretch"
'End Sub
#End Region

#Region Properties

'sets or gets the TabStripMode, if true the underline width is the full tab
Public Sub getTabStripMode As Boolean
	Return g_TabStripMode
End Sub

Public Sub setTabStripMode(enable As Boolean)
	g_TabStripMode = enable
	SetUnderline2NewPos
End Sub

Public Sub setCommitMode(commit_mode As String)
	g_commitmode = commit_mode
End Sub

Public Sub getCommitMode As String
	Return g_commitmode
End Sub

'for example take this enum for parameter: Badge_MIDDLERIGHT
'Has no effect with only Text
Public Sub setBadge_Gravity(badge_gravity As String)
	g_badge_gravity = badge_gravity
	If g_commitmode = getCommitMode_AUTOMATIC Then Base_Resize(mBase.Width,mBase.Height)
End Sub

Public Sub getBadge_Gravity As String
	Return g_badge_gravity
End Sub

'shows the badge with all important settings to save lines of code
Public Sub Badge_setVisibleEasy(index As Int,number As Int,color As Int)
	Badge_setColor(index,color)
	Badge_setText(index,number)
	Badge_setVisible(index,True)
End Sub

'gets or sets the badge color
Public Sub Badge_setColor(index As Int,color As Int)
	Dim tmp_base As B4XView = xpnl_tabbase.GetView(index)
	Dim xlbl_badge As B4XView = tmp_base.GetView(2)
	xlbl_badge.Color = color
End Sub

Public Sub Badge_getColor(index As Int) As Int
	Return xpnl_tabbase.GetView(index).GetView(2).Color
End Sub

'gets the badge label, to modify it to your own
Public Sub Badge_getLabel(index As Int) As B4XView
	Return xpnl_tabbase.GetView(index).GetView(2)	
End Sub

'sets the badge number, set it to -1 to have only the color
Public Sub Badge_setText(index As Int,number As Int)
	Dim tmp_base As B4XView = xpnl_tabbase.GetView(index)
	Dim xlbl_badge As B4XView = tmp_base.GetView(2)
	If number < 0 Then
		xlbl_badge.Text = ""
		Else If number > 9 Then
		xlbl_badge.Text = "9+"
		Else
		xlbl_badge.Text = number
	End If	
End Sub

'gets or sets the badge height, per default it is 15dip
Public Sub Badge_setHeight(size As Float)
	badge_height = size	
	If g_commitmode = getCommitMode_AUTOMATIC Then Base_Resize(mBase.Width,mBase.Height)
End Sub

Public Sub Badge_getHeight As Float
	Return badge_height
End Sub

'show or hide the badge on a tab
Public Sub Badge_setVisible(index As Int,visible As Boolean)
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	tmp_tab.badge_visible = visible
	xpnl_tabbase.GetView(index).Tag = tmp_tab
	If g_commitmode = getCommitMode_AUTOMATIC Then Base_Resize(mBase.Width,mBase.Height)
End Sub

Public Sub Badge_getVisible(index As Int) As Boolean
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	Return tmp_tab.badge_visible
End Sub

'sets or gets the background color of a tab 
Public Sub setTabBackgroundColor (index As Int, colour As Int)
	Dim tmp_tab As B4XView = xpnl_tabbase.GetView(index)
	tmp_tab.Color = colour
End Sub

Public Sub getTabBackgroundColor(index As Int) As Int
	Dim tmp_tab As B4XView = xpnl_tabbase.GetView(index)
	Return tmp_tab.Color
End Sub

'gets the current tab index
Public Sub getCurrentIndex As Int
	Return CurrenIndex
End Sub

'gets or sets the gravity of the underline
Public Sub getCurrentTabUnderlineGravity As String
	Return g_CurrentTabUnderlineGravity
End Sub

Public Sub setCurrentTabUnderlineGravity(underline_gravity As String)
	g_CurrentTabUnderlineGravity = underline_gravity
	SetUnderline2NewPos
	If g_commitmode = getCommitMode_AUTOMATIC Then Base_Resize(mBase.Width,mBase.Height)
End Sub

'gets or sets the tag of a tab
Public Sub getTabTag(index As Int) As Object
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	Return tmp_tab.Tag
End Sub

Public Sub setTabTag(index As Int,tag As Object)
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	tmp_tab.Tag = tag
	xpnl_tabbase.GetView(index).Tag = tmp_tab
End Sub

'gets or sets the text of a tab
Public Sub getTabText(index As Int) As String
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	Return tmp_tab.TabText
End Sub

Public Sub setTabText(index As Int,text As String)
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	tmp_tab.TabText = text
	xpnl_tabbase.GetView(index).Tag = tmp_tab
	If g_commitmode = getCommitMode_AUTOMATIC Then Base_Resize(mBase.Width,mBase.Height)
End Sub

'gets or sets the icon of a tab
Public Sub getTabIcon(index As Int) As B4XBitmap
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	Return tmp_tab.Icon
End Sub

Public Sub setTabIcon(index As Int,icon As B4XBitmap)
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	tmp_tab.Icon = icon
	xpnl_tabbase.GetView(index).Tag = tmp_tab
	If g_commitmode = getCommitMode_AUTOMATIC Then Base_Resize(mBase.Width,mBase.Height)
End Sub

'gets or sets the color of the underline
Public Sub getUnderLineColor As Int
	Return ul_clr
End Sub

Public Sub setUnderLineColor(clr As Int)
	ul_clr = clr
	Base_Resize(mBase.Width,mBase.Height)
End Sub

'gets or sets the thickness of the underline
Public Sub getUnderLineHeight As Float
	Return ul_height
End Sub

Public Sub setUnderLineHeight(height As Float)
	ul_height = height
	SetUnderline2NewPos
	Base_Resize(mBase.Width,mBase.Height)
End Sub

'gets or sets the color of the parting line
Public Sub getPartingLineColor As Int
	Return pl_clr
End Sub

Public Sub setPartingLineColor(clr As Int)
	pl_clr = clr
	Base_Resize(mBase.Width,mBase.Height)
End Sub

'gets or sets the thickness of the parting line
Public Sub getPartingLineWidth As Float
	Return pl_width
End Sub

Public Sub setPartingLineWidth(width As Float)
	pl_width = width
	Base_Resize(mBase.Width,mBase.Height)
End Sub

'show or hide the parting line
Public Sub getPartingLineVisible As Boolean
	Return g_PartingLineVisible
End Sub

Public Sub setPartingLineVisible(visible As Boolean)
	g_PartingLineVisible = visible
	If g_commitmode = getCommitMode_AUTOMATIC Then Base_Resize(mBase.Width,mBase.Height)
End Sub

'gets the mbase
Public Sub getBaseView As B4XView
	Return mBase
End Sub

'gets or sets the tab click color
Public Sub getTabClickColor As Int
	Return g_TabClickColor
End Sub

Public Sub setTabClickColor(color As Int)
	g_TabClickColor = color
End Sub

'gets or sets the text color of the selected tab
Public Sub getSelectedTabTextColor As Int
	Return g_SelectedTabTextColor
End Sub

Public Sub setSelectedTabTextColor(color As Int)
	g_SelectedTabTextColor = color
End Sub

'enable or disable the tab text color on clicking on a tab
Public Sub getEnableSelectedTabTextColor As Boolean
	Return g_EnableSelectedTabTextColor
End Sub

Public Sub setEnableSelectedTabTextColor(enable As Boolean)
	g_EnableSelectedTabTextColor = enable
End Sub

'gets or sets the duration of the underline animation
Public Sub getCurrentTabUnderlineAnimationDuration As Int
	Return g_CurrentTabUnderlineAnimationDuration
End Sub

Public Sub setCurrentTabUnderlineAnimationDuration(duration As Int)
	g_CurrentTabUnderlineAnimationDuration = duration
End Sub

'gets or sets the underline animation
Public Sub getCurrentTabUnderlineAnimation As String
	Return g_CurrentTabUnderlineAnimation
End Sub

Public Sub setCurrentTabUnderlineAnimation(animation As String)
	g_CurrentTabUnderlineAnimation = animation
End Sub

'hide or shows the underline
Public Sub getCurrentTabUnderline As Boolean
	Return g_CurrentTabUnderline
End Sub

Public Sub setCurrentTabUnderline(show As Boolean)
	g_CurrentTabUnderline = show
	xpnl_underline.Visible = show
	SetUnderline2NewPos
End Sub

'gets or sets the tab style
Public Sub getTabStyle As String
	Return g_TabStyle
End Sub

Public Sub setTabStyle(style As String)
	g_TabStyle = style
	Base_Resize(xpnl_tabbase.Width,xpnl_tabbase.Height)
	SetUnderline2NewPos
End Sub

'gets or sets the non selected tab text color
Public Sub setTabTextColor(color As Int)
	g_TabTextColor = color
	If g_commitmode = getCommitMode_AUTOMATIC Then Base_Resize(xpnl_tabbase.Width,xpnl_tabbase.Height)
	SetUnderline2NewPos
End Sub

Public Sub getTabTextColor As Int
	Return g_TabTextColor
End Sub

'Gets the Number of Tabs
Public Sub getTabSize As Int
	Return xpnl_tabbase.NumberOfViews
End Sub

Public Sub ViewEnable(enable As Boolean)
	For i = 0 To xpnl_tabbase.NumberOfViews -1		
		#If B4I
		Dim tmp_pnl As Panel = xpnl_tabbase.GetView(i)
		tmp_pnl.UserInteractionEnabled = False
		#Else
		xpnl_tabbase.GetView(i).Enabled = enable
		#End If
	Next
End Sub

'adds a new tab
Public Sub AddTab(background_color As Int,text As String,icon As B4XBitmap,tag As Object)
	
	Dim xpnl_base As B4XView = xui.CreatePanel("xpnl_base")
	xpnl_base.Color = background_color
	
	Dim xlbl_text As B4XView = CreateLabel("")
	Dim ximg_icon As B4XView = CreateImageView("")
	Dim xlbl_badge As B4XView = CreateLabel("")
	
	xpnl_base.AddView(xlbl_text,0,0,0,0)
	xpnl_base.AddView(ximg_icon,0,0,0,0)
	xpnl_base.AddView(xlbl_badge,0,0,0,0)
		
	xlbl_badge.SetColorAndBorder(xlbl_badge.Color,0,0,badge_height/2)
	xlbl_badge.SetTextAlignment("CENTER","CENTER")
	xlbl_badge.Font = xui.CreateDefaultfont(10)
	xlbl_badge.TextColor = xui.Color_White
		
	xpnl_base.Tag = CreateTabs(text,icon,tag,xpnl_tabbase.NumberOfViews,False,True)
	
	xpnl_tabbase.AddView(xpnl_base,0,0,0,0)
	
	Dim xpnl_partingline As B4XView = xui.CreatePanel("")
	mBase.AddView(xpnl_partingline,0,0,0,0)
	
	Base_Resize(xpnl_tabbase.Width,xpnl_tabbase.Height)
	
'	If xpnl_tabbase.NumberOfViews = 1 Then
'		SetTab(0,False,False)
'	End If
	SetUnderline2NewPos
	
	
End Sub

'sets the selected tab
Public Sub SetTab(index As Int,withClickEvent As Boolean,withHalo As Boolean)
' %%%  
  withhalo = g_HaloEffect 
	TabClick(xpnl_tabbase.GetView(index),withClickEvent,withHalo)
End Sub

'Removes the tab on the given index, if the current index is higher then the number of views, then the current index is set to 0 and the first tab is clicked
Public Sub RemoveAt(index As Int)	
	xpnl_tabbase.GetView(index).RemoveViewFromParent
	mBase.GetView(index + 2).RemoveViewFromParent
	For i = 0 To xpnl_tabbase.NumberOfViews -1
		
		Dim tmp_base As B4XView = xpnl_tabbase.GetView(i)
		Dim tmp_tabs As Tabs = tmp_base.Tag
		tmp_tabs.index = i
		tmp_base.Tag = tmp_tabs
	Next
	Base_Resize(mBase.Width,mBase.Height)
	setCurrentTabUnderline(g_CurrentTabUnderline)
End Sub

Public Sub RemoveAllTabs
	xpnl_tabbase.RemoveAllViews
End Sub

Public Sub VisibleAt(index As Int,visible As Boolean)
	Dim tmp_tab As Tabs = xpnl_tabbase.GetView(index).Tag
	tmp_tab.Visible = visible
	xpnl_tabbase.GetView(index).Tag = tmp_tab
	Base_Resize(mBase.Width,mBase.Height)
	setCurrentTabUnderline(g_CurrentTabUnderline)
End Sub

#End Region

#Region Events

#If B4J
Private Sub xpnl_base_MouseClicked (EventData As MouseEvent)
#Else
Private Sub xpnl_base_Click
#End If	
	TabClick(Sender,True,g_EnableSelectedTabTextColor)
End Sub

Private Sub TabClick(xpnl_base As B4XView,withEvent As Boolean,withHalo As Boolean)
	
	Dim tmp_tab As Tabs = xpnl_base.Tag
	CurrenIndex = tmp_tab.index
'	If withHalo = True Then CreateHaloEffect(xpnl_base, xpnl_base.Width/2, xpnl_base.Height/2, g_TabClickColor)
	
	For i = 0 To xpnl_tabbase.NumberOfViews -1
		Dim tmp_base As B4XView = xpnl_tabbase.GetView(i)
		Dim tmp_tabs As Tabs = tmp_base.Tag
		
		Dim xlbl_text As B4XView = tmp_base.GetView(0)
		Dim ximg_icon As B4XView = tmp_base.GetView(1)
		
		If tmp_tabs.index <> tmp_tab.index Then
			xlbl_text.TextColor = g_TabTextColor
			If g_TabStyle = "Icon" Or g_TabStyle = "TextIcon" Then
				If tmp_tabs.Icon.IsInitialized Then	ximg_icon.SetBitmap(ChangeColorBasedOnAlphaLevel(tmp_tabs.Icon,g_TabTextColor).Resize(ximg_icon.Width,ximg_icon.Height,True))
			End If
		Else
			xlbl_text.TextColor = g_SelectedTabTextColor
			If g_TabStyle = "Icon" Or g_TabStyle = "TextIcon" Then
				If tmp_tabs.Icon.IsInitialized Then	ximg_icon.SetBitmap(ChangeColorBasedOnAlphaLevel(tmp_tabs.Icon,g_SelectedTabTextColor).Resize(ximg_icon.Width,ximg_icon.Height,True))
			End If
		End If
	Next
	
	SetUnderline2NewPos
	
	If withEvent = True Then
	If xui.SubExists(mCallBack, mEventName & "_TabClick",1) Then
		CallSub2(mCallBack, mEventName & "_TabClick",tmp_tab.index)
	End If
	End If
End Sub

#End Region

#Region Functions
'https://www.b4x.com/android/forum/threads/fontawesome-to-bitmap.95155/post-603250
Public Sub FontToBitmap (text As String, IsMaterialIcons As Boolean, FontSize As Float, color As Int) As B4XBitmap
	Dim xui As XUI
	Dim p As B4XView = xui.CreatePanel("")
	p.SetLayoutAnimated(0, 0, 0, 32dip, 32dip)
	Dim cvs1 As B4XCanvas
	cvs1.Initialize(p)
	Dim fnt As B4XFont
	If IsMaterialIcons Then fnt = xui.CreateMaterialIcons(FontSize) Else fnt = xui.CreateFontAwesome(FontSize)
	Dim r As B4XRect = cvs1.MeasureText(text, fnt)
	Dim BaseLine As Int = cvs1.TargetRect.CenterY - r.Height / 2 - r.Top
	cvs1.DrawText(text, cvs1.TargetRect.CenterX, BaseLine, fnt, color, "CENTER")
	Dim b As B4XBitmap = cvs1.CreateBitmap
	cvs1.Release
	Return b
End Sub

Private Sub CreateTabs (TabText As String, Icon As B4XBitmap, Tag As Object,index As Int,badge_visible As Boolean,visible As Boolean) As Tabs
	Dim t1 As Tabs
	t1.Initialize
	t1.TabText = TabText
	t1.Icon = Icon
	t1.Tag = Tag
	t1.index = index
	t1.badge_visible = badge_visible
	t1.Visible = visible
	Return t1
End Sub

Private Sub CreateLabel(EventName As String) As B4XView	
	Dim tmp_lbl As Label
	tmp_lbl.Initialize(EventName)
	#If B4A
	Dim r As Reflector
	r.Target = tmp_lbl
	r.RunMethod2("setSingleLine", True, "java.lang.boolean")
	r.RunMethod2("setEllipsize", "END", "android.text.TextUtils$TruncateAt")
	#End If
	Return tmp_lbl	
End Sub

Private Sub CreateImageView(EventName As String) As B4XView	
	Dim tmp_imageview As ImageView
	tmp_imageview.Initialize(EventName)	
	Return tmp_imageview
End Sub

'https://www.b4x.com/android/forum/threads/b4x-xui-simple-halo-animation.80267/#content
Private Sub CreateHaloEffect (Parent As B4XView, x As Int, y As Int, clr As Int)
	Dim cvs As B4XCanvas
	Dim p As B4XView = xui.CreatePanel("")
	Dim radius As Int = 150dip
	p.SetLayoutAnimated(0, 0, 0, radius * 2, radius * 2)
	cvs.Initialize(p)
	cvs.DrawCircle(cvs.TargetRect.CenterX, cvs.TargetRect.CenterY, cvs.TargetRect.Width / 2, clr, True, 0)
	Dim bmp As B4XBitmap = cvs.CreateBitmap
	For i = 1 To 1
		CreateHaloEffectHelper(Parent,bmp, x, y, radius)
		Sleep(800)
	Next
End Sub

Private Sub CreateHaloEffectHelper (Parent As B4XView,bmp As B4XBitmap, x As Int, y As Int, radius As Int)
	Dim iv As ImageView
	iv.Initialize("")
	Dim p As B4XView = iv
	p.SetBitmap(bmp)
	Parent.AddView(p, x, y, 0, 0)
	Dim duration As Int = 1000
	p.SetLayoutAnimated(duration, x - radius, y - radius, 2 * radius, 2 * radius)
	p.SetVisibleAnimated(duration, False)
	Sleep(duration)
	p.RemoveViewFromParent
End Sub

'https://www.b4x.com/android/forum/threads/b4x-xui-add-measuretextwidth-and-measuretextheight-to-b4xcanvas.91865/post-580637
Private Sub MeasureTextWidth(Text As String, Font1 As B4XFont) As Int
#If B4A
	Private bmp As Bitmap
	bmp.InitializeMutable(2dip, 2dip)
	Private cvs As Canvas
	cvs.Initialize2(bmp)
	Return cvs.MeasureStringWidth(Text, Font1.ToNativeFont, Font1.Size)
#Else If B4i
    Return Text.MeasureWidth(Font1.ToNativeFont)
#Else If B4J
    Dim jo As JavaObject
    jo.InitializeNewInstance("javafx.scene.text.Text", Array(Text))
    jo.RunMethod("setFont",Array(Font1.ToNativeFont))
    jo.RunMethod("setLineSpacing",Array(0.0))
    jo.RunMethod("setWrappingWidth",Array(0.0))
    Dim Bounds As JavaObject = jo.RunMethod("getLayoutBounds",Null)
    Return Bounds.RunMethod("getWidth",Null)
#End If
End Sub

'https://www.b4x.com/android/forum/threads/b4x-bitmapcreator-change-color-of-bitmap.95518/post-603416
Private Sub ChangeColorBasedOnAlphaLevel(bmp As B4XBitmap, NewColor As Int) As B4XBitmap
	Dim bc As BitmapCreator
	bc.Initialize(bmp.Width, bmp.Height)
	bc.CopyPixelsFromBitmap(bmp)
	Dim a1, a2 As ARGBColor
	bc.ColorToARGB(NewColor, a1)
	For y = 0 To bc.mHeight - 1
		For x = 0 To bc.mWidth - 1
			bc.GetARGB(x, y, a2)
			If a2.a > 0 Then
				a2.r = a1.r
				a2.g = a1.g
				a2.b = a1.b
				bc.SetARGB(x, y, a2)
			End If
		Next
	Next
	Return bc.Bitmap
End Sub

#End Region

