diff options
-rw-r--r-- | app/src/main/java/org/connectbot/ConsoleActivity.java | 45 | ||||
-rw-r--r-- | app/src/main/java/org/connectbot/service/TerminalManager.java | 5 |
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; } |