com.android.sdklib.devices.Screen Java Examples
The following examples show how to use
com.android.sdklib.devices.Screen.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HardwareConfigHelper.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns a user-displayable description of the given Nexus device * @param device the device to check * @return the label * @see #isNexus(com.android.sdklib.devices.Device) */ @NonNull public static String getNexusLabel(@NonNull Device device) { String name = device.getDisplayName(); Screen screen = device.getDefaultHardware().getScreen(); float length = (float) screen.getDiagonalLength(); // Round dimensions to the nearest tenth length = Math.round(10 * length) / 10.0f; return String.format(Locale.US, "%1$s (%3$s\", %2$s)", name, getResolutionString(device), Float.toString(length)); }
Example #2
Source File: HardwareConfigHelper.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns a user displayable screen resolution string for the given device * @param device the device to look up the string for * @return a user displayable string */ @NonNull public static String getResolutionString(@NonNull Device device) { Screen screen = device.getDefaultHardware().getScreen(); return String.format(Locale.US, "%1$d \u00D7 %2$d: %3$s", // U+00D7: Unicode multiplication sign screen.getXDimension(), screen.getYDimension(), screen.getPixelDensity().getResourceValue()); }
Example #3
Source File: AvdHwProfile.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
public Screen createScreen() { Screen screen = new Screen(); screen.setMultitouch(Multitouch.JAZZ_HANDS); screen.setMechanism(TouchScreen.FINGER); screen.setScreenType(ScreenType.CAPACITIVE); screen.setScreenRound((round.isSelected()) ? ScreenRound.ROUND : ScreenRound.NOTROUND); int screenWidth = (int) resolutionX.getValue(); int screenHeight = (int) resolutionY.getValue(); double screenDiagonal = (double) screenSize.getValue(); double effectiveDiagonal = screenDiagonal; if (round.isSelected()) { // For round devices, compute the diagonal of // the enclosing square. effectiveDiagonal *= Math.sqrt(2.0); } screen.setDiagonalLength(screenDiagonal); screen.setSize(getScreenSize(effectiveDiagonal)); screen.setXDimension(screenWidth); screen.setYDimension(screenHeight); screen.setRatio(getScreenRatio(screenWidth, screenHeight)); Double dpi = calculateDpi(screenWidth, screenHeight, screenDiagonal, round.isSelected()); dpi = Math.round(dpi * 100) / 100.0d; screen.setYdpi(dpi); screen.setXdpi(dpi); DeviceType dt = (DeviceType) deviceType.getSelectedItem(); screen.setPixelDensity(getScreenDensity(dt == DeviceType.TV, dpi, screenHeight)); return screen; }
Example #4
Source File: DeviceConfigHelper.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
/** * Returns a {@link FolderConfiguration} based on the given state * * @param state * The {@link State} of the {@link Device} to base the * {@link FolderConfiguration} on. Can be null. * @return A {@link FolderConfiguration} based on the given {@link State}. * If the given {@link State} is null, the result is also null; */ @Nullable public static FolderConfiguration getFolderConfig(@Nullable State state) { if (state == null) { return null; } Hardware hw = state.getHardware(); FolderConfiguration config = new FolderConfiguration(); config.createDefault(); Screen screen = hw.getScreen(); config.setDensityQualifier(new DensityQualifier(screen.getPixelDensity())); config.setNavigationMethodQualifier(new NavigationMethodQualifier(hw.getNav())); ScreenDimensionQualifier sdq; if (screen.getXDimension() > screen.getYDimension()) { sdq = new ScreenDimensionQualifier(screen.getXDimension(), screen.getYDimension()); } else { sdq = new ScreenDimensionQualifier(screen.getYDimension(), screen.getXDimension()); } config.setScreenDimensionQualifier(sdq); config.setScreenRatioQualifier(new ScreenRatioQualifier(screen.getRatio())); config.setScreenSizeQualifier(new ScreenSizeQualifier(screen.getSize())); config.setTextInputMethodQualifier(new TextInputMethodQualifier(hw.getKeyboard())); config.setTouchTypeQualifier(new TouchScreenQualifier(screen.getMechanism())); config.setKeyboardStateQualifier(new KeyboardStateQualifier(state.getKeyState())); config.setNavigationStateQualifier(new NavigationStateQualifier(state.getNavState())); config.setScreenOrientationQualifier( new ScreenOrientationQualifier(state.getOrientation())); config.updateScreenWidthAndHeight(); // Setup some default qualifiers config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL)); config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT)); config.setCountryCodeQualifier(new CountryCodeQualifier()); config.setLanguageQualifier(new LanguageQualifier()); config.setLayoutDirectionQualifier(new LayoutDirectionQualifier()); config.setNetworkCodeQualifier(new NetworkCodeQualifier()); config.setRegionQualifier(new RegionQualifier()); config.setVersionQualifier(new VersionQualifier()); return config; }
Example #5
Source File: HardwareConfigHelper.java From javaide with GNU General Public License v3.0 | 4 votes |
/** * Creates and returns the HardwareConfig object. * @return the config */ @SuppressWarnings("SuspiciousNameCombination") // Deliberately swapping orientations @NonNull public HardwareConfig getConfig() { Screen screen = mDevice.getDefaultHardware().getScreen(); // compute width and height to take orientation into account. int x = screen.getXDimension(); int y = screen.getYDimension(); int width, height; if (x > y) { if (mScreenOrientation == ScreenOrientation.LANDSCAPE) { width = x; height = y; } else { width = y; height = x; } } else { if (mScreenOrientation == ScreenOrientation.LANDSCAPE) { width = y; height = x; } else { width = x; height = y; } } if (mOverrideRenderHeight != -1) { width = mOverrideRenderWidth; } if (mOverrideRenderHeight != -1) { height = mOverrideRenderHeight; } if (mMaxRenderWidth != -1) { width = mMaxRenderWidth; } if (mMaxRenderHeight != -1) { height = mMaxRenderHeight; } return new HardwareConfig( width, height, screen.getPixelDensity(), (float) screen.getXdpi(), (float) screen.getYdpi(), screen.getSize(), mScreenOrientation, mDevice.getDefaultHardware().getScreen().getScreenRound(), mDevice.getDefaultHardware().getButtonType() == ButtonType.SOFT); }
Example #6
Source File: DeviceConfigHelper.java From javaide with GNU General Public License v3.0 | 4 votes |
/** * Returns a {@link FolderConfiguration} based on the given state * * @param state * The {@link State} of the {@link Device} to base the * {@link FolderConfiguration} on. Can be null. * @return A {@link FolderConfiguration} based on the given {@link State}. * If the given {@link State} is null, the result is also null; */ @Nullable public static FolderConfiguration getFolderConfig(@Nullable State state) { if (state == null) { return null; } Hardware hw = state.getHardware(); FolderConfiguration config = new FolderConfiguration(); config.createDefault(); Screen screen = hw.getScreen(); config.setDensityQualifier(new DensityQualifier(screen.getPixelDensity())); config.setNavigationMethodQualifier(new NavigationMethodQualifier(hw.getNav())); ScreenDimensionQualifier sdq; if (screen.getXDimension() > screen.getYDimension()) { sdq = new ScreenDimensionQualifier(screen.getXDimension(), screen.getYDimension()); } else { sdq = new ScreenDimensionQualifier(screen.getYDimension(), screen.getXDimension()); } config.setScreenDimensionQualifier(sdq); config.setScreenRatioQualifier(new ScreenRatioQualifier(screen.getRatio())); config.setScreenSizeQualifier(new ScreenSizeQualifier(screen.getSize())); config.setTextInputMethodQualifier(new TextInputMethodQualifier(hw.getKeyboard())); config.setTouchTypeQualifier(new TouchScreenQualifier(screen.getMechanism())); ScreenRound screenRound = screen.getScreenRound(); if (screenRound == null) { // The default is not round. screenRound = ScreenRound.NOTROUND; } config.setScreenRoundQualifier(new ScreenRoundQualifier(screenRound)); config.setKeyboardStateQualifier(new KeyboardStateQualifier(state.getKeyState())); config.setNavigationStateQualifier(new NavigationStateQualifier(state.getNavState())); config.setScreenOrientationQualifier( new ScreenOrientationQualifier(state.getOrientation())); config.updateScreenWidthAndHeight(); // Setup some default qualifiers config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL)); config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT)); config.setCountryCodeQualifier(new CountryCodeQualifier()); config.setLocaleQualifier(new LocaleQualifier()); config.setLayoutDirectionQualifier(new LayoutDirectionQualifier()); config.setNetworkCodeQualifier(new NetworkCodeQualifier()); config.setVersionQualifier(new VersionQualifier()); return config; }