B4A Library fgCustomDialog ( Modal-Dialog)

Star-Dust

Expert
Licensed User
Longtime User
You've created a new activity to hook up the Box panel. I doubt it can make the activity completely transparent.

In my MessageBox class I hooked up a transparent panel into the main Activity that you can pass as a parameter.

In CustomView, you can go back to activity with the "parent" method by scrolling through the views starting from the DesignerCreateView "Base" Panel.
 

Star-Dust

Expert
Licensed User
Longtime User
I tried yesterday the code I saw on my device did not have the desired effect. My own however was just a tip
 

Star-Dust

Expert
Licensed User
Longtime User
I realized that the problem was that because they were used as library in other App that did not have the Translucent attribute did not have the same effect, so I suggested the solution I adopted. :):):)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You still need to add the attribute with the manifest editor. You need to specify the full name:
B4X:
SetActivityAttribute(b4a.example.actcustomdialog, android:theme, @android:style/Theme.Translucent.NoTitleBar)
It will work in release mode. It will fail in debug mode due to an issue with compiled libraries with activities.

I think that it is not a good idea to implement it with Activity as it causes the parent activity to jump and the style is different. A regular panel will behave better, even if the developer needs to add three lines of code to Activity_Keypress event.
 

Star-Dust

Expert
Licensed User
Longtime User
... A regular panel will behave better, even if the developer needs to add three lines of code to Activity_Keypress event.

Thanks @Erel, this solution also affects me. Is it possible to handle the Activity_KeyPressed event from a Class?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The Activity_Keypress event will be raised in the activity.
You can create a sub such as:
B4X:
Public Sub CallFromKeyPress(Keycode As Int) As Boolean
 If DialogIsVisible AND Keycode = 4 Then '4 = BACK
   'close dialog
   Return True
 Else
   Return False
 End If
End Sub

The user will call it with:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 
   If MyDialog.CallFromKeyPress(KeyCode) Then Return True
   'other code here if needed
End Sub

It would be nice if one could also program Modale dialogues with B4x
Modal dialogs are being replaced with async dialogs: DoEvents deprecated and async dialogs (msgbox)
 

Star-Dust

Expert
Licensed User
Longtime User
[/code]

The user will call it with:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
   If MyDialog.CallFromKeyPress(KeyCode) Then Return True
   'other code here if needed
End Sub

I wonder how he did Andrew Graham in his Dialogs Library to intercept the key back.

Also the Dialogs library goes up hook up the Activity dialogs window? And how do you go back to the activity as destined in this thread to post # 2?

I saw that you updated the Dialogs Libray, I think you had to deal with these questions.

Thank's
 

Star-Dust

Expert
Licensed User
Longtime User
Hi @Filippo, I found a solution to engage KEYCODE_BACK without crunching the activity, I tried on my Library.

Thanks to this thread I found a new solution: https://www.b4x.com/android/forum/t...n-a-class-two-times-called.80594/#post-510504
it seems that you can intercept KeyPress on EditText.
So I inserted a EditText object with external coordinates to the display (-30dip, -30dip) so it is invisible.

Set focus to edittext and then intercept the keypress ... the rest and easy ...
 

Star-Dust

Expert
Licensed User
Longtime User
On my Library
B4X:
Public Sub Initialize(MyActivity As Activity, Me_CallBack As Object,EventName As String)
    My=MyActivity
    CallBack=Me_CallBack
    If EventName.IndexOf("_")=-1 Then Event=EventName  & "_Response" Else Event="@" & EventName
    IsInitialized=True
   
    Dim E As EditText
    E.Initialize("")
    MyActivity.AddView(e,-30dip,-30dip,30dip,30dip)
    e.RequestFocus
    SetReflector(e)
End Sub

Public Sub SetReflector(v As View)
    Dim r As Reflector
    r.Target = v
    r.SetOnKeyListener("On_KeyPress")
    r.RunMethod2("setFocusable", "True", "java.lang.boolean")
    r.RunMethod2("setFocusableInTouchMode", "True", "java.lang.boolean")
End Sub

Private Sub On_KeyPress(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
 
        Dim j As JavaObject = KeyEvent
        Dim eventCode As Int = j.RunMethod("getAction",Null)
        If (eventCode = 0) Then
            Response=DialogResponse.CANCEL
            Pan.RemoveView
            T.Enabled=False
            If SubExists(CallBack,Event) Then CallSub2(CallBack,Event,Response)
            If SubExists(CallBack,Event.Replace("@","")) And Event.IndexOf("@")>-1 Then CallSub(CallBack,Event.Replace("@",""))
            End If
        Return True
    Else
        Return False
    End If
End Sub
 
Top