/** * compare two nodes. two nodes are equals if the tag function return the same value * @param node object to compare * @return true both object have the same tag value */ @Override public boolean equals(Object node) { return (node instanceof Node) && (node == this || getTag().equals(((Node) node).getTag())); }//equals
/** * prepare the arguments to pass to this fragment * * @param n node that this fragment has to manage * @return bundle to pass as argument to a NodeContainerFragment */ public static Bundle prepareArguments(Node n) { Bundle args = new Bundle(); args.putString(NODE_TAG, n.getTag()); return args; }
public static void appendArguments(Intent i,Node n){ Bundle args = new Bundle(); args.putString(NODE_TAG, n.getTag()); i.putExtra(NODE_BUNDLE,args); }
/** * get the device name with some product tag info (BLE Address) * @return the device friendly Name */ public String getFriendlyName(){ if (mFriendlyName == null) { String strTagClean = "NA"; if (getTag() != null && getTag().length() > 0) strTagClean = getTag().replace(":", ""); mFriendlyName = getName() + " @" + strTagClean.substring(strTagClean.length() - Math.min(6, strTagClean.length()), strTagClean.length()); } return mFriendlyName; }//getFriendlyName
/** * if present return the node with that specific tag * * @param tag unique string that identify a node * @return the node with that tag or null if is not present on the list of the discovered node */ public @Nullable Node getNodeWithTag(@NonNull String tag) { synchronized (mDiscoverNode) { for (Node n : mDiscoverNode) { if (n.getTag().equals(tag)) return n; }//for } //synchronized return null; }//getNodeWithTag
/** * insert a node into this manager, the addition will be notify to all the listener * @param newNode node to add * @return true if the node is added, false if a node with the same tag is present */ public boolean addNode(final Node newNode){ synchronized (mDiscoverNode) { String newTag = newNode.getTag(); for(final Node n : mDiscoverNode){ if(newTag.equals(n.getTag())) return false; }//for mDiscoverNode.add(newNode); }//synchronized notifyNewNodeDiscovered(newNode); return true; }//addNode
/** * create an intent for start this activity * * @param c context used for create the intent * @param node node to use for the demo * @return intent for start a demo activity that use the node as data source */ public static Intent getStartIntent(Context c, @NonNull Node node) { Intent i = new Intent(c, FeatureListActivity.class); i.putExtra(NODE_TAG, node.getTag()); i.putExtras(NodeContainerFragment.prepareArguments(node)); return i; }//getStartIntent
/** * create an intent for start the activity that will log the information from the node * * @param c context used for create the intent * @param node note that will be used by the activity * @return intent for start this activity */ public static Intent getStartIntent(Context c, @NonNull Node node) { Intent i = new Intent(c, DebugConsoleActivity.class); i.putExtra(NODE_TAG, node.getTag()); i.putExtras(NodeContainerFragment.prepareArguments(node)); return i; }
/** * check if the new node match the one tag and if do it stop the search * @param m manager that discover the node * @param node new node discovered */ @Override public void onNodeDiscovered(Manager m, Node node) { String foundTag = node.getTag(); for(String temp : tags){ if(foundTag.equalsIgnoreCase(temp)) { foundNode = node; mActivity.stopNodeDiscovery(); }//if }//for }//onNodeDiscovered };
/** * search the tag on the already discovered node * @param tags list of tag that we are searching * @return first node that match one tag or null if doesn't find anything */ private Node searchOnAlreadyDiscoveredNodes(String... tags){ List<Node> nodes = Manager.getSharedInstance().getNodes(); for(Node n : nodes){ String nodeTag = n.getTag(); for(String tag : tags){ if(nodeTag.equalsIgnoreCase(tag)) return n; }//for tag }//for node return null; }//searchOnAlreadyDiscoveredNodes
viewHolder.sensorTag.setText(sensor.getTag()); switch (sensor.getType()) {
private Node buildMockNode() { Node n = mock(Node.class); when(n.isBounded()).thenReturn(false); when(n.getTag()).thenReturn(""+nBuildNode++); return n; }
@Test public void TestGetNodeByTag() { final String nodeTag1 = "TestNode1"; final String nodeTag2 = "TestNode2"; Node node1 = buildMockNode(); Node node2 = buildMockNode(); when(node1.getTag()).thenReturn(nodeTag1); when(node2.getTag()).thenReturn(nodeTag2); mManager.addNode(node1); mManager.addNode(node2); Assert.assertEquals(node1, mManager.getNodeWithTag(nodeTag1)); Assert.assertEquals(node2, mManager.getNodeWithTag(nodeTag2)); }
synchronized (mDiscoverNode) { for (Node node : mDiscoverNode) { if (node.getTag().equals(deviceAddr)) {