B4A Library SegmentedBarView

This is a wrapper for this github-project.


687474703a2f2f692e696d6775722e636f6d2f4531697654374e2e706e67


SegmentedBarView
Version:
1
  • Segment
    Methods:
    • GetApplicationDrawable (DrawableName As String) As Drawable
      Get a Drawable from the Application Resources.
      Returns Null if the Drawable is not found.
    • Initialize (minvalue As Float, maxvalue As Float, color As Int)
    • IsInitialized As Boolean
    Properties:
    • Color As Int
    • CustomText As String
    • DescriptionText As String
    • MaxValue As Float
    • MinValue As Float
  • SegmentedBarView
    Fields:
    • ba As BA
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • GetApplicationDrawable (DrawableName As String) As Drawable
      Get a Drawable from the Application Resources.
      Returns Null if the Drawable is not found.
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • setValueSignSize (width As Int, height As Int)
    • setValueWithUnit (value As Float, unitHtml As String)
    Properties:
    • Background As Drawable
    • BarHeight As Int [write only]
    • Color As Int [write only]
    • DescriptionBoxHeight As Int [write only]
    • DescriptionTextColor As Int [write only]
    • DescriptionTextSize As Int [write only]
    • EmptySegmentColor As Int [write only]
    • Enabled As Boolean
    • GapWidth As Int [write only]
    • Height As Int
    • Left As Int
    • SegmentTextColor As Int [write only]
    • SegmentTextSize As Int [write only]
    • Segments As List [write only]
    • ShowDescriptionText As Boolean [write only]
    • ShowSegmentText As Boolean [write only]
    • SideStyle As Int [write only]
    • SideTextStyle As Int [write only]
    • Tag As Object
    • Top As Int
    • Unit As String [write only]
    • Value As Float [write only]
    • ValueSegment As Integer
    • ValueSignColor As Int [write only]
    • ValueTextColor As Int [write only]
    • ValueTextSize As Int [write only]
    • Visible As Boolean
    • Width As Int


B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private bar1 As SegmentedBarView
    Private s1,s2,s3,s4,s5 As Segment
    Private value As Float
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    value = 35
    s1.Initialize(0,20,Colors.Blue)
    s1.DescriptionText = "1"
    s1.CustomText = "1st"
    s2.Initialize(20,40,Colors.Cyan)
    s2.DescriptionText = "2"
    s3.Initialize(40,60,Colors.DarkGray)
    s3.DescriptionText = "3"
    s4.Initialize(60,80,Colors.Yellow)
    s4.DescriptionText = "4"
    s5.Initialize(80,100,Colors.Green)
    s5.DescriptionText = "5"
    s5.CustomText = "5th"


    Dim segments As List
    segments.Initialize
    segments.Add(s1)
    segments.Add(s2)
    segments.Add(s3)
    segments.Add(s4)
    segments.Add(s5)

    bar1.DescriptionTextColor = Colors.White
    bar1.DescriptionTextSize = 80
    bar1.DescriptionBoxHeight = 25dip
    bar1.ShowDescriptionText = True

    ' The bars color when there are no segments.
    bar1.EmptySegmentColor = Colors.Red

    bar1.GapWidth = 1dip
    bar1.SegmentTextColor = Colors.Black
    bar1.SegmentTextSize = 60

    ' 0 = Rectangle
    ' 1 = Rounded
    ' 2 = Triangle
    bar1.SideStyle = 1

    ' 0 One sided
    ' 1 Two sided
    ' But honestly; i dont know what the different is here :-)
    bar1.SideTextStyle = 0

    bar1.Segments = segments
    bar1.BarHeight = 50dip

    bar1.setValueSignSize(100dip,30dip)
    bar1.ValueSignColor = Colors.Red
    bar1.ValueTextColor = Colors.White
    bar1.ValueTextSize = 80
    bar1.setValueWithUnit(value,"%")


End Sub


If you want to donate for my work building the wrapper you can do it here:
 

Attachments

  • libSegmentedBarViewV1.0.0.zip
    18.8 KB · Views: 489
  • SegmentedBarViewEx.zip
    9.8 KB · Views: 411
Last edited:

Mahares

Expert
Licensed User
Longtime User
I ran Manfred's example using B4A version 4.3 and 5.2 and got this weird display. Did anyone else experience this?
upload_2015-10-9_13-21-15.png

EDIT: That was on a tablet with OS4 Ran it on a phone with OS5 and it looked ok.
 

Attachments

  • SegmentedBarExampleDonManfred.png
    SegmentedBarExampleDonManfred.png
    54.5 KB · Views: 260
Last edited:

Sergey Kravchenko

Active Member
Licensed User
Longtime User
But then I changed the text size. (added dip)
The result became better.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    value = 35
  
    s1.Initialize(0,20,Colors.Blue)
    s1.DescriptionText = "1"
    s1.CustomText = "1st"
    s2.Initialize(20,40,Colors.Cyan)
    s2.DescriptionText = "2"
    s3.Initialize(40,60,Colors.DarkGray)
    s3.DescriptionText = "3"
    s4.Initialize(60,80,Colors.Yellow)
    s4.DescriptionText = "4"
    s5.Initialize(80,100,Colors.Green)
    s5.DescriptionText = "5"
    s5.CustomText = "5th"
  
    Dim segments As List
    segments.Initialize
    segments.Add(s1)
    segments.Add(s2)
    segments.Add(s3)
    segments.Add(s4)
    segments.Add(s5)

    bar1.DescriptionTextColor = Colors.White
    bar1.DescriptionTextSize = 20dip
    bar1.DescriptionBoxHeight = 25dip
    bar1.ShowDescriptionText = True
  
    ' The bars color when there are no segments.
    bar1.EmptySegmentColor = Colors.Red
  
    bar1.GapWidth = 1dip
    bar1.SegmentTextColor = Colors.Black
    bar1.SegmentTextSize = 10dip
  
    ' 0 = Rectangle
    ' 1 = Rounded
    ' 3 = Triangle
    bar1.SideStyle = 1
  
    ' 0 One sided
    ' 1 Two sided
    ' But honestly; i dont know what the different is here :-)
    bar1.SideTextStyle = 0
  
    bar1.Segments = segments
    bar1.BarHeight = 50dip
  
    bar1.setValueSignSize(100dip,30dip)
    bar1.ValueSignColor = Colors.Red
    bar1.ValueTextColor = Colors.White
    bar1.ValueTextSize = 20dip
    bar1.setValueWithUnit(value,"%")
  

End Sub
 

Attachments

  • Screenshot1.png
    Screenshot1.png
    35.4 KB · Views: 337
Top