Skip to content

Commit

Permalink
- Changed long click delete ar marker from asset to agent info (#90)
Browse files Browse the repository at this point in the history
- Smaller ar assets default scale
  • Loading branch information
t-constantin authored Nov 24, 2021
1 parent ed16dc8 commit c617c99
Showing 1 changed file with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setAgentUI(null);
setAgentUI(null, null);
}

@Override
Expand All @@ -160,7 +160,7 @@ private void setSelectedAgent(Agent agent) {
agent.deleteObserver(agentBuzzCommandObserver);
}
currentSelectedAgent = agent;
setAgentUI(agent);
setAgentUI(agent, null);
}

private void initializeRenderables() {
Expand Down Expand Up @@ -291,7 +291,7 @@ private void updateCommands(Agent agent) {
}
}

private void setAgentUI(Agent agent) {
private void setAgentUI(Agent agent, Node transformableNode) {
Boolean isAgentSelected = agent != null;

FloatingActionButton refreshCommands = getView().findViewById(R.id.refresh_agent_commands);
Expand All @@ -305,6 +305,33 @@ private void setAgentUI(Agent agent) {
});
}

if (transformableNode != null) {
getView().findViewById(R.id.agent_ar_selected).setOnLongClickListener(view -> {
// Open delete popup
String alertMsg = "Delete Current Selected AR Marker?";
new AlertDialog.Builder(requireContext())
.setTitle("Unrelevant AR Marker")
.setMessage(alertMsg)
.setPositiveButton("Yes", (dialog, whichButton) -> {
timerTextViews.computeIfPresent(agent, (k, v) -> null); // remove from list
AnchorNode arAgentNode = (AnchorNode) transformableNode.getParent();
arFragment.getArSceneView().getScene().removeChild(arAgentNode);
arAgentNode.getAnchor().detach();
arAgentNode.setParent(null);
// If deleting the current selected agent, notify the new value
if (currentSelectedAgent == agent) {
setSelectedAgent(null);
}
}).setNegativeButton("No", (dialog, whichButton) -> {
// Do nothing.
}).show();
return true;
});
} else {
// Remove callback if nothing is selected
getView().findViewById(R.id.agent_ar_selected).setOnLongClickListener(null);
}

LinearLayout agentInfoLayout = getView().findViewById(R.id.agent_ar_selected);
agentInfoLayout.setVisibility(isAgentSelected ? LinearLayout.VISIBLE : LinearLayout.GONE);
TextView agentName = getView().findViewById(R.id.agent_ar_selected_name);
Expand Down Expand Up @@ -479,9 +506,9 @@ private void initARIndicator(AnchorNode parent, Agent agent) {
arAgentRootNode.setName(AR_AGENT_ROOT);
arAgentRootNode.getRotationController().setEnabled(false);
arAgentRootNode.getTranslationController().setEnabled(false);
arAgentRootNode.getScaleController().setMinScale(0.5f);
arAgentRootNode.getScaleController().setMaxScale(1.5f);
arAgentRootNode.setLocalScale(new Vector3(0.75f, 0.75f, 0.75f));
arAgentRootNode.getScaleController().setMinScale(0.25f);
arAgentRootNode.getScaleController().setMaxScale(1.0f);
arAgentRootNode.setLocalScale(new Vector3(0.5f, 0.5f, 0.5f));
arAgentRootNode.setParent(parent);
AlwaysStraightNode indicatorNode = new AlwaysStraightNode();
indicatorNode.setRenderable(arrowRenderable);
Expand Down Expand Up @@ -514,7 +541,7 @@ private void selectAgentFromAR(TransformableNode node, Agent agent) {
agent.deleteObserver(agentBuzzCommandObserver);
}
currentSelectedAgent = agent;
setAgentUI(agent);
setAgentUI(agent, node);
}

private void selectVisualNode(TransformableNode node) {
Expand Down Expand Up @@ -553,27 +580,7 @@ private void setAgentARInfoRenderable(CameraFacingNode tNode, TransformableNode
.thenAccept(viewRenderable -> {
viewRenderable.setShadowCaster(false);
viewRenderable.setShadowReceiver(false);
viewRenderable.getView().findViewById(R.id.ar_view_layout).setOnLongClickListener(view -> {
// Open delete popup
String alertMsg = "Delete Current Selected AR Marker?";
new AlertDialog.Builder(requireContext())
.setTitle("Unrelevant AR Marker")
.setMessage(alertMsg)
.setPositiveButton("Yes", (dialog, whichButton) -> {
timerTextViews.computeIfPresent(agent, (k, v) -> null); // remove from list
AnchorNode arAgentNode = (AnchorNode) tNode.getParent().getParent();
arFragment.getArSceneView().getScene().removeChild(arAgentNode);
arAgentNode.getAnchor().detach();
arAgentNode.setParent(null);
// If deleting the current selected agent, notify the new value
if (currentSelectedAgent == agent) {
setSelectedAgent(null);
}
}).setNegativeButton("No", (dialog, whichButton) -> {
// Do nothing.
}).show();
return true;
});

viewRenderable.getView().findViewById(R.id.ar_view_layout).setOnClickListener(view -> {
selectAgentFromAR(parent, agent);
});
Expand Down

0 comments on commit c617c99

Please sign in to comment.