Exemplo n.º 1
1
  @Implementation
  public void setTo(Configuration o) {
    // commented out lines are coming in a newer version of Android SDK

    realConfiguration.fontScale = o.fontScale;
    realConfiguration.mcc = o.mcc;
    realConfiguration.mnc = o.mnc;
    if (o.locale != null) {
      realConfiguration.locale = (Locale) o.locale.clone();
      // realConfiguration.textLayoutDirection = o.textLayoutDirection;
    }
    // realConfiguration.userSetLocale = o.userSetLocale;
    realConfiguration.touchscreen = o.touchscreen;
    realConfiguration.keyboard = o.keyboard;
    realConfiguration.keyboardHidden = o.keyboardHidden;
    realConfiguration.hardKeyboardHidden = o.hardKeyboardHidden;
    realConfiguration.navigation = o.navigation;
    realConfiguration.navigationHidden = o.navigationHidden;
    realConfiguration.orientation = o.orientation;
    realConfiguration.screenLayout = o.screenLayout;
    realConfiguration.uiMode = o.uiMode;
    realConfiguration.screenWidthDp = o.screenWidthDp;
    realConfiguration.screenHeightDp = o.screenHeightDp;
    realConfiguration.smallestScreenWidthDp = o.smallestScreenWidthDp;
    // realConfiguration.compatScreenWidthDp = o.compatScreenWidthDp;
    // realConfiguration.compatScreenHeightDp = o.compatScreenHeightDp;
    // realConfiguration.compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp;
    // realConfiguration.seq = o.seq;
  }
  private Configuration getConfiguration() {
    Configuration config = new Configuration();

    HardwareConfig hardwareConfig = mParams.getHardwareConfig();

    ScreenSize screenSize = hardwareConfig.getScreenSize();
    if (screenSize != null) {
      switch (screenSize) {
        case SMALL:
          config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
          break;
        case NORMAL:
          config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
          break;
        case LARGE:
          config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
          break;
        case XLARGE:
          config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
          break;
      }
    }

    Density density = hardwareConfig.getDensity();
    if (density == null) {
      density = Density.MEDIUM;
    }

    config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
    config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
    if (config.screenHeightDp < config.screenWidthDp) {
      //noinspection SuspiciousNameCombination
      config.smallestScreenWidthDp = config.screenHeightDp;
    } else {
      config.smallestScreenWidthDp = config.screenWidthDp;
    }
    config.densityDpi = density.getDpiValue();

    // never run in compat mode:
    config.compatScreenWidthDp = config.screenWidthDp;
    config.compatScreenHeightDp = config.screenHeightDp;

    ScreenOrientation orientation = hardwareConfig.getOrientation();
    if (orientation != null) {
      switch (orientation) {
        case PORTRAIT:
          config.orientation = Configuration.ORIENTATION_PORTRAIT;
          break;
        case LANDSCAPE:
          config.orientation = Configuration.ORIENTATION_LANDSCAPE;
          break;
        case SQUARE:
          //noinspection deprecation
          config.orientation = Configuration.ORIENTATION_SQUARE;
          break;
      }
    } else {
      config.orientation = Configuration.ORIENTATION_UNDEFINED;
    }

    // TODO: fill in more config info.

    return config;
  }