Commit f1430a05 authored by Ralf's avatar Ralf
Browse files

Merge branch 'master' of ralfj.de:saartuer

parents d72b6eb3 9a0250c3
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <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-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:icon="@drawable/icon" android:label="@string/app_name"> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name="de.hacksaar.andtuer.DoorActivity" android:label="@string/app_name"> <activity android:name="de.hacksaar.andtuer.DoorActivity" android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
......
# This file is automatically generated by IntelliJ IDEA # This file is automatically generated by IntelliJ IDEA
# Project target. # Project target.
target=android-7 target=android-14
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent">
android:layout_height="match_parent">
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" <LinearLayout android:layout_height="64sp" android:layout_width="match_parent"
android:layout_centerInParent="true" android:orientation="vertical"> android:orientation="horizontal">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" <Button android:layout_height="match_parent" android:layout_width="0dip" android:layout_weight="1"
android:id="@+id/connect_button" android:id="@+id/connect_button" android:text="@string/connect"/>
android:text="@string/connect"/> <Button android:layout_height="match_parent" android:layout_width="0dip" android:id="@+id/buzz_button"
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/buzz_button" android:layout_weight="1" android:text="@string/buzz" android:enabled="false"/>
android:text="@string/buzz" android:enabled="false"/> <Button android:layout_height="match_parent" android:layout_width="0dip" android:id="@+id/unlock_button"
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/open_button" android:layout_weight="1" android:text="@string/unlock_door" android:enabled="false"/>
android:text="@string/open_door" android:enabled="false"/> <Button android:layout_height="match_parent" android:layout_width="0dip" android:layout_weight="1"
<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"
android:id="@+id/disconnect_button" android:text="@string/disconnect" android:enabled="false"/> android:id="@+id/disconnect_button" android:text="@string/disconnect" android:enabled="false"/>
</LinearLayout> </LinearLayout>
</RelativeLayout> <TextView android:id="@+id/logout" android:layout_height="0dip" android:layout_width="match_parent"
\ No newline at end of file android:layout_weight="1"/>
</LinearLayout>
\ No newline at end of file
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
<string name="buzz">Buzz</string> <string name="buzz">Buzz</string>
<string name="open_door">Open door</string> <string name="open_door">Open door</string>
<string name="close_door">Close door</string> <string name="close_door">Close door</string>
<string name="unlock_door">Unlock</string>
<string name="preferences">Preferences</string> <string name="preferences">Preferences</string>
</resources> </resources>
\ No newline at end of file
...@@ -5,6 +5,10 @@ import android.util.Log; ...@@ -5,6 +5,10 @@ import android.util.Log;
import de.hacksaar.javatuer.InteractiveLogin; import de.hacksaar.javatuer.InteractiveLogin;
import de.hacksaar.javatuer.TyshellClient; 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.LinkedList;
import java.util.Queue; import java.util.Queue;
...@@ -50,10 +54,28 @@ class AsyncTyshell extends AsyncTask<Void, Void, Void> { ...@@ -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 @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
TyshellClient client = new TyshellClient(hostname, port, new AndroidLogging()); TyshellClient client = new TyshellClient(hostname, port, new AndroidLogging());
client.connect(username, keyFile, new AsyncInteractiveLogin()); client.connect(username, keyFile, new AsyncInteractiveLogin());
readUnlimited(client.getInputStream());
while (disconnect) { while (disconnect) {
String msg = null; String msg = null;
synchronized (messages) { synchronized (messages) {
......
...@@ -23,6 +23,7 @@ public class DoorActivity extends Activity implements View.OnClickListener { ...@@ -23,6 +23,7 @@ public class DoorActivity extends Activity implements View.OnClickListener {
private static final int DIALOG_STRING = 14; private static final int DIALOG_STRING = 14;
private static final int TEXT_ID = 42; private static final int TEXT_ID = 42;
private final AsyncTyshell.Prompter prompter = new DialogPrompter(); private final AsyncTyshell.Prompter prompter = new DialogPrompter();
private TextView logText;
private AsyncTyshell task; private AsyncTyshell task;
private String pendingMessage; private String pendingMessage;
...@@ -95,11 +96,8 @@ public class DoorActivity extends Activity implements View.OnClickListener { ...@@ -95,11 +96,8 @@ public class DoorActivity extends Activity implements View.OnClickListener {
case R.id.buzz_button: case R.id.buzz_button:
onBuzzClick(); onBuzzClick();
break; break;
case R.id.open_button: case R.id.unlock_button:
onOpenClick(); onUnlockClick();
break;
case R.id.close_button:
onCloseClick();
break; break;
case R.id.disconnect_button: case R.id.disconnect_button:
onDisconnectClick(); onDisconnectClick();
...@@ -121,21 +119,23 @@ public class DoorActivity extends Activity implements View.OnClickListener { ...@@ -121,21 +119,23 @@ public class DoorActivity extends Activity implements View.OnClickListener {
preferences.getString(DoorSettings.PREF_USER_KEYFILE, DoorSettings.DEFAULT_KEYFILE), preferences.getString(DoorSettings.PREF_USER_KEYFILE, DoorSettings.DEFAULT_KEYFILE),
prompter); prompter);
task.execute(); task.execute();
findViewById(R.id.open_button).setEnabled(true); findViewById(R.id.connect_button).setEnabled(false);
findViewById(R.id.close_button).setEnabled(true);
findViewById(R.id.buzz_button).setEnabled(true);
findViewById(R.id.disconnect_button).setEnabled(true);
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.door); setContentView(R.layout.door);
findViewById(R.id.open_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(R.id.close_button).setOnClickListener(this); findViewById(view).setOnClickListener(this);
findViewById(R.id.buzz_button).setOnClickListener(this); }
findViewById(R.id.disconnect_button).setOnClickListener(this); logText = (TextView) findViewById(R.id.logout);
findViewById(R.id.connect_button).setOnClickListener(this); 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 @Override
...@@ -161,10 +161,10 @@ public class DoorActivity extends Activity implements View.OnClickListener { ...@@ -161,10 +161,10 @@ public class DoorActivity extends Activity implements View.OnClickListener {
task.sendCommand("exit"); task.sendCommand("exit");
task.disconnect(); task.disconnect();
} }
findViewById(R.id.open_button).setEnabled(false); findViewById(R.id.unlock_button).setEnabled(false);
findViewById(R.id.close_button).setEnabled(false);
findViewById(R.id.buzz_button).setEnabled(false); findViewById(R.id.buzz_button).setEnabled(false);
findViewById(R.id.disconnect_button).setEnabled(false); findViewById(R.id.disconnect_button).setEnabled(false);
findViewById(R.id.connect_button).setEnabled(true);
} }
@Override @Override
...@@ -178,12 +178,6 @@ public class DoorActivity extends Activity implements View.OnClickListener { ...@@ -178,12 +178,6 @@ public class DoorActivity extends Activity implements View.OnClickListener {
} }
} }
private void onOpenClick() {
if (task != null) {
task.sendCommand("open");
}
}
@Override @Override
protected void onPrepareDialog(int id, Dialog dialog) { protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) { switch (id) {
...@@ -198,6 +192,21 @@ public class DoorActivity extends Activity implements View.OnClickListener { ...@@ -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 { private class DialogPrompter implements AsyncTyshell.Prompter {
DialogPrompter() { DialogPrompter() {
} }
...@@ -229,7 +238,7 @@ public class DoorActivity extends Activity implements View.OnClickListener { ...@@ -229,7 +238,7 @@ public class DoorActivity extends Activity implements View.OnClickListener {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.d(TAG, "Message: " + message); writeLog(message);
} }
}); });
} }
......
...@@ -76,6 +76,10 @@ public class TyshellClient { ...@@ -76,6 +76,10 @@ public class TyshellClient {
return (client.isConnected() && inputStream != null && outputStream != null); return (client.isConnected() && inputStream != null && outputStream != null);
} }
public InputStreamReader getInputStream() {
return inputStream;
}
public void sendCommand(String command) { public void sendCommand(String command) {
if (isConnected()) { if (isConnected()) {
try { try {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment