Version 0.2 (includes log and icon \o/)
authormar-v-in <github@rvin.mooo.com>
Wed, 23 Oct 2013 20:02:28 +0000 (22:02 +0200)
committermar-v-in <github@rvin.mooo.com>
Wed, 23 Oct 2013 20:02:28 +0000 (22:02 +0200)
AndTuer/AndroidManifest.xml
AndTuer/project.properties
AndTuer/res/drawable/icon.png [deleted file]
AndTuer/res/layout/door.xml
AndTuer/res/values/strings.xml
AndTuer/src/de/hacksaar/andtuer/AsyncTyshell.java
AndTuer/src/de/hacksaar/andtuer/DoorActivity.java
JavaTuer/src/de/hacksaar/javatuer/TyshellClient.java

index 42c81c6137caa9e90dafea32520f253604127af9..85912508986a4ab26884454ba26cf4d0f59df243 100644 (file)
@@ -1,12 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          package="de.hacksaar.andtuer">
+          package="de.hacksaar.andtuer" android:versionCode="2" android:versionName="0.2">
     <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
     <uses-permission android:name="android.permission.INTERNET"/>
-    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
-    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-    <application android:icon="@drawable/icon" android:label="@string/app_name">
-        <activity android:name="de.hacksaar.andtuer.DoorActivity" android:label="@string/app_name">
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
+        <activity android:name="de.hacksaar.andtuer.DoorActivity" android:label="@string/app_name"
+                  android:configChanges="orientation|keyboardHidden|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN"/>
                 <category android:name="android.intent.category.LAUNCHER"/>
index 8ef3988fc6b697b476600116afbe4022e97ee0eb..2aef174167e13729fa0c6ee1245fe7987c36eb01 100644 (file)
@@ -1,3 +1,3 @@
 # This file is automatically generated by IntelliJ IDEA
 # Project target.
-target=android-7
+target=android-14
diff --git a/AndTuer/res/drawable/icon.png b/AndTuer/res/drawable/icon.png
deleted file mode 100644 (file)
index 08ee50d..0000000
Binary files a/AndTuer/res/drawable/icon.png and /dev/null differ
index d19b2249f51f5d17064d6172f2a080a35a5c4e15..8133e922f943be4ad0e7a2d9c926245da9266eb3 100644 (file)
@@ -1,21 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent">
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
+              android:orientation="vertical" android:layout_height="match_parent">
 
-    <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content"
-                  android:layout_centerInParent="true" android:orientation="vertical">
-        <Button android:layout_height="wrap_content" android:layout_width="wrap_content"
-                android:id="@+id/connect_button"
-                android:text="@string/connect"/>
-        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/buzz_button"
-                android:text="@string/buzz" android:enabled="false"/>
-        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/open_button"
-                android:text="@string/open_door" android:enabled="false"/>
-        <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/close_button"
-                android:text="@string/close_door" android:enabled="false"/>
-        <Button android:layout_height="wrap_content" android:layout_width="wrap_content"
+    <LinearLayout android:layout_height="64sp" android:layout_width="match_parent"
+                  android:orientation="horizontal">
+        <Button android:layout_height="match_parent" android:layout_width="0dip" android:layout_weight="1"
+                android:id="@+id/connect_button" android:text="@string/connect"/>
+        <Button android:layout_height="match_parent" android:layout_width="0dip" android:id="@+id/buzz_button"
+                android:layout_weight="1" android:text="@string/buzz" android:enabled="false"/>
+        <Button android:layout_height="match_parent" android:layout_width="0dip" android:id="@+id/unlock_button"
+                android:layout_weight="1" android:text="@string/unlock_door" android:enabled="false"/>
+        <Button android:layout_height="match_parent" android:layout_width="0dip" android:layout_weight="1"
                 android:id="@+id/disconnect_button" android:text="@string/disconnect" android:enabled="false"/>
     </LinearLayout>
-</RelativeLayout>
\ No newline at end of file
+    <TextView android:id="@+id/logout" android:layout_height="0dip" android:layout_width="match_parent"
+              android:layout_weight="1"/>
+</LinearLayout>
\ No newline at end of file
index a0e515389b8a8a2d30b4bd4c0717ba17a5e8c9c9..b87a4c32f08db8e68c8428c6ce1360abc747cfe9 100644 (file)
@@ -6,5 +6,6 @@
     <string name="buzz">Buzz</string>
     <string name="open_door">Open door</string>
     <string name="close_door">Close door</string>
+    <string name="unlock_door">Unlock</string>
     <string name="preferences">Preferences</string>
 </resources>
\ No newline at end of file
index 4dcdcafd719d4f27273045a48d9e8331bf7b8316..623698813e25c907a698cb679252883111676010 100644 (file)
@@ -5,6 +5,10 @@ import android.util.Log;
 import de.hacksaar.javatuer.InteractiveLogin;
 import de.hacksaar.javatuer.TyshellClient;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.LinkedList;
 import java.util.Queue;
 
@@ -50,10 +54,28 @@ class AsyncTyshell extends AsyncTask<Void, Void, Void> {
                }
        }
 
+       private void readUnlimited(InputStreamReader inputStreamReader) {
+               final BufferedReader reader = new BufferedReader(inputStreamReader);
+               new Thread(new Runnable() {
+                       @Override
+                       public void run() {
+                               String line;
+                               try {
+                                       while((line = reader.readLine()) != null) {
+                                               prompter.sendMessage(line);
+                                       }
+                               } catch (Exception e) {
+                                       Log.w("end read unlimited!", e);
+                               }
+                       }
+               }).start();
+       }
+
        @Override
        protected Void doInBackground(Void... voids) {
                TyshellClient client = new TyshellClient(hostname, port, new AndroidLogging());
                client.connect(username, keyFile, new AsyncInteractiveLogin());
+               readUnlimited(client.getInputStream());
                while (disconnect) {
                        String msg = null;
                        synchronized (messages) {
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);
                                }
                        });
                }
index 73d637d1bdeab60ca504c7b31b7f140469a0ba33..129a7bd2d84c4b84cc3a8873b2ba9cf7d2bb03f0 100644 (file)
@@ -76,6 +76,10 @@ public class TyshellClient {
                return (client.isConnected() && inputStream != null && outputStream != null);
        }
 
+       public InputStreamReader getInputStream() {
+               return inputStream;
+       }
+
        public void sendCommand(String command) {
                if (isConnected()) {
                        try {