-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathPictureReceiver.java
61 lines (49 loc) · 1.72 KB
/
PictureReceiver.java
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
package su.levenetc.android.interactivecanvas;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import java.net.InetAddress;
import java.util.concurrent.LinkedBlockingQueue;
/**
* Created by Eugene Levenetc.
*/
public class PictureReceiver implements Runnable, ITouchEventHandler {
private ReceiverView receiverView;
private InetAddress hostAddress;
private int touchPort;
private int picturesPort;
private int clientId;
private TouchEventsSendThread touchEventsSendThread;
private PicturesReceiverThread picturesReceiverThread;
private LinkedBlockingQueue<PictureWrapper> picturesQueue = new LinkedBlockingQueue<>();
public PictureReceiver(int clientId) {
this.clientId = clientId;
}
public void start() {
picturesReceiverThread = new PicturesReceiverThread(picturesPort, receiverView, this, picturesQueue);
picturesReceiverThread.start();
touchEventsSendThread = new TouchEventsSendThread(hostAddress, touchPort, clientId);
touchEventsSendThread.start();
}
public void destroy() {
if (picturesReceiverThread != null) picturesReceiverThread.interrupt();
if (touchEventsSendThread != null) touchEventsSendThread.interrupt();
}
public void setReceiverView(ReceiverView receiverView) {
this.receiverView = receiverView;
}
@Override public void run() {
try {
receiverView.setPicture(picturesQueue.take());
} catch (InterruptedException e) {
InternalLogger.logException(getClass(), e);
}
}
public void config(int picturesReceivePort, InetAddress hostAddress, int touchPort) {
this.picturesPort = picturesReceivePort;
this.hostAddress = hostAddress;
this.touchPort = touchPort;
}
public void handleTouchEvent(MotionEvent event) {
touchEventsSendThread.add(event);
}
}