A aeropic Active Member Licensed User Longtime User Jun 7, 2014 #1 Hi, I'm using cameraEX class in which the focus done triggers an event (Camera_FocusDone) I would want to modify the main activity layout according to the success of focus done event. I want to make visible a panel (PnlFocus) When I try this code, it fails: Code: Copy Private Sub Camera_FocusDone (Success As Boolean) If Success Then If shoot Then TakePicture Main.PnlFocus.visible = True '<====== FAILS HERE Else Log("AutoFocus error.") ToastMessageShow("unable to focus...", False) 'TakePicture End If End Sub I there a proper way to do this ? Thanks for your help Last edited: Jun 7, 2014
Hi, I'm using cameraEX class in which the focus done triggers an event (Camera_FocusDone) I would want to modify the main activity layout according to the success of focus done event. I want to make visible a panel (PnlFocus) When I try this code, it fails: Code: Copy Private Sub Camera_FocusDone (Success As Boolean) If Success Then If shoot Then TakePicture Main.PnlFocus.visible = True '<====== FAILS HERE Else Log("AutoFocus error.") ToastMessageShow("unable to focus...", False) 'TakePicture End If End Sub I there a proper way to do this ? Thanks for your help
Kjell Member Licensed User Longtime User Jun 7, 2014 #2 You write: I would want to modify the main activity layout according to the success of focus done event. I want to make visible a panel (PnlFocusDone) Click to expand... But the code sais: Code: Copy Main.PnlFocus.visible = True '<====== FAILS HERE Should it be? Code: Copy Main.PnlFocusDone.visible = True Upvote 0
You write: I would want to modify the main activity layout according to the success of focus done event. I want to make visible a panel (PnlFocusDone) Click to expand... But the code sais: Code: Copy Main.PnlFocus.visible = True '<====== FAILS HERE Should it be? Code: Copy Main.PnlFocusDone.visible = True
udg Expert Licensed User Longtime User Jun 7, 2014 #3 Hi, not yet used the CameraEx class, but if, as I believe, your Sub Camera_FocusDone is part of the class you could call a specialized sub in Main where you do all the settings you need. I mean something like: Code: Copy 'in camera class sub PrivateSub Camera_FocusDone (Success AsBoolean) If Success Then If shoot Then TakePicture CallSubDelayed2(main, "ShowPanel", True) ... end sub 'in main Sub ShowPanel(show as boolean) PnlFocus.visible = show end sub Or you can pass on class Initialize (or even to a different sub) reference to the calling Activity and use that to reach its elements like CallingActivity.GetView(x).... Umberto Upvote 0
Hi, not yet used the CameraEx class, but if, as I believe, your Sub Camera_FocusDone is part of the class you could call a specialized sub in Main where you do all the settings you need. I mean something like: Code: Copy 'in camera class sub PrivateSub Camera_FocusDone (Success AsBoolean) If Success Then If shoot Then TakePicture CallSubDelayed2(main, "ShowPanel", True) ... end sub 'in main Sub ShowPanel(show as boolean) PnlFocus.visible = show end sub Or you can pass on class Initialize (or even to a different sub) reference to the calling Activity and use that to reach its elements like CallingActivity.GetView(x).... Umberto
LucaMs Expert Licensed User Longtime User Jun 7, 2014 #4 In general, you can pass objects to classes, including Activities. In addition, you can call a method of TargetModule caller (the activity, in this case) using CallSubDelayed (look for it on the site). In this case, I imagine that the Panel1 you pass to the initialization is the panel that you want to manage. So, you can create a global private variable, for example mActPanel, and set: mActPanel = Panel1 in the Initialize; then: Code: Copy Private Sub Camera_FocusDone (Success As Boolean) If Success Then If shoot Then TakePicture mActPanel = True '<====== FAILS HERE Else Log("AutoFocus error.") ToastMessageShow("unable to focus...", False) 'TakePicture End If End Sub (Umberto was faster ) Upvote 0
In general, you can pass objects to classes, including Activities. In addition, you can call a method of TargetModule caller (the activity, in this case) using CallSubDelayed (look for it on the site). In this case, I imagine that the Panel1 you pass to the initialization is the panel that you want to manage. So, you can create a global private variable, for example mActPanel, and set: mActPanel = Panel1 in the Initialize; then: Code: Copy Private Sub Camera_FocusDone (Success As Boolean) If Success Then If shoot Then TakePicture mActPanel = True '<====== FAILS HERE Else Log("AutoFocus error.") ToastMessageShow("unable to focus...", False) 'TakePicture End If End Sub (Umberto was faster )
LucaMs Expert Licensed User Longtime User Jun 7, 2014 #5 Better yet: In the Class Code: Copy Private Sub Camera_FocusDone (Success As Boolean) If Success Then TakePicture If SubExists(target, event & "_" & "FocusDone") Then CallSubDelayed(target, event & "_" & "FocusDone") End If Else Log("AutoFocus error.") End If End Sub In the Activity Code: Copy Private Sub Camera1_FocusDone PnlFocus.Visible = False End Sub Upvote 0
Better yet: In the Class Code: Copy Private Sub Camera_FocusDone (Success As Boolean) If Success Then TakePicture If SubExists(target, event & "_" & "FocusDone") Then CallSubDelayed(target, event & "_" & "FocusDone") End If Else Log("AutoFocus error.") End If End Sub In the Activity Code: Copy Private Sub Camera1_FocusDone PnlFocus.Visible = False End Sub
A aeropic Active Member Licensed User Longtime User Jun 7, 2014 #6 Thanks a lot for your helpfull answers. I finished with Luca's solution adding a panel in the CameraEX class Initialize sub : Code: Copy Public Sub Initialize (Panel1 As Panel, FrontCamera As Boolean, TargetModule As Object, EventName As String, panelfocus As Panel) target = TargetModule event = EventName Front = FrontCamera pFocus = panelfocus coupled with the pFocus panel declared as global to the class, it is exactly what I was searching for. The event raising option is very interesting as it could be, indeed, a better way to decouple the class and the main... @udg : the callsubdelay is of course another solution @kjll : you're right my question was misleading, there was a typo in (PnlFocusDone) ==> I edited the post to (PnlFocus) Upvote 0
Thanks a lot for your helpfull answers. I finished with Luca's solution adding a panel in the CameraEX class Initialize sub : Code: Copy Public Sub Initialize (Panel1 As Panel, FrontCamera As Boolean, TargetModule As Object, EventName As String, panelfocus As Panel) target = TargetModule event = EventName Front = FrontCamera pFocus = panelfocus coupled with the pFocus panel declared as global to the class, it is exactly what I was searching for. The event raising option is very interesting as it could be, indeed, a better way to decouple the class and the main... @udg : the callsubdelay is of course another solution @kjll : you're right my question was misleading, there was a typo in (PnlFocusDone) ==> I edited the post to (PnlFocus)