Q qsrtech Active Member Licensed User Longtime User Jun 2, 2015 #1 I thought Code: Copy if obj is activity then else end if but it doesn't work. Any other way to test if "obj" is an activity? EDIT: For now I've resorted to using a try/catch/finally until a better way is established Last edited: Jun 2, 2015
I thought Code: Copy if obj is activity then else end if but it doesn't work. Any other way to test if "obj" is an activity? EDIT: For now I've resorted to using a try/catch/finally until a better way is established
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #2 If GetType(obj) = "android.widget.FrameLayout" Then IsActivity = True Upvote 0
Q qsrtech Active Member Licensed User Longtime User Jun 2, 2015 #3 hmmm. idk if I did something wrong but the activity is coming up as "java.lang.Class" Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jun 2, 2015 #4 You can use this code: Code: Copy Sub IsActivity(obj As Object) As Boolean If Not(obj Is Panel) Then Return False Dim jo As JavaObject = obj Dim parent As Object = jo.RunMethod("getParent", Null) Return parent <> Null And (GetType(parent) = "android.widget.FrameLayout" Or _ GetType(parent) = "anywheresoftware.b4a.objects.IME$ExtendedBALayout") End Sub Upvote 0
You can use this code: Code: Copy Sub IsActivity(obj As Object) As Boolean If Not(obj Is Panel) Then Return False Dim jo As JavaObject = obj Dim parent As Object = jo.RunMethod("getParent", Null) Return parent <> Null And (GetType(parent) = "android.widget.FrameLayout" Or _ GetType(parent) = "anywheresoftware.b4a.objects.IME$ExtendedBALayout") End Sub
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #5 Erel said: You can use this code: Code: Copy Sub IsActivity(obj As Object) As Boolean If Not(obj Is Panel) Then Return False Dim jo As JavaObject = obj Dim parent As Object = jo.RunMethod("getParent", Null) Return parent <> Null And (GetType(parent) = "android.widget.FrameLayout" Or _ GetType(parent) = "anywheresoftware.b4a.objects.IME$ExtendedBALayout") End Sub Click to expand... This means that the Module Scale should be updated, given that my answer is part of it Upvote 0
Erel said: You can use this code: Code: Copy Sub IsActivity(obj As Object) As Boolean If Not(obj Is Panel) Then Return False Dim jo As JavaObject = obj Dim parent As Object = jo.RunMethod("getParent", Null) Return parent <> Null And (GetType(parent) = "android.widget.FrameLayout" Or _ GetType(parent) = "anywheresoftware.b4a.objects.IME$ExtendedBALayout") End Sub Click to expand... This means that the Module Scale should be updated, given that my answer is part of it
Erel B4X founder Staff member Licensed User Longtime User Jun 2, 2015 #6 Not sure that I understand??? Upvote 0
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #7 Erel said: Not sure that I understand??? Click to expand... My code, post #2, is part of Module Scale; if it is not correct, we should (must) replace it with yours. Upvote 0
Erel said: Not sure that I understand??? Click to expand... My code, post #2, is part of Module Scale; if it is not correct, we should (must) replace it with yours.
Erel B4X founder Staff member Licensed User Longtime User Jun 2, 2015 #8 Your code as it is, is not clear. What is obj? I guess that you copied a small part of a larger code snippet. So it is impossible to say whether it is correct or not. Upvote 0
Your code as it is, is not clear. What is obj? I guess that you copied a small part of a larger code snippet. So it is impossible to say whether it is correct or not.
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #9 Erel, my obj is the @qsrtech's obj and in Module Scale there is: Code: Copy Public Sub IsActivity(v As View) As Boolean Dim obj As Object obj = GetParent(v) If GetType(obj) = "android.widget.FrameLayout" Then Return True Else Return False End If End Sub Upvote 0
Erel, my obj is the @qsrtech's obj and in Module Scale there is: Code: Copy Public Sub IsActivity(v As View) As Boolean Dim obj As Object obj = GetParent(v) If GetType(obj) = "android.widget.FrameLayout" Then Return True Else Return False End If End Sub
Erel B4X founder Staff member Licensed User Longtime User Jun 2, 2015 #10 The code you now posted is 99% correct (though you still didn't post the GetParent sub). The only case where it will not work is if someone uses IME.AddHeightChangedEvent. Upvote 0
The code you now posted is 99% correct (though you still didn't post the GetParent sub). The only case where it will not work is if someone uses IME.AddHeightChangedEvent.
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #11 Erel said: The code you now posted is 99% correct (though you still didn't post the GetParent sub). Click to expand... I did not need of GetParent ! @qsrtech required only if OBJ is an Activity. Upvote 0
Erel said: The code you now posted is 99% correct (though you still didn't post the GetParent sub). Click to expand... I did not need of GetParent ! @qsrtech required only if OBJ is an Activity.
Erel B4X founder Staff member Licensed User Longtime User Jun 2, 2015 #12 You need to understand how the code works... It tests the object parent to see whether it is a frame layout or not. The activity itself is the same native object as a panel. Upvote 0
You need to understand how the code works... It tests the object parent to see whether it is a frame layout or not. The activity itself is the same native object as a panel.
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #13 Well I'm lost, and I can say: "luckily" because you can use: IsActivity(AnyDeclaredView) but you can not use: IsActivity(SecondActivity) where SecondActivity should be an activity object, but it is only a class! Please, do not answer or I will be forced to go to study Android + Java + Eclipse and then seek a mental hospital still open Upvote 0
Well I'm lost, and I can say: "luckily" because you can use: IsActivity(AnyDeclaredView) but you can not use: IsActivity(SecondActivity) where SecondActivity should be an activity object, but it is only a class! Please, do not answer or I will be forced to go to study Android + Java + Eclipse and then seek a mental hospital still open
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #14 Well, if obj (#1) is an activity object, "is activity" works. Code: Copy Sub Activity_Create(FirstTime As Boolean) pnl.Initialize("") Activity.AddView(pnl, 0, 0, 50dip, 50dip) Dim Parent As Object = GetParent(pnl) If Parent Is Activity Then Log("Yes") Else Log("No") End If End Sub Code: Copy Sub GetParent(v As View) As Object Dim jobj = v As JavaObject Return jobj.RunMethod("getParent", Null) End Sub Upvote 0
Well, if obj (#1) is an activity object, "is activity" works. Code: Copy Sub Activity_Create(FirstTime As Boolean) pnl.Initialize("") Activity.AddView(pnl, 0, 0, 50dip, 50dip) Dim Parent As Object = GetParent(pnl) If Parent Is Activity Then Log("Yes") Else Log("No") End If End Sub Code: Copy Sub GetParent(v As View) As Object Dim jobj = v As JavaObject Return jobj.RunMethod("getParent", Null) End Sub
Q qsrtech Active Member Licensed User Longtime User Jun 2, 2015 #15 LucaMs said: Well, if obj (#1) is an activity object, "is activity" works. Code: Copy Sub Activity_Create(FirstTime As Boolean) pnl.Initialize("") Activity.AddView(pnl, 0, 0, 50dip, 50dip) Dim Parent As Object = GetParent(pnl) If Parent Is Activity Then Log("Yes") Else Log("No") End If End Sub Code: Copy Sub GetParent(v As View) As Object Dim jobj = v As JavaObject Return jobj.RunMethod("getParent", Null) End Sub Click to expand... I think it's because the parent is the actual activity you are calling it in. I suspect it won't work if the "parent" is from another activity. Anyway, i'm moving away from using multiple activities within in an app. I mainly needed this piece of code temporarily while testing. I would encourage others to do the same, especially to make your app more ready for other platforms. Another benefit is you can make use of a drawer much easier. Now if we could only get a template feature it would sure help in the process. Btw, how's things going with you? You probably noticed i was absent for quite a while. B4i kinda pulled me back in Upvote 0
LucaMs said: Well, if obj (#1) is an activity object, "is activity" works. Code: Copy Sub Activity_Create(FirstTime As Boolean) pnl.Initialize("") Activity.AddView(pnl, 0, 0, 50dip, 50dip) Dim Parent As Object = GetParent(pnl) If Parent Is Activity Then Log("Yes") Else Log("No") End If End Sub Code: Copy Sub GetParent(v As View) As Object Dim jobj = v As JavaObject Return jobj.RunMethod("getParent", Null) End Sub Click to expand... I think it's because the parent is the actual activity you are calling it in. I suspect it won't work if the "parent" is from another activity. Anyway, i'm moving away from using multiple activities within in an app. I mainly needed this piece of code temporarily while testing. I would encourage others to do the same, especially to make your app more ready for other platforms. Another benefit is you can make use of a drawer much easier. Now if we could only get a template feature it would sure help in the process. Btw, how's things going with you? You probably noticed i was absent for quite a while. B4i kinda pulled me back in
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #16 The problem is that I have already forgotten a lot 'of things . When you use "Me" or an Activity name, for example StartActivity(...), the parameter is a class name, not an object, instance of an Activity. You can use another Activity but obj must "contain" an Activity, not its class name. I think that rarely you can use one Activity only, without going crazy with dozens of views and panels. qsrtech said: Btw, how's things going with you? You probably noticed i was absent for quite a while. B4i kinda pulled me back in Click to expand... I should answer with a not nice word, like sht, but I can't So, welcome back Upvote 0
The problem is that I have already forgotten a lot 'of things . When you use "Me" or an Activity name, for example StartActivity(...), the parameter is a class name, not an object, instance of an Activity. You can use another Activity but obj must "contain" an Activity, not its class name. I think that rarely you can use one Activity only, without going crazy with dozens of views and panels. qsrtech said: Btw, how's things going with you? You probably noticed i was absent for quite a while. B4i kinda pulled me back in Click to expand... I should answer with a not nice word, like sht, but I can't So, welcome back
Q qsrtech Active Member Licensed User Longtime User Jun 2, 2015 #17 LucaMs said: I think that rarely you can use one Activity only, without going crazy with dozens of views and panels So, welcome back Click to expand... Actually it's quite easy and more flexible. You simply convert your activity to a class and have a panel within that class that you load your layout into. I'll post a skeleton class when i get to my comp. In your main activity you simply handle the showing/hiding of the form classes. It's basically how you need to do it in b4i so it's better to do it in b4a as well. Another benefit is you can create multi windows a lot easier. A good example would be spreadsheet pages. I think i'll create a navigation class like the one in b4i to handle all the "page" stuff in b4a. Then it's just a matter of a few conditionals and b4a apps are pretty much ready for b4i. There's a great tool to significantly help convert b4a layouts to b4i. (Just wish it was a more drag and drop tool vs cmd line) Of course android is far superior to ios but unfortunately with around 30% of the market share i have no choice but to support it. Thanks Edit: I should add with classes vs activities, you don't have all the issues of recreating you activity everytime you switch between them (and saving state) Upvote 0
LucaMs said: I think that rarely you can use one Activity only, without going crazy with dozens of views and panels So, welcome back Click to expand... Actually it's quite easy and more flexible. You simply convert your activity to a class and have a panel within that class that you load your layout into. I'll post a skeleton class when i get to my comp. In your main activity you simply handle the showing/hiding of the form classes. It's basically how you need to do it in b4i so it's better to do it in b4a as well. Another benefit is you can create multi windows a lot easier. A good example would be spreadsheet pages. I think i'll create a navigation class like the one in b4i to handle all the "page" stuff in b4a. Then it's just a matter of a few conditionals and b4a apps are pretty much ready for b4i. There's a great tool to significantly help convert b4a layouts to b4i. (Just wish it was a more drag and drop tool vs cmd line) Of course android is far superior to ios but unfortunately with around 30% of the market share i have no choice but to support it. Thanks Edit: I should add with classes vs activities, you don't have all the issues of recreating you activity everytime you switch between them (and saving state)
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #18 Good, become a B4i expert, so when I have released an Android app (2059 ), I will ask you to convert it to iOS. qsrtech said: In your main activity you simply handle the showing/hiding of the form classes Click to expand... ... and write in the Main Activity all the code needed for "each Activity", including events. Uhm... mumble mumble Upvote 0
Good, become a B4i expert, so when I have released an Android app (2059 ), I will ask you to convert it to iOS. qsrtech said: In your main activity you simply handle the showing/hiding of the form classes Click to expand... ... and write in the Main Activity all the code needed for "each Activity", including events. Uhm... mumble mumble
Q qsrtech Active Member Licensed User Longtime User Jun 2, 2015 #19 LucaMs said: Good, become a B4i expert, so when I have released an Android app (2059 ), I will ask you to convert it to iOS. ... and write in the Main Activity all the code needed for "each Activity", including events. Uhm... mumble mumble Click to expand... No silly, all the events are handled within the class. You only call back the main activity if you need to, probably not much different than what you do now with inter-activity stuff. Upvote 0
LucaMs said: Good, become a B4i expert, so when I have released an Android app (2059 ), I will ask you to convert it to iOS. ... and write in the Main Activity all the code needed for "each Activity", including events. Uhm... mumble mumble Click to expand... No silly, all the events are handled within the class. You only call back the main activity if you need to, probably not much different than what you do now with inter-activity stuff.
LucaMs Expert Licensed User Longtime User Jun 2, 2015 #20 Sorry, I can not see the benefits. Let's see if I understood. You have the Activity Main, in which you declare x number of classes, we could call them "Activity classes". Then, at any given time, you use that class and show its layout within a panel. The class is generic, it does not contain specific code, so all the app code is contained in the Main Activity. Is it so? Upvote 0
Sorry, I can not see the benefits. Let's see if I understood. You have the Activity Main, in which you declare x number of classes, we could call them "Activity classes". Then, at any given time, you use that class and show its layout within a panel. The class is generic, it does not contain specific code, so all the app code is contained in the Main Activity. Is it so?