I am working on a project where people can leave comments in AR at specific locations. To test this I was trying to have it display some test messages.
public void getStarted(Anchor anchor){
ArrayList<String> comments = new ArrayList<String>();
comments.add("Have a nice day");
for (String x : comments) {
if (closeEnough()) {
ViewRenderable.builder()
.setView(x, )
.build()
.thenAccept(renderable -> placeComment(anchor, renderable, comments));
}
}
}
I was able to test it and it crashes when you try to place the test view. It crashes when .build() is called. Do you have any suggestions for fixing this?
I'll add the function leading up to the one before.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkSystemSupport(this)) {
Button button = (Button) findViewById(R.id.button);
arCam = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.arCameraArea);
arCam.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
Anchor anchor = hitResult.createAnchor();
getStarted((anchor));
});
}
}
And the one that does the placing and edit of the text.
private void placeComment(Anchor anchor, @NonNull ViewRenderable renderable, String comments) {
TextView t = renderable.getView().findViewById(R.id.post);
t.setText(comments);
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arCam.getArSceneView().getScene());
TransformableNode model = new TransformableNode(arCam.getTransformationSystem());
model.setParent(anchorNode);
model.setRenderable(renderable);
model.select();
}