<?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"/>
# This file is automatically generated by IntelliJ IDEA
# Project target.
-target=android-7
+target=android-14
<?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
<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
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;
}
}
+ 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) {
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);
}
});
}
return (client.isConnected() && inputStream != null && outputStream != null);
}
+ public InputStreamReader getInputStream() {
+ return inputStream;
+ }
+
public void sendCommand(String command) {
if (isConnected()) {
try {