summaryrefslogtreecommitdiff
path: root/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
blob: eec69fc38ec1eafbece682f8232fdec9d8d67f6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.libreoffice.impressremote.communication;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.Messenger;

public class CommunicationService extends Service {

	/**
	 * Return the service to clients.
	 */
	public class CBinder extends Binder {
		public CommunicationService getService() {
			return CommunicationService.this;
		}
	}

	private final IBinder mBinder = new CBinder();

	public enum Protocol {
		NETWORK, BLUETOOTH
	};

	public static final int MSG_SLIDE_CHANGED = 1;
	public static final int MSG_SLIDE_PREVIEW = 2;

	private Transmitter mTransmitter;

	private Client mClient;

	private Receiver mReceiver = new Receiver();

	public void setActivityMessenger(Messenger aActivityMessenger) {
		mReceiver.setActivityMessenger(aActivityMessenger);
	}

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return mBinder;
	}

	@Override
	public void onCreate() {
		// TODO Create a notification (if configured).
	}

	@Override
	public void onDestroy() {
		// TODO Destroy the notification (as necessary).
	}

	public Transmitter getTransmitter() {
		return mTransmitter;
	}

	public void connectTo(Protocol aProtocol, String address) {
		switch (aProtocol) {
		case NETWORK:
			mClient = new NetworkClient(address);
			mTransmitter = new Transmitter(mClient);
			mClient.setReceiver(mReceiver);
			break;

		}

	}

	public void disconnect() {
		mClient.closeConnection();
	}

}