// This method is called when 'Add Channel' button is clicked private void addNewChannel(final boolean isMaster) { Log.v(TAG, "addNewChannel..."); if (null != mChannelService) { ChannelInfo newChannelInfo; try { // Telling the ChannelService to add a new channel. This method // in ChannelService contains code required to acquire an ANT // channel from ANT Radio Service. newChannelInfo = mChannelService.addNewChannel(isMaster); } catch (ChannelNotAvailableException e) { // Occurs when a channel is not available. Printing out the // stack trace will show why no channels are available. Toast.makeText(this, "Channel Not Available", Toast.LENGTH_SHORT).show(); return; } if (null != newChannelInfo) { // Adding new channel info to the list addChannelToList(newChannelInfo); mChannelListAdapter.notifyDataSetChanged(); } } Log.v(TAG, "...addNewChannel"); }
@Override public void onServiceConnected(ComponentName name, IBinder serviceBinder) { Log.v(TAG, "mChannelServiceConnection.onServiceConnected..."); mChannelService = (ChannelServiceComm) serviceBinder; // Sets a listener that handles channel events mChannelService.setOnChannelChangedListener( new ChannelChangedListener() { // Occurs when a channel has new info/data @Override public void onChannelChanged(final ChannelInfo newInfo) { Integer index = mIdChannelListIndexMap.get(newInfo.deviceNumber); if (null != index && index.intValue() < mChannelDisplayList.size()) { mChannelDisplayList.set(index.intValue(), getDisplayText(newInfo)); runOnUiThread( new Runnable() { @Override public void run() { mChannelListAdapter.notifyDataSetChanged(); } }); } } // Updates the UI to allow/disallow acquiring new channels @Override public void onAllowAddChannel(boolean addChannelAllowed) { // Enable Add Channel button and Master/Slave toggle if // adding channels is allowed ((Button) findViewById(R.id.button_AddChannel)).setEnabled(addChannelAllowed); ((Button) findViewById(R.id.toggleButton_MasterSlave)) .setEnabled(addChannelAllowed); } }); // Initial check when connecting to ChannelService if adding channels is allowed boolean allowAcquireChannel = mChannelService.isAddChannelAllowed(); ((Button) findViewById(R.id.button_AddChannel)).setEnabled(allowAcquireChannel); ((Button) findViewById(R.id.toggleButton_MasterSlave)).setEnabled(allowAcquireChannel); refreshList(); Log.v(TAG, "...mChannelServiceConnection.onServiceConnected"); }
private void clearAllChannels() { Log.v(TAG, "clearAllChannels..."); if (null != mChannelService) { // Telling ChannelService to close all the channels mChannelService.clearAllChannels(); mChannelDisplayList.clear(); mIdChannelListIndexMap.clear(); mChannelListAdapter.notifyDataSetChanged(); } Log.v(TAG, "...clearAllChannels"); }
private void refreshList() { Log.v(TAG, "refreshList..."); if (null != mChannelService) { ArrayList<ChannelInfo> chInfoList = mChannelService.getCurrentChannelInfoForAllChannels(); mChannelDisplayList.clear(); for (ChannelInfo i : chInfoList) { addChannelToList(i); } mChannelListAdapter.notifyDataSetChanged(); } Log.v(TAG, "...refreshList"); }