use of com.android.sdklib.devices.State in project android by JetBrains.
the class Configuration method getScreenSize.
/** Returns the screen size required for this configuration */
@Nullable
public ScreenSize getScreenSize() {
// Look up the screen size for the current state
State deviceState = getDeviceState();
if (deviceState != null) {
FolderConfiguration folderConfig = DeviceConfigHelper.getFolderConfig(deviceState);
if (folderConfig != null) {
ScreenSizeQualifier qualifier = folderConfig.getScreenSizeQualifier();
assert qualifier != null;
return qualifier.getValue();
}
}
ScreenSize screenSize = null;
Device device = getDevice();
if (device != null) {
List<State> states = device.getAllStates();
for (State state : states) {
FolderConfiguration folderConfig = DeviceConfigHelper.getFolderConfig(state);
if (folderConfig != null) {
ScreenSizeQualifier qualifier = folderConfig.getScreenSizeQualifier();
assert qualifier != null;
screenSize = qualifier.getValue();
break;
}
}
}
return screenSize;
}
use of com.android.sdklib.devices.State in project android by JetBrains.
the class Configuration method computeBestDevice.
@Nullable
private Device computeBestDevice() {
for (Device device : myManager.getRecentDevices()) {
String stateName = myStateName;
if (stateName == null) {
stateName = device.getDefaultState().getName();
}
State selectedState = ConfigurationFileState.getState(device, stateName);
Module module = myManager.getModule();
FolderConfiguration currentConfig = getFolderConfig(module, selectedState, getLocale(), getTarget());
if (currentConfig != null) {
if (myEditedConfig.isMatchFor(currentConfig)) {
LocalResourceRepository resources = AppResourceRepository.getAppResources(module, true);
if (resources != null && myFile != null) {
ResourceFolderType folderType = ResourceHelper.getFolderType(myFile);
if (folderType != null) {
if (ResourceFolderType.VALUES.equals(folderType)) {
// If it's a file in the values folder, ResourceRepository.getMatchingFiles won't work.
// We get instead all the available folders and check that there is one compatible.
LocalResourceManager resourceManager = LocalResourceManager.getInstance(module);
if (resourceManager != null) {
for (PsiFile resourceFile : resourceManager.findResourceFiles("values")) {
if (myFile.equals(resourceFile.getVirtualFile()) && resourceFile.getParent() != null) {
FolderConfiguration folderConfiguration = FolderConfiguration.getConfigForFolder(resourceFile.getParent().getName());
if (currentConfig.isMatchFor(folderConfiguration)) {
return device;
}
}
}
}
} else {
List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType);
if (!types.isEmpty()) {
ResourceType type = types.get(0);
List<VirtualFile> matches = resources.getMatchingFiles(myFile, type, currentConfig);
if (matches.contains(myFile)) {
return device;
}
}
}
} else if ("Kotlin".equals(myFile.getFileType().getName())) {
return device;
} else if (myFile.equals(myManager.getProject().getProjectFile())) {
// takes care of correct device selection for Theme Editor
return device;
}
}
}
}
}
return myManager.getDefaultDevice();
}
use of com.android.sdklib.devices.State in project android by JetBrains.
the class NlUsageTrackerManagerTest method getConfigurationMock.
private static Configuration getConfigurationMock() {
IAndroidTarget target = mock(IAndroidTarget.class);
when(target.getVersion()).thenReturn(new AndroidVersion(0, "mock"));
State state = mock(State.class);
when(state.getOrientation()).thenReturn(PORTRAIT);
Configuration configuration = mock(Configuration.class);
when(configuration.getTarget()).thenReturn(target);
when(configuration.getDeviceState()).thenReturn(state);
return configuration;
}
use of com.android.sdklib.devices.State in project android by JetBrains.
the class ScreenView method toggleOrientation.
public void toggleOrientation() {
Configuration configuration = getConfiguration();
configuration.getDeviceState();
State current = configuration.getDeviceState();
State flip = configuration.getNextDeviceState(current);
if (flip != null) {
configuration.setDeviceState(flip);
}
}
use of com.android.sdklib.devices.State in project android by JetBrains.
the class ScreenView method getPreferredSize.
/**
* Returns the current preferred size for the view.
* @param dimension optional existing {@link Dimension} instance to be reused. If not null, the values will be set and this instance
* returned.
*/
@NotNull
public Dimension getPreferredSize(@Nullable Dimension dimension) {
if (dimension == null) {
dimension = new Dimension();
}
Configuration configuration = getConfiguration();
Device device = configuration.getDevice();
State state = configuration.getDeviceState();
if (device != null && state != null) {
HardwareConfig config = new HardwareConfigHelper(device).setOrientation(state.getOrientation()).getConfig();
dimension.setSize(config.getScreenWidth(), config.getScreenHeight());
}
return dimension;
}
Aggregations