use of com.android.resources.ScreenOrientation in project android by JetBrains.
the class OrientationMenuAction method getOrientation.
@NotNull
public static ScreenOrientation getOrientation(@NotNull State state) {
FolderConfiguration config = DeviceConfigHelper.getFolderConfig(state);
ScreenOrientation orientation = null;
if (config != null && config.getScreenOrientationQualifier() != null) {
orientation = config.getScreenOrientationQualifier().getValue();
}
if (orientation == null) {
orientation = ScreenOrientation.PORTRAIT;
}
return orientation;
}
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);
}
use of com.android.resources.ScreenOrientation in project android by JetBrains.
the class ConfigureAvdOptionsStep method bindComponents.
private void bindComponents() {
myBindings.bindTwoWay(new TextProperty(myAvdDisplayName), getModel().avdDisplayName());
myBindings.bind(new TextProperty(myAvdId), new StringExpression(getModel().avdDisplayName()) {
@NotNull
@Override
public String get() {
String displayName = getModel().avdDisplayName().get();
getModel().avdId().set(StringUtil.isNotEmpty(displayName) ? AvdWizardUtils.cleanAvdName(connection, displayName, !displayName.equals(myOriginalName)) : "");
return getModel().avdId().get();
}
});
myBindings.bindTwoWay(new TextProperty(mySystemImageName), getModel().systemImageName());
myBindings.bindTwoWay(new TextProperty(mySystemImageDetails), getModel().systemImageDetails());
myBindings.bindTwoWay(new SelectedProperty(myQemu2CheckBox), getModel().useQemu2());
myBindings.bindTwoWay(new SelectedItemProperty<Integer>(myCoreCount), getModel().cpuCoreCount());
myBindings.bindTwoWay(myRamStorage.storage(), getModel().getAvdDeviceData().ramStorage());
myBindings.bindTwoWay(myVmHeapStorage.storage(), getModel().vmHeapStorage());
myBindings.bindTwoWay(myInternalStorage.storage(), getModel().internalStorage());
myBindings.bindTwoWay(myBuiltInSdCardStorage.storage(), new OptionalToValuePropertyAdapter<Storage>(getModel().sdCardStorage()));
myBindings.bindTwoWay(new SelectedItemProperty<GpuMode>(myHostGraphics), getModel().hostGpuMode());
myBindings.bindTwoWay(new SelectedProperty(myDeviceFrameCheckbox), getModel().hasDeviceFrame());
myBindings.bindTwoWay(new SelectedItemProperty<File>(mySkinComboBox.getComboBox()), getModel().getAvdDeviceData().customSkinFile());
myOrientationToggle.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
ScreenOrientation orientation = myOrientationToggle.getSelectedElement();
if (orientation == null) {
getModel().selectedAvdOrientation().set(ScreenOrientation.PORTRAIT);
} else {
getModel().selectedAvdOrientation().set(orientation);
}
}
});
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, true);
}
};
fileChooserDescriptor.setHideIgnored(false);
myExternalSdCard.addBrowseFolderListener("Select SD Card", "Select an existing SD card image", myProject, fileChooserDescriptor);
myBindings.bindTwoWay(new TextProperty(myExternalSdCard.getTextField()), getModel().externalSdCardLocation());
myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myFrontCameraCombo)), getModel().selectedFrontCamera());
myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myBackCameraCombo)), getModel().selectedBackCamera());
myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkSpeed>(new SelectedItemProperty<AvdNetworkSpeed>(mySpeedCombo)), getModel().selectedNetworkSpeed());
myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkLatency>(new SelectedItemProperty<AvdNetworkLatency>(myLatencyCombo)), getModel().selectedNetworkLatency());
myBindings.bindTwoWay(new SelectedProperty(myEnableComputerKeyboard), getModel().enableHardwareKeyboard());
myBindings.bindTwoWay(new SelectedProperty(myExternalRadioButton), getModel().useExternalSdCard());
myBindings.bindTwoWay(new SelectedProperty(myBuiltInRadioButton), getModel().useBuiltInSdCard());
myCheckSdForChanges = true;
}
use of com.android.resources.ScreenOrientation in project android by JetBrains.
the class ConfigureAvdOptionsStep method toggleOptionals.
/**
* Enable/Disable controls based on the capabilities of the selected device. For example, some devices may
* not have a front facing camera.
*/
private void toggleOptionals(@NotNull Optional<Device> device, boolean deviceChange) {
boolean IsDevicePresent = device.isPresent();
Hardware deviceDefaultHardware = IsDevicePresent ? device.get().getDefaultHardware() : null;
myChangeSystemImageButton.setEnabled(IsDevicePresent);
myFrontCameraCombo.setEnabled(IsDevicePresent && deviceDefaultHardware.getCamera(CameraLocation.FRONT) != null);
myBackCameraCombo.setEnabled(IsDevicePresent && deviceDefaultHardware.getCamera(CameraLocation.BACK) != null);
myOrientationToggle.setEnabled(IsDevicePresent && device.get().getDefaultState().getOrientation() != ScreenOrientation.SQUARE);
myEnableComputerKeyboard.setEnabled(IsDevicePresent && !deviceDefaultHardware.getKeyboard().equals(Keyboard.QWERTY));
if (deviceChange) {
ScreenOrientation orientation = IsDevicePresent ? device.get().getDefaultState().getOrientation() : ScreenOrientation.PORTRAIT;
myOrientationToggle.setSelectedElement(orientation);
}
File customSkin = getModel().getAvdDeviceData().customSkinFile().getValueOrNull();
File backupSkin = getModel().backupSkinFile().getValueOrNull();
// If there is a backup skin but no normal skin, the "use device frame" checkbox should be unchecked.
if (backupSkin != null && customSkin == null) {
getModel().hasDeviceFrame().set(false);
}
File hardwareSkin = null;
if (IsDevicePresent && getModel().systemImage().get().isPresent()) {
hardwareSkin = AvdWizardUtils.resolveSkinPath(deviceDefaultHardware.getSkinFile(), getModel().systemImage().getValue(), FileOpUtils.create());
myDeviceName.setIcon(DeviceDefinitionPreview.getIcon(getModel().getAvdDeviceData()));
myDeviceName.setText(getModel().device().getValue().getDisplayName());
updateDeviceDetails();
}
if (customSkin == null) {
if (backupSkin != null) {
customSkin = backupSkin;
} else {
customSkin = hardwareSkin;
}
}
if (customSkin != null) {
mySkinComboBox.getComboBox().setSelectedItem(customSkin);
getModel().getAvdDeviceData().customSkinFile().setValue(customSkin);
}
}
use of com.android.resources.ScreenOrientation in project android by JetBrains.
the class DeviceArtPainter method createFrame.
/** Creates a frame around the given image, using the given descriptor */
public static BufferedImage createFrame(BufferedImage image, DeviceArtDescriptor descriptor, boolean addShadow, boolean addReflection) {
double imgAspectRatio = image.getWidth() / (double) image.getHeight();
ScreenOrientation orientation = imgAspectRatio >= (1 - ImageUtils.EPSILON) ? ScreenOrientation.LANDSCAPE : ScreenOrientation.PORTRAIT;
if (!descriptor.canFrameImage(image, orientation)) {
return image;
}
File shadow = descriptor.getDropShadow(orientation);
File background = descriptor.getFrame(orientation);
File reflection = descriptor.getReflectionOverlay(orientation);
Graphics2D g2d = null;
try {
BufferedImage bg = ImageIO.read(background);
// Size of screen in ninepatch; will be stretched
Dimension screen = descriptor.getScreenSize(orientation);
// Size of full ninepatch, including stretchable screen area
Dimension frameSize = descriptor.getFrameSize(orientation);
Point screenPos = descriptor.getScreenPos(orientation);
boolean stretchable = descriptor.isStretchable();
if (stretchable) {
assert screen != null;
assert frameSize != null;
int newWidth = image.getWidth() + frameSize.width - screen.width;
int newHeight = image.getHeight() + frameSize.height - screen.height;
bg = stretchImage(bg, newWidth, newHeight);
} else if (screen.width < image.getWidth()) {
// if the frame isn't stretchable, but is smaller than the image, then scale down the image
double scale = (double) screen.width / image.getWidth();
if (Math.abs(scale - 1.0) > ImageUtils.EPSILON) {
image = ImageUtils.scale(image, scale, scale);
}
}
g2d = bg.createGraphics();
if (addShadow && shadow != null) {
BufferedImage shadowImage = ImageIO.read(shadow);
if (stretchable) {
shadowImage = stretchImage(shadowImage, bg.getWidth(), bg.getHeight());
}
g2d.drawImage(shadowImage, 0, 0, null, null);
}
// If the device art has a mask, make sure that the image is clipped by the mask
File maskFile = descriptor.getMask(orientation);
if (maskFile != null) {
BufferedImage mask = ImageIO.read(maskFile);
// Render the current image on top of the mask using it as the alpha composite
Graphics2D maskG2d = mask.createGraphics();
maskG2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN));
maskG2d.drawImage(image, screenPos.x, screenPos.y, null);
maskG2d.dispose();
// Render the masked image to the destination
g2d.drawImage(mask, 0, 0, null);
} else {
g2d.drawImage(image, screenPos.x, screenPos.y, null);
}
if (addReflection && reflection != null) {
// Nexus One for example does not supply reflection image
BufferedImage reflectionImage = ImageIO.read(reflection);
if (stretchable) {
reflectionImage = stretchImage(reflectionImage, bg.getWidth(), bg.getHeight());
}
g2d.drawImage(reflectionImage, 0, 0, null, null);
}
return bg;
} catch (IOException e) {
return image;
} finally {
if (g2d != null) {
g2d.dispose();
}
}
}
Aggregations