aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Klein <jlklein@google.com>2015-07-22 12:07:12 -0700
committerJeremy Klein <jlklein@google.com>2015-07-27 11:46:36 -0700
commit53236de2e0b4299b58913c811e03500bc909eb2f (patch)
treebb669fd2e0b6eb8e2e1634e11097ed8213dde794
parent20065b316e552d49d2aea17dfb255b03a9b4a0bb (diff)
downloadconnectbot-53236de2e0b4299b58913c811e03500bc909eb2f.tar.gz
connectbot-53236de2e0b4299b58913c811e03500bc909eb2f.tar.bz2
connectbot-53236de2e0b4299b58913c811e03500bc909eb2f.zip
Switch the handling of the disconnect all intent to HostListActivity.
-rw-r--r--app/src/main/AndroidManifest.xml3
-rw-r--r--app/src/main/java/org/connectbot/ConsoleActivity.java33
-rw-r--r--app/src/main/java/org/connectbot/HostListActivity.java64
-rw-r--r--app/src/main/java/org/connectbot/service/ConnectionNotifier.java7
4 files changed, 68 insertions, 39 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2bfc525..61bace5 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -41,7 +41,7 @@
android:backupAgent=".service.BackupAgent"
android:killAfterRestore="true">
- <activity android:name=".HostListActivity" >
+ <activity android:name=".HostListActivity" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@@ -78,7 +78,6 @@
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 4c7fa38..e7a8f7d 100644
--- a/app/src/main/java/org/connectbot/ConsoleActivity.java
+++ b/app/src/main/java/org/connectbot/ConsoleActivity.java
@@ -18,8 +18,6 @@
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;
@@ -82,7 +80,6 @@ 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;
@@ -142,8 +139,6 @@ 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();
@@ -181,13 +176,6 @@ 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) {
@@ -920,11 +908,6 @@ 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)
@@ -935,7 +918,6 @@ public class ConsoleActivity extends Activity {
super.onNewIntent(intent);
Log.d(TAG, "onNewIntent called");
- setIntent(intent);
requested = intent.getData();
@@ -1133,21 +1115,6 @@ 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/HostListActivity.java b/app/src/main/java/org/connectbot/HostListActivity.java
index 2fd9560..0e0deab 100644
--- a/app/src/main/java/org/connectbot/HostListActivity.java
+++ b/app/src/main/java/org/connectbot/HostListActivity.java
@@ -17,6 +17,7 @@
package org.connectbot;
+import java.util.ArrayList;
import java.util.List;
import org.connectbot.bean.HostBean;
@@ -65,6 +66,9 @@ import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class HostListActivity extends ListActivity {
+ public final static String TAG = "CB.HostListActivity";
+ public static final String DISCONNECT_ACTION = "org.connectbot.action.DISCONNECT";
+
public final static int REQUEST_EDIT = 1;
public final static int REQUEST_EULA = 2;
@@ -88,6 +92,14 @@ public class HostListActivity extends ListActivity {
protected boolean makingShortcut = false;
+ private boolean waitingForDisconnectAll = false;
+
+ /**
+ * Whether to close the activity when disconnectAll is called. True if this activity was
+ * only brought to the foreground via the notification button to disconnect all hosts.
+ */
+ private boolean closeOnDisconnectAll = true;
+
protected Handler updateHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -101,6 +113,10 @@ public class HostListActivity extends ListActivity {
// update our listview binder to find the service
HostListActivity.this.updateList();
+
+ if (waitingForDisconnectAll) {
+ disconnectAll();
+ }
}
public void onServiceDisconnected(ComponentName className) {
@@ -129,11 +145,33 @@ public class HostListActivity extends ListActivity {
this.hostdb.close();
this.hostdb = null;
}
+
+ closeOnDisconnectAll = true;
}
@Override
public void onResume() {
super.onResume();
+
+ // Must disconnectAll before setting closeOnDisconnectAll to know whether to keep the
+ // activity open after disconnecting.
+ if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0 &&
+ getIntent().getAction() == DISCONNECT_ACTION) {
+ Log.d(TAG, "Got disconnect all request");
+ disconnectAll();
+ }
+
+ // Still close on disconnect if waiting for a disconnect.
+ closeOnDisconnectAll = waitingForDisconnectAll && closeOnDisconnectAll;
+ }
+
+ /* (non-Javadoc)
+ * @see android.app.Activity#onNewIntent(android.content.Intent)
+ */
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ setIntent(intent);
}
@Override
@@ -394,13 +432,37 @@ public class HostListActivity extends ListActivity {
hostdb.deleteHost(host);
updateHandler.sendEmptyMessage(-1);
}
- })
+ })
.setNegativeButton(R.string.delete_neg, null).create().show();
return true;
}
});
}
+ /**
+ * Disconnects all active connections and closes the activity if appropriate.
+ */
+ 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);
+ }
+ updateHandler.sendEmptyMessage(-1);
+ waitingForDisconnectAll = false;
+
+ if (closeOnDisconnectAll) {
+ // Clear the intent so that the activity can be relaunched without closing.
+ // TODO(jlklein): Find a better way to do this.
+ setIntent(new Intent());
+ finish();
+ }
+ }
+
/**
* @param text
diff --git a/app/src/main/java/org/connectbot/service/ConnectionNotifier.java b/app/src/main/java/org/connectbot/service/ConnectionNotifier.java
index 38b911b..a68fffc 100644
--- a/app/src/main/java/org/connectbot/service/ConnectionNotifier.java
+++ b/app/src/main/java/org/connectbot/service/ConnectionNotifier.java
@@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.connectbot.ConsoleActivity;
+import org.connectbot.HostListActivity;
import org.connectbot.R;
import org.connectbot.bean.HostBean;
import org.connectbot.util.HostDatabase;
@@ -117,15 +118,15 @@ 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);
+ Intent disconnectIntent = new Intent(context, HostListActivity.class);
+ disconnectIntent.setAction(HostListActivity.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,
+ disconnectIntent,
0));
return builder.build();