diff --git a/app/build.gradle b/app/build.gradle index 0913b4e2..67e6c01e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ android { defaultConfig { applicationId "org.connectbot" - minSdkVersion 4 + minSdkVersion 8 targetSdkVersion 22 ndk { @@ -64,6 +64,8 @@ android { dependencies { compile "com.android.support:support-v4:22.2.1" + compile "com.android.support:appcompat-v7:22.2.1" + compile "com.android.support:design:22.2.0" } buildTypes { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a1b65015..7358c88e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,7 +21,7 @@ android:versionCode="375" android:installLocation="auto"> - + diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java index 214f8789..d6ee629e 100644 --- a/app/src/main/java/org/connectbot/ConsoleActivity.java +++ b/app/src/main/java/org/connectbot/ConsoleActivity.java @@ -23,6 +23,7 @@ import org.connectbot.bean.HostBean; import org.connectbot.bean.SelectionArea; +import org.connectbot.service.BridgeDisconnectedListener; import org.connectbot.service.PromptHelper; import org.connectbot.service.TerminalBridge; import org.connectbot.service.TerminalKeyListener; @@ -50,9 +51,11 @@ import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; +import android.support.design.widget.TabLayout; import android.support.v4.view.MotionEventCompat; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.widget.Toolbar; import android.text.ClipboardManager; import android.util.Log; import android.view.ContextMenu; @@ -88,7 +91,7 @@ import android.widget.Toast; import de.mud.terminal.vt320; -public class ConsoleActivity extends Activity { +public class ConsoleActivity extends Activity implements BridgeDisconnectedListener { public final static String TAG = "CB.ConsoleActivity"; protected static final int REQUEST_EDIT = 1; @@ -98,6 +101,8 @@ public class ConsoleActivity extends Activity { private static final int KEYBOARD_DISPLAY_TIME = 1500; protected ViewPager pager = null; + protected TabLayout tabs = null; + protected Toolbar toolbar = null; @Nullable protected TerminalManager bound = null; protected TerminalPagerAdapter adapter = null; @@ -152,7 +157,7 @@ public void onServiceConnected(ComponentName className, IBinder service) { bound = ((TerminalManager.TerminalBinder) service).getService(); // let manager know about our event handling services - bound.disconnectHandler = disconnectHandler; + bound.disconnectListener = ConsoleActivity.this; bound.setResizeAllowed(true); final String requestedNickname = (requested != null) ? requested.getFragment() : null; @@ -192,21 +197,16 @@ public void handleMessage(Message msg) { } }; - protected Handler disconnectHandler = new Handler() { - @Override - public void handleMessage(Message msg) { + public void onDisconnected(TerminalBridge bridge) { + synchronized (adapter) { + adapter.notifyDataSetChanged(); Log.d(TAG, "Someone sending HANDLE_DISCONNECT to parentHandler"); - // someone below us requested to display a password dialog - // they are sending nickname and requested - TerminalBridge bridge = (TerminalBridge) msg.obj; - - adapter.notifyDataSetChanged(); if (bridge.isAwaitingClose()) { closeBridge(bridge); } } - }; + } protected OnClickListener emulatedKeysListener = new OnClickListener() { @Override @@ -262,14 +262,12 @@ private void onEmulatedKeyClicked(View v) { * @param bridge */ private void closeBridge(final TerminalBridge bridge) { - synchronized (pager) { - updateEmptyVisible(); - updatePromptVisible(); + updateEmptyVisible(); + updatePromptVisible(); - // If we just closed the last bridge, go back to the previous activity. - if (pager.getChildCount() == 0) { - finish(); - } + // If we just closed the last bridge, go back to the previous activity. + if (pager.getChildCount() == 0) { + finish(); } } @@ -362,6 +360,7 @@ public void onCreate(Bundle icicle) { inflater = LayoutInflater.from(this); + toolbar = (Toolbar) findViewById(R.id.toolbar); pager = (ViewPager) findViewById(R.id.console_flip); registerForContextMenu(pager); pager.addOnPageChangeListener( @@ -371,6 +370,8 @@ public void onPageSelected(int position) { onTerminalChanged(); } }); + adapter = new TerminalPagerAdapter(); + pager.setAdapter(adapter); empty = (TextView) findViewById(android.R.id.empty); @@ -464,6 +465,10 @@ public void onMenuVisibilityChanged(boolean isVisible) { } }); + tabs = (TabLayout) findViewById(R.id.tabs); + if (tabs != null) + tabs.setupWithViewPager(pager); + // detect fling gestures to switch between terminals final GestureDetector detect = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { private float totalY = 0; @@ -635,9 +640,6 @@ public boolean onTouch(View v, MotionEvent event) { } }); - - adapter = new TerminalPagerAdapter(); - pager.setAdapter(adapter); } /** @@ -1225,6 +1227,15 @@ public TerminalBridge getBridgeAtPosition(int position) { return bridges.get(position); } + @Override + public void notifyDataSetChanged() { + super.notifyDataSetChanged(); + if (tabs != null) { + toolbar.setVisibility(this.getCount() > 1 ? View.VISIBLE : View.GONE); + tabs.setTabsFromPagerAdapter(this); + } + } + @Override public boolean isViewFromObject(View view, Object object) { return view == object; diff --git a/app/src/main/java/org/connectbot/service/TerminalBridge.java b/app/src/main/java/org/connectbot/service/TerminalBridge.java index 6333c17c..f7be0aec 100644 --- a/app/src/main/java/org/connectbot/service/TerminalBridge.java +++ b/app/src/main/java/org/connectbot/service/TerminalBridge.java @@ -456,8 +456,19 @@ public void run() { awaitingClose = true; // Tell the TerminalManager that we can be destroyed now. - if (disconnectListener != null) - disconnectListener.onDisconnected(TerminalBridge.this); + if (disconnectListener != null) { + // The disconnect listener should be run on the main thread if possible. + if (parent != null) { + parent.post(new Runnable() { + @Override + public void run() { + disconnectListener.onDisconnected(TerminalBridge.this); + } + }); + } else { + disconnectListener.onDisconnected(TerminalBridge.this); + } + } } } }); diff --git a/app/src/main/java/org/connectbot/service/TerminalManager.java b/app/src/main/java/org/connectbot/service/TerminalManager.java index 80015611..a15dff02 100644 --- a/app/src/main/java/org/connectbot/service/TerminalManager.java +++ b/app/src/main/java/org/connectbot/service/TerminalManager.java @@ -54,9 +54,7 @@ import android.media.MediaPlayer.OnCompletionListener; import android.net.Uri; import android.os.Binder; -import android.os.Handler; import android.os.IBinder; -import android.os.Message; import android.os.Vibrator; import android.preference.PreferenceManager; import android.util.Log; @@ -81,7 +79,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen public List disconnected = new LinkedList(); - public Handler disconnectHandler = null; + public BridgeDisconnectedListener disconnectListener = null; public Map loadedKeypairs = new HashMap(); @@ -329,6 +327,7 @@ public TerminalBridge getConnectedBridge(final String nickname) { */ public void onDisconnected(TerminalBridge bridge) { boolean shouldHideRunningNotification = false; + Log.d(TAG, "Bridge Disconnected. Removing it."); synchronized (bridges) { // remove this bridge from our list @@ -345,6 +344,10 @@ public void onDisconnected(TerminalBridge bridge) { mPendingReconnect.size() == 0) { shouldHideRunningNotification = true; } + + // pass notification back up to gui + if (disconnectListener != null) + disconnectListener.onDisconnected(bridge); } synchronized (disconnected) { @@ -354,10 +357,6 @@ public void onDisconnected(TerminalBridge bridge) { if (shouldHideRunningNotification) { ConnectionNotifier.getInstance().hideRunningNotification(this); } - - // pass notification back up to gui - if (disconnectHandler != null) - Message.obtain(disconnectHandler, -1, bridge).sendToTarget(); } public boolean isKeyLoaded(String nickname) { diff --git a/app/src/main/res/layout-large/act_console.xml b/app/src/main/res/layout-large/act_console.xml new file mode 100644 index 00000000..d7353332 --- /dev/null +++ b/app/src/main/res/layout-large/act_console.xml @@ -0,0 +1,296 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +