B4A Library FancyButton V1.0.3

DonManfred

Expert
Licensed User
FancyBtn This Library-Wrapper is based on this Github-Project.
FancyBtn
Version: 1.03

  • Methods:
    • onTouch (view As View, motionEvent As MotionEvent) As Boolean
  • FancyBtn
    Events:
    • click (v as Object As , tag As Object)
    • hover (v as Object As , tag As Object)
    • ondismiss (v as Object As , tag As Object)
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String, iconres As String, IconPosition As Int, tag As Object, AllowDismiss As Boolean)
    • IsInitialized As Boolean
    • uniplus (s As String) As String
    Properties:
    • Background As Drawable [write only]
    • BackgroundColor As Int [write only]
      Sets the BackgroundColor to use with the FancyButton
    • BackgroundColor2 As String [write only]
      Sets the BackgroundColor to use with the FancyButton
      here you can give a hexstring representating the color
    • BorderColor As Int [write only]
      Sets the BorderColor to use with the FancyButton
    • BorderWidth As Int [write only]
      Sets the BorderWidth to use with the FancyButton
    • CustomIconFont As String [write only]
      Set a new Iconfont to use in the FancyButton.
      It must be a name from a file in the assets-folder
      fontawesome.ttf for ex.
    • CustomTextFont As String [write only]
      Set a new Textfont to use in the FancyButton.
      It must be a name from a file in the assets-folder
      robotoregular.ttf for ex.
    • FontIconSize As Int [write only]
      Sets the Size of the icon to use with the FancyButton
      Only works when using an Icon from the IconFont.
    • Icon As String [write only]
      Sets the Icon to use with the FancyButton. You need to give an unicode
      string representating the Icon in the Iconfont. For ex. ?
    • IconDrawable As String [write only]
      Sets the Icon to use with the FancyButton
      You can give the filename of a drawable in the
      drawable folder in your res folder.
    • IconPosition As Int [write only]
      Set the Icon-Position of the FancyButton.
      1 = Left
      POSITION_LEFT = 1;
      POSITION_RIGHT = 2;
      POSITION_TOP = 3;
      POSITION_BOTTOM = 4;
    • Left As Int
    • Radius As Int [write only]
      Sets the Radius to use with the FancyButtons edges
    • Tag As Object
      Sets the Tag for this FancyButton
    • Text As String [write only]
      Sets the Text to use with the FancyButton
    • TextSize As Int [write only]
      Sets the Textsize to use with the FancyButton
    • Textcolor As Int [write only]
      Sets the TextColor to use with the FancyButton
    • Top As Int
    • Visible As Boolean
      Sets the FancyButtons visibility
    • Width As Int

See this cheat for a list of all included Icons in the Iconfont



This library is Donationware. You can download the library, you can test the library. But if you want to USE the library in your App you need to Donate for it.
Please click here to donate (You can donate any amount you want to donate for the library (or my work) :)
 

Attachments

Last edited:

bluedude

Well-Known Member
Licensed User
See my post in pgogress wheel. Could this easily be combined with the progresswheel for a click and progress button?
 

DonManfred

Expert
Licensed User
To whom it may concern:

Fancy Buttons can use 9-Patch images

a9p_09_11_01063.9.png




a9p_09_11_00712.9.png



You need the following sub and the files must be in objects\res\drawable\

B4X:
Sub SetNinePatchDrawable(Control As View, ImageName As String)
   Dim r As Reflector
   Dim package As String
   Dim id As Int
   package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
   id = r.GetStaticField(package & ".R$drawable", ImageName)
   r.Target = r.GetContext
   r.Target = r.RunMethod("getResources")
   Control.Background = r.RunMethod2("getDrawable", id, "java.lang.int")
End Sub
You can set a 9-patch to an FancyButton with
B4X:
    SetNinePatchDrawable(FancyButton1,"a9p_09_11_00712")
to set the file "a9p_09_11_00712.9.png" as 9-patch
 

MarcoRome

Expert
Licensed User
Hi DonManfred if i have 2 button f1, f2 .

