Skip to content

Commit

Permalink
Add support for Android 4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
orrc committed Nov 18, 2011
1 parent e5e8ec9 commit 860addc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
25 changes: 20 additions & 5 deletions src/main/java/hudson/plugins/android_emulator/AndroidEmulator.java
Expand Up @@ -658,7 +658,7 @@ private String isConfigValid(String avdName, String osVersion, String screenDens
if (result.isFatal()) {
return result.getMessage();
}
result = descriptor.doCheckScreenResolution(screenResolution, null, false);
result = descriptor.doCheckScreenResolution(screenResolution, null, null, false);
if (result.isFatal()) {
return result.getMessage();
}
Expand Down Expand Up @@ -932,12 +932,12 @@ private ValidationResult doCheckScreenDensity(String density, boolean allowVaria
}

public FormValidation doCheckScreenResolution(@QueryParameter String value,
@QueryParameter String density) {
return doCheckScreenResolution(value, density, true).getFormValidation();
@QueryParameter String density, @QueryParameter String osVersion) {
return doCheckScreenResolution(value, density, osVersion, true).getFormValidation();
}

private ValidationResult doCheckScreenResolution(String resolution, String density,
boolean allowVariables) {
String osVersion, boolean allowVariables) {
if (resolution == null || resolution.equals("")) {
return ValidationResult.error(Messages.SCREEN_RESOLUTION_REQUIRED());
}
Expand All @@ -946,7 +946,22 @@ private ValidationResult doCheckScreenResolution(String resolution, String densi
regex += "|"+ Constants.REGEX_VARIABLE;
}
if (!resolution.matches(regex)) {
return ValidationResult.error(Messages.INVALID_RESOLUTION_FORMAT());
return ValidationResult.warning(Messages.INVALID_RESOLUTION_FORMAT());
}

// Warn about inconsistent WXGA skin names between Android 3.x and 4.x
AndroidPlatform platform = AndroidPlatform.valueOf(osVersion);
if (platform != null) {
int sdkLevel = platform.getSdkLevel();
if (sdkLevel >= 11 && platform.getSdkLevel() <= 13) {
if (resolution.equals("WXGA720") || resolution.equals("WXGA800")) {
String msg = String.format("That doesn't look right for Android %s. Did you mean WXGA?", platform);
return ValidationResult.warning(msg);
}
} else if (sdkLevel >= 14 && resolution.equals("WXGA")) {
String msg = String.format("That doesn't look right for Android %s. Did you mean WXGA720 or WXGA800?", platform);
return ValidationResult.warning(msg);
}
}

// Check for shenanigans
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/hudson/plugins/android_emulator/Constants.java
Expand Up @@ -37,7 +37,7 @@ public interface Constants {
static final String REGEX_LOCALE = "[a-z]{2}_[A-Z]{2}";
static final String REGEX_SCREEN_DENSITY = "[0-9]{2,4}|(?i)(x?h|[lm])dpi";
static final String REGEX_SCREEN_RESOLUTION = "[0-9]{3,4}x[0-9]{3,4}";
static final String REGEX_SCREEN_RESOLUTION_ALIAS = "(([HQ]|F?WQ?)V|WX)GA";
static final String REGEX_SCREEN_RESOLUTION_ALIAS = "(([HQ]|F?W[SQ]?)V|WX)GA(720|800|-[LP])?";
static final String REGEX_SCREEN_RESOLUTION_FULL = REGEX_SCREEN_RESOLUTION_ALIAS +"|"+ REGEX_SCREEN_RESOLUTION;
static final String REGEX_SD_CARD_SIZE = "(?i)([0-9]{1,12}) ?([KM])[B]?";
static final String REGEX_SNAPSHOT = "[0-9]+ +"+ SNAPSHOT_NAME +" +[0-9]+M ";
Expand Down Expand Up @@ -66,9 +66,10 @@ class AndroidPlatform implements Serializable {
static final AndroidPlatform SDK_3_0 = new AndroidPlatform("3.0", 11);
static final AndroidPlatform SDK_3_1 = new AndroidPlatform("3.1", 12);
static final AndroidPlatform SDK_3_2 = new AndroidPlatform("3.2", 13);
static final AndroidPlatform SDK_4_0 = new AndroidPlatform("4.0", 14);
static final AndroidPlatform[] PRESETS = new AndroidPlatform[] { SDK_1_5, SDK_1_6, SDK_2_1,
SDK_2_2, SDK_2_3, SDK_2_3_3,
SDK_3_0, SDK_3_1, SDK_3_2 };
SDK_2_2, SDK_2_3_3, SDK_3_0,
SDK_3_1, SDK_3_2, SDK_4_0 };

private final String name;
private final int level;
Expand All @@ -88,7 +89,8 @@ public static AndroidPlatform valueOf(String version) {
}

for (AndroidPlatform preset : PRESETS) {
if (version.equals(preset.name) || version.equals(preset.level +"")) {
if (version.equals(preset.name) || version.equals(String.valueOf(preset.level))
|| version.equals(preset.getTargetName())) {
return preset;
}
}
Expand Down Expand Up @@ -200,10 +202,17 @@ class ScreenResolution implements Serializable {
ScreenDensity.MEDIUM, ScreenDensity.HIGH);
static final ScreenResolution FWVGA = new ScreenResolution(480, 854, "FWVGA", "WVGA854",
ScreenDensity.MEDIUM, ScreenDensity.HIGH);
static final ScreenResolution WSVGA = new ScreenResolution(1024, 654, "WSVGA", "WSVGA",
ScreenDensity.MEDIUM, ScreenDensity.HIGH);
static final ScreenResolution WXGA_720 = new ScreenResolution(1280, 720, "WXGA720", "WXGA720",
ScreenDensity.MEDIUM);
static final ScreenResolution WXGA_800 = new ScreenResolution(1280, 800, "WXGA800", "WXGA800",
ScreenDensity.MEDIUM);
static final ScreenResolution WXGA = new ScreenResolution(1280, 800, "WXGA", "WXGA",
ScreenDensity.MEDIUM);
static final ScreenResolution[] PRESETS = new ScreenResolution[] { QVGA, WQVGA, FWQVGA,
HVGA, WVGA, FWVGA, WXGA };
static final ScreenResolution[] PRESETS = new ScreenResolution[] { QVGA, WQVGA, FWQVGA, HVGA,
WVGA, FWVGA, WSVGA,
WXGA_720, WXGA_800, WXGA };

private final int width;
private final int height;
Expand Down
Expand Up @@ -35,7 +35,9 @@
<f:entry title="${%Screen resolution}" help="/plugin/android-emulator/help-screenResolution.html">
<f:editableComboBox id="android-emulator.screenResolution" field="screenResolution"
items="${descriptor.deviceResolutions}"
checkUrl="'descriptorByName/AndroidEmulator/checkScreenResolution?value='+escape(this.value)+'&amp;density='+escape(Form.findMatchingInput(this,'android-emulator.screenDensity').value)" />
checkUrl="'descriptorByName/AndroidEmulator/checkScreenResolution?value='+ escape(this.value)
+'&amp;density='+ escape(Form.findMatchingInput(this,'android-emulator.screenDensity').value)
+'&amp;osVersion='+ escape(document.getElementById('android-emulator.osVersion').value)" />
</f:entry>
<f:entry title="${%Device locale}" help="/plugin/android-emulator/help-deviceLocale.html">
<f:editableComboBox id="android-emulator.deviceLocale" field="deviceLocale"
Expand Down

0 comments on commit 860addc

Please sign in to comment.