use of com.android.resources.ScreenOrientation in project android by JetBrains.
the class DeviceArtPainterTest method testCropData.
// This test no longer applies; it was used to convert assets with a lot of padding into more tightly cropped screenshots.
// We're preserving the code since for future device releases we might get new artwork which includes padding.
@Test
@Ignore
public void testCropData() throws Exception {
// Apply crop
DeviceArtPainter framePainter = DeviceArtPainter.getInstance();
Device device = newDevice();
File srcDir = DeviceArtDescriptor.getBundledDescriptorsFolder();
File destDir = new File(myTemporaryFolder.newFolder(), "device-art");
if (!destDir.exists()) {
boolean ok = destDir.mkdirs();
assertTrue(ok);
}
StringBuilder sb = new StringBuilder(1000);
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<!-- Copyright (C) 2013 The Android Open Source Project\n" + "\n" + " Licensed under the Apache License, Version 2.0 (the \"License\");\n" + " you may not use this file except in compliance with the License.\n" + " You may obtain a copy of the License at\n" + "\n" + " http://www.apache.org/licenses/LICENSE-2.0\n" + "\n" + " Unless required by applicable law or agreed to in writing, software\n" + " distributed under the License is distributed on an \"AS IS\" BASIS,\n" + " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + " See the License for the specific language governing permissions and\n" + " limitations under the License.\n" + "-->\n" + "<devices>\n" + "\n");
for (DeviceArtDescriptor spec : framePainter.getDescriptors()) {
sb.append(" <device id=\"");
sb.append(spec.getId());
sb.append("\" name=\"");
sb.append(spec.getName());
sb.append("\">\n");
DeviceData deviceData = new DeviceData(device, spec);
for (ScreenOrientation orientation : ScreenOrientation.values()) {
if (orientation == ScreenOrientation.SQUARE) {
continue;
}
if (orientation != ScreenOrientation.LANDSCAPE && spec.getId().startsWith("tv_")) {
// Android TV only uses landscape orientation
continue;
}
Rectangle cropRect = spec.getCrop(orientation);
sb.append(" <orientation name=\"");
sb.append(orientation.getResourceValue());
sb.append("\" ");
DeviceArtDescriptor descriptor = deviceData.getDescriptor();
if (spec.getName().startsWith("Generic ") || cropRect == null || spec.getName().startsWith("Android TV")) {
System.out.println("Nothing to do for " + spec.getId() + " orientation " + orientation);
cropRect = new Rectangle(0, 0, descriptor.getFrameSize(orientation).width, descriptor.getFrameSize(orientation).height);
}
sb.append("size=\"");
sb.append(Integer.toString(cropRect.width));
sb.append(",");
sb.append(Integer.toString(cropRect.height));
sb.append("\" screenPos=\"");
sb.append(Integer.toString(descriptor.getScreenPos(orientation).x - cropRect.x));
sb.append(",");
sb.append(Integer.toString(descriptor.getScreenPos(orientation).y - cropRect.y));
sb.append("\" screenSize=\"");
sb.append(Integer.toString(descriptor.getScreenSize(orientation).width));
sb.append(",");
sb.append(Integer.toString(descriptor.getScreenSize(orientation).height));
sb.append("\"");
if (descriptor.getDropShadow(orientation) != null) {
sb.append(" shadow=\"");
//noinspection ConstantConditions
sb.append(descriptor.getDropShadow(orientation).getName());
sb.append("\"");
}
if (descriptor.getFrame(orientation) != null) {
sb.append(" back=\"");
//noinspection ConstantConditions
sb.append(descriptor.getFrame(orientation).getName());
sb.append("\"");
}
if (descriptor.getReflectionOverlay(orientation) != null) {
sb.append(" lights=\"");
//noinspection ConstantConditions
sb.append(descriptor.getReflectionOverlay(orientation).getName());
sb.append("\"");
}
if (descriptor.getMask(orientation) != null) {
sb.append(" mask=\"");
//noinspection ConstantConditions
sb.append(descriptor.getMask(orientation).getName());
sb.append("\"");
}
sb.append("/>\n");
// Must use computeImage rather than getImage here since we want to get the
// full size images, not the already cropped images
writeCropped(srcDir, destDir, spec, cropRect, descriptor.getFrame(orientation));
writeCropped(srcDir, destDir, spec, cropRect, descriptor.getDropShadow(orientation));
writeCropped(srcDir, destDir, spec, cropRect, descriptor.getReflectionOverlay(orientation));
writeCropped(srcDir, destDir, spec, cropRect, descriptor.getMask(orientation));
}
// (3) Rewrite emulator skin file
File layoutFile = new File(srcDir, spec.getId() + File.separator + SdkConstants.FN_SKIN_LAYOUT);
if (layoutFile.exists() && !spec.getId().startsWith("tv_")) {
// no crop data in tv (and lack of portrait fails below)
String layout = Files.toString(layoutFile, Charsets.UTF_8);
final Rectangle portraitCrop = spec.getCrop(ScreenOrientation.PORTRAIT);
if (portraitCrop != null) {
final Rectangle landscapeCrop = spec.getCrop(ScreenOrientation.LANDSCAPE);
layout = replace(layout, new String[] { "layouts {", "portrait {", "width " }, new Function<Integer, Integer>() {
@Override
public Integer apply(@Nullable Integer input) {
return portraitCrop.width;
}
});
layout = replace(layout, new String[] { "layouts {", "portrait {", "height " }, new Function<Integer, Integer>() {
@Override
public Integer apply(@Nullable Integer input) {
return portraitCrop.height;
}
});
layout = replace(layout, new String[] { "layouts {", "portrait {", "part2 {", "x " }, new Function<Integer, Integer>() {
@Override
public Integer apply(@Nullable Integer input) {
//noinspection ConstantConditions
return input - portraitCrop.x;
}
});
layout = replace(layout, new String[] { "layouts {", "portrait {", "part2 {", "y " }, new Function<Integer, Integer>() {
@Override
public Integer apply(@Nullable Integer input) {
//noinspection ConstantConditions
return input - portraitCrop.y;
}
});
// landscape
layout = replace(layout, new String[] { "layouts {", "landscape {", "width " }, new Function<Integer, Integer>() {
@Override
public Integer apply(@Nullable Integer input) {
return landscapeCrop.width;
}
});
layout = replace(layout, new String[] { "layouts {", "landscape {", "height " }, new Function<Integer, Integer>() {
@Override
public Integer apply(@Nullable Integer input) {
return landscapeCrop.height;
}
});
layout = replace(layout, new String[] { "layouts {", "landscape {", "part2 {", "x " }, new Function<Integer, Integer>() {
@Override
public Integer apply(@Nullable Integer input) {
//noinspection ConstantConditions
return input - landscapeCrop.x;
}
});
layout = replace(layout, new String[] { "layouts {", "landscape {", "part2 {", "y " }, new Function<Integer, Integer>() {
@Override
public Integer apply(@Nullable Integer input) {
//noinspection ConstantConditions
return input - landscapeCrop.y;
}
});
File outputLayoutFile = new File(destDir, spec.getId() + File.separator + SdkConstants.FN_SKIN_LAYOUT);
if (!outputLayoutFile.getParentFile().exists()) {
boolean mkdirs = outputLayoutFile.getParentFile().mkdirs();
assertTrue(mkdirs);
}
Files.write(layout, outputLayoutFile, Charsets.UTF_8);
} else {
// No crop data found; this device frame has already been cropped
}
}
sb.append(" </device>\n\n");
}
sb.append("\n</devices>\n");
File deviceArt = new File(destDir, "device-art.xml");
Files.write(sb.toString(), deviceArt, Charsets.UTF_8);
System.out.println("Wrote device art file " + deviceArt);
}
use of com.android.resources.ScreenOrientation in project android_frameworks_base by crdroidandroid.
the class RenderAction method getConfiguration.
// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
Configuration config = new Configuration();
HardwareConfig hardwareConfig = params.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;
}
ScreenRound roundness = hardwareConfig.getScreenRoundness();
if (roundness != null) {
switch(roundness) {
case ROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
break;
case NOTROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
}
} else {
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
}
String locale = params.getLocale();
if (locale != null && !locale.isEmpty())
config.locale = new Locale(locale);
return config;
}
use of com.android.resources.ScreenOrientation in project platform_frameworks_base by android.
the class RenderAction method getConfiguration.
// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
Configuration config = new Configuration();
HardwareConfig hardwareConfig = params.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;
}
ScreenRound roundness = hardwareConfig.getScreenRoundness();
if (roundness != null) {
switch(roundness) {
case ROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
break;
case NOTROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
}
} else {
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
}
String locale = params.getLocale();
if (locale != null && !locale.isEmpty())
config.locale = new Locale(locale);
return config;
}
use of com.android.resources.ScreenOrientation in project android_frameworks_base by ParanoidAndroid.
the class RenderAction method getConfiguration.
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) {
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:
config.orientation = Configuration.ORIENTATION_SQUARE;
break;
}
} else {
config.orientation = Configuration.ORIENTATION_UNDEFINED;
}
return config;
}
use of com.android.resources.ScreenOrientation in project android by JetBrains.
the class AvdOptionsModel method updateValuesWithAvdInfo.
private void updateValuesWithAvdInfo(@NotNull AvdInfo avdInfo) {
List<Device> devices = DeviceManagerConnection.getDefaultDeviceManagerConnection().getDevices();
Device selectedDevice = null;
String manufacturer = avdInfo.getDeviceManufacturer();
String deviceId = avdInfo.getProperties().get(AvdManager.AVD_INI_DEVICE_NAME);
for (Device device : devices) {
if (manufacturer.equals(device.getManufacturer()) && deviceId.equals(device.getId())) {
selectedDevice = device;
break;
}
}
myDevice.setNullableValue(selectedDevice);
SystemImageDescription systemImageDescription = null;
ISystemImage selectedImage = avdInfo.getSystemImage();
if (selectedImage != null) {
systemImageDescription = new SystemImageDescription(selectedImage);
mySystemImage.setValue(systemImageDescription);
}
myAvdDeviceData = new AvdDeviceData(selectedDevice, systemImageDescription);
Map<String, String> properties = avdInfo.getProperties();
myUseQemu2.set(properties.containsKey(AvdWizardUtils.CPU_CORES_KEY));
String cpuCoreCount = properties.get(AvdWizardUtils.CPU_CORES_KEY);
myCpuCoreCount.setValue(cpuCoreCount == null ? 1 : Integer.parseInt(cpuCoreCount));
Storage storage = getStorageFromIni(properties.get(AvdWizardUtils.RAM_STORAGE_KEY));
if (storage != null) {
myAvdDeviceData.ramStorage().set(storage);
}
storage = getStorageFromIni(properties.get(AvdWizardUtils.VM_HEAP_STORAGE_KEY));
if (storage != null) {
myVmHeapStorage.set(storage);
}
storage = getStorageFromIni(properties.get(AvdWizardUtils.INTERNAL_STORAGE_KEY));
if (storage != null) {
myInternalStorage.set(storage);
}
String sdCardLocation = null;
if (properties.get(AvdWizardUtils.EXISTING_SD_LOCATION) != null) {
sdCardLocation = properties.get(AvdWizardUtils.EXISTING_SD_LOCATION);
} else if (properties.get(AvdWizardUtils.SD_CARD_STORAGE_KEY) != null) {
sdCardLocation = FileUtil.join(avdInfo.getDataFolderPath(), "sdcard.img");
}
existingSdLocation = new StringValueProperty(nullToEmpty(sdCardLocation));
String dataFolderPath = avdInfo.getDataFolderPath();
File sdLocationFile = null;
if (sdCardLocation != null) {
sdLocationFile = new File(sdCardLocation);
}
if (sdLocationFile != null) {
if (Objects.equal(sdLocationFile.getParent(), dataFolderPath)) {
// the image is in the AVD folder, consider it to be internal
File sdFile = new File(sdCardLocation);
Storage sdCardSize = new Storage(sdFile.length());
myUseExternalSdCard.set(false);
myUseBuiltInSdCard.set(true);
myOriginalSdCard = new ObjectValueProperty<>(sdCardSize);
mySdCardStorage.setValue(sdCardSize);
} else {
// the image is external
myUseExternalSdCard.set(true);
myUseBuiltInSdCard.set(false);
externalSdCardLocation().set(sdCardLocation);
}
}
myUseHostGpu.set(fromIniString(properties.get(AvdWizardUtils.USE_HOST_GPU_KEY)));
mySelectedAvdFrontCamera.set(AvdCamera.fromName(properties.get(AvdWizardUtils.FRONT_CAMERA_KEY)));
mySelectedAvdBackCamera.set(AvdCamera.fromName(properties.get(AvdWizardUtils.BACK_CAMERA_KEY)));
mySelectedNetworkLatency.set(AvdNetworkLatency.fromName(properties.get(AvdWizardUtils.NETWORK_LATENCY_KEY)));
mySelectedNetworkSpeed.set(AvdNetworkSpeed.fromName(properties.get(AvdWizardUtils.NETWORK_SPEED_KEY)));
myEnableHardwareKeyboard.set(fromIniString(properties.get(AvdWizardUtils.HAS_HARDWARE_KEYBOARD_KEY)));
myAvdDisplayName.set(AvdManagerConnection.getAvdDisplayName(avdInfo));
myHasDeviceFrame.set(fromIniString(properties.get(AvdWizardUtils.DEVICE_FRAME_KEY)));
ScreenOrientation screenOrientation = null;
String orientation = properties.get(HardwareProperties.HW_INITIAL_ORIENTATION);
if (!Strings.isNullOrEmpty(orientation)) {
screenOrientation = ScreenOrientation.getByShortDisplayName(orientation);
}
mySelectedAvdOrientation.set((screenOrientation == null) ? ScreenOrientation.PORTRAIT : screenOrientation);
String skinPath = properties.get(AvdWizardUtils.CUSTOM_SKIN_FILE_KEY);
if (skinPath != null) {
File skinFile = (skinPath.equals(AvdWizardUtils.NO_SKIN.getPath())) ? AvdWizardUtils.NO_SKIN : new File(skinPath);
if (skinFile.isDirectory()) {
myAvdDeviceData.customSkinFile().setValue(skinFile);
}
}
String backupSkinPath = properties.get(AvdWizardUtils.BACKUP_SKIN_FILE_KEY);
if (backupSkinPath != null) {
File skinFile = new File(backupSkinPath);
if (skinFile.isDirectory() || FileUtil.filesEqual(skinFile, AvdWizardUtils.NO_SKIN)) {
backupSkinFile().setValue(skinFile);
}
}
String modeString = properties.get(AvdWizardUtils.HOST_GPU_MODE_KEY);
myHostGpuMode.setValue(GpuMode.fromGpuSetting(modeString));
myIsInEditMode.set(true);
}
Aggregations