use of com.android.sdklib.devices.State in project android by JetBrains.
the class ConfigureDeviceModel method createState.
@Nullable
private static State createState(ScreenOrientation orientation, Hardware hardware, boolean hasHardwareKeyboard) {
State state = null;
String name = "";
String description = "";
if (orientation == ScreenOrientation.LANDSCAPE) {
name = "Landscape";
description = "The device in landscape orientation";
state = new State();
} else if (orientation == ScreenOrientation.PORTRAIT) {
name = "Portrait";
description = "The device in portrait orientation";
state = new State();
}
if (state != null) {
if (hasHardwareKeyboard) {
name += " with keyboard";
description += " with a keyboard open";
state.setKeyState(KeyboardState.EXPOSED);
} else {
if (hardware.getKeyboard() != null && hardware.getKeyboard().equals(Keyboard.NOKEY)) {
state.setKeyState(KeyboardState.SOFT);
} else {
state.setKeyState(KeyboardState.HIDDEN);
}
}
state.setName(name);
state.setHardware(hardware);
state.setOrientation(orientation);
state.setDescription(description);
state.setNavState(hardware.getNav().equals(Navigation.NONAV) ? NavigationState.HIDDEN : NavigationState.EXPOSED);
}
return state;
}
use of com.android.sdklib.devices.State in project android by JetBrains.
the class ConfigurationMatcher method adaptConfigSelection.
/**
* Adapts the current device/config selection so that it's compatible with
* the configuration.
* <p/>
* If the current selection is compatible, nothing is changed.
* <p/>
* If it's not compatible, configs from the current devices are tested.
* <p/>
* If none are compatible, it reverts to
* {@link #findAndSetCompatibleConfig(boolean)}
*/
void adaptConfigSelection(boolean needBestMatch) {
// check the device config (ie sans locale)
// if still true, we need to find another config.
boolean needConfigChange = true;
boolean currentConfigIsCompatible = false;
State selectedState = myConfiguration.getDeviceState();
FolderConfiguration editedConfig = myConfiguration.getEditedConfig();
Module module = myConfiguration.getModule();
if (selectedState != null) {
FolderConfiguration currentConfig = Configuration.getFolderConfig(module, selectedState, myConfiguration.getLocale(), myConfiguration.getTarget());
if (currentConfig != null && editedConfig.isMatchFor(currentConfig)) {
// current config is compatible
currentConfigIsCompatible = true;
if (!needBestMatch || isCurrentFileBestMatchFor(currentConfig)) {
needConfigChange = false;
}
}
}
if (needConfigChange) {
List<Locale> localeList = getPrioritizedLocales();
// if the current state/locale isn't a correct match, then
// look for another state/locale in the same device.
FolderConfiguration testConfig = new FolderConfiguration();
// first look in the current device.
State matchState = null;
int localeIndex = -1;
Device device = myConfiguration.getDevice();
IAndroidTarget target = myConfiguration.getTarget();
if (device != null && target != null) {
VersionQualifier versionQualifier = new VersionQualifier(target.getVersion().getFeatureLevel());
mainloop: for (State state : device.getAllStates()) {
testConfig.set(Configuration.getFolderConfig(module, state, myConfiguration.getLocale(), target));
testConfig.setVersionQualifier(versionQualifier);
// loop on the locales.
for (int i = 0; i < localeList.size(); i++) {
Locale locale = localeList.get(i);
// update the test config with the locale qualifiers
testConfig.setLocaleQualifier(locale.qualifier);
if (editedConfig.isMatchFor(testConfig) && isCurrentFileBestMatchFor(testConfig)) {
matchState = state;
localeIndex = i;
break mainloop;
}
}
}
}
if (matchState != null) {
myConfiguration.startBulkEditing();
myConfiguration.setDeviceState(matchState);
myConfiguration.setEffectiveDevice(device, matchState);
myConfiguration.finishBulkEditing();
} else {
// no match in current device with any state/locale
// attempt to find another device that can display this
// particular state.
findAndSetCompatibleConfig(currentConfigIsCompatible);
}
}
}
use of com.android.sdklib.devices.State in project android by JetBrains.
the class ConfigurationMatcher method getBetterMatch.
/**
* Returns a different file which is a better match for the given device, orientation, target version, etc
* than the current one. You can supply {@code null} for all parameters; in that case, the current value
* in the configuration is used.
*/
@Nullable
public static VirtualFile getBetterMatch(@NotNull Configuration configuration, @Nullable Device device, @Nullable String stateName, @Nullable Locale locale, @Nullable IAndroidTarget target) {
VirtualFile file = configuration.getFile();
Module module = configuration.getModule();
if (file != null && module != null) {
if (device == null) {
device = configuration.getDevice();
}
if (stateName == null) {
State deviceState = configuration.getDeviceState();
stateName = deviceState != null ? deviceState.getName() : null;
}
State selectedState = ConfigurationFileState.getState(device, stateName);
if (selectedState == null) {
// Invalid state name passed in for the current device
return null;
}
if (locale == null) {
locale = configuration.getLocale();
}
if (target == null) {
target = configuration.getTarget();
}
FolderConfiguration currentConfig = Configuration.getFolderConfig(module, selectedState, locale, target);
if (currentConfig != null) {
LocalResourceRepository resources = AppResourceRepository.getAppResources(module, true);
if (resources != null) {
ResourceFolderType folderType = ResourceHelper.getFolderType(file);
if (folderType != null) {
List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType);
if (!types.isEmpty()) {
ResourceType type = types.get(0);
List<VirtualFile> matches = resources.getMatchingFiles(file, type, currentConfig);
if (!matches.contains(file) && !matches.isEmpty()) {
return matches.get(0);
}
}
}
}
}
}
return null;
}
use of com.android.sdklib.devices.State in project android by JetBrains.
the class ConfigurationFileState method saveState.
public void saveState(@NotNull Configuration configuration) {
Device device = configuration.getDevice();
myDeviceState = null;
if (device != null) {
State deviceState = configuration.getDeviceState();
if (deviceState != null && deviceState != device.getDefaultState()) {
myDeviceState = deviceState.getName();
}
}
// Null out if same as the default
UiMode dockMode = configuration.getUiMode();
if (dockMode != UiMode.NORMAL) {
myDockMode = dockMode.getResourceValue();
} else {
myDockMode = null;
}
myDockMode = StringUtil.nullize(dockMode.getResourceValue());
NightMode nightMode = configuration.getNightMode();
if (nightMode != NightMode.NOTNIGHT) {
myNightMode = nightMode.getResourceValue();
} else {
myNightMode = null;
}
myTheme = StringUtil.nullize(configuration.getTheme());
}
use of com.android.sdklib.devices.State in project android by JetBrains.
the class Configuration method getNextDeviceState.
/**
* Get the next cyclical state after the given state
*
* @param from the state to start with
* @return the following state following
*/
@Nullable
public State getNextDeviceState(@Nullable State from) {
Device device = getDevice();
if (device == null) {
return null;
}
List<State> states = device.getAllStates();
for (int i = 0; i < states.size(); i++) {
if (states.get(i) == from) {
return states.get((i + 1) % states.size());
}
}
// Search by name instead
if (from != null) {
String name = from.getName();
for (int i = 0; i < states.size(); i++) {
if (states.get(i).getName().equals(name)) {
return states.get((i + 1) % states.size());
}
}
}
return null;
}
Aggregations