Search in sources :

Example 1 with Stub

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());
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Stub(com.volosyukivan.PortUpdateListener.Stub) ComponentName(android.content.ComponentName) Intent(android.content.Intent) Stub(com.volosyukivan.PortUpdateListener.Stub) RemoteException(android.os.RemoteException)

Aggregations

ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 ServiceConnection (android.content.ServiceConnection)1 IBinder (android.os.IBinder)1 RemoteException (android.os.RemoteException)1 Stub (com.volosyukivan.PortUpdateListener.Stub)1