001/* 002 * $URL: svn://svn.webarts.bc.ca/open/trunk/projects/WebARTS/android/TomsRemoteController/src/ca/bc/webarts/android/TomsRemoteControllerActivity.java $ 003 * $Author: tgutwin $ 004 * $Revision: 622 $ 005 * $Date: 2014-04-08 20:20:24 -0700 (Tue, 08 Apr 2014) $ 006 */ 007/* 008 * 009 * Written by Tom Gutwin - WebARTS Design. 010 * Copyright (C) 2014 WebARTS Design, North Vancouver Canada 011 * http://www.webarts.bc.ca 012 * 013 * This program is free software; you can redistribute it and/or modify 014 * it under the terms of the GNU General Public License as published by 015 * the Free Software Foundation; either version 3 of the License. 016 * 017 * This program is distributed in the hope that it will be useful, 018 * but WITHOUT ANY WARRANTY; without_ even the implied warranty of 019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 020 * GNU General Public License for more details. 021 * 022 * You should have received a copy of the GNU General Public License 023 * along with this program; if not, write to the Free Software 024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 025 */ 026 027package ca.bc.webarts.android; 028 029import android.view.KeyEvent; 030import android.view.View; 031import android.view.ViewParent; 032import android.app.Activity; 033import android.content.Context; 034import android.content.Intent; 035import android.os.Bundle; 036import android.util.Log; 037import android.widget.ArrayAdapter; 038import android.widget.Button; 039import android.widget.EditText; 040import android.widget.Spinner; 041import android.widget.TableLayout; 042import android.widget.TableRow; 043import android.widget.Toast; 044 045import android.graphics.Color; 046import java.io.PrintStream; 047import java.io.IOException; 048import java.util.ArrayList; 049import java.util.Iterator; 050import java.util.List; 051import java.net.UnknownHostException; 052 053import ca.bc.webarts.android.ShawDirectLircCommands; 054import ca.bc.webarts.android.TCPSocketClient; 055import ca.bc.webarts.android.Util; 056import ca.bc.webarts.tools.eiscp.IscpCommands; 057import ca.bc.webarts.tools.eiscp.Eiscp; 058import ca.bc.webarts.tools.isy.ISYRestRequester; 059 060import tkj.android.homecontrol.mythmote.MythCom; 061import tkj.android.homecontrol.mythmote.FrontendLocation; 062 063 064/** Android activity to simulate a custom multi-device remote control.<br /> 065 * It controls (wraps) communication/control to the following devices:<ul> 066 * <li>Onkyo - using Java eISCP</li> 067 * <li>MythTV - Using MythMote and MythTV commands https://code.google.com/p/mythmote/wiki/MythFrontEndCommands</li> 068 * <li>ISY-994 - Using calls to the UDI ISY99 REST webservices</li> 069 * <li>ShawDirect STB via lirc blaster</li></ul><br />It uses a few different helper classes that handle the communication 070 * protocols to the various devices. All have an IP based interface.<br /><ul> 071 * <li>Onkyo uses the <a href="http://links.webarts.ca/eISCP">Java eISCP protocol implementation</a> also written by me.</li> 072 * <li>MythTV uses the <a href="https://code.google.com/p/mythmote">MythMote implementation</a> of the 073 * <a href="http://www.mythtv.org">MythTV</a> Control Socket 074 * protocol also released under the GPL2 written by TKj.</li> 075 * <li>ISY-99 uses a simple <a href="http://links.webarts.ca/isyRestRequester">Java REST web services client</a> called 076 * ca.bc.webarts.tools.isy.ISYRestRequester also written by me.</li> 077 * <li>ShawDirect is accessed through an IR blaster connected to a <a href="http://lirc.org">lirc</a> server that is accessed 078 * via a simple TCPSocketClient I wrote specifically for this app. It is also part of the ca.bc.webarts.android package.</li> 079 * </ul> 080 *<br /> 081 * This class is Written by Tom Gutwin - WebARTS Design.<br /> 082 * Copyright (C) 2014 WebARTS Design, North Vancouver Canada<br /> 083 * http://www.webarts.bc.ca<br /> 084 *<br /> 085 * This program is free software; you can redistribute it and/or modify<br /> 086 * it under the terms of the GNU General Public License as published by<br /> 087 * the Free Software Foundation; either version 3 of the License.<br /> 088 * The full licesnce is available at <a href="https://gnu.org/licenses/gpl.html">gnu.org gpl</a> 089 **/ 090public class TomsRemoteControllerActivity extends Activity implements MythCom.StatusChangedEventListener 091{ 092 093 /** A holder This classes name (used when logging). **/ 094 private static String CLASSNAME = ca.bc.webarts.android.Util.getCurrentClassName(); //"ca.bc.webarts.android.myFirstApp.myFirstActivity"; 095 /** The string that gets tagged at the front of all debugging output messages.**/ 096 public static final String LOG_TAG = "TomsRemoteControllerActivity"; //CLASSNAME; //+"."+ca.bc.webarts.android.Util.getCurrentClassName(); 097 /** flags the control of debugging output messages.**/ 098 public static boolean debugOut_ = true; 099 /** class flag that gets set when the onCreate method has been called and the buttons are up on the screen.**/ 100 public static boolean isInit_ = false; 101 102 /** Helper Class var for passing the Onkyo eISCP related message associated with the button that just gor pressed. **/ 103 private static int activatedOnkyoCommand_=-1; 104 /** Helper Class var for passing the MythTV related message associated with the button that just gor pressed. **/ 105 private static String activatedMythCommand_=""; 106 /** Helper Class var for passing the Shawdirect related message associated with the button that just gor pressed. **/ 107 private static String activatedShawDirectCommand_=""; 108 109 /** DEFAULT IP address for the Onkyo AVR.**/ 110 private static final String DEFAULT_ONKYO_IP = "10.0.0.203"; 111 /** DEFAULT IP address for the MythTV frontend.**/ 112 private static final String DEFAULT_MYTHTV_IP = "10.0.0.213"; 113 /** DEFAULT IP address for the Lirc server to usefor Shaw Direct commands.**/ 114 private static final String DEFAULT_LIRC_IP = "10.0.0.213"; 115 116 /** Class Instance IP address for the Onkyo AVR.**/ 117 private String onkyoAddress_ = DEFAULT_ONKYO_IP; 118 /** Helper class instance that wraps all the available eISCP commands. They get used/sent to the eiscp_ instance.**/ 119 private IscpCommands iscpCommands_ = IscpCommands.getInstance(); 120 /** Helper class instance for communicating to the oNKYO. **/ 121 private Eiscp eiscp_ = new Eiscp(onkyoAddress_); 122 private MythCom myth_ = null; 123 private FrontendLocation mythFrontend_ = null; 124 private String mythName_ = "mythtv"; 125 /** IP address for the MythTV server.**/ 126 private String mythAddress_ = DEFAULT_MYTHTV_IP; 127 128 /** IP address for the ShawDirect IR blaster Lirc server.**/ 129 private String lircServerIP_ = DEFAULT_LIRC_IP; 130 /** IP port for the ShawDirect IR blaster Lirc server.**/ 131 private int lircPort_ = 8765; 132 133 /** Helper class instance for communicating ShawDirect remote control commands blasted from the Lirc server this instance is connected to.**/ 134 private TCPSocketClient shawDirectLircClient_ = new TCPSocketClient(lircServerIP_,lircPort_); 135 136 /** Helper class instance for communicating REST requests to the ISY. **/ 137 private ISYRestRequester isyRest = new ISYRestRequester(); 138 139 /** Flag marking if the current numPad is laied out for mythTV (or the ShawDirect when false) control. **/ 140 private boolean mythPadLayout_ = true; 141 private int [] numPadIdsToswap = {R.id.button32, R.id.button33, R.id.button34, 142 R.id.button42, R.id.button43, R.id.button44, 143 R.id.button52, R.id.button53, R.id.button54, 144 R.id.button62, R.id.button63, R.id.button64}; 145 private int [] sdNumPadResourceName = {R.string.button_32sd,R.string.button_33sd,R.string.button_34sd, 146 R.string.button_42sd,R.string.button_43sd,R.string.button_44sd, 147 R.string.button_52sd,R.string.button_53sd,R.string.button_54sd, 148 R.string.button_62sd,R.string.button_63sd,R.string.button_64sd}; 149 private int [] mythNumPadresourceName = {R.string.button_32,R.string.button_33,R.string.button_34, 150 R.string.button_42,R.string.button_43,R.string.button_44, 151 R.string.button_52,R.string.button_53,R.string.button_54, 152 R.string.button_62,R.string.button_63,R.string.button_64}; 153 154 155 /** Called when the activity is first created. */ 156 @Override 157 public void onCreate(Bundle savedInstanceState) 158 { 159 super.onCreate(savedInstanceState); 160 if(debugOut_) logStart(Util.getCurrentMethodName()); 161 setContentView(R.layout.main); 162 if(!isInit_ && mythPadLayout_)setNumPadToShawDirect(); 163 isInit_=true; 164 if(debugOut_) logExit(Util.getCurrentMethodName()); 165 } 166 167 168@Override 169public boolean dispatchKeyEvent(KeyEvent event) 170{ 171 int action = event.getAction(); 172 int keyCode = event.getKeyCode(); 173 switch (keyCode) 174 { 175 case KeyEvent.KEYCODE_VOLUME_UP: 176 //if (action == KeyEvent.ACTION_UP) 177 if (action == KeyEvent.ACTION_DOWN) 178 { 179 activatedOnkyoCommand_=IscpCommands.VOLUME_UP1; 180 sendEiscpCommand(); 181 } 182 return true; 183 case KeyEvent.KEYCODE_VOLUME_DOWN: 184 if (action == KeyEvent.ACTION_DOWN) 185 { 186 activatedOnkyoCommand_=IscpCommands.VOLUME_DOWN1; 187 sendEiscpCommand(); 188 } 189 return true; 190 default: 191 } 192 return super.dispatchKeyEvent(event); 193} 194 195 196 /* **************************************************************************************************** */ 197 /* Row 1 */ 198 /* ****** */ 199 /** All buttonPressedXY methods are directly called by the related button X is row Y is column. **/ 200 public void buttonPressed11(View view){activatedOnkyoCommand_=IscpCommands.POWER_OFF; sendEiscpCommand();} 201 public void buttonPressed12(View view){activatedOnkyoCommand_=IscpCommands.SOURCE_SATELLITE; sendEiscpCommand();if(mythPadLayout_)setNumPadToShawDirect();} 202 public void buttonPressed13(View view){activatedOnkyoCommand_=IscpCommands.SOURCE_DVR; sendEiscpCommand();if(!mythPadLayout_)setNumPadToMyth();} 203 public void buttonPressed14(View view){} 204 public void buttonPressed15(View view){eiscp_.toggleMute();} 205 206 207 /* Row 2 */ 208 /* ****** */ 209 public void buttonPressed21(View view){activatedShawDirectCommand_=ShawDirectLircCommands.EXIT; sendShawDirectCommand( view);} 210 public void buttonPressed22(View view){activatedShawDirectCommand_=ShawDirectLircCommands.GUIDE; sendShawDirectCommand( view);} 211 public void buttonPressed23(View view) 212 { 213 if(debugOut_) logStart(Util.getCurrentMethodName()); 214 activatedOnkyoCommand_=IscpCommands.VIDEO_WIDE_QUERY; 215 String resp = queryEiscpCommand(); 216 if (resp.equals(iscpCommands_.getCommandStr(IscpCommands.VIDEO_WIDE_FULL))) 217 { 218 activatedOnkyoCommand_=IscpCommands.VIDEO_WIDE_ZOOM; sendEiscpCommand(); 219 } 220 else if (resp.equals(iscpCommands_.getCommandStr(IscpCommands.VIDEO_WIDE_ZOOM))) 221 { 222 activatedOnkyoCommand_=IscpCommands.VIDEO_WIDE_WIDEZOOM; sendEiscpCommand(); 223 } 224 else 225 { 226 activatedOnkyoCommand_=IscpCommands.VIDEO_WIDE_FULL; sendEiscpCommand(); 227 } 228 if(debugOut_) logExit(Util.getCurrentMethodName()); 229 } 230 public void buttonPressed24(View view) 231 { 232 if(debugOut_) logStart(Util.getCurrentMethodName()); 233 activatedOnkyoCommand_=IscpCommands.LISTEN_MODE_QUERY; String resp = queryEiscpCommand(); 234 if (resp.equals(iscpCommands_.getCommandStr(IscpCommands.LISTEN_MODE_PLII_MOVIE_DSX))) 235 { 236 activatedOnkyoCommand_=IscpCommands.LISTEN_MODE_THEATER_DIMENSIONAL; sendEiscpCommand(); 237 } 238 else 239 { 240 activatedOnkyoCommand_=IscpCommands.LISTEN_MODE_PLII_MOVIE_DSX; sendEiscpCommand(); 241 } 242 if(debugOut_) logExit(Util.getCurrentMethodName()); 243 } 244 245 public void buttonPressed25(View view){activatedOnkyoCommand_=IscpCommands.VOLUME_UP1; sendEiscpCommand();} 246 247 248 /* Row 3 */ 249 /* ****** */ 250 public void buttonPressed31(View view){activatedShawDirectCommand_=ShawDirectLircCommands.UP; sendShawDirectCommand( view);} 251 public void buttonPressed32(View view) 252 { 253 if(debugOut_) logStart(Util.getCurrentMethodName()); 254 if( mythPadLayout_) 255 { 256 activatedMythCommand_="jump managerecordings"; sendMythTVCommand( view); 257 } 258 else 259 { 260 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_1; sendShawDirectCommand( view); 261 } 262 if(debugOut_) logExit(Util.getCurrentMethodName()); 263 } 264 public void buttonPressed33(View view) 265 { 266 if(debugOut_) logStart(Util.getCurrentMethodName()); 267 if( mythPadLayout_) 268 { 269 activatedMythCommand_="key up"; sendMythTVCommand( view); 270 } 271 else 272 { 273 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_2; sendShawDirectCommand( view); 274 275 } 276 if(debugOut_) logExit(Util.getCurrentMethodName()); 277 } 278 public void buttonPressed34(View view) 279 { 280 if(debugOut_) logStart(Util.getCurrentMethodName()); 281 if( mythPadLayout_) 282 { 283 activatedMythCommand_="jump mainmenu"; sendMythTVCommand( view); 284 activatedMythCommand_="key enter"; sendMythTVCommand( view); 285 activatedMythCommand_="key enter"; sendMythTVCommand( view); 286 } 287 else 288 { 289 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_3; sendShawDirectCommand( view); 290 291 } 292 if(debugOut_) logExit(Util.getCurrentMethodName()); 293 } 294 public void buttonPressed35(View view){activatedOnkyoCommand_=IscpCommands.VOLUME_DOWN1; sendEiscpCommand();} 295 296 297 /* Row 4 */ 298 /* ****** */ 299 public void buttonPressed41(View view){activatedShawDirectCommand_=ShawDirectLircCommands.DOWN; sendShawDirectCommand( view);} 300 public void buttonPressed42(View view) 301 { 302 if(debugOut_) logStart(Util.getCurrentMethodName()); 303 if( mythPadLayout_) 304 { 305 activatedMythCommand_="key left"; sendMythTVCommand( view); 306 } 307 else 308 { 309 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_4; sendShawDirectCommand( view); 310 311 } 312 if(debugOut_) logExit(Util.getCurrentMethodName()); 313 } 314 public void buttonPressed43(View view) 315 { 316 if(debugOut_) logStart(Util.getCurrentMethodName()); 317 if( mythPadLayout_) 318 { 319 activatedMythCommand_="key enter"; sendMythTVCommand( view); 320 } 321 else 322 { 323 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_5; sendShawDirectCommand( view); 324 325 } 326 if(debugOut_) logExit(Util.getCurrentMethodName()); 327 } 328 public void buttonPressed44(View view) 329 { 330 if(debugOut_) logStart(Util.getCurrentMethodName()); 331 if( mythPadLayout_) 332 { 333 activatedMythCommand_="key right"; sendMythTVCommand( view); 334 } 335 else 336 { 337 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_6; sendShawDirectCommand( view); 338 339 } 340 if(debugOut_) logExit(Util.getCurrentMethodName()); 341 } 342 public void buttonPressed45(View view){activatedShawDirectCommand_=ShawDirectLircCommands.CH_UP; sendShawDirectCommand( view);} 343 344 345 /* Row 5 */ 346 /* ****** */ 347 public void buttonPressed51(View view){} 348 public void buttonPressed52(View view) 349 { 350 if(debugOut_) logStart(Util.getCurrentMethodName()); 351 if( mythPadLayout_) 352 { 353 activatedMythCommand_="key escape"; sendMythTVCommand( view); 354 } 355 else 356 { 357 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_7; sendShawDirectCommand( view); 358 359 } 360 if(debugOut_) logExit(Util.getCurrentMethodName()); 361 } 362 public void buttonPressed53(View view) 363 { 364 if(debugOut_) logStart(Util.getCurrentMethodName()); 365 if( mythPadLayout_) 366 { 367 activatedMythCommand_="key down"; sendMythTVCommand( view); 368 } 369 else 370 { 371 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_8; sendShawDirectCommand( view); 372 373 } 374 if(debugOut_) logExit(Util.getCurrentMethodName()); 375 } 376 public void buttonPressed54(View view) 377 { 378 if(debugOut_) logStart(Util.getCurrentMethodName()); 379 if( mythPadLayout_) 380 { 381 382 } 383 else 384 { 385 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_9; sendShawDirectCommand( view); 386 387 } 388 if(debugOut_) logExit(Util.getCurrentMethodName()); 389 } 390 public void buttonPressed55(View view){activatedShawDirectCommand_=ShawDirectLircCommands.CH_DOWN; sendShawDirectCommand( view);} 391 392 393 /* Row 6 */ 394 /* ****** */ 395 public void buttonPressed61(View view){} 396 public void buttonPressed62(View view) 397 { 398 if(debugOut_) logStart(Util.getCurrentMethodName()); 399 if( mythPadLayout_) 400 { 401 if(debugOut_) android.util.Log.d(LOG_TAG, Util.getCurrentMethodName()+ " - mythPad"); 402 403 } 404 else 405 { 406 if(debugOut_) android.util.Log.d(LOG_TAG, Util.getCurrentMethodName()+ " - shawPad"); 407 activatedShawDirectCommand_=ShawDirectLircCommands.LAST; sendShawDirectCommand( view); 408 } 409 if(debugOut_) logExit(Util.getCurrentMethodName()); 410 } 411 public void buttonPressed63(View view) 412 { 413 if(debugOut_) logStart(Util.getCurrentMethodName()); 414 if( mythPadLayout_) 415 { 416 417 } 418 else 419 { 420 activatedShawDirectCommand_=ShawDirectLircCommands.NUMBER_0; sendShawDirectCommand( view); 421 } 422 } 423 public void buttonPressed64(View view) 424 { 425 if(debugOut_) logStart(Util.getCurrentMethodName()); 426 if( mythPadLayout_) 427 { 428 429 } 430 else 431 { 432 activatedShawDirectCommand_=ShawDirectLircCommands.ENTER; sendShawDirectCommand( view); 433 } 434 if(debugOut_) logExit(Util.getCurrentMethodName()); 435 } 436 public void buttonPressed65(View view){} 437 438 439 /* Row 7 */ 440 /* ****** */ 441 public void buttonPressed71(View view){isyRest.deviceToggle(isyRest.VALENCEFRONTLIGHTS_ADDR);} 442 public void buttonPressed72(View view) 443 { 444 if(debugOut_) logStart(Util.getCurrentMethodName()); 445 int stat = isyRest.deviceToggle(isyRest.VALENCESURROUNDLIGHTS_ADDR); 446 if (stat>0) isyRest.deviceOff(isyRest.FAMILYMAINLIGHTS_ADDR); 447 else if (stat!=-1) isyRest.deviceOn(isyRest.FAMILYMAINLIGHTS_ADDR); 448 if(debugOut_) logExit(Util.getCurrentMethodName()); 449 } 450 public void buttonPressed73(View view) 451 { 452 if(debugOut_) logStart(Util.getCurrentMethodName()); 453 isyRest.deviceToggle(isyRest.DWNKITCHEN_ADDR); 454 if(debugOut_) logExit(Util.getCurrentMethodName()); 455 } 456 public void buttonPressed74(View view){isyRest.deviceToggle(isyRest.GAMESROOMLIGHTS_ADDR);} 457 public void buttonPressed75(View view){} 458 459 460 /** Helper method that logs a methodstart log message. **/ 461 private void logStart(String m){if(debugOut_) android.util.Log.d(LOG_TAG,m+" - methodEntry");} 462 463 464 /** Helper method that logs a methodExit log message. **/ 465 private void logExit(String m){if(debugOut_) android.util.Log.d(LOG_TAG,m+" - methodExit");} 466 467 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 468 /** switches the numPad buttons to the ShawDirect number pad using the class vars numPadIdsToswap and sdNumPadresourceName. **/ 469 private void setNumPadToShawDirect() 470 { 471 if(debugOut_) logStart(Util.getCurrentMethodName()); 472 Button b = null; 473 String str = ""; 474 String clr = ""; 475 476 for (int i =0; i<numPadIdsToswap.length;i++) 477 { 478 b = (Button) findViewById(numPadIdsToswap[i]); // button63 is the zero key 479 str = getResources().getString(sdNumPadResourceName[i]); //"\n0\n\n" 480 clr = getResources().getString(R.string.sd_colour); 481 b.setText(new StringBuilder(str)); 482 b.setBackgroundColor(android.graphics.Color.parseColor(clr)); 483 } 484 mythPadLayout_ = false; 485 if(debugOut_) logExit(Util.getCurrentMethodName()); 486 } 487 488 489 /** switches the numPad buttons to the MythTV number pad using the class vars numPadIdsToswap and mythNumPadresourceName. **/ 490 private void setNumPadToMyth() 491 { 492 if(debugOut_) logStart(Util.getCurrentMethodName()); 493 Button b = null; 494 String str = ""; 495 String clr = ""; 496 497 for (int i =0; i<numPadIdsToswap.length;i++) 498 { 499 if(debugOut_) android.util.Log.d(LOG_TAG,Util.getCurrentMethodName()+" - methodEntry"); 500 b = (Button) findViewById(numPadIdsToswap[i]); // button63 is the zero key 501 str = getResources().getString(mythNumPadresourceName[i]); //"\n0\n\n" 502 clr = getResources().getString(R.string.myth_colour); 503 b.setText(new StringBuilder(str)); 504 b.setBackgroundColor(android.graphics.Color.parseColor(clr)); 505 } 506 mythPadLayout_ = true; 507 if(debugOut_) logExit(Util.getCurrentMethodName()); 508 } 509 510 511 /** Toggles the numPad between the myth layout and the ShawDirect Layout based on the mythPadLayout_ var. **/ 512 private void toggleNumPad() 513 { 514 if(debugOut_) logStart(Util.getCurrentMethodName()); 515 if( mythPadLayout_) 516 setNumPadToShawDirect(); 517 else 518 setNumPadToMyth(); 519 if(debugOut_) logExit(Util.getCurrentMethodName()); 520 } 521 522 523 /** Called when the user selects an Onkyo command button. */ 524 private void sendEiscpCommand() 525 { 526 queryEiscpCommand(); 527 } 528 529 530 /** Called to send an eISCP message when the user selects an Onkyo command button. */ 531 private String queryEiscpCommand() 532 { 533 if(debugOut_) logStart(Util.getCurrentMethodName()); 534 String commandStr = ""; 535 String queryResponse = "Invalid Command"; 536 String qryRespOut = ""; 537 Context context = getApplicationContext(); 538 539 //int command = iscpCommands_.getCommand(activatedOnkyoCommand_); 540 commandStr = iscpCommands_.getCommandStr(activatedOnkyoCommand_); 541 if (activatedOnkyoCommand_!=-1) 542 { 543 queryResponse = eiscp_.sendQueryCommand(activatedOnkyoCommand_,false,false).trim(); 544 545 Toast.makeText(context, "Command: " + iscpCommands_.getCommandName(commandStr), Toast.LENGTH_SHORT).show(); 546 547 } 548 if (queryResponse.equals("")) 549 queryResponse = (!eiscp_.testConnection() ? "Can't Connect": "Empty Response"); 550 else 551 { 552 String decipherResponse = iscpCommands_.getCommandName(queryResponse.trim()); 553 qryRespOut = commandStr +" response: " +decipherResponse + " ("+queryResponse +")"; 554 System.out.println("\n"+qryRespOut); 555 // System.out.println("\n"+commandStr +" response: " + 556 // queryResponse.substring(18,(queryResponse.length()-9))); 557 } 558 if(debugOut_) logExit(Util.getCurrentMethodName()); 559 return queryResponse; 560 } 561 562 563 /** Called to send an Lirc message to the Shawdirect Lirc server when the user selects an ShawDirect command button. */ 564 private void sendShawDirectCommand(View view) 565 { 566 if(debugOut_) logStart(Util.getCurrentMethodName()); 567 568 String commandStr = ""; 569 570 if(mythPadLayout_) setNumPadToShawDirect(); 571 if (activatedShawDirectCommand_!=null&&!activatedShawDirectCommand_.equals("")) 572 { 573 if(debugOut_) android.util.Log.d(LOG_TAG+"."+Util.getCurrentMethodName(),activatedShawDirectCommand_); 574 575 try 576 { 577 shawDirectLircClient_.initSocket(); 578 if (shawDirectLircClient_.isInit()) 579 { 580 shawDirectLircClient_.sendAndWait(ShawDirectLircCommands.getLircMessage(activatedShawDirectCommand_),1000); 581 shawDirectLircClient_.closeSocket(); 582 } 583 else 584 System.out.println("Socket NOT init"); 585 } 586 catch (UnknownHostException e) 587 { 588 System.err.println("Don't know about lirc host " + lircServerIP_); 589 } 590 catch (IOException ioEx) 591 { 592 //ioEx.printStackTrace(); 593 System.err.println("Couldn't get I/O for the connection to the host " + lircServerIP_); 594 } 595 596 } 597 if(debugOut_) logExit(Util.getCurrentMethodName()); 598 } 599 600 601 /** Called o send an command to the MythTV server when the user selects an MythTV command button. */ 602 private void sendMythTVCommand(View view) 603 { 604 if(debugOut_) logStart(Util.getCurrentMethodName()); 605 String commandStr = ""; 606 String queryResponse = "Invalid Command"; 607 String qryRespOut = ""; 608 609 if(!mythPadLayout_)setNumPadToMyth(); 610 if (activatedMythCommand_!=null&&!activatedMythCommand_.equals("")) 611 { 612 if(debugOut_) android.util.Log.d(LOG_TAG+"."+Util.getCurrentMethodName(),activatedMythCommand_); 613 myth_.SendCommand(activatedMythCommand_.trim()); 614 615 } 616 if(debugOut_) logExit(Util.getCurrentMethodName()); 617 } 618 619 //public static Context getApplicationContext(){return getApplicationContext();} 620 621 622 /** Called soon after created. */ 623 @Override 624 protected void onStart() 625 { 626 if(debugOut_) logStart(Util.getCurrentMethodName()); 627 super.onStart(); 628 629 } 630 631 632 /** Called soon after reStarting. **/ 633 @Override 634 protected void onRestart() 635 { 636 super.onRestart(); // Always call the superclass method first 637 if(debugOut_) logStart(Util.getCurrentMethodName()); 638 639 // Activity being restarted from stopped state 640 } 641 642 643 /** Called when the activity is being paused. */ 644 @Override 645 public void onPause() 646 { 647 if(debugOut_) logStart(Util.getCurrentMethodName()); 648 super.onPause(); // Always call the superclass method first 649 650 // Release the resources because we don't need it when paused 651 // and other activities might need to use it. 652 //if (mCamera != null) { 653 // mCamera.release() 654 // mCamera = null; 655 } 656 657 658 /** Called when the activity is started or resumed from pause. It also re-connects to the MythtV server. */ 659 @Override 660 protected void onResume() 661 { 662 if(debugOut_) logStart(Util.getCurrentMethodName()); 663 super.onResume(); 664 //set mythcom status handler 665 if (mythFrontend_==null) 666 { 667 mythFrontend_= new FrontendLocation(); 668 mythFrontend_.Address=mythAddress_; 669 mythFrontend_.Name=mythName_; 670 } 671 if(myth_==null&&mythFrontend_!=null) 672 { 673 myth_ = MythCom.GetMythCom( this); 674 myth_.Connect(mythFrontend_); 675 myth_.SetOnStatusChangeHandler(this); 676 } 677 if(debugOut_) logExit(Util.getCurrentMethodName()); 678 } 679 680 681 /** 682 * Called when the activity is being destroyed 683 */ 684 @Override 685 public void onDestroy() 686 { 687 super.onDestroy(); 688 if(debugOut_) logStart(Util.getCurrentMethodName()); 689 690 if (myth_ != null) 691 { 692 myth_.ActivityOnDestroy(); 693 myth_ = null; 694 } 695 } 696 697 698 /** 699 * Called when MythCom status changes 700 */ 701 public void StatusChanged(String StatusMsg, int statusCode) 702 { 703 if(debugOut_) logStart(Util.getCurrentMethodName()); 704 final String msg = StatusMsg; 705 final int code = statusCode; 706 final Context c = getApplicationContext(); 707 708 this.runOnUiThread(new Runnable() 709 { 710 711 @Override 712 public void run() 713 { 714 // set titleJUMPPOINT_guidegrid 715 //setTitle(msg); 716 717 // change color based on status code 718 if (code == MythCom.STATUS_ERROR) 719 { 720 setTitleColor(Color.RED); 721 } 722 else if (code == MythCom.STATUS_DISCONNECTED) 723 { 724 setTitleColor(Color.RED); 725 } 726 else if (code == MythCom.STATUS_CONNECTED) 727 { 728 setTitleColor(Color.GREEN); 729 } 730 else if (code == MythCom.STATUS_CONNECTING) 731 { 732 setTitleColor(Color.YELLOW); 733 } 734 735 //Toast.makeText(c, "MythCommandResult: " + msg, Toast.LENGTH_SHORT).show(); 736 737 } 738 739 }); 740 } 741}