/** * check that all the other feature exported by the characteristics aren't in notification mode * @param characteristic characteristic that export the feature * @param currentFeature feature that we want to disable * @return true if we can disable the notification without disturb other feature */ private boolean characteristicsHasOtherEnabledFeatures(BluetoothGattCharacteristic characteristic, Feature currentFeature){ List<Feature> features = mCharFeatureMap.get(characteristic); if(features.size()==1) return false; for(Feature f: features){ if(f == currentFeature) break; if(isEnableNotification(f)) return true; }//for return false; }
/** * stop all the enabled notification */ private void disableNeedNotification() { List<Feature> features = mNode.getFeatures(); for (Feature f : features) { if (mNode.isEnableNotification(f)) mNode.disableNotification(f); }//for sTestFeature }//disableNeedNotification
/** * ask to the node to notify when the feature change its value * @param feature feature to look * @return false if the feature is not handle by this node or disabled */ public boolean enableNotification(Feature feature){ if(!feature.isEnabled() || feature.getParentNode()!=this) return false; if(isEnableNotification(feature)) return true; BluetoothGattCharacteristic featureChar = getCorrespondingChar(feature); if(charCanBeNotify(featureChar)) { mNotifyFeature.add(feature); return changeNotificationStatus(featureChar, true); } return false; }//enableNotification
/** * When a user select a row we enable/disable the notification for that feature * * @param adapterView list view * @param view selected view * @param position selected row * @param l selected id */ @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Feature selectedFeature = mFeatureListAdapter.getItem(position); if(selectedFeature==null) return; if (mNode.isEnableNotification(selectedFeature)) { selectedFeature.removeFeatureListener(mGenericUpdate); mNode.disableNotification(selectedFeature); ((TextView) view).setText(selectedFeature.getName()); //reset the cell name } else { //create a listener that will update the selected view mGenericUpdate = new GenericFragmentUpdate((TextView) view); selectedFeature.addFeatureListener(mGenericUpdate); mNode.enableNotification(selectedFeature); }//if-else }//onItemClick
Assert.assertFalse(n.isEnableNotification(f)); Assert.assertTrue(n.enableNotification(f)); Assert.assertTrue(n.isEnableNotification(f)); Assert.assertTrue(n.disableNotification(f)); Assert.assertFalse(n.isEnableNotification(f));