private static void activityStarted() {
    Logger.D(TAG, "activityStarted (1): sActivitiesActive=" + sActivitiesActive);
    if (sActivitiesActive == 0) {
      Logger.D(TAG, "first activity started");

      RhodesService r = RhodesService.getInstance();
      if (r != null) r.handleAppActivation();
    }
    ++sActivitiesActive;
    Logger.D(TAG, "activityStarted (2): sActivitiesActive=" + sActivitiesActive);
  }
  public static void activityStopped() {
    Logger.D(TAG, "activityStopped (1): sActivitiesActive=" + sActivitiesActive);

    --sActivitiesActive;
    if (sActivitiesActive == 0) {
      Logger.D(TAG, "last activity stopped");

      RhodesService r = RhodesService.getInstance();
      if (r != null) r.handleAppDeactivation();
    }
    Logger.D(TAG, "activityStopped (2): sActivitiesActive=" + sActivitiesActive);
  }
    public void reread(Context context) {
      Logger.T(TAG, "Updating screen properties");

      WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

      Display d = wm.getDefaultDisplay();

      mScreenWidth = d.getWidth();
      mScreenHeight = d.getHeight();

      DisplayMetrics metrics = new DisplayMetrics();
      d.getMetrics(metrics);

      mScreenPpiX = metrics.xdpi;
      mScreenPpiY = metrics.ydpi;

      mScreenOrientation =
          AndroidFunctionalityManager.getAndroidFunctionality().getScreenOrientation(context);

      Logger.D(
          TAG,
          "New screen properties - width: "
              + mScreenWidth
              + ", height: "
              + mScreenHeight
              + ", orientation: "
              + mScreenOrientation);
    }
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    Logger.T(TAG, "onConfigurationChanged");
    super.onConfigurationChanged(newConfig);
    if (!sScreenAutoRotate) {
      Logger.D(
          TAG,
          "Screen rotation is disabled. Force old orientation: "
              + getScreenProperties().getOrientation());
      setRequestedOrientation(getScreenProperties().getOrientation());
    } else {
      ScreenProperties props = getScreenProperties();
      props.reread(this);

      int rotation = 0;
      switch (props.getOrientation()) {
        case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
          rotation = 90;
          break;
        case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
          rotation = 180;
          break;
        case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
          rotation = 270;
          break;
        case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
        default:
          rotation = 0;
          break;
      }

      RhodesService.onScreenOrientationChanged(props.getWidth(), props.getHeight(), rotation);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Logger.T(TAG, "onCreate");

    Intent intent = new Intent(this, RhodesService.class);
    intent.putExtra(RhodesService.INTENT_SOURCE, INTENT_SOURCE);
    ComponentName serviceName = startService(intent);
    if (serviceName == null) throw new RuntimeException("Can not start Rhodes service");
    bindService(intent, this, Context.BIND_AUTO_CREATE);
    mBoundToService = true;

    if (RhoConf.isExist("disable_screen_rotation")) {
      sScreenAutoRotate = !RhoConf.getBool("disable_screen_rotation");
    }

    if (sScreenProp == null) {
      sScreenProp = new ScreenProperties(this);
    } else {
      if (!sScreenAutoRotate) {
        Logger.D(
            TAG,
            "Screen rotation is disabled. Force orientation: "
                + getScreenProperties().getOrientation());
        setRequestedOrientation(getScreenProperties().getOrientation());
      }
    }
  }