Navigation Menu

Skip to content

Commit

Permalink
Widget sample: don't crash if Send button is activated before session…
Browse files Browse the repository at this point in the history
… connected

Apparently some phones/devices/platforms do this when the activity is started.
  • Loading branch information
steven676 committed May 15, 2012
1 parent 2274fa8 commit cb7b980
Showing 1 changed file with 14 additions and 3 deletions.
Expand Up @@ -53,10 +53,16 @@ public boolean onEditorAction(TextView v, int action, KeyEvent ev) {
if (ev != null && ev.getAction() == KeyEvent.ACTION_UP) {
return false;
}
// Don't try to send something if we're not connected yet
TermSession session = mSession;
if (mSession == null) {
return true;
}

Editable e = (Editable) v.getText();
// Write to the terminal session
mSession.write(e.toString());
mSession.write('\r');
session.write(e.toString());
session.write('\r');
TextKeyListener.clear(e);
return true;
}
Expand All @@ -67,8 +73,13 @@ public boolean onEditorAction(TextView v, int action, KeyEvent ev) {
Button sendButton = (Button) findViewById(R.id.term_entry_send);
sendButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Don't try to send something if we're not connected yet
TermSession session = mSession;
if (mSession == null) {
return;
}
Editable e = (Editable) mEntry.getText();
mSession.write(e.toString());
session.write(e.toString());
TextKeyListener.clear(e);
}
});
Expand Down

0 comments on commit cb7b980

Please sign in to comment.