Permalink
Browse files

Don't try to initialize EmulatorView before a TermSession is attached

This avoids a crash when the view is inflated from XML and a TermSession
isn't attached right away.

Because onSizeChanged() no longer tries to initialize the view if no
TermSession is attached, we now need to call initialize() in
attachSession() if the view hasn't been initialized at that point.
  • Loading branch information...
1 parent 14866d3 commit de3838810310341ef61563d4c1f65138ee8aba96 @steven676 steven676 committed May 7, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 libraries/emulatorview/src/jackpal/androidterm/emulatorview/EmulatorView.java
@@ -73,6 +73,9 @@
*/
private boolean mKnownSize;
+ // Set if initialization was deferred because a TermSession wasn't attached
+ private boolean mDeferInit = false;
+
private int mVisibleWidth;
private int mVisibleHeight;
@@ -286,6 +289,13 @@ public void attachSession(TermSession session) {
mTermSession = session;
mKeyListener = new TermKeyListener(session);
+
+ // Do init now if it was deferred until a TermSession was attached
+ if (mDeferInit) {
+ mDeferInit = false;
+ mKnownSize = true;
+ initialize();
+ }
}
/**
@@ -1053,6 +1063,12 @@ private void updateText() {
*/
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ if (mTermSession == null) {
+ // Not ready, defer until TermSession is attached
+ mDeferInit = true;
+ return;
+ }
+
if (!mKnownSize) {
mKnownSize = true;
initialize();

0 comments on commit de38388

Please sign in to comment.