diff options
author | Tor Norbye <tnorbye@google.com> | 2012-11-28 15:11:33 -0800 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-11-28 15:11:33 -0800 |
commit | 925701c36b849e32f740aedcdb68527900115c77 (patch) | |
tree | f813a3cd9166ee7369869452a31dc474b2099bcd | |
parent | 489398ac8f1635a14d862b48e763edaf3f9ce5e7 (diff) | |
parent | 29dee25da24aea80e6df619f230f8608285abe93 (diff) | |
download | sdk-925701c36b849e32f740aedcdb68527900115c77.zip sdk-925701c36b849e32f740aedcdb68527900115c77.tar.gz sdk-925701c36b849e32f740aedcdb68527900115c77.tar.bz2 |
Merge "Adjust the build and target comboboxes to ensure >= minSdkVersion"
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java index e698ac1..0b003f3 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java @@ -546,9 +546,6 @@ public class NewProjectPage extends WizardPage Object source = e.getSource(); if (source == mMinSdkCombo) { mValues.minSdk = getSelectedMinSdk(); - // If higher than build target, adjust build target - // TODO: implement - Integer minSdk = mMinNameToApi.get(mValues.minSdk); if (minSdk == null) { try { @@ -559,6 +556,49 @@ public class NewProjectPage extends WizardPage } mValues.iconState.minSdk = minSdk.intValue(); mValues.minSdkLevel = minSdk.intValue(); + + // If higher than build target, adjust build target + if (mValues.minSdkLevel > mValues.getBuildApi()) { + // Try to find a build target with an adequate build API + IAndroidTarget[] targets = (IAndroidTarget[]) mBuildSdkCombo.getData(); + IAndroidTarget best = null; + int bestApi = Integer.MAX_VALUE; + int bestTargetIndex = -1; + for (int i = 0; i < targets.length; i++) { + IAndroidTarget target = targets[i]; + if (!target.isPlatform()) { + continue; + } + int api = target.getVersion().getApiLevel(); + if (api >= mValues.minSdkLevel && api < bestApi) { + best = target; + bestApi = api; + bestTargetIndex = i; + } + } + + if (best != null) { + assert bestTargetIndex != -1; + mValues.target = best; + try { + mIgnore = true; + mBuildSdkCombo.select(bestTargetIndex); + } finally { + mIgnore = false; + } + } + } + + // If higher than targetSdkVersion, adjust targetSdkVersion + if (mValues.minSdkLevel > mValues.targetSdkLevel) { + mValues.targetSdkLevel = mValues.minSdkLevel; + try { + mIgnore = true; + setSelectedTargetSdk(mValues.targetSdkLevel); + } finally { + mIgnore = false; + } + } } else if (source == mBuildSdkCombo) { mValues.target = getSelectedBuildTarget(); @@ -614,6 +654,10 @@ public class NewProjectPage extends WizardPage mMinSdkCombo.select(api - 1); // -1: First API level (at index 0) is 1 } + private void setSelectedTargetSdk(int api) { + mTargetSdkCombo.select(api - 1); // -1: First API level (at index 0) is 1 + } + @Nullable private IAndroidTarget getSelectedBuildTarget() { IAndroidTarget[] targets = (IAndroidTarget[]) mBuildSdkCombo.getData(); |