aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main
diff options
context:
space:
mode:
authorJeremy Klein <jlklein@google.com>2015-07-21 19:40:07 -0700
committerJeremy Klein <jlklein@google.com>2015-07-27 11:46:36 -0700
commit20065b316e552d49d2aea17dfb255b03a9b4a0bb (patch)
tree1ea08a7349902597f4dbbe4a31cd0ca05837bc98 /app/src/main
parent1a47c5ed12da8893fb2595ae1a99d4082ec36bd7 (diff)
downloadconnectbot-20065b316e552d49d2aea17dfb255b03a9b4a0bb.tar.gz
connectbot-20065b316e552d49d2aea17dfb255b03a9b4a0bb.tar.bz2
connectbot-20065b316e552d49d2aea17dfb255b03a9b4a0bb.zip
Add a disconnect button to the active notification dialog.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml1
-rw-r--r--app/src/main/java/org/connectbot/ConsoleActivity.java33
-rw-r--r--app/src/main/java/org/connectbot/service/ConnectionNotifier.java12
3 files changed, 46 insertions, 0 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 406f3b9..2bfc525 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -78,6 +78,7 @@
android:launchMode="singleTop" android:hardwareAccelerated="false">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
+ <action android:name="org.connectbot.action.DISCONNECT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="ssh" />
diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java
index e7a8f7d..4c7fa38 100644
--- a/app/src/main/java/org/connectbot/ConsoleActivity.java
+++ b/app/src/main/java/org/connectbot/ConsoleActivity.java
@@ -18,6 +18,8 @@
package org.connectbot;
import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.connectbot.bean.SelectionArea;
@@ -80,6 +82,7 @@ import de.mud.terminal.vt320;
public class ConsoleActivity extends Activity {
public final static String TAG = "CB.ConsoleActivity";
+ public static final String DISCONNECT_ACTION = "org.connectbot.action.DISCONNECT";
protected static final int REQUEST_EDIT = 1;
@@ -139,6 +142,8 @@ public class ConsoleActivity extends Activity {
private boolean inActionBarMenu = false;
private boolean titleBarHide;
+ private boolean waitingForDisconnectAll = false;
+
private ServiceConnection connection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
bound = ((TerminalManager.TerminalBinder) service).getService();
@@ -176,6 +181,13 @@ public class ConsoleActivity extends Activity {
}
setDisplayedTerminal(requestedIndex);
+
+ // This needs to happen after the views are constructed in order to
+ // know when it's safe to kill this activity.
+ if (waitingForDisconnectAll) {
+ waitingForDisconnectAll = false;
+ disconnectAll();
+ }
}
public void onServiceDisconnected(ComponentName className) {
@@ -908,6 +920,11 @@ public class ConsoleActivity extends Activity {
if (forcedOrientation && bound != null)
bound.setResizeAllowed(true);
+
+ if (getIntent().getAction() == DISCONNECT_ACTION) {
+ Log.d(TAG, "Got disconnect request");
+ disconnectAll();
+ }
}
/* (non-Javadoc)
@@ -918,6 +935,7 @@ public class ConsoleActivity extends Activity {
super.onNewIntent(intent);
Log.d(TAG, "onNewIntent called");
+ setIntent(intent);
requested = intent.getData();
@@ -1115,6 +1133,21 @@ public class ConsoleActivity extends Activity {
}
/**
+ * Disconnects and closes all open terminals.
+ */
+ private void disconnectAll() {
+ // TODO(jklein24): Show a confirm dialog before actually disconnecting.
+ if (bound == null) {
+ waitingForDisconnectAll = true;
+ return;
+ }
+ // Copy the bridges list because bridges are removed from the array when disconnected.
+ for (TerminalBridge bridge : new ArrayList<TerminalBridge>(bound.bridges)) {
+ bridge.dispatchDisconnect(true);
+ }
+ }
+
+ /**
* Adds a new TerminalBridge to the current set of views in our ViewFlipper.
*
* @param bridge TerminalBridge to add to our ViewFlipper
diff --git a/app/src/main/java/org/connectbot/service/ConnectionNotifier.java b/app/src/main/java/org/connectbot/service/ConnectionNotifier.java
index c480143..38b911b 100644
--- a/app/src/main/java/org/connectbot/service/ConnectionNotifier.java
+++ b/app/src/main/java/org/connectbot/service/ConnectionNotifier.java
@@ -45,6 +45,7 @@ import android.support.v4.app.NotificationCompat;
public abstract class ConnectionNotifier {
private static final int ONLINE_NOTIFICATION = 1;
private static final int ACTIVITY_NOTIFICATION = 2;
+ private static final int ONLINE_DISCONNECT_NOTIFICATION = 3;
public static ConnectionNotifier getInstance() {
if (PreferenceConstants.PRE_ECLAIR)
@@ -116,6 +117,17 @@ public abstract class ConnectionNotifier {
builder.setContentTitle(res.getString(R.string.app_name));
builder.setContentText(res.getString(R.string.app_is_running));
+ Intent notificationIntent = new Intent(context, ConsoleActivity.class);
+ notificationIntent.setAction(ConsoleActivity.DISCONNECT_ACTION);
+ builder.addAction(
+ android.R.drawable.ic_menu_close_clear_cancel,
+ res.getString(R.string.list_host_disconnect),
+ PendingIntent.getActivity(
+ context,
+ ONLINE_DISCONNECT_NOTIFICATION,
+ notificationIntent,
+ 0));
+
return builder.build();
}