Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to customize keyboard shortcuts. Fix for: #92 and #13 #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package net.christianbeier.droidvnc_ng;

public class HotkeyBinding implements Comparable<HotkeyBinding> {
private final VNCKey[] keys = new VNCKey[3];
// placeholder for command to execute by this hotkey
private final ICommand command;
// user-friendly name. Uses in GUI
public final String friendlyName;
// uses for settings serialization
public final String PREFS_NAME;

public HotkeyBinding(String friendlyName, String prefsName, VNCKey key1, VNCKey key2, VNCKey key3, ICommand command) {
keys[0] = key1;
keys[1] = key2;
keys[2] = key3;
this.command = command;
this.friendlyName = friendlyName;
this.PREFS_NAME = prefsName;
}

public boolean isTriggered() {
for (VNCKey key : keys) {
if (key != null && key != VNCKey.Empty && key.isNotDown())
return false;
}
return true;
}

public boolean tryExecute() {
if (isTriggered()) {
command.execute();
return true;
}
return false;
}

public VNCKey getKey(int index) {
if (index > 3) return VNCKey.Empty;
return keys[index];
}

public void setKey(int index, VNCKey key) {
if (index > 3) return;
keys[index] = key;
}

@Override
public int compareTo(HotkeyBinding hotkeyBinding) {
return hotkeyBinding.keys.length - keys.length;
}

public interface ICommand {
void execute();
}
}
Loading