Skip to content

Commit

Permalink
Merge pull request vx#124 from jklein24/tabs
Browse files Browse the repository at this point in the history
Add tabs when there's more than one terminal active.
  • Loading branch information
kruton committed Aug 14, 2015
2 parents a043260 + 64f59c9 commit 25458db
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 40 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {

defaultConfig {
applicationId "org.connectbot"
minSdkVersion 4
minSdkVersion 8
targetSdkVersion 22

ndk {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:versionCode="375"
android:installLocation="auto">

<uses-sdk android:targetSdkVersion="22" android:minSdkVersion="4" />
<uses-sdk android:targetSdkVersion="22" android:minSdkVersion="8" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
Expand Down
53 changes: 32 additions & 21 deletions app/src/main/java/org/connectbot/ConsoleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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(
Expand All @@ -371,6 +370,8 @@ public void onPageSelected(int position) {
onTerminalChanged();
}
});
adapter = new TerminalPagerAdapter();
pager.setAdapter(adapter);

empty = (TextView) findViewById(android.R.id.empty);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -635,9 +640,6 @@ public boolean onTouch(View v, MotionEvent event) {
}

});

adapter = new TerminalPagerAdapter();
pager.setAdapter(adapter);
}

/**
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/org/connectbot/service/TerminalBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
});
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/org/connectbot/service/TerminalManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -81,7 +79,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen

public List<HostBean> disconnected = new LinkedList<HostBean>();

public Handler disconnectHandler = null;
public BridgeDisconnectedListener disconnectListener = null;

public Map<String, KeyHolder> loadedKeypairs = new HashMap<String, KeyHolder>();

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit 25458db

Please sign in to comment.