I think I have to create a custom PageRenderer for the ArchitectView? How would I go about this?
Any help greatly appreciated!
Robert
A
Andreas Schacherbauer
said
over 7 years ago
Hi Robert, Right now we do not have any example on how to use our Component with Xamarin Forms as we don't offer the missing glue code to use our Component within a Xamarin Forms application.
You're right, you would need to implement your own PageRenderer like it's described here.
Best regards,
Andreas
R
Robert Wilde
said
over 7 years ago
Thanks!
I'm half way into writing a custom ViewRenderer for the ArchitectView for Android.
namespace Wikitude { public partial class App : Application { public App() { InitializeComponent();
MainPage = new ArchitectViewPage(); } } }
I can't access the StartupConfiguration class in the portable code part of the project. So I created the properties in the custom control and get the values in the platform specific custom renderer.
namespace Wikitude { public class FormsArchitectView : View { #region Bindable Properties public static readonly BindableProperty LicenseKeyProperty = BindableProperty.Create( propertyName: "LicenseKey", returnType: typeof(string), declaringType: typeof(FormsArchitectView), defaultValue: default(string));
namespace Wikitude.Droid { public class ArchitectViewRenderer : ViewRenderer<Wikitude.FormsArchitectView, Wikitude.Architect.ArchitectView> { protected override void OnElementChanged(ElementChangedEventArgs<Wikitude.FormsArchitectView> e) { base.OnElementChanged(e);
if (Control == null) { var architectView = new ArchitectView(Forms.Context); SetNativeControl(architectView); }
if (e.OldElement != null) {
}
if (e.NewElement != null) { var startupConfiguration = new StartupConfiguration(Element.LicenseKey, Element.Feature); architectView.OnCreate(startupConfiguration); } } } }
But I'm stuck. At the moment the app crashes directly after start. Where do I call architectView.OnCreate(startupConfiguration), architectView.OnPostCreate(), and architectView.Load(SAMPLE_WORLD_URL)?
Any help would be greatly appreciated.
Robert
R
Robert Wilde
said
over 7 years ago
Anyone?
A
Andreas Schacherbauer
said
over 7 years ago
Hi Robert, onCreate and onPostCreate are Android application lifecycle methods. You usually call the Wikitude SDK equivalents in the corresponding Android Activity subclass. I'm not sure where to call them in a Xamarin Form ViewRenderer. You can try to call onPostCreate right after onCreate.
Load can be called as soon as you know the Architect World URL. You can try to call it right after onCreate/onPostCreate.
Best regards,
Andreas
R
Robert Wilde
said
over 7 years ago
I've now reached a state where the app does not crash. The app shows the Wikitude logo, and then the camera image. For some unknown reason it does not load the world located in "Assets/samples/1_Client$Recognition_1_Image$On$Target/index.html".
There's no error message when calling architectView.load except a log stating " ImeThread is not enabled."
A
Andreas Schacherbauer
said
over 7 years ago
Hi Robert, The Architect World path that you pass is correct? You can implement the 'ArchitectView.ArchitectWorldLoadedListener' to get a callback in case the Wikitude SDK is unable to load the Architect World from a given URL.
The console log you posted is not from the Wikitdue SDK.
Best regards,
Andreas
R
Robert Wilde
said
over 7 years ago
Thanks!
I implemented the listener an it reports that the world was loaded.
I can see the camera image, but it does not show any HTML content, or 3d models.
I get a few logs like:
called unimplemented OpenGL ES API <core_glHint:84>: GL_INVALID_ENUM Cannot call determinedVisibility() - never saw a connection for the pid: 21425
I am not sure if that has anything to do with that. There might be problems with the ArchitectWebView and the Open GL rendering in Xamarin Forms?
A
Andreas Schacherbauer
said
over 7 years ago
Hi Robert, The logs are not directly related to the Wikitude SDK. You find them in our example application as well.
If you don't see any html element, I still guess that the world is not loaded correctly. You could try to attach the device to the Chrome JS debugger and see if there is actually something loaded.
Maybe there are some lifecycle methods missing or called to early, but If you see the camera this already seems fine.
You could try to load any other .html file just to see if our SDK is able to load the web page from the given url.
Best regards,
Andreas
A
Andreas Schacherbauer
said
over 7 years ago
Awesome! Congratulations!
R
Robert Wilde
said
over 7 years ago
Thank you!
I had to set the build action for the sample assets to "Android Asset". When I copied and pasted the world from the sample project to my project, it had set it to "None" instead.
Now it works nicely! Thanks a lot!
C
Chernov.a.vl
said
over 7 years ago
Hey, Robert. I'm trying to accomplish the same task as you. Could you, please, explain how did you handle this issue about calling OnCreate and OnPostCreate methods of ArchitectView from ViewRenderer? I simply call them one after another and all I get is loaded Wikitude control, but without any image from camera, only black screen with html/js controls in it. Thanks in advance.
C
Cyril.lefebvre
said
over 7 years ago
Hi Robert,
Your integration of Wikitude in Xamarin.Forms looks really good !
Can you share the last update of your code please ?
Robert Wilde