Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Don't try to initialize EmulatorView before a TermSession is attached
Browse files Browse the repository at this point in the history
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
steven676 committed May 13, 2012
1 parent 14866d3 commit de38388
Showing 1 changed file with 16 additions and 0 deletions.
Expand Up @@ -73,6 +73,9 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe
*/
private boolean mKnownSize;

// Set if initialization was deferred because a TermSession wasn't attached
private boolean mDeferInit = false;

private int mVisibleWidth;
private int mVisibleHeight;

Expand Down Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit de38388

Please sign in to comment.