Search in sources :

Example 6 with EmulatorView

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

the class Term method onUpdate.

// Called when the list of sessions changes
public void onUpdate() {
    SessionList sessions = mTermSessions;
    if (sessions == null) {
        return;
    }
    if (sessions.size() == 0) {
        mStopServiceOnFinish = true;
        finish();
    } else if (sessions.size() < mViewFlipper.getChildCount()) {
        for (int i = 0; i < mViewFlipper.getChildCount(); ++i) {
            EmulatorView v = (EmulatorView) mViewFlipper.getChildAt(i);
            if (!sessions.contains(v.getTermSession())) {
                v.onPause();
                mViewFlipper.removeView(v);
                --i;
            }
        }
    }
}
Also used : EmulatorView(jackpal.androidterm.emulatorview.EmulatorView) SessionList(jackpal.androidterm.util.SessionList)

Example 7 with EmulatorView

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

the class TermViewFlipper method adjustChildSize.

private void adjustChildSize() {
    updateVisibleRect();
    Rect visible = mVisibleRect;
    int width = visible.width();
    int height = visible.height();
    if (mCurWidth != width || mCurHeight != height) {
        mCurWidth = width;
        mCurHeight = height;
        LayoutParams params = mChildParams;
        params.width = width;
        params.height = height;
        for (View v : this) {
            updateViewLayout(v, params);
        }
        mRedoLayout = true;
        EmulatorView currentView = (EmulatorView) getCurrentView();
        if (currentView != null) {
            currentView.updateSize(false);
        }
    }
}
Also used : Rect(android.graphics.Rect) EmulatorView(jackpal.androidterm.emulatorview.EmulatorView) EmulatorView(jackpal.androidterm.emulatorview.EmulatorView) View(android.view.View)

Example 8 with EmulatorView

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

the class TermViewFlipper method resumeCurrentView.

public void resumeCurrentView() {
    EmulatorView view = (EmulatorView) getCurrentView();
    if (view == null) {
        return;
    }
    view.onResume();
    view.requestFocus();
}
Also used : EmulatorView(jackpal.androidterm.emulatorview.EmulatorView)

Example 9 with EmulatorView

use of jackpal.androidterm.emulatorview.EmulatorView 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)

Example 10 with EmulatorView

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

the class Term method populateViewFlipper.

private void populateViewFlipper() {
    if (mTermService != null) {
        mTermSessions = mTermService.getSessions();
        if (mTermSessions.size() == 0) {
            try {
                mTermSessions.add(createTermSession());
            } catch (IOException e) {
                Toast.makeText(this, "Failed to start terminal session", Toast.LENGTH_LONG).show();
                finish();
                return;
            }
        }
        mTermSessions.addCallback(this);
        for (TermSession session : mTermSessions) {
            EmulatorView view = createEmulatorView(session);
            mViewFlipper.addView(view);
        }
        updatePrefs();
        if (onResumeSelectWindow >= 0) {
            mViewFlipper.setDisplayedChild(onResumeSelectWindow);
            onResumeSelectWindow = -1;
        }
        mViewFlipper.onResume();
    }
}
Also used : EmulatorView(jackpal.androidterm.emulatorview.EmulatorView) IOException(java.io.IOException) TermSession(jackpal.androidterm.emulatorview.TermSession)

Aggregations

EmulatorView (jackpal.androidterm.emulatorview.EmulatorView)10 TermSession (jackpal.androidterm.emulatorview.TermSession)5 View (android.view.View)3 DisplayMetrics (android.util.DisplayMetrics)2 TextView (android.widget.TextView)2 Intent (android.content.Intent)1 Rect (android.graphics.Rect)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 IOException (java.io.IOException)1