X-Git-Url: https://git.ralfj.de/saartuer.git/blobdiff_plain/5bceb6534d5f640dcdd4d5015cecfbad4e82a7b7..0889e9a1ec6bda2c4b16dabf0ab40793ac17756c:/AndTuer/src/de/hacksaar/andtuer/DoorActivity.java?ds=inline diff --git a/AndTuer/src/de/hacksaar/andtuer/DoorActivity.java b/AndTuer/src/de/hacksaar/andtuer/DoorActivity.java index fc2fc9e..20d1d60 100644 --- a/AndTuer/src/de/hacksaar/andtuer/DoorActivity.java +++ b/AndTuer/src/de/hacksaar/andtuer/DoorActivity.java @@ -23,6 +23,7 @@ public class DoorActivity extends Activity implements View.OnClickListener { 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; @@ -95,11 +96,8 @@ public class DoorActivity extends Activity implements View.OnClickListener { 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(); @@ -121,21 +119,23 @@ public class DoorActivity extends Activity implements View.OnClickListener { 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 @@ -161,10 +161,10 @@ public class DoorActivity extends Activity implements View.OnClickListener { 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 @@ -178,12 +178,6 @@ public class DoorActivity extends Activity implements View.OnClickListener { } } - private void onOpenClick() { - if (task != null) { - task.sendCommand("open"); - } - } - @Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { @@ -198,6 +192,21 @@ public class DoorActivity extends Activity implements View.OnClickListener { } + 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() { } @@ -229,7 +238,7 @@ public class DoorActivity extends Activity implements View.OnClickListener { runOnUiThread(new Runnable() { @Override public void run() { - Log.d(TAG, "Message: " + message); + writeLog(message); } }); }