Commit fb09c083 authored by Thomas Krex's avatar Thomas Krex
Browse files

Dialoge während dem reconnecting hinzugefügt, Reconnecting kann so manuell abgebrochen werden.

Aufnahme wird dabei nicht gestoppt.
parent 409eee78
......@@ -2,8 +2,8 @@
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
eclipse.preferences.version=1
encoding//src/com/example/tttrecorderandroid/Start_session.java=UTF-8
encoding//src/tttrec/connections/Connection.java=UTF-8
encoding//src/tttrec/connections/RFBConnection.java=UTF-8
encoding//src/tttrec/core/RfbProtocol.java=UTF-8
......@@ -6,7 +6,7 @@
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
......
......@@ -3,18 +3,25 @@ package com.example.tttrecorderandroid;
import java.util.ArrayList;
import java.util.List;
import tttrec.core.RfbProtocol;
import tttrec.customviews.AnnotationView;
import tttrec.customviews.ScaleAwareImageView;
import tttrec.interaction.AnnotationCanvasTouchListener;
import tttrec.interaction.InteractionManager;
import tttrec.util.ReconnectDialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
......@@ -33,6 +40,8 @@ public class MainActivity extends Activity {
private GestureDetector gestureDetector;
private List<ImageButton> colourButtons;
private ReconnectDialog rDialog;
private ImageButton freehandAnnotationButton;
private ImageButton highlightAnnotationButton;
......@@ -90,7 +99,8 @@ public class MainActivity extends Activity {
}
});
tttRec = new TTTRecorderAndroid(annotationView, imgV, new Handler());
tttRec = new TTTRecorderAndroid(annotationView, imgV, new Handler(),
getApplicationContext());
Thread t = new Thread(tttRec);
t.start();
......@@ -103,6 +113,23 @@ public class MainActivity extends Activity {
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(
connectionReceiver,
new IntentFilter(RfbProtocol.BROADCAST_ACTION_RECONNECTING));
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(
connectionReceiver);
}
private List<ImageButton> createColorButtonList() {
List<ImageButton> result = new ArrayList<ImageButton>();
result.add((ImageButton) findViewById(R.id.colour_button_yellow));
......@@ -239,9 +266,9 @@ public class MainActivity extends Activity {
@Override
public void onClick(DialogInterface dialog, int which) {
tttRec.cancelConnection();
tttRec = null;
MainActivity.this.finish();
// stops recording, closes connection to server and
// returns to login activity
exitActivity();
}
});
......@@ -250,4 +277,92 @@ public class MainActivity extends Activity {
}
public void exitActivity() {
if (recording) {
im.stopRecording();
annotationView.recording = false;
}
tttRec.cancelConnection();
tttRec = null;
MainActivity.this.finish();
}
private final BroadcastReceiver connectionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String status = intent.getStringExtra(RfbProtocol.BROADCAST_STATUS);
if (status.equals(RfbProtocol.BROADCAT_STATUS_RECONNECTING)) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
displayReconnectionDialog();
}
});
} else if (status.equals(RfbProtocol.BROADCAST_STATUS_FAIL)) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
rDialog.dismiss();
displayFailDialog();
}
});
} else if (status.equals(RfbProtocol.BROADCAST_STATUS_RECONNECTED)) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
rDialog.dismiss();
}
});
} else {
Log.e("LocalBroadcastReceiver", "Unknown Message from Intent");
}
}
};
public void displayReconnectionDialog() {
rDialog = new ReconnectDialog(this);
rDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Abort",
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
exitActivity();
}
});
rDialog.show();
}
public void displayFailDialog() {
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("No Connection");
builder.setMessage("Failed to reconnect to Server. Session will be closed");
builder.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
exitActivity();
}
});
AlertDialog failDialog = builder.create();
failDialog.show();
}
}
......@@ -15,6 +15,7 @@ import tttrec.messages.DeleteAllAnnotation;
import tttrec.messages.DeleteAnnotation;
import tttrec.messages.UserInputMessage;
import tttrec.recording.Recorder;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.os.Handler;
......@@ -28,16 +29,16 @@ import android.os.Handler;
*/
public class TTTRecorderAndroid implements Runnable {
private final RFBConnection connection = null;
private RfbProtocol rfbProtocol = null;
public static RFBConnection rfbCon;
public static RFBConnection rfbCon = null;
private final ScaleAwareImageView imgv;
// TODO Move to Graphics Context
private final AnnotationView annotationView;
private final Handler uiThreadHandler;
private final Context context;
private Recorder recorder;
private InteractionManager interactionManager;
......@@ -130,10 +131,11 @@ public class TTTRecorderAndroid implements Runnable {
};
public TTTRecorderAndroid(AnnotationView annotationView,
ScaleAwareImageView imgv, Handler uiThreadHandler) {
ScaleAwareImageView imgv, Handler uiThreadHandler, Context context) {
this.uiThreadHandler = uiThreadHandler;
this.annotationView = annotationView;
this.imgv = imgv;
this.context = context;
}
......@@ -237,9 +239,8 @@ public class TTTRecorderAndroid implements Runnable {
@Override
public void run() {
// establishConnection("192.168.178.20", 5900, "1234");
rfbProtocol = new RfbProtocol(rfbCon, imgv, annotationView, this);
rfbProtocol = new RfbProtocol(rfbCon, imgv, annotationView, this,
context);
Thread t = new Thread(rfbProtocol);
t.start();
......@@ -254,6 +255,8 @@ public class TTTRecorderAndroid implements Runnable {
public void cancelConnection() {
if (rfbProtocol != null) {
rfbProtocol.close();
interactionManager = null;
rfbProtocol = null;
}
}
......
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universitt Mnchen
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universitt Mnchen
//
// This file is part of TeleTeachingTool.
//
......@@ -29,22 +29,23 @@ import java.io.InputStream;
import java.io.OutputStream;
import tttrec.core.ProtocolPreferences;
import tttrec.util.ReconnectException;
public interface Connection {
public static final byte CONNECTION_SUCCESSFULL = 0;
public static final byte WRONG_PASSWORD = 1;
public static final byte CONNECTION_ERROR = 2;
public InputStream getInputStream();
public OutputStream getOutputStream();
public byte connect() throws IOException;
public void reconnect();
public ProtocolPreferences getProtocolPreferences();
public void close();
public InputStream getInputStream();
public OutputStream getOutputStream();
public byte connect() throws IOException;
public void reconnect() throws ReconnectException;
public ProtocolPreferences getProtocolPreferences();
public void close();
}
......@@ -34,6 +34,10 @@ import tttrec.messages.MessageConsumer;
import tttrec.messages.MessageProducer;
import tttrec.messages.UserInputMessage;
import tttrec.recording.Recorder;
import tttrec.util.ReconnectException;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.widget.ImageView;
......@@ -42,6 +46,12 @@ import com.example.tttrecorderandroid.TTTRecorderAndroid;
public class RfbProtocol extends GraphicsContext implements Runnable,
MessageProducer {
public static String BROADCAST_ACTION_RECONNECTING = "reconnecting";
public static String BROADCAST_STATUS = "status";
public static String BROADCAST_STATUS_FAIL = "reconnecting failed";
public static String BROADCAT_STATUS_RECONNECTING = "reconnecting";
public static String BROADCAST_STATUS_RECONNECTED = "reconnected";
// I/O
private Connection connection;
private DataInputStream is;
......@@ -49,12 +59,15 @@ public class RfbProtocol extends GraphicsContext implements Runnable,
public Recorder recorder;
private final Context context;
// The constructor
public RfbProtocol(Connection connection, ImageView imgView,
AnnotationView annV, TTTRecorderAndroid tnc) {
AnnotationView annV, TTTRecorderAndroid tnc, Context context) {
super(connection.getProtocolPreferences(), imgView, annV, tnc);
this.connection = connection;
this.context = context;
if (prefs.framebufferWidth > 1024 || prefs.framebufferHeight > 768) {
Log.w("blub", "Warning:\n" + "The current VNC desktop size is "
......@@ -120,6 +133,7 @@ public class RfbProtocol extends GraphicsContext implements Runnable,
// Thread
@Override
public void run() {
running = true;
while (running)
try {
......@@ -134,7 +148,42 @@ public class RfbProtocol extends GraphicsContext implements Runnable,
e.printStackTrace();
// try to continue
connection.reconnect();
try {
// send Intent to MainActivity if reconnecting
Intent reconnectIntent = new Intent(
BROADCAST_ACTION_RECONNECTING);
reconnectIntent.putExtra(BROADCAST_STATUS,
BROADCAT_STATUS_RECONNECTING);
LocalBroadcastManager.getInstance(context)
.sendBroadcastSync(reconnectIntent);
connection.reconnect();
// send Intent to MainActivity if reconnecting succeeded
Intent sucessIntent = new Intent(
BROADCAST_ACTION_RECONNECTING);
sucessIntent.putExtra(BROADCAST_STATUS,
BROADCAST_STATUS_RECONNECTED);
LocalBroadcastManager.getInstance(context)
.sendBroadcast(sucessIntent);
} catch (ReconnectException e1) {
e1.printStackTrace();
Log.e("Run-Loop", "ReconnectException caught");
// Intent to MainActivity if reconnecting failed
Intent failIntent = new Intent(
BROADCAST_ACTION_RECONNECTING);
failIntent.putExtra(BROADCAST_STATUS,
BROADCAST_STATUS_FAIL);
LocalBroadcastManager.getInstance(context)
.sendBroadcast(failIntent);
running = false;
break;
}
}
}
}
......
package tttrec.util;
import android.app.ProgressDialog;
import android.content.Context;
public class ReconnectDialog extends ProgressDialog {
public ReconnectDialog(Context context) {
super(context);
setCancelable(false);
setTitle("Lost Connection to Server");
setMessage("Trying to Reconnect");
setProgressStyle(ProgressDialog.STYLE_SPINNER);
}
}
package tttrec.util;
public class ReconnectException extends Exception {
}
package tttrec.util;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
public class StatusReceiver extends ResultReceiver {
private final ProgressDialog dialog;
public StatusReceiver(Handler handler, ProgressDialog dialog) {
super(handler);
this.dialog = dialog;
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
}
}
Markdown is supported
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