ARCore-Location
ARCore-Location copied to clipboard
Multiple Custom marker layout Viewrendering issue
The LocationMarker's setRenderEvent block calls after a long time When i add my custom layout ( too many UI components are available in layout ) using CompletableFuture<ViewRenderable> and CompletableFuture.allOf(exampleLayout). So, it creates positioning issue in rendered Locationmarkers. Please let me know how can overcome with this issue.
Here is my code:
< for (int i = 0; i < listApi.size() ; i++) {
CompletableFuture<ViewRenderable> exampleLayout;
if (listApi.get(i).getType().toLowerCase().equalsIgnoreCase("lenses")) {
//inflate lenses layout
exampleLayout =
ViewRenderable.builder()
.setView(getApplicationContext(), R.layout.layout_pin_lense)
.build();
} else {
//inflate other pin layout
exampleLayout =
ViewRenderable.builder()
.setView(getApplicationContext(), R.layout.layout_pin)
.build();
}
// When you build a Renderable, Sceneform loads its resources in the background while returning
// a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get().
int index = i;
CompletableFuture.allOf(exampleLayout)
.handle((notUsed, throwable) -> {
int finalI1 = (index >= listApi.size()) ? -1 : index;
if (finalI1 < 0) return null;
// When you build a Renderable, Sceneform loads its resources in the background while
// returning a CompletableFuture. Call handle(), thenAccept(), or check isDone()
// before calling get().
if (throwable != null) {
DemoUtils.displayError(getApplicationContext(), "Unable to load renderables", throwable);
return null;
}
try {
ViewRenderable eView = exampleLayout.get();
Node base = new Node();
base.setRenderable(eView);
//Context c = this;
// Add listeners etc here
/*eView.getView().setOnTouchListener((v, event) -> {
Toast.makeText(
getApplicationContext(), "Location marker touched.", Toast.LENGTH_LONG)
.show();
return false;
});*/
eView.getView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//CommonUtils.makeToast(listToSet.get(finalI1).getPlaceName(), DashBoardMainActivity.this);
//showAlertDialogPinDetail(listToSet.get(finalI1));
if (finalI1 < listApi.size()) {
//if type is not lenses then open pin detail
if (!listApi.get(finalI1).getType().toLowerCase().equalsIgnoreCase("lenses")) {
showAlertDialogPinDetail(listApi.get(finalI1), finalI1);
}
}
}
});
LocationMarker layoutLocationMarker = new LocationMarker(
Double.parseDouble(listApi.get(finalI1).getLongitude()),
Double.parseDouble(listApi.get(finalI1).getLattitude()),
base
);
// An example "onRender" event, called every frame
// Updates the layout with the markers distance
layoutLocationMarker.setRenderEvent(node -> {
try {
System.out.println("Position inner child @@@@@@@@@@@ " + finalI1);
View eView1 = eView.getView();
if (listApi.get(finalI1).getType().toLowerCase().equalsIgnoreCase("lenses")) {
//lenses design
CircleImageView imgUser = eView1.findViewById(R.id.imgUser);
LinearLayout llMain = eView1.findViewById(R.id.llMain);
TextView tvUsername = eView1.findViewById(R.id.tvUsername);
TextView tvMsg = eView1.findViewById(R.id.tvMsg);
TextView tvWebsite = eView1.findViewById(R.id.tvWebsite);
TextView tvStartingDateValue = eView1.findViewById(R.id.tvStartingDateValue);
TextView tvEndDateValue = eView1.findViewById(R.id.tvEndDateValue);
tvUsername.setText(listApi.get(finalI1).getFullname());
tvMsg.setText(listApi.get(finalI1).getMessage());
tvWebsite.setText(listApi.get(finalI1).getWebsite());
//put space
String start_date = listApi.get(finalI1).getStart_date();
if (CommonUtils.isValidString(start_date)) {
tvStartingDateValue.setText(" " + CommonUtils.getConvertedDate("dd/MM/yyyy",
"dd MMM, yyyy", start_date));
}
//put space
String end_date = listApi.get(finalI1).getEnd_date();
if (CommonUtils.isValidString(end_date)) {
tvEndDateValue.setText(" " + CommonUtils.getConvertedDate("dd/MM/yyyy",
"dd MMM, yyyy", end_date));
}
//set image
String imageVal = listApi.get(finalI1).getImage();
if (CommonUtils.isValidString(imageVal)) {
if (imageVal.startsWith("http") || imageVal.startsWith("www")) {
//do not append url load it
CommonUtils.setUserImageGlide(DashBoardMainActivity.this, imageVal, imgUser);
} else {
//append image url
CommonUtils.setUserImageGlide(DashBoardMainActivity.this, WebServicesAPI.IMAGE_URL_APPEND + imageVal, imgUser);
}
} else {
CommonUtils.setUserImageGlide(DashBoardMainActivity.this, "", imgUser);
}
} else {
//other pin detail
CircleImageView imgUser = eView1.findViewById(R.id.imgUser);
LinearLayout llMain = eView1.findViewById(R.id.llMain);
TextView tvUsername = eView1.findViewById(R.id.tvUsername);
TextView tvMsg = eView1.findViewById(R.id.tvMsg);
TextView tvTimeDate = eView1.findViewById(R.id.tvTimeDate);
TextView tvLikeNumber = eView1.findViewById(R.id.tvLikeNumber);
TextView tvShareNumber = eView1.findViewById(R.id.tvShareNumber);
if (listApi.get(finalI1).getType().toLowerCase().equalsIgnoreCase("private")) {
//private
llMain.setBackground(CommonUtils.getDrawables(DashBoardMainActivity.this, R.drawable.blue_bubble));
} else if (listApi.get(finalI1).getType().toLowerCase().equalsIgnoreCase("public")) {
//public
llMain.setBackground(CommonUtils.getDrawables(DashBoardMainActivity.this, R.drawable.green_bubble));
}
//set like unlike images
if (listApi.get(finalI1).getMessage_likes().equalsIgnoreCase("0")) {
tvLikeNumber.setCompoundDrawablesWithIntrinsicBounds(CommonUtils.getDrawables(DashBoardMainActivity.this, R.drawable.unlike_big), null, null, null);
} else {
tvLikeNumber.setCompoundDrawablesWithIntrinsicBounds(CommonUtils.getDrawables(DashBoardMainActivity.this, R.drawable.like_big_pin_detail), null, null, null);
}
tvUsername.setText(listApi.get(finalI1).getFullname());
tvMsg.setText(listApi.get(finalI1).getMessage());
tvTimeDate.setText(listApi.get(finalI1).getTime());
tvLikeNumber.setText(listApi.get(finalI1).getLike());
tvShareNumber.setText(listApi.get(finalI1).getReplay());
//set image
String imageVal = listApi.get(finalI1).getImage();
if (CommonUtils.isValidString(imageVal)) {
if (imageVal.startsWith("http") || imageVal.startsWith("www")) {
//do not append url load it
CommonUtils.setUserImageGlide(DashBoardMainActivity.this, imageVal, imgUser);
} else {
//append image url
CommonUtils.setUserImageGlide(DashBoardMainActivity.this, WebServicesAPI.IMAGE_URL_APPEND + imageVal, imgUser);
}
} else {
CommonUtils.setUserImageGlide(DashBoardMainActivity.this, "", imgUser);
}
}
} catch (Exception e) {
e.printStackTrace();
}
/*}*/
});
// Adding the marker
if (!locationScene.mLocationMarkers.contains(layoutLocationMarker)) {
locationScene.mLocationMarkers.add(layoutLocationMarker);
//locationScene.refreshAnchors();
}
} catch (Exception ex) {
ex.printStackTrace();
//DemoUtils.displayError(getApplicationContext(), "Unable to load renderables", ex);
}
return null;
});
/*//TODO: add ar final
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
System.out.println("Position Delay @@@@@@@@@@@ " + index);
}
}, 5000);*/
}
Frame frame = ar_scene_view.getArFrame(); //Frame frame = locationScene.mArSceneView.getArFrame(); if (frame == null) { return; }
if (frame.getCamera().getTrackingState() != TrackingState.TRACKING) {
return;
}
if (locationScene != null) { locationScene.processFrame(frame); }
@Ronakgadhia I have same problem with you. Have you found solution for this issue?