Search in sources :

Example 11 with TermSession

use of jackpal.androidterm.emulatorview.TermSession in project Android-Terminal-Emulator by jackpal.

the class Term method doCloseWindow.

private void doCloseWindow() {
    if (mTermSessions == null) {
        return;
    }
    EmulatorView view = getCurrentEmulatorView();
    if (view == null) {
        return;
    }
    TermSession session = mTermSessions.remove(mViewFlipper.getDisplayedChild());
    view.onPause();
    session.finish();
    mViewFlipper.removeView(view);
    if (mTermSessions.size() != 0) {
        mViewFlipper.showNext();
    }
}
Also used : EmulatorView(jackpal.androidterm.emulatorview.EmulatorView) TermSession(jackpal.androidterm.emulatorview.TermSession)

Example 12 with TermSession

use of jackpal.androidterm.emulatorview.TermSession in project Android-Terminal-Emulator by jackpal.

the class Term method createTermSession.

private TermSession createTermSession() throws IOException {
    TermSettings settings = mSettings;
    TermSession session = createTermSession(this, settings, settings.getInitialCommand());
    session.setFinishCallback(mTermService);
    return session;
}
Also used : TermSettings(jackpal.androidterm.util.TermSettings) TermSession(jackpal.androidterm.emulatorview.TermSession)

Example 13 with TermSession

use of jackpal.androidterm.emulatorview.TermSession in project Android-Terminal-Emulator by jackpal.

the class Term method doCreateNewWindow.

private void doCreateNewWindow() {
    if (mTermSessions == null) {
        Log.w(TermDebug.LOG_TAG, "Couldn't create new window because mTermSessions == null");
        return;
    }
    try {
        TermSession session = createTermSession();
        mTermSessions.add(session);
        TermView view = createEmulatorView(session);
        view.updatePrefs(mSettings);
        mViewFlipper.addView(view);
        mViewFlipper.setDisplayedChild(mViewFlipper.getChildCount() - 1);
    } catch (IOException e) {
        Toast.makeText(this, "Failed to create a session", Toast.LENGTH_SHORT).show();
    }
}
Also used : IOException(java.io.IOException) TermSession(jackpal.androidterm.emulatorview.TermSession)

Example 14 with TermSession

use of jackpal.androidterm.emulatorview.TermSession in project Android-Terminal-Emulator by jackpal.

the class TermService method onDestroy.

@Override
public void onDestroy() {
    compat.stopForeground(true);
    for (TermSession session : mTermSessions) {
        /* Don't automatically remove from list of sessions -- we clear the
             * list below anyway and we could trigger
             * ConcurrentModificationException if we do */
        session.setFinishCallback(null);
        session.finish();
    }
    mTermSessions.clear();
    return;
}
Also used : TermSession(jackpal.androidterm.emulatorview.TermSession)

Example 15 with TermSession

use of jackpal.androidterm.emulatorview.TermSession in project Android-Terminal-Emulator by jackpal.

the class TermActivity method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.term_activity);
    /* Text entry box at the bottom of the activity.  Note that you can
           also send input (whether from a hardware device or soft keyboard)
           directly to the EmulatorView. */
    mEntry = (EditText) findViewById(R.id.term_entry);
    mEntry.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        public boolean onEditorAction(TextView v, int action, KeyEvent ev) {
            // Ignore enter-key-up events
            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
            session.write(e.toString());
            session.write('\r');
            TextKeyListener.clear(e);
            return true;
        }
    });
    /* Sends the content of the text entry box to the terminal, without
           sending a carriage return afterwards */
    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();
            session.write(e.toString());
            TextKeyListener.clear(e);
        }
    });
    /**
         * EmulatorView setup.
         */
    EmulatorView view = (EmulatorView) findViewById(R.id.emulatorView);
    mEmulatorView = view;
    /* Let the EmulatorView know the screen's density. */
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    view.setDensity(metrics);
    /* Create a TermSession. */
    Intent myIntent = getIntent();
    String sessionType = myIntent.getStringExtra("type");
    TermSession session;
    if (sessionType != null && sessionType.equals("telnet")) {
        /* Telnet connection: we need to do the network connect on a
               separate thread, so kick that off and wait for it to finish. */
        connectToTelnet(myIntent.getStringExtra("host"));
        return;
    } else {
        // Create a local shell session.
        session = createLocalTermSession();
        if (session == null) {
            finish();
            return;
        }
        mSession = session;
    }
    /* Attach the TermSession to the EmulatorView. */
    view.attachSession(session);
/* That's all you have to do!  The EmulatorView will call the attached
           TermSession's initializeEmulator() automatically, once it can
           calculate the appropriate screen size for the terminal emulator. */
}
Also used : Intent(android.content.Intent) TermSession(jackpal.androidterm.emulatorview.TermSession) TextView(android.widget.TextView) EmulatorView(jackpal.androidterm.emulatorview.EmulatorView) View(android.view.View) DisplayMetrics(android.util.DisplayMetrics) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) EmulatorView(jackpal.androidterm.emulatorview.EmulatorView) Editable(android.text.Editable) TextView(android.widget.TextView)

Aggregations

TermSession (jackpal.androidterm.emulatorview.TermSession)18 EmulatorView (jackpal.androidterm.emulatorview.EmulatorView)5 IOException (java.io.IOException)5 Intent (android.content.Intent)3 View (android.view.View)3 TextView (android.widget.TextView)3 DisplayMetrics (android.util.DisplayMetrics)2 Activity (android.app.Activity)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Editable (android.text.Editable)1 KeyEvent (android.view.KeyEvent)1 Window (android.view.Window)1 Button (android.widget.Button)1 SessionList (jackpal.androidterm.util.SessionList)1 TermSettings (jackpal.androidterm.util.TermSettings)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1