B4X:
Sub fb_click
.... Sender or what ?? 
End sub
Possibile one little example ?
Thank you
Marco
 

MarcoRome

Expert
Licensed User
Hi DonManfred if i have 2 button f1, f2 .

B4X:
Sub fb_click
.... Sender or what ??
End sub
Possibile one little example ?
Thank you
Marco
Hi all. Today our good DonManfred is Busy... and so this is for management to click event:



B4X:
     fb1.Initialize("fb1","\uf082",0)
    Activity.AddView(fb1, 0,0dip,100dip,100dip)
    fb1.TextSize = 30
    fb1.Radius = 50dip
    fb1.Text = "FB"
    fb1.Tag = "1"
   
    fb2.Initialize("fb2","\uf0ed",3)
    Activity.AddView(fb2,110dip,0dip,100dip,100dip)
    fb2.BackgroundColor = Colors.Red
    fb2.BorderColor = Colors.Yellow
    fb2.BorderWidth = 1dip
    fb2.Text = "Cloud"
    fb2.Tag = "2"
   
.................
 
'For manage the click event
 
Sub fb1_Click
Log(fb1.Tag)
End Sub
Sub fb2_Click
Log(fb2.Tag)
End Sub
That all.
Thank you DonManfred for this great library.
Tomorrow you shall have my contribution ( donate ) to your work.
Bye
Marco
 

DonManfred

Expert
Licensed User
I have updated the lib (Post #1)
In the Initialize you now have an additional Parameter "AllowDismiss" true/false
When set to true the button will become a "SwipeToDismiss-Feature"

Additional i have extended the Exmple showing how to use the new Versions of the Event-subs.

B4X:
Sub fb_ondismiss(v As Object, Tag As Object)
    Log($"fb_ondismiss"$)
    Log("token: "&Tag)
    If v Is FancyBtn Then
        Dim fb As FancyBtn = v
        Log("fbtag: "&fb.Tag)
    End If
    'fb.Text = "X"
   
End Sub

Sub fb_Click(v As Object, Tag As Object)
    Log($"fb_Click"$)
    If v Is FancyBtn Then
        Dim fb As FancyBtn = v
        fb.Text = "Clicked"
    End If
End Sub
Sub fb_LongClick(v As Object, Tag As Object)
    Log($"fb_LongClick"$)
    If v Is FancyBtn Then
        Dim fb As FancyBtn = v
        fb.Text = "LongClicked"
    End If
End Sub
 

MarcoRome

Expert
Licensed User
Hi DonManfred, all work fine.
A suggestion if i can. In the property can you add also "Pressed Drawable Color" so when user press button change color.
Marco
 

DonManfred

Expert
Licensed User
In the property can you add also "Pressed Drawable Color" so when user press button change color.
There is no such property in this view. You can for sure change the buttons color (or set another 9patch-drawable) when you press the button. But this is not really a "pressed-state"...

What you can do:
DONT use SwipeToDismiss to get the OnTouch event raise in your app... On Motion.Down you set the pressed color on this button and on Motion.Up you set back the old color...

BUT: I need to extend the lib to raise an event for onTouch (it´s actually not exposed/biuiltin in library) instead of the SwipetoDismiss event.
 

tdocs2

Well-Known Member
Licensed User
Hello, Don, and thank you for this lib.

I am trying it out, but I get this error:

B4X:
B4A version 4.30
Parsing code.                           0.00
Compiling code.                         0.02
   
ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code.                 0.02
Generating R file.                      0.05
Compiling generated Java code.          Error
B4A line: 37
fb1.Initialize(\
javac 1.7.0_51
src\b4a\example\main.java:330: error: method Initialize in class FancyBtn cannot be applied to given types;
mostCurrent._v5.Initialize(processBA,"fb","\\uf082",(int) (0),(Object)(1),anywheresoftware.b4a.keywords.Common.True);
               ^
  required: BA,String,String,int
  found: BA,String,String,int,Object,boolean
  reason: actual and formal argument lists differ in length
1 error
 
Top