@Override
    public boolean onSingleTapUp(MotionEvent e) {
      // Let the EmulatorView handle taps if mouse tracking is active
      if (view.isMouseTrackingActive()) return false;

      // Check for link at tap location
      String link = view.getURLat(e.getX(), e.getY());
      if (link != null) execURL(link);
      else
        doUIToggle((int) e.getX(), (int) e.getY(), view.getVisibleWidth(), view.getVisibleHeight());
      return true;
    }
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    mHaveFullHwKeyboard = checkHaveFullHwKeyboard(newConfig);

    EmulatorView v = (EmulatorView) mViewFlipper.getCurrentView();
    if (v != null) {
      v.updateSize(false);
    }

    if (mWinListAdapter != null) {
      // Force Android to redraw the label in the navigation dropdown
      mWinListAdapter.notifyDataSetChanged();
    }
  }
  @Override
  public void onResume() {
    super.onResume();

    SessionList sessions = mTermSessions;
    TermViewFlipper viewFlipper = mViewFlipper;
    if (sessions != null) {
      sessions.addCallback(this);
      WindowListAdapter adapter = mWinListAdapter;
      if (adapter != null) {
        sessions.addCallback(adapter);
        sessions.addTitleChangedListener(adapter);
        viewFlipper.addCallback(adapter);
      }
    }
    if (sessions != null && sessions.size() < viewFlipper.getChildCount()) {
      for (int i = 0; i < viewFlipper.getChildCount(); ++i) {
        EmulatorView v = (EmulatorView) viewFlipper.getChildAt(i);
        if (!sessions.contains(v.getTermSession())) {
          v.onPause();
          viewFlipper.removeView(v);
          --i;
        }
      }
    }

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    // the HOME dir needs to be set here since it comes from Context
    SharedPreferences.Editor editor = mPrefs.edit();
    String defValue = getDir("HOME", MODE_PRIVATE).getAbsolutePath();
    String homePath = mPrefs.getString("home_path", defValue);
    editor.putString("home_path", homePath);
    editor.commit();

    mSettings.readPrefs(mPrefs);
    updatePrefs();

    if (onResumeSelectWindow >= 0) {
      viewFlipper.setDisplayedChild(onResumeSelectWindow);
      onResumeSelectWindow = -1;
    }
    viewFlipper.onResume();
  }
  // 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;
        }
      }
    }
  }
  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) {
      mStopServiceOnFinish = true;
      finish();
    } else {
      mViewFlipper.showNext();
    }
  }
  private void updatePrefs() {
    mUseKeyboardShortcuts = mSettings.getUseKeyboardShortcutsFlag();

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    ColorScheme colorScheme = new ColorScheme(mSettings.getColorScheme());

    mViewFlipper.updatePrefs(mSettings);

    for (View v : mViewFlipper) {
      ((EmulatorView) v).setDensity(metrics);
      ((TermView) v).updatePrefs(mSettings);
    }

    if (mTermSessions != null) {
      for (TermSession session : mTermSessions) {
        ((ShellTermSession) session).updatePrefs(mSettings);
      }
    }

    {
      Window win = getWindow();
      WindowManager.LayoutParams params = win.getAttributes();
      final int FULLSCREEN = WindowManager.LayoutParams.FLAG_FULLSCREEN;
      int desiredFlag = mSettings.showStatusBar() ? 0 : FULLSCREEN;
      if (desiredFlag != (params.flags & FULLSCREEN)
          || (AndroidCompat.SDK >= 11 && mActionBarMode != mSettings.actionBarMode())) {
        if (mAlreadyStarted) {
          // Can't switch to/from fullscreen after
          // starting the activity.
          restart();
        } else {
          win.setFlags(desiredFlag, FULLSCREEN);
          if (mActionBarMode == TermSettings.ACTION_BAR_MODE_HIDES) {
            mActionBar.hide();
          }
        }
      }
    }

    int orientation = mSettings.getScreenOrientation();
    int o = 0;
    if (orientation == 0) {
      o = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    } else if (orientation == 1) {
      o = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    } else if (orientation == 2) {
      o = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    } else {
      /* Shouldn't be happened. */
    }
    setRequestedOrientation(o);
  }
  private void updatePrefs() {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    ColorScheme colorScheme = new ColorScheme(mSettings.getColorScheme());

    mViewFlipper.updatePrefs(mSettings);

    for (View v : mViewFlipper) {
      ((EmulatorView) v).setDensity(metrics);
      ((TermView) v).updatePrefs(mSettings);
    }

    if (mTermSessions != null) {
      for (TermSession session : mTermSessions) {
        ((ShellTermSession) session).updatePrefs(mSettings);
      }
    }

    {
      Window win = getWindow();
      WindowManager.LayoutParams params = win.getAttributes();
      final int FULLSCREEN = WindowManager.LayoutParams.FLAG_FULLSCREEN;
      int desiredFlag = mSettings.showStatusBar() ? 0 : FULLSCREEN;
      if (desiredFlag != (params.flags & FULLSCREEN)
          || (AndroidCompat.SDK >= 11 && mActionBarMode != mSettings.actionBarMode())) {
        if (mAlreadyStarted) {
          // Can't switch to/from fullscreen after
          // starting the activity.
          restart();
        } else {
          win.setFlags(desiredFlag, FULLSCREEN);
          if (mActionBarMode == TermSettings.ACTION_BAR_MODE_HIDES) {
            mActionBar.hide();
          }
        }
      }
    }
  }
 @Override
 public boolean onSingleTapUp(MotionEvent e) {
   doUIToggle((int) e.getX(), (int) e.getY(), view.getVisibleWidth(), view.getVisibleHeight());
   return true;
 }