aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2015-08-07 23:25:19 -0600
committerKenny Root <kenny@the-b.org>2015-08-07 23:25:22 -0600
commit374952ea62dd5199b38da51cc7efe075d999120a (patch)
tree6783a5e43b3f05b386fab77c7466d13ec5477a5f /app
parentc7f0ab6934e86f3d85d1895c6a71e16173993213 (diff)
downloadconnectbot-374952ea62dd5199b38da51cc7efe075d999120a.tar.gz
connectbot-374952ea62dd5199b38da51cc7efe075d999120a.tar.bz2
connectbot-374952ea62dd5199b38da51cc7efe075d999120a.zip
Allow indexing into bridges to assist with ViewPager
Since ViewPager seems to have no way to inspect its items, we need to query the adapter for the item at the selected index.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/org/connectbot/ConsoleActivity.java45
-rw-r--r--app/src/main/java/org/connectbot/service/TerminalManager.java5
2 files changed, 32 insertions, 18 deletions
diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java
index 91abb82..e011c93 100644
--- a/app/src/main/java/org/connectbot/ConsoleActivity.java
+++ b/app/src/main/java/org/connectbot/ConsoleActivity.java
@@ -47,6 +47,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.preference.PreferenceManager;
+import android.support.v4.app.ActivityCompat;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
@@ -197,8 +198,9 @@ public class ConsoleActivity extends Activity {
TerminalBridge bridge = (TerminalBridge) msg.obj;
adapter.notifyDataSetChanged();
- if (bridge.isAwaitingClose())
+ if (bridge.isAwaitingClose()) {
closeBridge(bridge);
+ }
}
};
@@ -218,9 +220,10 @@ public class ConsoleActivity extends Activity {
}
protected View findCurrentView(int id) {
- if (adapter.getCount() == 0) return null;
- View view = pager.getChildAt(pager.getCurrentItem());
- if (view == null) return null;
+ TerminalView view = adapter.getCurrentTerminalView();
+ if (view == null) {
+ return null;
+ }
return view.findViewById(id);
}
@@ -308,11 +311,7 @@ public class ConsoleActivity extends Activity {
new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
- View overlay = findCurrentView(R.id.terminal_overlay);
- if (overlay != null)
- overlay.startAnimation(fade_out_delayed);
- updateDefault();
- updatePromptVisible();
+ onTerminalChanged();
}
});
@@ -1084,14 +1083,25 @@ public class ConsoleActivity extends Activity {
}
/**
+ * Called whenever the displayed terminal is changed.
+ */
+ private void onTerminalChanged() {
+ View overlay = findCurrentView(R.id.terminal_overlay);
+ if (overlay != null)
+ overlay.startAnimation(fade_out_delayed);
+ updateDefault();
+ updatePromptVisible();
+ ActivityCompat.invalidateOptionsMenu(ConsoleActivity.this);
+ }
+
+ /**
* Displays the child in the ViewPager at the requestedIndex and updates the prompts.
*
* @param requestedIndex the index of the terminal view to display
*/
private void setDisplayedTerminal(int requestedIndex) {
pager.setCurrentItem(requestedIndex);
- updatePromptVisible();
- updateEmptyVisible();
+ onTerminalChanged();
}
private void pasteIntoTerminal() {
@@ -1135,9 +1145,8 @@ public class ConsoleActivity extends Activity {
terminal.setId(R.id.console_flip);
view.addView(terminal, 0);
- // Tag the view with its position so that it can be retrieved later.
- // Unfortunately, position here != child position in the ViewPager.
- view.setTag(position);
+ // Tag the view with its bridge so it can be retrieved later.
+ view.setTag(bridge);
container.addView(view);
overlay.startAnimation(fade_out_delayed);
@@ -1157,7 +1166,7 @@ public class ConsoleActivity extends Activity {
TerminalView terminal = (TerminalView) view.findViewById(R.id.console_flip);
final HostBean host = terminal.bridge.host;
int itemIndex = -1;
- int i = 0;
+ int i = 0;
for (TerminalBridge bridge : bound.getBridges()) {
if (bridge.host.equals(host)) {
itemIndex = i;
@@ -1172,6 +1181,10 @@ public class ConsoleActivity extends Activity {
}
}
+ public TerminalBridge getItemAtPosition(int position) {
+ return bound.getBridges().get(position);
+ }
+
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
@@ -1183,7 +1196,7 @@ public class ConsoleActivity extends Activity {
}
public TerminalView getCurrentTerminalView() {
- View currentView = pager.findViewWithTag(pager.getCurrentItem());
+ View currentView = pager.findViewWithTag(adapter.getItemAtPosition(pager.getCurrentItem()));
if (currentView == null) return null;
return (TerminalView) currentView.findViewById(R.id.console_flip);
}
diff --git a/app/src/main/java/org/connectbot/service/TerminalManager.java b/app/src/main/java/org/connectbot/service/TerminalManager.java
index b5d891d..8001561 100644
--- a/app/src/main/java/org/connectbot/service/TerminalManager.java
+++ b/app/src/main/java/org/connectbot/service/TerminalManager.java
@@ -22,6 +22,7 @@ import java.lang.ref.WeakReference;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
@@ -70,7 +71,7 @@ import android.util.Log;
public class TerminalManager extends Service implements BridgeDisconnectedListener, OnSharedPreferenceChangeListener {
public final static String TAG = "CB.TerminalManager";
- private List<TerminalBridge> bridges = new LinkedList<TerminalBridge>();
+ private ArrayList<TerminalBridge> bridges = new ArrayList<TerminalBridge>();
public Map<HostBean, WeakReference<TerminalBridge>> mHostBridgeMap =
new HashMap<HostBean, WeakReference<TerminalBridge>>();
public Map<String, WeakReference<TerminalBridge>> mNicknameBridgeMap =
@@ -471,7 +472,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
}
}
- public List<TerminalBridge> getBridges() {
+ public ArrayList<TerminalBridge> getBridges() {
return bridges;
}