Android Question How to create Floating Dialog/Tray in Acivity

AndroidMadhu

Active Member
Licensed User
Hello,
I want to create a Floating Dialog/Tray on GMAP activity.[From button to up.]
Where from that Dialog/Tray user can click the button in-side the tray/Dialog for other action[For booking or any other action].
Is that possible at version B4A 9.80.

Any link or test project will be good for me to understand...

Thanks
 

AndroidMadhu

Active Member
Licensed User
I have found some code and it is working fine. But only the corner on top is showing the white space.
How do I make the activity transparent.
I am uploading the code for your convenience.

Code from main Activity

B4X:
#Region  Project Attributes
    #ApplicationLabel: CustomBottomSheet
    #VersionCode: 1
    #VersionName: 1.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #LibraryName: CustomBottomSheet
    #LibraryVersion: 1.0
    #LibraryAuthor: 
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region


Sub Process_Globals

End Sub

Sub Globals
   
       Private BottomSheet As CustomBottomSheet
                Private LayoutPanel As Panel
                Private Button1 As Button
                Private SeekBar1 As SeekBar
                Private SeekValueLabel As Label
               
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
                LayoutPanel.Initialize("")
    'LayoutPanel.SetLayoutAnimated(400,0,0,LayoutPanel.Width,LayoutPanel.Height)
                LayoutPanel.LoadLayout("Layout1")
                BottomSheet.Initialize(Activity, Me, "Done", LayoutPanel)

End Sub

Sub Activity_Resume
    BottomSheet.OpenBottomSheet
End Sub

Sub Activity_Pause(UserClosed As Boolean)

End Sub

Sub Button1_Click
   
                If BottomSheet.IsOpen Then
                   
                      BottomSheet.CloseBottomSheet
                           
       Else
                   
                         BottomSheet.OpenBottomSheet
                   
                End If
                   
End Sub

Sub SeekBar1_ValueChanged(Value As Int, UserChanged As Boolean)
   
       SeekValueLabel.Text = "Seek value: " & Value
   
End Sub

Sub Done_AnimationComplete(State As Boolean)
   
       If State Then
               
                   Button1.Text = "" 'FontAwesome Arrow down

                Else
                   
                      Button1.Text = "" 'FontAwesome Arrow up
                       
       End If
               
End Sub

Code from CustomButtonClass
B4X:
#Event: AnimationComplete(State As Boolean)

Private Sub Class_Globals

                                Private r As Reflector
                               
                    Private SlidingPanel As Panel
                    Private downY As Int
                    Private ACTION_UP, ACTION_DOWN, ACTION_MOVE As Int
                               
                                Private IsSheetOpen As Boolean
                               
                                Private cCallback As Object
                                Private cEventName As String

End Sub

Public Sub Initialize(Parent As Activity, Callback As Object, EventName As String,    LayoutContainer As Panel)
           
                            cCallback = Callback
                            cEventName = EventName
                           
                            ACTION_UP = Parent.ACTION_UP
                            ACTION_DOWN = Parent.ACTION_DOWN
                            ACTION_MOVE = Parent.ACTION_MOVE
                           
                            SlidingPanel = LayoutContainer
                           
                            r.Target = SlidingPanel
                r.SetOnTouchListener("SlidingPanel_Touch")                          
         
                            Parent.AddView(LayoutContainer, 0dip, 100%y - 50dip, 100%x, LayoutContainer.GetView(0).Height*.7)

End Sub

'Open the CustomBottomSheet.
Public Sub OpenBottomSheet
   
          IsSheetOpen = True
                           
                            SlidingPanel.Top = 100%y - SlidingPanel.Height
                           
                      If SubExists(cCallback, cEventName & "_AnimationComplete") Then
                   
             CallSubDelayed2(cCallback, cEventName & "_AnimationComplete", IsSheetOpen)
                                       
          End If
   
End Sub

'Close the CustomBottomSheet.
Public Sub CloseBottomSheet
   
          IsSheetOpen = False
                           
                            SlidingPanel.Top = 100%y - 50dip
                           
                      If SubExists(cCallback, cEventName & "_AnimationComplete") Then
                   
             CallSubDelayed2(cCallback, cEventName & "_AnimationComplete", IsSheetOpen)
                                       
          End If                          
                 
End Sub

Public Sub IsOpen As Boolean
   
          Return IsSheetOpen
   
End Sub


Private Sub SlidingPanel_Touch(Obj As Object, Action As Int, X As Float, Y As Float, Motion As Object) As Boolean

                                If Action = ACTION_DOWN Then

           downY = Y

        End If
                               
                                If Action = ACTION_MOVE Then

           SlidingPanel.Top = SlidingPanel.Top + Y - downY
                                           
                                            If SlidingPanel.Top > 100%y - 50dip Then SlidingPanel.Top = 100%y - 50dip
                                            If SlidingPanel.Top < 100%y - SlidingPanel.Height Then SlidingPanel.Top = 100%y - SlidingPanel.Height

                                End If
                               
                                If Action = ACTION_UP Then
                                   
                                      If SlidingPanel.Top + 50dip < 100%y - SlidingPanel.Height / 3 Then
                                               
                                                  SlidingPanel.Top = 100%y - SlidingPanel.Height 'Open
                                                       
                                                     IsSheetOpen = True
                                                       
                                                        If SubExists(cCallback, cEventName & "_AnimationComplete") Then
                           
                                      CallSubDelayed2(cCallback, cEventName & "_AnimationComplete", IsSheetOpen)
                                       
                                   End If
                                                       
                                      End If
                                           
                                            If SlidingPanel.Top + SlidingPanel.Height > 100%y Then
                                               
                                                  SlidingPanel.Top = 100%y - 50dip 'Close
                                                       
                                                     IsSheetOpen = False
                                                       
                                                        If SubExists(cCallback, cEventName & "_AnimationComplete") Then
                           
                                      CallSubDelayed2(cCallback, cEventName & "_AnimationComplete", IsSheetOpen)
                                       
                                   End If                                                      
                                                       
                                            End If

        End If
                               
        Return True
                       
End Sub

Please advice
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is that possible at version B4A 9.80.
1. No reason to use an old version of B4A.

2. You can of course create anything you like in the activity. Do you want to show the activity above other apps?

3. You should learn how to use resumable subs that return value. The CallSubDelayed calls are not needed.

Button1.Text = "" 'FontAwesome Arrow down
This is not the correct way to show icons. Use the built-in icon picker.
 
Upvote 0
Top