use of com.volosyukivan.PortUpdateListener.Stub in project wifikeyboard by IvanVolosyuk.
the class WiFiKeyboard method onResume.
@Override
public void onResume() {
super.onResume();
// // FIXME: block default port out of use
// ServerSocketChannel ch;
// try {
// ch = ServerSocketChannel.open();
// ch.socket().setReuseAddress(true);
// ch.socket().bind(new java.net.InetSocketAddress(7777));
// ch = ServerSocketChannel.open();
// ch.socket().setReuseAddress(true);
// ch.socket().bind(new java.net.InetSocketAddress(1111));
// } catch (IOException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
serviceConnection = new ServiceConnection() {
//@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Debug.d("WiFiInputMethod connected to HttpService.");
try {
Stub listener = new PortUpdateListener.Stub() {
@Override
public void portUpdated(int newPort) throws RemoteException {
if (newPort != port) {
port = newPort;
setContentView(createView());
}
}
};
RemoteKeyboard.Stub.asInterface(service).setPortUpdateListener(listener);
} catch (RemoteException e) {
throw new RuntimeException("WiFiInputMethod failed to connected to HttpService.", e);
}
}
//@Override
public void onServiceDisconnected(ComponentName name) {
Debug.d("WiFiInputMethod disconnected from HttpService.");
}
};
if (this.bindService(new Intent(this, HttpService.class), serviceConnection, BIND_AUTO_CREATE) == false) {
throw new RuntimeException("failed to connect to HttpService");
}
setContentView(createView());
}
Aggregations