private static final int DIALOG_STRING = 14;
private static final int TEXT_ID = 42;
private final AsyncTyshell.Prompter prompter = new DialogPrompter();
+ private TextView logText;
private AsyncTyshell task;
private String pendingMessage;
case R.id.buzz_button:
onBuzzClick();
break;
- case R.id.open_button:
- onOpenClick();
- break;
- case R.id.close_button:
- onCloseClick();
+ case R.id.unlock_button:
+ onUnlockClick();
break;
case R.id.disconnect_button:
onDisconnectClick();
preferences.getString(DoorSettings.PREF_USER_KEYFILE, DoorSettings.DEFAULT_KEYFILE),
prompter);
task.execute();
- findViewById(R.id.open_button).setEnabled(true);
- findViewById(R.id.close_button).setEnabled(true);
- findViewById(R.id.buzz_button).setEnabled(true);
- findViewById(R.id.disconnect_button).setEnabled(true);
+ findViewById(R.id.connect_button).setEnabled(false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.door);
- findViewById(R.id.open_button).setOnClickListener(this);
- findViewById(R.id.close_button).setOnClickListener(this);
- findViewById(R.id.buzz_button).setOnClickListener(this);
- findViewById(R.id.disconnect_button).setOnClickListener(this);
- findViewById(R.id.connect_button).setOnClickListener(this);
+ for (int view : new int[]{R.id.unlock_button, R.id.buzz_button, R.id.disconnect_button, R.id.connect_button}) {
+ findViewById(view).setOnClickListener(this);
+ }
+ logText = (TextView) findViewById(R.id.logout);
+ try {
+ logText.setText("Welcome to Hacksaar AndTuer, Version " +
+ getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
+ } catch (Exception e) {
+ logText.setText("Welcome to Hacksaar AndTuer, [unknown version]");
+ }
}
@Override
task.sendCommand("exit");
task.disconnect();
}
- findViewById(R.id.open_button).setEnabled(false);
- findViewById(R.id.close_button).setEnabled(false);
+ findViewById(R.id.unlock_button).setEnabled(false);
findViewById(R.id.buzz_button).setEnabled(false);
findViewById(R.id.disconnect_button).setEnabled(false);
+ findViewById(R.id.connect_button).setEnabled(true);
}
@Override
}
}
- private void onOpenClick() {
- if (task != null) {
- task.sendCommand("open");
- }
- }
-
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
}
+ private void onUnlockClick() {
+ if (task != null) {
+ task.sendCommand("unlock");
+ }
+ }
+
+ private void writeLog(String msg) {
+ Log.d(TAG, "Log: " + msg);
+ logText.setText(logText.getText() + "\n" + msg);
+
+ findViewById(R.id.unlock_button).setEnabled(true);
+ findViewById(R.id.buzz_button).setEnabled(true);
+ findViewById(R.id.disconnect_button).setEnabled(true);
+ }
+
private class DialogPrompter implements AsyncTyshell.Prompter {
DialogPrompter() {
}
runOnUiThread(new Runnable() {
@Override
public void run() {
- Log.d(TAG, "Message: " + message);
+ writeLog(message);
}
});
}