/* * This file is part of the Remote Sensor Actuator Interface (ReSAI). * * Copyright(c) Andreas Kipp, Frederic Siepmann * http://opensource.cit-ec.de/projects/resai * * This file may be licensed under the terms of of the * GNU Lesser General Public License Version 3 (the ``LGPL''), * or (at your option) any later version. * * Software distributed under the License is distributed * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either * express or implied. See the LGPL for the specific language * governing rights and limitations. * * You should have received a copy of the LGPL along with this * program. If not, go to http://www.gnu.org/licenses/lgpl.html * or write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * The development of this software was supported by the * Excellence Cluster EXC 277 Cognitive Interaction Technology. * The Excellence Cluster EXC 277 is a grant of the Deutsche * Forschungsgemeinschaft (DFG) in the context of the German * Excellence Initiative. * */ /** * Tab used to communicate with the log dispatcher. * * @author akipp */ package de.unibi.airobots.resaidroid.tabactivities; import java.util.HashMap; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.TableLayout; import android.widget.TableRow; import de.unibi.airobots.resaidroid.R; import de.unibi.airobots.resaidroid.constants.ServerConfig; import de.unibi.airobots.resaidroid.tabactivities.template.TabTemplate; public class TabLogDispatcher extends TabTemplate { private TableLayout tblLogElements; private Button btnStart; private Button btnStop; private HashMap loggedComponents = new HashMap(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.logdispatcher); tblLogElements = (TableLayout) findViewById(R.id.tblLogElements); btnStart = (Button) findViewById(R.id.btnStart); btnStart.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //TODO outsource this code? addProperty("TAG", "LogDispatcher"); addProperty("START", "true"); for (String logElement : loggedComponents.keySet()) { if (loggedComponents.get(logElement).isChecked()) { addProperty(logElement, "ELEMENT"); } // DEACTIVATE CHECKBOXES loggedComponents.get(logElement).setEnabled(false); } sendMessage(ServerConfig.RECIPIENT_FULL); btnStart.setEnabled(false); btnStop.setEnabled(true); } }); btnStop = (Button) findViewById(R.id.btnStop); btnStop.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //TODO outsource? addProperty("TAG", "LogDispatcher"); addProperty("STOP", "true"); sendMessage(ServerConfig.RECIPIENT_FULL); btnStart.setEnabled(true); btnStop.setEnabled(false); // ACTIVATE CHECKBOXES for (String logElement : loggedComponents.keySet()) { loggedComponents.get(logElement).setEnabled(true); } } }); //TODO outsource? addProperty("TAG", "LogDispatcher"); //addProperty(cm.getComponent(TAG), "TRUE"); addProperty("GETLIST", "true"); sendMessage(ServerConfig.RECIPIENT_FULL); } @Override public void processProperties() { Log.i(TAG ,"NEW PROPERTIES"); messageHandler.post(new Runnable() { public void run() { try { synchronized (receivedProperties) { if (receivedProperties.containsKey("SETLIST")) { Log.i(TAG, "NEW LIST"); for (String prop : receivedProperties.keySet()) { if (receivedProperties.get(prop).equals( "ELEMENT")) { Log.i(TAG, "NEW ELEMENT " + prop); final CheckBox cb = new CheckBox( getApplicationContext()); cb.setText(prop); loggedComponents.put(cb.getText() .toString(), cb); TableRow tr = new TableRow( getApplicationContext()); tr.addView(cb); tblLogElements.addView(tr); } } } } } catch (Exception e) { //TODO Log.i(TAG, "### EXCEPTION " + e.getMessage()); } } }); } }