Change D-Pad buttons behaviour, so that they don't fire a command on each touch event. The other scheme makes them too sensitive, which causes them to issue commands when the user swipes on the remote screen for instance.
This commit is contained in:
parent
8ce709c55a
commit
a429ec17b4
|
@ -44,8 +44,7 @@ public class EventServerConnection {
|
|||
* Host to connect too
|
||||
*/
|
||||
private final HostInfo hostInfo;
|
||||
private final InetAddress hostInetAddress;
|
||||
private boolean isConnected = false;
|
||||
private InetAddress hostInetAddress = null;
|
||||
|
||||
// Handler on which packets will be posted, to send them asynchronously
|
||||
private Handler commHandler = null;
|
||||
|
@ -56,32 +55,31 @@ public class EventServerConnection {
|
|||
@Override
|
||||
public void run() {
|
||||
LogUtils.LOGD(TAG, "Pinging EventServer");
|
||||
try {
|
||||
packetPING.send(hostInetAddress, hostInfo.getEventServerPort());
|
||||
} catch (IOException exc) {
|
||||
LogUtils.LOGD(TAG, "Got an IOException when sending a PING Packet to Kodi's EventServer");
|
||||
if (hostInetAddress != null) {
|
||||
try {
|
||||
packetPING.send(hostInetAddress, hostInfo.getEventServerPort());
|
||||
} catch (IOException exc) {
|
||||
LogUtils.LOGD(TAG, "Got an IOException when sending a PING Packet to Kodi's EventServer");
|
||||
}
|
||||
}
|
||||
commHandler.postDelayed(this, PING_INTERVAL);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor. Starts the thread that keeps the connection alive. Make sure to call quit() when done.
|
||||
* @param hostInfo Host to connect to
|
||||
* @throws UnknownHostException
|
||||
* Interface to notify users if the connection was sucessfull
|
||||
*/
|
||||
public EventServerConnection(final HostInfo hostInfo) throws UnknownHostException{
|
||||
this.hostInfo = hostInfo;
|
||||
hostInetAddress = InetAddress.getByName(hostInfo.getAddress());
|
||||
|
||||
startEventClient();
|
||||
public interface EventServerConnectionCallback {
|
||||
void OnConnect(boolean success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the HandlerThread that will be used to post packets, establishes a connection with EventServer
|
||||
* (sends HELO packet) and starts the ping thread
|
||||
* Constructor. Starts the thread that keeps the connection alive. Make sure to call quit() when done.
|
||||
* @param hostInfo Host to connect to
|
||||
*/
|
||||
private void startEventClient() {
|
||||
public EventServerConnection(final HostInfo hostInfo, final EventServerConnectionCallback callback) {
|
||||
this.hostInfo = hostInfo;
|
||||
|
||||
LogUtils.LOGD(TAG, "Starting EventServer Thread");
|
||||
// Handler thread that will keep pinging and send the requests to Kodi
|
||||
handlerThread = new HandlerThread("EventServerConnection", Process.THREAD_PRIORITY_DEFAULT);
|
||||
|
@ -90,29 +88,28 @@ public class EventServerConnection {
|
|||
// Get the HandlerThread's Looper and use it for our Handler
|
||||
commHandler = new Handler(handlerThread.getLooper());
|
||||
|
||||
// Now, get the host InetAddress in the background
|
||||
commHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
hostInetAddress = InetAddress.getByName(hostInfo.getAddress());
|
||||
} catch (UnknownHostException exc) {
|
||||
LogUtils.LOGD(TAG, "Got an UnknownHostException, disabling EventServer");
|
||||
hostInetAddress = null;
|
||||
}
|
||||
callback.OnConnect(hostInetAddress != null);
|
||||
}
|
||||
});
|
||||
|
||||
// Send Hello Packet
|
||||
// commHandler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// PacketHELO p;
|
||||
// p = new PacketHELO(DEVICE_NAME);
|
||||
// try {
|
||||
// p.send(hostInetAddress, hostInfo.getEventServerPort());
|
||||
// } catch (IOException exc) {
|
||||
// // We are ignoring this one... Not sure if a good idea, but we're not on the UI thread
|
||||
// LogUtils.LOGD(TAG, "Got an IOException when sending a HELO Packet to Kodi's EventServer");
|
||||
// }
|
||||
//
|
||||
// // Start pinging
|
||||
// commHandler.postDelayed(pingRunnable, PING_INTERVAL);
|
||||
// }
|
||||
// });
|
||||
// sendPacket(new PacketHELO(DEVICE_NAME));
|
||||
|
||||
// Start pinging
|
||||
commHandler.postDelayed(pingRunnable, PING_INTERVAL);
|
||||
|
||||
isConnected = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stops the HandlerThread that is being used to send packets to Kodi
|
||||
*/
|
||||
|
@ -124,7 +121,6 @@ public class EventServerConnection {
|
|||
} else {
|
||||
handlerThread.quit();
|
||||
}
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +129,7 @@ public class EventServerConnection {
|
|||
* @param p Packet to send
|
||||
*/
|
||||
public void sendPacket(final Packet p) {
|
||||
if (!isConnected) {
|
||||
if (!handlerThread.isAlive() || (hostInetAddress == null)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,15 +177,15 @@ public class RemoteFragment extends Fragment
|
|||
setupEventServerButton(rightButton, ButtonCodes.REMOTE_RIGHT);
|
||||
setupEventServerButton(upButton, ButtonCodes.REMOTE_UP);
|
||||
setupEventServerButton(downButton, ButtonCodes.REMOTE_DOWN);
|
||||
setupEventServerButton(selectButton, ButtonCodes.REMOTE_SELECT);
|
||||
//setupEventServerButton(selectButton, ButtonCodes.REMOTE_SELECT);
|
||||
} else {
|
||||
// Otherwise, use json-rpc
|
||||
setupRepeatButton(leftButton, new Input.Left());
|
||||
setupRepeatButton(rightButton, new Input.Right());
|
||||
setupRepeatButton(upButton, new Input.Up());
|
||||
setupRepeatButton(downButton, new Input.Down());
|
||||
setupDefaultButton(selectButton, new Input.Select(), null);
|
||||
}
|
||||
setupDefaultButton(selectButton, new Input.Select(), null);
|
||||
|
||||
// Other buttons
|
||||
setupDefaultButton(backButton, new Input.Back(), null);
|
||||
|
@ -269,12 +269,17 @@ public class RemoteFragment extends Fragment
|
|||
}
|
||||
|
||||
private void createEventServerConnection() {
|
||||
try {
|
||||
eventServerConnection = new EventServerConnection(hostManager.getHostInfo());
|
||||
} catch (UnknownHostException exc) {
|
||||
LogUtils.LOGD(TAG, "Got an UnknownHostException, disabling EventServer");
|
||||
eventServerConnection = null;
|
||||
}
|
||||
eventServerConnection = new EventServerConnection(
|
||||
hostManager.getHostInfo(),
|
||||
new EventServerConnection.EventServerConnectionCallback() {
|
||||
@Override
|
||||
public void OnConnect(boolean success) {
|
||||
if (!success) {
|
||||
LogUtils.LOGD(TAG, "Couldnt setup EventServer, disabling it");
|
||||
eventServerConnection = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupRepeatButton(View button, final ApiMethod<String> action) {
|
||||
|
@ -312,40 +317,53 @@ public class RemoteFragment extends Fragment
|
|||
}
|
||||
|
||||
private void setupEventServerButton(View button, final String action) {
|
||||
short amount = 0;
|
||||
byte axis = 0;
|
||||
final Packet packetDown =
|
||||
new PacketBUTTON(ButtonCodes.MAP_REMOTE, action, true, true, false, amount, axis);
|
||||
final Packet packetUp =
|
||||
new PacketBUTTON(ButtonCodes.MAP_REMOTE, action, false, false, false, amount, axis);
|
||||
|
||||
// Set animation and packet
|
||||
button.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
buttonInAnim.setFillAfter(true);
|
||||
v.startAnimation(buttonInAnim);
|
||||
eventServerConnection.sendPacket(packetDown);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
v.startAnimation(buttonOutAnim);
|
||||
eventServerConnection.sendPacket(packetUp);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Nothing to do
|
||||
}
|
||||
});
|
||||
final Packet packet =
|
||||
new PacketBUTTON(ButtonCodes.MAP_REMOTE, action, false, true, true, (short)0, (byte)0);
|
||||
button.setOnTouchListener(new RepeatListener(UIUtils.initialButtonRepeatInterval, UIUtils.buttonRepeatInterval,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
eventServerConnection.sendPacket(packet);
|
||||
}
|
||||
}, buttonInAnim, buttonOutAnim));
|
||||
}
|
||||
|
||||
|
||||
// private void setupEventServerButton(View button, final String action) {
|
||||
// short amount = 0;
|
||||
// byte axis = 0;
|
||||
// final Packet packetDown =
|
||||
// new PacketBUTTON(ButtonCodes.MAP_REMOTE, action, true, true, false, amount, axis);
|
||||
// final Packet packetUp =
|
||||
// new PacketBUTTON(ButtonCodes.MAP_REMOTE, action, false, false, false, amount, axis);
|
||||
//
|
||||
// // Set animation and packet
|
||||
// button.setOnTouchListener(new View.OnTouchListener() {
|
||||
// @Override
|
||||
// public boolean onTouch(View v, MotionEvent event) {
|
||||
// switch (event.getAction()) {
|
||||
// case MotionEvent.ACTION_DOWN:
|
||||
// buttonInAnim.setFillAfter(true);
|
||||
// v.startAnimation(buttonInAnim);
|
||||
// eventServerConnection.sendPacket(packetDown);
|
||||
// break;
|
||||
// case MotionEvent.ACTION_UP:
|
||||
// case MotionEvent.ACTION_CANCEL:
|
||||
// v.startAnimation(buttonOutAnim);
|
||||
// eventServerConnection.sendPacket(packetUp);
|
||||
// break;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
// button.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// // Nothing to do
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
/**
|
||||
* Default callback for methods that don't return anything
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue