change the way the waker works: let others register to be called by it
[saartuer.git] / AndTuer / src / de / hacksaar / andtuer / DoorActivity.java
index fc2fc9ece9b97bc0c04e31f58b4eb741ea31c7b9..20d1d60d971d4b28bb9686a0d6763f88652fb3a9 100644 (file)
@@ -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);
                                }
                        });
                }