Search in sources :

Example 1 with SessionList

use of jackpal.androidterm.util.SessionList in project Android-Terminal-Emulator by jackpal.

the class RemoteInterface method appendToWindow.

protected String appendToWindow(String handle, String iInitialCommand) {
    TermService service = getTermService();
    // Find the target window
    SessionList sessions = service.getSessions();
    GenericTermSession target = null;
    int index;
    for (index = 0; index < sessions.size(); ++index) {
        GenericTermSession session = (GenericTermSession) sessions.get(index);
        String h = session.getHandle();
        if (h != null && h.equals(handle)) {
            target = session;
            break;
        }
    }
    if (target == null) {
        // Target window not found, open a new one
        return openNewWindow(iInitialCommand);
    }
    if (iInitialCommand != null) {
        target.write(iInitialCommand);
        target.write('\r');
    }
    Intent intent = new Intent(PRIVACT_SWITCH_WINDOW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(PRIVEXTRA_TARGET_WINDOW, index);
    startActivity(intent);
    return handle;
}
Also used : Intent(android.content.Intent) SessionList(jackpal.androidterm.util.SessionList)

Example 2 with SessionList

use of jackpal.androidterm.util.SessionList in project Android-Terminal-Emulator by jackpal.

the class WindowListAdapter method getView.

public View getView(int position, View convertView, ViewGroup parent) {
    Activity act = findActivityFromContext(parent.getContext());
    View child = act.getLayoutInflater().inflate(R.layout.window_list_item, parent, false);
    View close = child.findViewById(R.id.window_list_close);
    TextView label = (TextView) child.findViewById(R.id.window_list_label);
    String defaultTitle = act.getString(R.string.window_title, position + 1);
    label.setText(getSessionTitle(position, defaultTitle));
    final SessionList sessions = mSessions;
    final int closePosition = position;
    close.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            TermSession session = sessions.remove(closePosition);
            if (session != null) {
                session.finish();
                notifyDataSetChanged();
            }
        }
    });
    return child;
}
Also used : Activity(android.app.Activity) TextView(android.widget.TextView) SessionList(jackpal.androidterm.util.SessionList) TermSession(jackpal.androidterm.emulatorview.TermSession) TextView(android.widget.TextView) View(android.view.View)

Example 3 with SessionList

use of jackpal.androidterm.util.SessionList 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 4 with SessionList

use of jackpal.androidterm.util.SessionList in project Android-Terminal-Emulator by jackpal.

the class TermService method onCreate.

@Override
public void onCreate() {
    // should really belong to the Application class, but we don't use one...
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = prefs.edit();
    String defValue = getDir("HOME", MODE_PRIVATE).getAbsolutePath();
    String homePath = prefs.getString("home_path", defValue);
    editor.putString("home_path", homePath);
    editor.commit();
    compat = new ServiceForegroundCompat(this);
    mTermSessions = new SessionList();
    /* Put the service in the foreground. */
    Notification notification = new Notification(R.drawable.ic_stat_service_notification_icon, getText(R.string.service_notify_text), System.currentTimeMillis());
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    Intent notifyIntent = new Intent(this, Term.class);
    notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
    notification.setLatestEventInfo(this, getText(R.string.application_terminal), getText(R.string.service_notify_text), pendingIntent);
    compat.startForeground(RUNNING_NOTIFICATION, notification);
    Log.d(TermDebug.LOG_TAG, "TermService started");
    return;
}
Also used : ServiceForegroundCompat(jackpal.androidterm.compat.ServiceForegroundCompat) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SessionList(jackpal.androidterm.util.SessionList) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 5 with SessionList

use of jackpal.androidterm.util.SessionList in project Android-Terminal-Emulator by jackpal.

the class RemoteInterface method finish.

@Override
public void finish() {
    ServiceConnection conn = mTSConnection;
    if (conn != null) {
        unbindService(conn);
        // Stop the service if no terminal sessions are running
        TermService service = mTermService;
        if (service != null) {
            SessionList sessions = service.getSessions();
            if (sessions == null || sessions.size() == 0) {
                stopService(mTSIntent);
            }
        }
        mTSConnection = null;
        mTermService = null;
    }
    super.finish();
}
Also used : ServiceConnection(android.content.ServiceConnection) SessionList(jackpal.androidterm.util.SessionList)

Aggregations

SessionList (jackpal.androidterm.util.SessionList)5 Intent (android.content.Intent)2 Activity (android.app.Activity)1 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 ServiceConnection (android.content.ServiceConnection)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 TextView (android.widget.TextView)1 ServiceForegroundCompat (jackpal.androidterm.compat.ServiceForegroundCompat)1 EmulatorView (jackpal.androidterm.emulatorview.EmulatorView)1 TermSession (jackpal.androidterm.emulatorview.TermSession)1