If you think the Android project Android-Apps listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2011 Tom Quist/*www.java2s.com*/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You can get the GNU General Public License at
* http://www.gnu.org/licenses/gpl.html
*/package com.kniezrec.voiceremote2;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.concurrent.TimeoutException;
import android.util.Log;
import de.quist.samy.remocon.ConnectionDeniedException;
import de.quist.samy.remocon.Key;
import de.quist.samy.remocon.RemoteSession;
publicclass CSeriesSender implements KeyCodeSender, TextSender {
privatestaticfinal String TAG = CSeriesSender.class.getSimpleName();
privatestaticfinal String NAME = "Voice Remote";
private String mHost;
private String macAddress;
private RemoteSession session;
privateboolean isFseries;
public CSeriesSender(String host, String mac, boolean isFSeries) {
this.mHost = host;
this.macAddress = mac;
this.isFseries = isFSeries;
}
publicvoid initialize() throws IOException {
try {
Log.v(TAG, "Creating session");
session = RemoteSession.create(NAME, macAddress, mHost, 55000);
Log.v(TAG, "Successfully created session");
} catch (ConnectionDeniedException e) {
thrownew IOException("Connection denied");
} catch (TimeoutException e) {
thrownew IOException("Timeout");
}
}
publicvoid sendCode(int... codes) throws UnknownHostException,
IOException, InterruptedException {
if (session == null)
initialize();
for (int code : codes) {
Key key;
if (isFseries) {
key = FSeriesButtons.MAPPINGS.get(code);
} else {
key = CSeriesButtons.MAPPINGS.get(code);
}
if (key != null) {
session.sendKey(key);
Log.v(TAG, "Sending code " + key);
Thread.sleep(300);
}
}
}
publicvoid sendText(String text) throws UnknownHostException, IOException,
InterruptedException {
Log.v(TAG, "Sending text " + text);
if (session == null)
initialize();
if (session != null)
session.sendText(text);
}
publicvoid uninitialize() {
Log.v(TAG, "Uninitializing C-Series Sender...");
if (session != null) {
session.destroy();
Log.v(TAG, "...Uninitialized C-Series Sender");
} else {
Log.v(TAG, "...Nothing to uninitialize, session is null");
}
}
}